| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(jacobr): use _Lists.dart to remove some of the duplicated | 5 // TODO(jacobr): use _Lists.dart to remove some of the duplicated |
| 6 // functionality. | 6 // functionality. |
| 7 class _ChildrenElementList implements ElementList { | 7 class _ChildrenElementList implements ElementList { |
| 8 // Raw Element. | 8 // Raw Element. |
| 9 final _ElementImpl _element; | 9 final _ElementImpl _element; |
| 10 final _HTMLCollectionImpl _childElements; | 10 final _HTMLCollectionImpl _childElements; |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 * All your element measurement needs in one place | 617 * All your element measurement needs in one place |
| 618 * @domName none | 618 * @domName none |
| 619 */ | 619 */ |
| 620 class _ElementRectImpl implements ElementRect { | 620 class _ElementRectImpl implements ElementRect { |
| 621 final ClientRect client; | 621 final ClientRect client; |
| 622 final ClientRect offset; | 622 final ClientRect offset; |
| 623 final ClientRect scroll; | 623 final ClientRect scroll; |
| 624 | 624 |
| 625 // TODO(jacobr): should we move these outside of ElementRect to avoid the | 625 // TODO(jacobr): should we move these outside of ElementRect to avoid the |
| 626 // overhead of computing them every time even though they are rarely used. | 626 // overhead of computing them every time even though they are rarely used. |
| 627 final _ClientRectImpl _boundingClientRect; | 627 final _ClientRectImpl _boundingClientRect; |
| 628 final _ClientRectListImpl _clientRects; | 628 final _ClientRectListImpl _clientRects; |
| 629 | 629 |
| 630 _ElementRectImpl(_ElementImpl element) : | 630 _ElementRectImpl(_ElementImpl element) : |
| 631 client = new _SimpleClientRect(element.$dom_clientLeft, | 631 client = new _SimpleClientRect(element.$dom_clientLeft, |
| 632 element.$dom_clientTop, | 632 element.$dom_clientTop, |
| 633 element.$dom_clientWidth, | 633 element.$dom_clientWidth, |
| 634 element.$dom_clientHeight), | 634 element.$dom_clientHeight), |
| 635 offset = new _SimpleClientRect(element.$dom_offsetLeft, | 635 offset = new _SimpleClientRect(element.$dom_offsetLeft, |
| 636 element.$dom_offsetTop, | 636 element.$dom_offsetTop, |
| 637 element.$dom_offsetWidth, | 637 element.$dom_offsetWidth, |
| 638 element.$dom_offsetHeight), | 638 element.$dom_offsetHeight), |
| 639 scroll = new _SimpleClientRect(element.$dom_scrollLeft, | 639 scroll = new _SimpleClientRect(element.$dom_scrollLeft, |
| 640 element.$dom_scrollTop, | 640 element.$dom_scrollTop, |
| 641 element.$dom_scrollWidth, | 641 element.$dom_scrollWidth, |
| 642 element.$dom_scrollHeight), | 642 element.$dom_scrollHeight), |
| 643 _boundingClientRect = element.$dom_getBoundingClientRect(), | 643 _boundingClientRect = element.$dom_getBoundingClientRect(), |
| 644 _clientRects = element.$dom_getClientRects(); | 644 _clientRects = element.$dom_getClientRects(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 // TODO(jacobr): last param should be null, see b/5045788 | 713 // TODO(jacobr): last param should be null, see b/5045788 |
| 714 return getComputedStyle(''); | 714 return getComputedStyle(''); |
| 715 } | 715 } |
| 716 | 716 |
| 717 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) { | 717 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) { |
| 718 return _createMeasurementFuture( | 718 return _createMeasurementFuture( |
| 719 () => _window.$dom_getComputedStyle(this, pseudoElement), | 719 () => _window.$dom_getComputedStyle(this, pseudoElement), |
| 720 new Completer<CSSStyleDeclaration>()); | 720 new Completer<CSSStyleDeclaration>()); |
| 721 } | 721 } |
| 722 | 722 |
| 723 void addText(String text) { | |
| 724 this.insertAdjacentText('beforeend', text); | |
| 725 } | |
| 726 | |
| 727 void addHTML(String text) { | |
| 728 this.insertAdjacentHTML('beforeend', text); | |
| 729 } | |
| 730 | |
| 731 // Hooks to support custom WebComponents. | 723 // Hooks to support custom WebComponents. |
| 732 var xtag; | 724 var xtag; |
| 733 | 725 |
| 734 $if DARTIUM | 726 $if DARTIUM |
| 735 noSuchMethod(String name, List args) { | 727 noSuchMethod(String name, List args) { |
| 736 if (dynamicUnknownElementDispatcher == null) { | 728 if (dynamicUnknownElementDispatcher == null) { |
| 737 throw new NoSuchMethodException(this, name, args); | 729 throw new NoSuchMethodException(this, name, args); |
| 738 } else { | 730 } else { |
| 739 return dynamicUnknownElementDispatcher(this, name, args); | 731 return dynamicUnknownElementDispatcher(this, name, args); |
| 740 } | 732 } |
| 741 } | 733 } |
| 742 $else | 734 $else |
| 743 // TODO(vsm): Implement noSuchMethod or similar for dart2js. | 735 // TODO(vsm): Implement noSuchMethod or similar for dart2js. |
| 744 $endif | 736 $endif |
| 745 | 737 |
| 746 $if DART2JS | |
| 747 /** @domName Element.insertAdjacentText */ | |
| 748 void insertAdjacentText(String where, String text) { | |
| 749 if (JS('bool', '!!this.insertAdjacentText')) { | |
| 750 _insertAdjacentText(where, text); | |
| 751 } else { | |
| 752 _insertAdjacentNode(where, new Text(text)); | |
| 753 } | |
| 754 } | |
| 755 | |
| 756 void _insertAdjacentText(String where, String text) | |
| 757 native 'insertAdjacentText'; | |
| 758 | |
| 759 /** @domName Element.insertAdjacentHTML */ | |
| 760 void insertAdjacentHTML(String where, String text) { | |
| 761 if (JS('bool', '!!this.insertAdjacentHTML')) { | |
| 762 _insertAdjacentHTML(where, text); | |
| 763 } else { | |
| 764 _insertAdjacentNode(where, new DocumentFragment.html(text)); | |
| 765 } | |
| 766 } | |
| 767 | |
| 768 void _insertAdjacentHTML(String where, String text) | |
| 769 native 'insertAdjacentHTML'; | |
| 770 | |
| 771 /** @domName Element.insertAdjacentHTML */ | |
| 772 void insertAdjacentElement(String where, Element element) { | |
| 773 if (JS('bool', '!!this.insertAdjacentElement')) { | |
| 774 _insertAdjacentElement(where, element); | |
| 775 } else { | |
| 776 _insertAdjacentNode(where, element); | |
| 777 } | |
| 778 } | |
| 779 | |
| 780 void _insertAdjacentElement(String where, String text) | |
| 781 native 'insertAdjacentElement'; | |
| 782 | |
| 783 void _insertAdjacentNode(String where, Node node) { | |
| 784 switch (where.toLowerCase()) { | |
| 785 case 'beforebegin': | |
| 786 this.parent.insertBefore(node, this); | |
| 787 break; | |
| 788 case 'afterbegin': | |
| 789 this.insertBefore(node, this.nodes.first); | |
| 790 break; | |
| 791 case 'beforeend': | |
| 792 this.nodes.add(node); | |
| 793 break; | |
| 794 case 'afterend': | |
| 795 this.parent.insertBefore(node, this.nextNode); | |
| 796 break; | |
| 797 default: | |
| 798 throw new IllegalArgumentException("Invalid position ${where}"); | |
| 799 } | |
| 800 } | |
| 801 $endif | |
| 802 | |
| 803 $!MEMBERS | 738 $!MEMBERS |
| 804 } | 739 } |
| 805 | 740 |
| 806 // Temporary dispatch hook to support WebComponents. | 741 // Temporary dispatch hook to support WebComponents. |
| 807 Function dynamicUnknownElementDispatcher; | 742 Function dynamicUnknownElementDispatcher; |
| 808 | 743 |
| 809 final _START_TAG_REGEXP = const RegExp('<(\\w+)'); | 744 final _START_TAG_REGEXP = const RegExp('<(\\w+)'); |
| 810 class _ElementFactoryProvider { | 745 class _ElementFactoryProvider { |
| 811 static final _CUSTOM_PARENT_TAG_MAP = const { | 746 static final _CUSTOM_PARENT_TAG_MAP = const { |
| 812 'body' : 'html', | 747 'body' : 'html', |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 | 795 |
| 861 /** @domName Document.createElement */ | 796 /** @domName Document.createElement */ |
| 862 $if DART2JS | 797 $if DART2JS |
| 863 // Optimization to improve performance until the dart2js compiler inlines this | 798 // Optimization to improve performance until the dart2js compiler inlines this |
| 864 // method. | 799 // method. |
| 865 factory Element.tag(String tag) native "return document.createElement(tag)"; | 800 factory Element.tag(String tag) native "return document.createElement(tag)"; |
| 866 $else | 801 $else |
| 867 factory Element.tag(String tag) => _document.$dom_createElement(tag); | 802 factory Element.tag(String tag) => _document.$dom_createElement(tag); |
| 868 $endif | 803 $endif |
| 869 } | 804 } |
| OLD | NEW |