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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 node = node.previousSibling; | 649 node = node.previousSibling; |
650 leftOffset += node.textContent.length; | 650 leftOffset += node.textContent.length; |
651 } | 651 } |
652 node = node.parentNodeOrShadowHost(); | 652 node = node.parentNodeOrShadowHost(); |
653 } | 653 } |
654 | 654 |
655 return leftOffset; | 655 return leftOffset; |
656 } | 656 } |
657 | 657 |
658 /** | 658 /** |
| 659 * @return {string} |
| 660 */ |
| 661 Node.prototype.deepTextContent = function() |
| 662 { |
| 663 var node = this.traverseNextTextNode(this); |
| 664 var result = []; |
| 665 var nonTextTags = { "STYLE": 1, "SCRIPT": 1 }; |
| 666 while (node) { |
| 667 if (!nonTextTags[node.parentElement.nodeName]) |
| 668 result.push(node.textContent); |
| 669 node = node.traverseNextTextNode(this); |
| 670 } |
| 671 return result.join(""); |
| 672 } |
| 673 |
| 674 /** |
659 * @param {?Node} node | 675 * @param {?Node} node |
660 * @return {boolean} | 676 * @return {boolean} |
661 */ | 677 */ |
662 Node.prototype.isAncestor = function(node) | 678 Node.prototype.isAncestor = function(node) |
663 { | 679 { |
664 if (!node) | 680 if (!node) |
665 return false; | 681 return false; |
666 | 682 |
667 var currentNode = node.parentNodeOrShadowHost(); | 683 var currentNode = node.parentNodeOrShadowHost(); |
668 while (currentNode) { | 684 while (currentNode) { |
(...skipping 30 matching lines...) Expand all Loading... |
699 { | 715 { |
700 return !!node && (node === this || this.isDescendant(node)); | 716 return !!node && (node === this || this.isDescendant(node)); |
701 } | 717 } |
702 | 718 |
703 /** | 719 /** |
704 * @param {!Node=} stayWithin | 720 * @param {!Node=} stayWithin |
705 * @return {?Node} | 721 * @return {?Node} |
706 */ | 722 */ |
707 Node.prototype.traverseNextNode = function(stayWithin) | 723 Node.prototype.traverseNextNode = function(stayWithin) |
708 { | 724 { |
709 var node = this.firstChild; | 725 if (this.firstChild) |
710 if (node) | 726 return this.firstChild; |
711 return node; | 727 |
| 728 if (this.shadowRoot) |
| 729 return this.shadowRoot; |
712 | 730 |
713 if (stayWithin && this === stayWithin) | 731 if (stayWithin && this === stayWithin) |
714 return null; | 732 return null; |
715 | 733 |
716 node = this.nextSibling; | 734 var node = this.nextSibling; |
717 if (node) | 735 if (node) |
718 return node; | 736 return node; |
719 | 737 |
720 node = this; | 738 node = this; |
721 while (node && !node.nextSibling && (!stayWithin || !node.parentNodeOrShadow
Host() || node.parentNodeOrShadowHost() !== stayWithin)) | 739 while (node && !node.nextSibling && (!stayWithin || !node.parentNodeOrShadow
Host() || node.parentNodeOrShadowHost() !== stayWithin)) |
722 node = node.parentNodeOrShadowHost(); | 740 node = node.parentNodeOrShadowHost(); |
723 if (!node) | 741 if (!node) |
724 return null; | 742 return null; |
725 | 743 |
726 return node.nextSibling; | 744 return node.nextSibling; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 */ | 810 */ |
793 function isEnterKey(event) { | 811 function isEnterKey(event) { |
794 // Check if in IME. | 812 // Check if in IME. |
795 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; | 813 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; |
796 } | 814 } |
797 | 815 |
798 function consumeEvent(e) | 816 function consumeEvent(e) |
799 { | 817 { |
800 e.consume(); | 818 e.consume(); |
801 } | 819 } |
OLD | NEW |