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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: client/html/src/SVGElementWrappingImplementation.dart
diff --git a/client/html/src/SVGElementWrappingImplementation.dart b/client/html/src/SVGElementWrappingImplementation.dart
index 71203a4a513cb8d7a983d664f44e7dafb09f8ed1..7ef398d7efe8ab74c610ced3a0c0abe0799481f9 100644
--- a/client/html/src/SVGElementWrappingImplementation.dart
+++ b/client/html/src/SVGElementWrappingImplementation.dart
@@ -9,6 +9,23 @@ class SVGElementWrappingImplementation extends ElementWrappingImplementation imp
LevelDom.wrapSVGElement(dom.document.createElementNS(
"http://www.w3.org/2000/svg", tag));
+ factory SVGElementWrappingImplementation.svg(String svg) {
+ Element parentTag;
+ 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.
+ firstMatch(svg);
+ if (match != null && match.group(1).toLowerCase() == 'svg') {
+ parentTag = new Element.tag('div');
+ } else {
+ parentTag = new SVGSVGElement();
+ }
+
+ parentTag.innerHTML = svg;
+ if (parentTag.elements.length == 1) return parentTag.elements[0];
+
+ throw 'SVG had ${parentTag.elements.length} top-level elements but 1 ' +
+ 'expected';
+ }
+
String get id() { return _ptr.id; }
void set id(String value) { _ptr.id = value; }
@@ -20,4 +37,40 @@ class SVGElementWrappingImplementation extends ElementWrappingImplementation imp
String get xmlbase() { return _ptr.xmlbase; }
void set xmlbase(String value) { _ptr.xmlbase = value; }
+
+ ElementList get elements() {
+ if (_elements == null) {
+ _elements = new FilteredElementList(this);
+ }
+ return _elements;
+ }
+
+ // TODO: The type of value should be Collection<Element>. See http://b/5392897
+ void set elements(value) {
+ // Copy list first since we don't want liveness during iteration.
+ List copy = new List.from(value);
+ 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
+ elements.clear();
+ elements.addAll(copy);
+ }
+
+ String get outerHTML() {
+ final container = new Element.tag("div");
+ container.elements.add(this.clone(true));
+ return container.innerHTML;
+ }
+
+ String get innerHTML() {
+ final container = new Element.tag("div");
+ container.elements.addAll(this.clone(true).elements);
+ return container.innerHTML;
+ }
+
+ void set innerHTML(String svg) {
+ var container = new Element.tag("div");
+ // Wrap the SVG string in <svg> so that SVGElements are created, rather than
+ // HTMLElements.
+ container.innerHTML = '<svg version="1.1">$svg</svg>';
+ 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.
+ }
}

Powered by Google App Engine
This is Rietveld 408576698