Path: blob/trunk/third_party/closure/goog/dom/browserrange/webkitrange.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 WebKit 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.WebKitRange');2526goog.require('goog.dom.RangeEndpoint');27goog.require('goog.dom.browserrange.W3cRange');28goog.require('goog.userAgent');29303132/**33* The constructor for WebKit specific browser ranges.34* @param {Range} range The range object.35* @constructor36* @extends {goog.dom.browserrange.W3cRange}37* @final38*/39goog.dom.browserrange.WebKitRange = function(range) {40goog.dom.browserrange.W3cRange.call(this, range);41};42goog.inherits(43goog.dom.browserrange.WebKitRange, goog.dom.browserrange.W3cRange);444546/**47* Creates a range object that selects the given node's text.48* @param {Node} node The node to select.49* @return {!goog.dom.browserrange.WebKitRange} A WebKit range wrapper object.50*/51goog.dom.browserrange.WebKitRange.createFromNodeContents = function(node) {52return new goog.dom.browserrange.WebKitRange(53goog.dom.browserrange.W3cRange.getBrowserRangeForNode(node));54};555657/**58* Creates a range object that selects between the given nodes.59* @param {Node} startNode The node to start with.60* @param {number} startOffset The offset within the start node.61* @param {Node} endNode The node to end with.62* @param {number} endOffset The offset within the end node.63* @return {!goog.dom.browserrange.WebKitRange} A wrapper object.64*/65goog.dom.browserrange.WebKitRange.createFromNodes = function(66startNode, startOffset, endNode, endOffset) {67return new goog.dom.browserrange.WebKitRange(68goog.dom.browserrange.W3cRange.getBrowserRangeForNodes(69startNode, startOffset, endNode, endOffset));70};717273/** @override */74goog.dom.browserrange.WebKitRange.prototype.compareBrowserRangeEndpoints =75function(range, thisEndpoint, otherEndpoint) {76// Webkit pre-528 has some bugs where compareBoundaryPoints() doesn't work the77// way it is supposed to, but if we reverse the sense of two comparisons,78// it works fine.79// https://bugs.webkit.org/show_bug.cgi?id=2073880if (goog.userAgent.isVersionOrHigher('528')) {81return (82goog.dom.browserrange.WebKitRange.superClass_83.compareBrowserRangeEndpoints.call(84this, range, thisEndpoint, otherEndpoint));85}86return this.range_.compareBoundaryPoints(87otherEndpoint == goog.dom.RangeEndpoint.START ?88(thisEndpoint == goog.dom.RangeEndpoint.START ?89goog.global['Range'].START_TO_START :90goog.global['Range'].END_TO_START) : // Sense reversed91(thisEndpoint == goog.dom.RangeEndpoint.START ?92goog.global['Range'].START_TO_END : // Sense reversed93goog.global['Range'].END_TO_END),94/** @type {Range} */ (range));95};969798/** @override */99goog.dom.browserrange.WebKitRange.prototype.selectInternal = function(100selection, reversed) {101if (reversed) {102selection.setBaseAndExtent(103this.getEndNode(), this.getEndOffset(), this.getStartNode(),104this.getStartOffset());105} else {106selection.setBaseAndExtent(107this.getStartNode(), this.getStartOffset(), this.getEndNode(),108this.getEndOffset());109}110};111112113