Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: client/html/src/ElementWrappingImplementation.dart

Issue 9392028: Ensure that newly-constructed elements don't have parents. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 functionality. 5 // TODO(jacobr): use Lists.dart to remove some of the duplicated functionality.
6 class _ChildrenElementList implements ElementList { 6 class _ChildrenElementList implements ElementList {
7 // Raw Element. 7 // Raw Element.
8 final _element; 8 final _element;
9 final _childElements; 9 final _childElements;
10 10
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 if (match !== null) { 533 if (match !== null) {
534 tag = match.group(1).toLowerCase(); 534 tag = match.group(1).toLowerCase();
535 if (_CUSTOM_PARENT_TAG_MAP.containsKey(tag)) { 535 if (_CUSTOM_PARENT_TAG_MAP.containsKey(tag)) {
536 parentTag = _CUSTOM_PARENT_TAG_MAP[tag]; 536 parentTag = _CUSTOM_PARENT_TAG_MAP[tag];
537 } 537 }
538 } 538 }
539 // TODO(jacobr): make type dom.HTMLElement when dartium allows it. 539 // TODO(jacobr): make type dom.HTMLElement when dartium allows it.
540 var temp = dom.document.createElement(parentTag); 540 var temp = dom.document.createElement(parentTag);
541 temp.innerHTML = html; 541 temp.innerHTML = html;
542 542
543 var element;
Jacob 2012/02/14 02:31:06 var ==> Element
543 if (temp.childElementCount == 1) { 544 if (temp.childElementCount == 1) {
544 return LevelDom.wrapElement(temp.firstElementChild); 545 element = LevelDom.wrapElement(temp.firstElementChild);
545 } else if (parentTag == 'html' && temp.childElementCount == 2) { 546 } else if (parentTag == 'html' && temp.childElementCount == 2) {
546 // Work around for edge case in WebKit and possibly other browsers where 547 // Work around for edge case in WebKit and possibly other browsers where
547 // both body and head elements are created even though the inner html 548 // both body and head elements are created even though the inner html
548 // only contains a head or body element. 549 // only contains a head or body element.
549 return LevelDom.wrapElement(temp.children.item(tag == 'head' ? 0 : 1)); 550 element = LevelDom.wrapElement(temp.children.item(tag == 'head' ? 0 : 1));
550 } else { 551 } else {
551 throw new IllegalArgumentException('HTML had ${temp.childElementCount} ' + 552 throw new IllegalArgumentException('HTML had ${temp.childElementCount} ' +
552 'top level elements but 1 expected'); 553 'top level elements but 1 expected');
553 } 554 }
555 element.remove();
556 return element;
554 } 557 }
555 558
556 /** @domName Document.createElement */ 559 /** @domName Document.createElement */
557 factory ElementWrappingImplementation.tag(String tag) { 560 factory ElementWrappingImplementation.tag(String tag) {
558 return LevelDom.wrapElement(dom.document.createElement(tag)); 561 return LevelDom.wrapElement(dom.document.createElement(tag));
559 } 562 }
560 563
561 ElementWrappingImplementation._wrap(ptr) : super._wrap(ptr); 564 ElementWrappingImplementation._wrap(ptr) : super._wrap(ptr);
562 565
563 ElementAttributeMap _elementAttributeMap; 566 ElementAttributeMap _elementAttributeMap;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 782
780 ElementEvents get on() { 783 ElementEvents get on() {
781 if (_on === null) { 784 if (_on === null) {
782 _on = new ElementEventsImplementation._wrap(_ptr); 785 _on = new ElementEventsImplementation._wrap(_ptr);
783 } 786 }
784 return _on; 787 return _on;
785 } 788 }
786 789
787 Element clone(bool deep) => super.clone(deep); 790 Element clone(bool deep) => super.clone(deep);
788 } 791 }
OLDNEW
« no previous file with comments | « client/html/release/htmlimpl.dart ('k') | client/html/src/SVGElementWrappingImplementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698