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

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

Issue 8965006: Support SVGElement#elements, #innerHTML, and #outerHTML. Also add a .svg constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 9 years 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 473
474 List<ClientRect> get clientRects() { 474 List<ClientRect> get clientRects() {
475 final out = new List(_clientRects.length); 475 final out = new List(_clientRects.length);
476 for (num i = 0; i < _clientRects.length; i++) { 476 for (num i = 0; i < _clientRects.length; i++) {
477 out[i] = LevelDom.wrapClientRect(_clientRects.item(i)); 477 out[i] = LevelDom.wrapClientRect(_clientRects.item(i));
478 } 478 }
479 return out; 479 return out;
480 } 480 }
481 } 481 }
482 482
483 final _START_TAG_REGEXP = const RegExp('<(\\w+)');
484
483 /** @domName Element, HTMLElement */ 485 /** @domName Element, HTMLElement */
484 class ElementWrappingImplementation extends NodeWrappingImplementation implement s Element { 486 class ElementWrappingImplementation extends NodeWrappingImplementation implement s Element {
485 487
486 static final _START_TAG_REGEXP = const RegExp('<(\\w+)');
487 static final _CUSTOM_PARENT_TAG_MAP = const { 488 static final _CUSTOM_PARENT_TAG_MAP = const {
488 'body' : 'html', 489 'body' : 'html',
489 'head' : 'html', 490 'head' : 'html',
490 'caption' : 'table', 491 'caption' : 'table',
491 'td': 'tr', 492 'td': 'tr',
492 'tbody': 'table', 493 'tbody': 'table',
493 'colgroup': 'table', 494 'colgroup': 'table',
494 'col' : 'colgroup', 495 'col' : 'colgroup',
495 'tr' : 'tbody', 496 'tr' : 'tbody',
496 'tbody' : 'table', 497 'tbody' : 'table',
(...skipping 24 matching lines...) Expand all
521 temp.innerHTML = html; 522 temp.innerHTML = html;
522 523
523 if (temp.childElementCount == 1) { 524 if (temp.childElementCount == 1) {
524 return LevelDom.wrapElement(temp.firstElementChild); 525 return LevelDom.wrapElement(temp.firstElementChild);
525 } else if (parentTag == 'html' && temp.childElementCount == 2) { 526 } else if (parentTag == 'html' && temp.childElementCount == 2) {
526 // Work around for edge case in WebKit and possibly other browsers where 527 // Work around for edge case in WebKit and possibly other browsers where
527 // both body and head elements are created even though the inner html 528 // both body and head elements are created even though the inner html
528 // only contains a head or body element. 529 // only contains a head or body element.
529 return LevelDom.wrapElement(temp.children.item(tag == 'head' ? 0 : 1)); 530 return LevelDom.wrapElement(temp.children.item(tag == 'head' ? 0 : 1));
530 } else { 531 } else {
531 throw 'HTML had ${temp.childElementCount} top level elements but 1 expecte d'; 532 throw new IllegalArgumentException('HTML had ${temp.childElementCount} ' +
533 'top level elements but 1 expected');
532 } 534 }
533 } 535 }
534 536
535 /** @domName Document.createElement */ 537 /** @domName Document.createElement */
536 factory ElementWrappingImplementation.tag(String tag) { 538 factory ElementWrappingImplementation.tag(String tag) {
537 return LevelDom.wrapElement(dom.document.createElement(tag)); 539 return LevelDom.wrapElement(dom.document.createElement(tag));
538 } 540 }
539 541
540 ElementWrappingImplementation._wrap(ptr) : super._wrap(ptr); 542 ElementWrappingImplementation._wrap(ptr) : super._wrap(ptr);
541 543
(...skipping 15 matching lines...) Expand all
557 559
558 void set attributes(Map<String, String> value) { 560 void set attributes(Map<String, String> value) {
559 Map<String, String> attributes = this.attributes; 561 Map<String, String> attributes = this.attributes;
560 attributes.clear(); 562 attributes.clear();
561 for (String key in value.getKeys()) { 563 for (String key in value.getKeys()) {
562 attributes[key] = value[key]; 564 attributes[key] = value[key];
563 } 565 }
564 } 566 }
565 567
566 void set elements(Collection<Element> value) { 568 void set elements(Collection<Element> value) {
567 // Copy list first since we don't want liveness during iteration.
568 List copy = new List.from(value);
569 final elements = this.elements; 569 final elements = this.elements;
570 elements.clear(); 570 elements.clear();
571 elements.addAll(copy); 571 elements.addAll(value);
572 } 572 }
573 573
574 /** 574 /**
575 * @domName childElementCount, firstElementChild, lastElementChild, 575 * @domName childElementCount, firstElementChild, lastElementChild,
576 * children, appendChild 576 * children, appendChild
577 */ 577 */
578 ElementList get elements() { 578 ElementList get elements() {
579 if (_elements == null) { 579 if (_elements == null) {
580 _elements = new _ChildrenElementList._wrap(_ptr); 580 _elements = new _ChildrenElementList._wrap(_ptr);
581 } 581 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 new Completer<CSSStyleDeclaration>()); 758 new Completer<CSSStyleDeclaration>());
759 } 759 }
760 760
761 ElementEvents get on() { 761 ElementEvents get on() {
762 if (_on === null) { 762 if (_on === null) {
763 _on = new ElementEventsImplementation._wrap(_ptr); 763 _on = new ElementEventsImplementation._wrap(_ptr);
764 } 764 }
765 return _on; 765 return _on;
766 } 766 }
767 } 767 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698