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

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: 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 = ElementWrappingImplementation._START_TAG_REGEXP.
Jacob 2011/12/15 21:46:59 move this const to top level instead of within the
nweiz 2011/12/15 23:02:02 Done.
15 firstMatch(svg);
16 if (match != null && match.group(1).toLowerCase() == 'svg') {
17 parentTag = new Element.tag('div');
18 } else {
19 parentTag = new SVGSVGElement();
20 }
21
22 parentTag.innerHTML = svg;
23 if (parentTag.elements.length == 1) return parentTag.elements[0];
24
25 throw 'SVG had ${parentTag.elements.length} top-level elements but 1 ' +
26 'expected';
27 }
28
12 String get id() { return _ptr.id; } 29 String get id() { return _ptr.id; }
13 30
14 void set id(String value) { _ptr.id = value; } 31 void set id(String value) { _ptr.id = value; }
15 32
16 SVGSVGElement get ownerSVGElement() { return LevelDom.wrapSVGSVGElement(_ptr.o wnerSVGElement); } 33 SVGSVGElement get ownerSVGElement() { return LevelDom.wrapSVGSVGElement(_ptr.o wnerSVGElement); }
17 34
18 SVGElement get viewportElement() { return LevelDom.wrapSVGElement(_ptr.viewpor tElement); } 35 SVGElement get viewportElement() { return LevelDom.wrapSVGElement(_ptr.viewpor tElement); }
19 36
20 String get xmlbase() { return _ptr.xmlbase; } 37 String get xmlbase() { return _ptr.xmlbase; }
21 38
22 void set xmlbase(String value) { _ptr.xmlbase = value; } 39 void set xmlbase(String value) { _ptr.xmlbase = value; }
40
41 ElementList get elements() {
42 if (_elements == null) {
43 _elements = new FilteredElementList(this);
44 }
45 return _elements;
46 }
47
48 // TODO: The type of value should be Collection<Element>. See http://b/5392897
49 void set elements(value) {
50 // Copy list first since we don't want liveness during iteration.
51 List copy = new List.from(value);
52 final elements = this.elements;
Jacob 2011/12/15 21:46:59 i don't understand why liveness is a concern in th
nweiz 2011/12/15 23:02:02 I guess I just copied this from ElementWrappingImp
53 elements.clear();
54 elements.addAll(copy);
55 }
56
57 String get outerHTML() {
58 final container = new Element.tag("div");
59 container.elements.add(this.clone(true));
60 return container.innerHTML;
61 }
62
63 String get innerHTML() {
64 final container = new Element.tag("div");
65 container.elements.addAll(this.clone(true).elements);
66 return container.innerHTML;
67 }
68
69 void set innerHTML(String svg) {
70 var container = new Element.tag("div");
71 // Wrap the SVG string in <svg> so that SVGElements are created, rather than
72 // HTMLElements.
73 container.innerHTML = '<svg version="1.1">$svg</svg>';
74 this.elements = container.elements[0].elements;
Jacob 2011/12/15 21:46:59 nit: container.elements.first instead of containe
nweiz 2011/12/15 23:02:02 Done.
75 }
23 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698