OLD | NEW |
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 FilteredElementList implements ElementList { | 5 class FilteredElementList implements ElementList { |
6 final Node _node; | 6 final Node _node; |
7 final NodeList _childNodes; | 7 final NodeList _childNodes; |
8 | 8 |
9 FilteredElementList(Node node): _childNodes = node.nodes, _node = node; | 9 FilteredElementList(Node node): _childNodes = node.nodes, _node = node; |
10 | 10 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return new DocumentFragmentWrappingImplementation._wrap( | 157 return new DocumentFragmentWrappingImplementation._wrap( |
158 dom.document.createDocumentFragment()); | 158 dom.document.createDocumentFragment()); |
159 } | 159 } |
160 | 160 |
161 factory DocumentFragmentWrappingImplementation.html(String html) { | 161 factory DocumentFragmentWrappingImplementation.html(String html) { |
162 var fragment = new DocumentFragment(); | 162 var fragment = new DocumentFragment(); |
163 fragment.innerHTML = html; | 163 fragment.innerHTML = html; |
164 return fragment; | 164 return fragment; |
165 } | 165 } |
166 | 166 |
167 factory DocumentFragmentWrappingImplementation.xml(String xml) { | |
168 var fragment = new DocumentFragment(); | |
169 var e = new XMLElement.tag("xml"); | |
170 e.innerHTML = xml; | |
171 | |
172 // Copy list first since we don't want liveness during iteration. | |
173 List nodes = new List.from(e.nodes); | |
174 fragment.nodes.addAll(nodes); | |
175 return fragment; | |
176 } | |
177 | |
178 factory DocumentFragmentWrappingImplementation.svg(String svg) { | |
179 var fragment = new DocumentFragment(); | |
180 var e = new SVGSVGElement(); | |
181 e.innerHTML = svg; | |
182 | |
183 // Copy list first since we don't want liveness during iteration. | |
184 List nodes = new List.from(e.nodes); | |
185 fragment.nodes.addAll(nodes); | |
186 return fragment; | |
187 } | |
188 | |
189 ElementList get elements() { | 167 ElementList get elements() { |
190 if (_elements == null) { | 168 if (_elements == null) { |
191 _elements = new FilteredElementList(this); | 169 _elements = new FilteredElementList(this); |
192 } | 170 } |
193 return _elements; | 171 return _elements; |
194 } | 172 } |
195 | 173 |
196 // TODO: The type of value should be Collection<Element>. See http://b/5392897 | 174 // TODO: The type of value should be Collection<Element>. See http://b/5392897 |
197 void set elements(value) { | 175 void set elements(value) { |
198 // Copy list first since we don't want liveness during iteration. | 176 // Copy list first since we don't want liveness during iteration. |
199 List copy = new List.from(value); | 177 List copy = new List.from(value); |
200 final elements = this.elements; | 178 final elements = this.elements; |
201 elements.clear(); | 179 elements.clear(); |
202 elements.addAll(copy); | 180 elements.addAll(copy); |
203 } | 181 } |
204 | 182 |
205 String get innerHTML() { | 183 String get innerHTML() { |
206 var e = new Element.tag("div"); | 184 var e = new Element.tag("div"); |
207 e.nodes.add(this.clone(true)); | 185 e.nodes.add(this.clone(true)); |
208 return e.innerHTML; | 186 return e.innerHTML; |
209 } | 187 } |
210 | 188 |
211 String get outerHTML() => innerHTML; | 189 String get outerHTML() => innerHTML; |
212 | 190 |
213 // TODO(nweiz): Do we want to support some variant of innerHTML for XML and/or | |
214 // SVG strings? | |
215 void set innerHTML(String value) { | 191 void set innerHTML(String value) { |
216 this.nodes.clear(); | 192 this.nodes.clear(); |
217 | 193 |
218 var e = new Element.tag("div"); | 194 var e = new Element.tag("div"); |
219 e.innerHTML = value; | 195 e.innerHTML = value; |
220 | 196 |
221 // Copy list first since we don't want liveness during iteration. | 197 // Copy list first since we don't want liveness during iteration. |
222 List nodes = new List.from(e.nodes); | 198 List nodes = new List.from(e.nodes); |
223 this.nodes.addAll(nodes); | 199 this.nodes.addAll(nodes); |
224 } | 200 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 "Title can't be set for document fragments."); | 365 "Title can't be set for document fragments."); |
390 } | 366 } |
391 | 367 |
392 void set webkitdropzone(String value) { | 368 void set webkitdropzone(String value) { |
393 throw new UnsupportedOperationException( | 369 throw new UnsupportedOperationException( |
394 "WebKit drop zone can't be set for document fragments."); | 370 "WebKit drop zone can't be set for document fragments."); |
395 } | 371 } |
396 | 372 |
397 DocumentFragment clone(bool deep) => super.clone(deep); | 373 DocumentFragment clone(bool deep) => super.clone(deep); |
398 } | 374 } |
OLD | NEW |