Path: blob/trunk/third_party/closure/goog/dom/browserrange/operarange.js
2868 views
// Copyright 2009 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 Opera 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*/212223goog.provide('goog.dom.browserrange.OperaRange');2425goog.require('goog.dom.browserrange.W3cRange');26272829/**30* The constructor for Opera specific browser ranges.31* @param {Range} range The range object.32* @constructor33* @extends {goog.dom.browserrange.W3cRange}34* @final35*/36goog.dom.browserrange.OperaRange = function(range) {37goog.dom.browserrange.W3cRange.call(this, range);38};39goog.inherits(goog.dom.browserrange.OperaRange, goog.dom.browserrange.W3cRange);404142/**43* Creates a range object that selects the given node's text.44* @param {Node} node The node to select.45* @return {!goog.dom.browserrange.OperaRange} A Opera range wrapper object.46*/47goog.dom.browserrange.OperaRange.createFromNodeContents = function(node) {48return new goog.dom.browserrange.OperaRange(49goog.dom.browserrange.W3cRange.getBrowserRangeForNode(node));50};515253/**54* Creates a range object that selects between the given nodes.55* @param {Node} startNode The node to start with.56* @param {number} startOffset The offset within the node to start.57* @param {Node} endNode The node to end with.58* @param {number} endOffset The offset within the node to end.59* @return {!goog.dom.browserrange.OperaRange} A wrapper object.60*/61goog.dom.browserrange.OperaRange.createFromNodes = function(62startNode, startOffset, endNode, endOffset) {63return new goog.dom.browserrange.OperaRange(64goog.dom.browserrange.W3cRange.getBrowserRangeForNodes(65startNode, startOffset, endNode, endOffset));66};676869/** @override */70goog.dom.browserrange.OperaRange.prototype.selectInternal = function(71selection, reversed) {72// Avoid using addRange as we have to removeAllRanges first, which73// blurs editable fields in Opera.74selection.collapse(this.getStartNode(), this.getStartOffset());75if (this.getEndNode() != this.getStartNode() ||76this.getEndOffset() != this.getStartOffset()) {77selection.extend(this.getEndNode(), this.getEndOffset());78}79// This can happen if the range isn't in an editable field.80if (selection.rangeCount == 0) {81selection.addRange(this.range_);82}83};848586