| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 /** | 269 /** |
| 270 * @return {?Node} | 270 * @return {?Node} |
| 271 */ | 271 */ |
| 272 Node.prototype.parentNodeOrShadowHost = function() | 272 Node.prototype.parentNodeOrShadowHost = function() |
| 273 { | 273 { |
| 274 return this.parentNode || this.host || null; | 274 return this.parentNode || this.host || null; |
| 275 } | 275 } |
| 276 | 276 |
| 277 /** | 277 /** |
| 278 * @return {!Window} |
| 279 */ |
| 280 Node.prototype.window = function() |
| 281 { |
| 282 return this.ownerDocument.defaultView; |
| 283 } |
| 284 |
| 285 /** |
| 278 * @param {string} query | 286 * @param {string} query |
| 279 * @return {?Node} | 287 * @return {?Node} |
| 280 */ | 288 */ |
| 281 Element.prototype.query = function(query) | 289 Element.prototype.query = function(query) |
| 282 { | 290 { |
| 283 return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDE
RED_NODE_TYPE, null).singleNodeValue; | 291 return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDE
RED_NODE_TYPE, null).singleNodeValue; |
| 284 } | 292 } |
| 285 | 293 |
| 286 Element.prototype.removeChildren = function() | 294 Element.prototype.removeChildren = function() |
| 287 { | 295 { |
| 288 if (this.firstChild) | 296 if (this.firstChild) |
| 289 this.textContent = ""; | 297 this.textContent = ""; |
| 290 } | 298 } |
| 291 | 299 |
| 292 /** | 300 /** |
| 293 * @return {boolean} | 301 * @return {boolean} |
| 294 */ | 302 */ |
| 295 Element.prototype.isInsertionCaretInside = function() | 303 Element.prototype.isInsertionCaretInside = function() |
| 296 { | 304 { |
| 297 var selection = window.getSelection(); | 305 var selection = this.window().getSelection(); |
| 298 if (!selection.rangeCount || !selection.isCollapsed) | 306 if (!selection.rangeCount || !selection.isCollapsed) |
| 299 return false; | 307 return false; |
| 300 var selectionRange = selection.getRangeAt(0); | 308 var selectionRange = selection.getRangeAt(0); |
| 301 return selectionRange.startContainer.isSelfOrDescendant(this); | 309 return selectionRange.startContainer.isSelfOrDescendant(this); |
| 302 } | 310 } |
| 303 | 311 |
| 304 /** | 312 /** |
| 305 * @param {string} tagName | 313 * @param {string} tagName |
| 306 * @return {!Element} | 314 * @return {!Element} |
| 307 * @suppressGlobalPropertiesCheck | 315 * @suppressGlobalPropertiesCheck |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 return this; | 589 return this; |
| 582 } | 590 } |
| 583 | 591 |
| 584 /** | 592 /** |
| 585 * @return {?number} | 593 * @return {?number} |
| 586 */ | 594 */ |
| 587 Element.prototype.selectionLeftOffset = function() | 595 Element.prototype.selectionLeftOffset = function() |
| 588 { | 596 { |
| 589 // Calculate selection offset relative to the current element. | 597 // Calculate selection offset relative to the current element. |
| 590 | 598 |
| 591 var selection = window.getSelection(); | 599 var selection = this.window().getSelection(); |
| 592 if (!selection.containsNode(this, true)) | 600 if (!selection.containsNode(this, true)) |
| 593 return null; | 601 return null; |
| 594 | 602 |
| 595 var leftOffset = selection.anchorOffset; | 603 var leftOffset = selection.anchorOffset; |
| 596 var node = selection.anchorNode; | 604 var node = selection.anchorNode; |
| 597 | 605 |
| 598 while (node !== this) { | 606 while (node !== this) { |
| 599 while (node.previousSibling) { | 607 while (node.previousSibling) { |
| 600 node = node.previousSibling; | 608 node = node.previousSibling; |
| 601 leftOffset += node.textContent.length; | 609 leftOffset += node.textContent.length; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 { | 799 { |
| 792 window.removeEventListener("DOMContentLoaded", windowLoaded, false); | 800 window.removeEventListener("DOMContentLoaded", windowLoaded, false); |
| 793 callback(); | 801 callback(); |
| 794 } | 802 } |
| 795 | 803 |
| 796 if (document.readyState === "complete") | 804 if (document.readyState === "complete") |
| 797 callback(); | 805 callback(); |
| 798 else | 806 else |
| 799 window.addEventListener("DOMContentLoaded", windowLoaded, false); | 807 window.addEventListener("DOMContentLoaded", windowLoaded, false); |
| 800 } | 808 } |
| OLD | NEW |