| 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 |
| 723 // Hooks to support custom WebComponents. | 731 // Hooks to support custom WebComponents. |
| 724 var xtag; | 732 var xtag; |
| 725 | 733 |
| 726 $if DARTIUM | 734 $if DARTIUM |
| 727 noSuchMethod(String name, List args) { | 735 noSuchMethod(String name, List args) { |
| 728 if (dynamicUnknownElementDispatcher == null) { | 736 if (dynamicUnknownElementDispatcher == null) { |
| 729 throw new NoSuchMethodException(this, name, args); | 737 throw new NoSuchMethodException(this, name, args); |
| 730 } else { | 738 } else { |
| 731 return dynamicUnknownElementDispatcher(this, name, args); | 739 return dynamicUnknownElementDispatcher(this, name, args); |
| 732 } | 740 } |
| 733 } | 741 } |
| 734 $else | 742 $else |
| 735 // TODO(vsm): Implement noSuchMethod or similar for dart2js. | 743 // TODO(vsm): Implement noSuchMethod or similar for dart2js. |
| 736 $endif | 744 $endif |
| 737 | 745 |
| 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 Element insertAdjacentElement(String where, Element element) { |
| 773 if (JS('bool', '!!this.insertAdjacentElement')) { |
| 774 _insertAdjacentElement(where, element); |
| 775 } else { |
| 776 _insertAdjacentNode(where, element); |
| 777 } |
| 778 return element; |
| 779 } |
| 780 |
| 781 void _insertAdjacentElement(String where, Element element) |
| 782 native 'insertAdjacentElement'; |
| 783 |
| 784 void _insertAdjacentNode(String where, Node node) { |
| 785 switch (where.toLowerCase()) { |
| 786 case 'beforebegin': |
| 787 this.parent.insertBefore(node, this); |
| 788 break; |
| 789 case 'afterbegin': |
| 790 this.insertBefore(node, this.nodes.first); |
| 791 break; |
| 792 case 'beforeend': |
| 793 this.nodes.add(node); |
| 794 break; |
| 795 case 'afterend': |
| 796 this.parent.insertBefore(node, this.nextNode); |
| 797 break; |
| 798 default: |
| 799 throw new IllegalArgumentException("Invalid position ${where}"); |
| 800 } |
| 801 } |
| 802 $else |
| 803 $endif |
| 804 |
| 738 $!MEMBERS | 805 $!MEMBERS |
| 739 } | 806 } |
| 740 | 807 |
| 741 // Temporary dispatch hook to support WebComponents. | 808 // Temporary dispatch hook to support WebComponents. |
| 742 Function dynamicUnknownElementDispatcher; | 809 Function dynamicUnknownElementDispatcher; |
| 743 | 810 |
| 744 final _START_TAG_REGEXP = const RegExp('<(\\w+)'); | 811 final _START_TAG_REGEXP = const RegExp('<(\\w+)'); |
| 745 class _ElementFactoryProvider { | 812 class _ElementFactoryProvider { |
| 746 static final _CUSTOM_PARENT_TAG_MAP = const { | 813 static final _CUSTOM_PARENT_TAG_MAP = const { |
| 747 'body' : 'html', | 814 'body' : 'html', |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 862 |
| 796 /** @domName Document.createElement */ | 863 /** @domName Document.createElement */ |
| 797 $if DART2JS | 864 $if DART2JS |
| 798 // Optimization to improve performance until the dart2js compiler inlines this | 865 // Optimization to improve performance until the dart2js compiler inlines this |
| 799 // method. | 866 // method. |
| 800 factory Element.tag(String tag) native "return document.createElement(tag)"; | 867 factory Element.tag(String tag) native "return document.createElement(tag)"; |
| 801 $else | 868 $else |
| 802 factory Element.tag(String tag) => _document.$dom_createElement(tag); | 869 factory Element.tag(String tag) => _document.$dom_createElement(tag); |
| 803 $endif | 870 $endif |
| 804 } | 871 } |
| OLD | NEW |