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

Side by Side Diff: client/html/src/DocumentFragmentWrappingImplementation.dart

Issue 9478021: Add some sweet XML classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months 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
« no previous file with comments | « client/html/src/DocumentFragment.dart ('k') | client/html/src/XMLDocument.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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
167 ElementList get elements() { 189 ElementList get elements() {
168 if (_elements == null) { 190 if (_elements == null) {
169 _elements = new FilteredElementList(this); 191 _elements = new FilteredElementList(this);
170 } 192 }
171 return _elements; 193 return _elements;
172 } 194 }
173 195
174 // TODO: The type of value should be Collection<Element>. See http://b/5392897 196 // TODO: The type of value should be Collection<Element>. See http://b/5392897
175 void set elements(value) { 197 void set elements(value) {
176 // Copy list first since we don't want liveness during iteration. 198 // Copy list first since we don't want liveness during iteration.
177 List copy = new List.from(value); 199 List copy = new List.from(value);
178 final elements = this.elements; 200 final elements = this.elements;
179 elements.clear(); 201 elements.clear();
180 elements.addAll(copy); 202 elements.addAll(copy);
181 } 203 }
182 204
183 String get innerHTML() { 205 String get innerHTML() {
184 var e = new Element.tag("div"); 206 var e = new Element.tag("div");
185 e.nodes.add(this.clone(true)); 207 e.nodes.add(this.clone(true));
186 return e.innerHTML; 208 return e.innerHTML;
187 } 209 }
188 210
189 String get outerHTML() => innerHTML; 211 String get outerHTML() => innerHTML;
190 212
213 // TODO(nweiz): Do we want to support some variant of innerHTML for XML and/or
214 // SVG strings?
191 void set innerHTML(String value) { 215 void set innerHTML(String value) {
192 this.nodes.clear(); 216 this.nodes.clear();
193 217
194 var e = new Element.tag("div"); 218 var e = new Element.tag("div");
195 e.innerHTML = value; 219 e.innerHTML = value;
196 220
197 // Copy list first since we don't want liveness during iteration. 221 // Copy list first since we don't want liveness during iteration.
198 List nodes = new List.from(e.nodes); 222 List nodes = new List.from(e.nodes);
199 this.nodes.addAll(nodes); 223 this.nodes.addAll(nodes);
200 } 224 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 "Title can't be set for document fragments."); 389 "Title can't be set for document fragments.");
366 } 390 }
367 391
368 void set webkitdropzone(String value) { 392 void set webkitdropzone(String value) {
369 throw new UnsupportedOperationException( 393 throw new UnsupportedOperationException(
370 "WebKit drop zone can't be set for document fragments."); 394 "WebKit drop zone can't be set for document fragments.");
371 } 395 }
372 396
373 DocumentFragment clone(bool deep) => super.clone(deep); 397 DocumentFragment clone(bool deep) => super.clone(deep);
374 } 398 }
OLDNEW
« no previous file with comments | « client/html/src/DocumentFragment.dart ('k') | client/html/src/XMLDocument.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698