OLD | NEW |
1 // Copyright (c) 2012, 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 _TextFactoryProvider { | 5 class _TextFactoryProvider { |
6 | 6 |
7 factory Text(String data) => _document._createTextNode(data); | 7 factory Text(String data) => _document._createTextNode(data); |
8 } | 8 } |
9 | 9 |
10 class _EventFactoryProvider { | 10 class _EventFactoryProvider { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // final fragment = new DocumentFragment(); | 113 // final fragment = new DocumentFragment(); |
114 // final e = new XMLElement.tag("xml"); | 114 // final e = new XMLElement.tag("xml"); |
115 // e.innerHTML = xml; | 115 // e.innerHTML = xml; |
116 // | 116 // |
117 // // Copy list first since we don't want liveness during iteration. | 117 // // Copy list first since we don't want liveness during iteration. |
118 // final List nodes = new List.from(e.nodes); | 118 // final List nodes = new List.from(e.nodes); |
119 // fragment.nodes.addAll(nodes); | 119 // fragment.nodes.addAll(nodes); |
120 // return fragment; | 120 // return fragment; |
121 // } | 121 // } |
122 | 122 |
123 // TODO(nweiz): enable this when SVG is ported. | 123 factory DocumentFragment.svg(String svg) { |
124 // factory DocumentFragment.svg(String svg) { | 124 final fragment = new DocumentFragment(); |
125 // final fragment = new DocumentFragment(); | 125 final e = new SVGSVGElement(); |
126 // final e = new SVGSVGElement(); | 126 e.innerHTML = svg; |
127 // e.innerHTML = svg; | 127 |
128 // | 128 // Copy list first since we don't want liveness during iteration. |
129 // // Copy list first since we don't want liveness during iteration. | 129 final List nodes = new List.from(e.nodes); |
130 // final List nodes = new List.from(e.nodes); | 130 fragment.nodes.addAll(nodes); |
131 // fragment.nodes.addAll(nodes); | 131 return fragment; |
132 // return fragment; | 132 } |
133 // } | |
134 } | 133 } |
| 134 |
| 135 class _SVGElementFactoryProvider { |
| 136 factory SVGElement.tag(String tag) => |
| 137 _document._createElementNS("http://www.w3.org/2000/svg", tag); |
| 138 |
| 139 factory SVGElement.svg(String svg) { |
| 140 Element parentTag; |
| 141 final match = _START_TAG_REGEXP.firstMatch(svg); |
| 142 if (match != null && match.group(1).toLowerCase() == 'svg') { |
| 143 parentTag = new Element.tag('div'); |
| 144 } else { |
| 145 parentTag = new SVGSVGElement(); |
| 146 } |
| 147 |
| 148 parentTag.innerHTML = svg; |
| 149 if (parentTag.elements.length == 1) return parentTag.nodes.removeLast(); |
| 150 |
| 151 throw new IllegalArgumentException('SVG had ${parentTag.elements.length} ' + |
| 152 'top-level elements but 1 expected'); |
| 153 } |
| 154 } |
| 155 |
| 156 class _SVGSVGElementFactoryProvider { |
| 157 factory SVGSVGElement() { |
| 158 final el = new SVGElement.tag("svg"); |
| 159 // The SVG spec requires the version attribute to match the spec version |
| 160 el.attributes['version'] = "1.1"; |
| 161 return el; |
| 162 } |
| 163 } |
OLD | NEW |