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

Side by Side Diff: client/html/src/SVGElementWrappingImplementation.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 class SVGElementWrappingImplementation extends ElementWrappingImplementation imp lements SVGElement { 5 class SVGElementWrappingImplementation extends ElementWrappingImplementation imp lements SVGElement {
6 SVGElementWrappingImplementation._wrap(ptr) : super._wrap(ptr) {} 6 SVGElementWrappingImplementation._wrap(ptr) : super._wrap(ptr) {}
7 7
8 factory SVGElementWrappingImplementation.tag(String tag) => 8 factory SVGElementWrappingImplementation.tag(String tag) =>
9 LevelDom.wrapSVGElement(dom.document.createElementNS( 9 LevelDom.wrapSVGElement(dom.document.createElementNS(
10 "http://www.w3.org/2000/svg", tag)); 10 "http://www.w3.org/2000/svg", tag));
11 11
12 factory SVGElementWrappingImplementation.svg(String svg) {
13 Element parentTag;
14 final match = _START_TAG_REGEXP.firstMatch(svg);
15 if (match != null && match.group(1).toLowerCase() == 'svg') {
16 parentTag = new Element.tag('div');
17 } else {
18 parentTag = new SVGSVGElement();
19 }
20
21 parentTag.innerHTML = svg;
22 if (parentTag.elements.length == 1) return parentTag.elements[0];
23
24 throw new IllegalArgumentException('SVG had ${parentTag.elements.length} ' +
25 'top-level elements but 1 expected');
26 }
27
12 String get id() { return _ptr.id; } 28 String get id() { return _ptr.id; }
13 29
14 void set id(String value) { _ptr.id = value; } 30 void set id(String value) { _ptr.id = value; }
15 31
16 SVGSVGElement get ownerSVGElement() { return LevelDom.wrapSVGSVGElement(_ptr.o wnerSVGElement); } 32 SVGSVGElement get ownerSVGElement() { return LevelDom.wrapSVGSVGElement(_ptr.o wnerSVGElement); }
17 33
18 SVGElement get viewportElement() { return LevelDom.wrapSVGElement(_ptr.viewpor tElement); } 34 SVGElement get viewportElement() { return LevelDom.wrapSVGElement(_ptr.viewpor tElement); }
19 35
20 String get xmlbase() { return _ptr.xmlbase; } 36 String get xmlbase() { return _ptr.xmlbase; }
21 37
22 void set xmlbase(String value) { _ptr.xmlbase = value; } 38 void set xmlbase(String value) { _ptr.xmlbase = value; }
39
40 ElementList get elements() {
41 if (_elements == null) {
42 _elements = new FilteredElementList(this);
43 }
44 return _elements;
45 }
46
47 // TODO: The type of value should be Collection<Element>. See http://b/5392897
48 void set elements(value) {
49 final elements = this.elements;
50 elements.clear();
51 elements.addAll(value);
52 }
53
54 String get outerHTML() {
55 final container = new Element.tag("div");
56 container.elements.add(this.clone(true));
57 return container.innerHTML;
58 }
59
60 String get innerHTML() {
61 final container = new Element.tag("div");
62 container.elements.addAll(this.clone(true).elements);
sra1 2012/01/05 04:35:27 This breaks the build because the static type retu
Jacob 2012/01/05 16:39:48 The better fix is to define .clone on Element as w
63 return container.innerHTML;
64 }
65
66 void set innerHTML(String svg) {
67 var container = new Element.tag("div");
68 // Wrap the SVG string in <svg> so that SVGElements are created, rather than
69 // HTMLElements.
70 container.innerHTML = '<svg version="1.1">$svg</svg>';
71 this.elements = container.elements.first.elements;
72 }
23 } 73 }
OLDNEW
« no previous file with comments | « client/html/src/SVGElement.dart ('k') | client/html/src/SVGSVGElementWrappingImplementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698