Path: blob/trunk/third_party/closure/goog/dom/browserrange/geckorange.js
2868 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Definition of the Gecko specific range wrapper. Inherits most16* functionality from W3CRange, but adds exceptions as necessary.17*18* DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead.19*20* @author [email protected] (Robby Walker)21*/222324goog.provide('goog.dom.browserrange.GeckoRange');2526goog.require('goog.dom.browserrange.W3cRange');27282930/**31* The constructor for Gecko specific browser ranges.32* @param {Range} range The range object.33* @constructor34* @extends {goog.dom.browserrange.W3cRange}35* @final36*/37goog.dom.browserrange.GeckoRange = function(range) {38goog.dom.browserrange.W3cRange.call(this, range);39};40goog.inherits(goog.dom.browserrange.GeckoRange, goog.dom.browserrange.W3cRange);414243/**44* Creates a range object that selects the given node's text.45* @param {Node} node The node to select.46* @return {!goog.dom.browserrange.GeckoRange} A Gecko range wrapper object.47*/48goog.dom.browserrange.GeckoRange.createFromNodeContents = function(node) {49return new goog.dom.browserrange.GeckoRange(50goog.dom.browserrange.W3cRange.getBrowserRangeForNode(node));51};525354/**55* Creates a range object that selects between the given nodes.56* @param {Node} startNode The node to start with.57* @param {number} startOffset The offset within the node to start.58* @param {Node} endNode The node to end with.59* @param {number} endOffset The offset within the node to end.60* @return {!goog.dom.browserrange.GeckoRange} A wrapper object.61*/62goog.dom.browserrange.GeckoRange.createFromNodes = function(63startNode, startOffset, endNode, endOffset) {64return new goog.dom.browserrange.GeckoRange(65goog.dom.browserrange.W3cRange.getBrowserRangeForNodes(66startNode, startOffset, endNode, endOffset));67};686970/** @override */71goog.dom.browserrange.GeckoRange.prototype.selectInternal = function(72selection, reversed) {73if (!reversed || this.isCollapsed()) {74// The base implementation for select() is more robust, and works fine for75// collapsed and forward ranges. This works around76// https://bugzilla.mozilla.org/show_bug.cgi?id=773137, and is tested by77// range_test.html's testFocusedElementDisappears.78goog.dom.browserrange.GeckoRange.base(79this, 'selectInternal', selection, reversed);80} else {81// Reversed selection -- start with a caret on the end node, and extend it82// back to the start. Unfortunately, collapse() fails when focus is83// invalid.84selection.collapse(this.getEndNode(), this.getEndOffset());85selection.extend(this.getStartNode(), this.getStartOffset());86}87};888990