OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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) { | 12 factory SVGElementWrappingImplementation.svg(String svg) { |
13 Element parentTag; | 13 Element parentTag; |
14 final match = _START_TAG_REGEXP.firstMatch(svg); | 14 final match = _START_TAG_REGEXP.firstMatch(svg); |
15 if (match != null && match.group(1).toLowerCase() == 'svg') { | 15 if (match != null && match.group(1).toLowerCase() == 'svg') { |
16 parentTag = new Element.tag('div'); | 16 parentTag = new Element.tag('div'); |
17 } else { | 17 } else { |
18 parentTag = new SVGSVGElement(); | 18 parentTag = new SVGSVGElement(); |
19 } | 19 } |
20 | 20 |
21 parentTag.innerHTML = svg; | 21 parentTag.innerHTML = svg; |
22 if (parentTag.elements.length == 1) return parentTag.elements[0]; | 22 if (parentTag.elements.length == 1) return parentTag.elements[0]; |
23 | 23 |
24 throw new IllegalArgumentException('SVG had ${parentTag.elements.length} ' + | 24 throw new IllegalArgumentException('SVG had ${parentTag.elements.length} ' + |
25 'top-level elements but 1 expected'); | 25 'top-level elements but 1 expected'); |
26 } | 26 } |
27 | 27 |
28 String get id() { return _ptr.id; } | 28 String get id() { return _ptr.id; } |
29 | 29 |
30 void set id(String value) { _ptr.id = value; } | 30 void set id(String value) { |
| 31 assert(!_inMeasurementFrame || !_inDocument); |
| 32 _ptr.id = value; |
| 33 } |
31 | 34 |
32 SVGSVGElement get ownerSVGElement() { return LevelDom.wrapSVGSVGElement(_ptr.o
wnerSVGElement); } | 35 SVGSVGElement get ownerSVGElement() { return LevelDom.wrapSVGSVGElement(_ptr.o
wnerSVGElement); } |
33 | 36 |
34 SVGElement get viewportElement() { return LevelDom.wrapSVGElement(_ptr.viewpor
tElement); } | 37 SVGElement get viewportElement() { return LevelDom.wrapSVGElement(_ptr.viewpor
tElement); } |
35 | 38 |
36 String get xmlbase() { return _ptr.xmlbase; } | 39 String get xmlbase() { return _ptr.xmlbase; } |
37 | 40 |
38 void set xmlbase(String value) { _ptr.xmlbase = value; } | 41 void set xmlbase(String value) { |
| 42 assert(!_inMeasurementFrame || !_inDocument); |
| 43 _ptr.xmlbase = value; |
| 44 } |
39 | 45 |
40 ElementList get elements() { | 46 ElementList get elements() { |
41 if (_elements == null) { | 47 if (_elements == null) { |
42 _elements = new FilteredElementList(this); | 48 _elements = new FilteredElementList(this); |
43 } | 49 } |
44 return _elements; | 50 return _elements; |
45 } | 51 } |
46 | 52 |
47 // TODO: The type of value should be Collection<Element>. See http://b/5392897 | 53 // TODO: The type of value should be Collection<Element>. See http://b/5392897 |
48 void set elements(value) { | 54 void set elements(value) { |
| 55 assert(!_inMeasurementFrame || !_inDocument); |
49 final elements = this.elements; | 56 final elements = this.elements; |
50 elements.clear(); | 57 elements.clear(); |
51 elements.addAll(value); | 58 elements.addAll(value); |
52 } | 59 } |
53 | 60 |
54 String get outerHTML() { | 61 String get outerHTML() { |
55 final container = new Element.tag("div"); | 62 final container = new Element.tag("div"); |
56 container.elements.add(this.clone(true)); | 63 container.elements.add(this.clone(true)); |
57 return container.innerHTML; | 64 return container.innerHTML; |
58 } | 65 } |
59 | 66 |
60 String get innerHTML() { | 67 String get innerHTML() { |
61 final container = new Element.tag("div"); | 68 final container = new Element.tag("div"); |
62 container.elements.addAll(this.clone(true).elements); | 69 container.elements.addAll(this.clone(true).elements); |
63 return container.innerHTML; | 70 return container.innerHTML; |
64 } | 71 } |
65 | 72 |
66 void set innerHTML(String svg) { | 73 void set innerHTML(String svg) { |
| 74 assert(!_inMeasurementFrame || !_inDocument); |
67 var container = new Element.tag("div"); | 75 var container = new Element.tag("div"); |
68 // Wrap the SVG string in <svg> so that SVGElements are created, rather than | 76 // Wrap the SVG string in <svg> so that SVGElements are created, rather than |
69 // HTMLElements. | 77 // HTMLElements. |
70 container.innerHTML = '<svg version="1.1">$svg</svg>'; | 78 container.innerHTML = '<svg version="1.1">$svg</svg>'; |
71 this.elements = container.elements.first.elements; | 79 this.elements = container.elements.first.elements; |
72 } | 80 } |
73 | 81 |
74 SVGElement clone(bool deep) => super.clone(deep); | 82 SVGElement clone(bool deep) => super.clone(deep); |
75 } | 83 } |
OLD | NEW |