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

Side by Side Diff: tools/dom/templates/html/impl/impl_DocumentFragment.darttemplate

Issue 12039072: Removing many Element APIs from DocumentFragment (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « tests/html/documentfragment_test.dart ('k') | no next file » | 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 part of html; 5 part of html;
6 6
7 Future<CssStyleDeclaration> _emptyStyleFuture() {
8 return _createMeasurementFuture(() => new Element.tag('div').style,
9 new Completer<CssStyleDeclaration>());
10 }
11
12 class _FrozenCssClassSet extends CssClassSet {
13 void writeClasses(Set s) {
14 throw new UnsupportedError(
15 'frozen class set cannot be modified');
16 }
17 Set<String> readClasses() => new Set<String>();
18
19 bool get frozen => true;
20 }
21
22 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
23 factory $CLASSNAME() => _$(CLASSNAME)FactoryProvider.createDocumentFragment(); 8 factory $CLASSNAME() => _$(CLASSNAME)FactoryProvider.createDocumentFragment();
24 9
25 factory $CLASSNAME.html(String html) => 10 factory $CLASSNAME.html(String html) =>
26 _$(CLASSNAME)FactoryProvider.createDocumentFragment_html(html); 11 _$(CLASSNAME)FactoryProvider.createDocumentFragment_html(html);
27 12
28 factory $CLASSNAME.svg(String svgContent) => 13 factory $CLASSNAME.svg(String svgContent) =>
29 _$(CLASSNAME)FactoryProvider.createDocumentFragment_svg(svgContent); 14 _$(CLASSNAME)FactoryProvider.createDocumentFragment_svg(svgContent);
30 15
31 @deprecated 16 @deprecated
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 48
64 List<Element> queryAll(String selectors) => 49 List<Element> queryAll(String selectors) =>
65 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); 50 new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
66 51
67 String get innerHtml { 52 String get innerHtml {
68 final e = new Element.tag("div"); 53 final e = new Element.tag("div");
69 e.nodes.add(this.clone(true)); 54 e.nodes.add(this.clone(true));
70 return e.innerHtml; 55 return e.innerHtml;
71 } 56 }
72 57
73 String get outerHtml => innerHtml;
74
75 // TODO(nweiz): Do we want to support some variant of innerHtml for XML and/or 58 // TODO(nweiz): Do we want to support some variant of innerHtml for XML and/or
76 // SVG strings? 59 // SVG strings?
77 void set innerHtml(String value) { 60 void set innerHtml(String value) {
78 this.nodes.clear(); 61 this.nodes.clear();
79 62
80 final e = new Element.tag("div"); 63 final e = new Element.tag("div");
81 e.innerHtml = value; 64 e.innerHtml = value;
82 65
83 // Copy list first since we don't want liveness during iteration. 66 // Copy list first since we don't want liveness during iteration.
84 List nodes = new List.from(e.nodes); 67 List nodes = new List.from(e.nodes);
85 this.nodes.addAll(nodes); 68 this.nodes.addAll(nodes);
86 } 69 }
87 70
88 Node _insertAdjacentNode(String where, Node node) {
89 switch (where.toLowerCase()) {
90 case "beforebegin": return null;
91 case "afterend": return null;
92 case "afterbegin":
93 var first = this.nodes.length > 0 ? this.nodes[0] : null;
94 this.insertBefore(node, first);
95 return node;
96 case "beforeend":
97 this.nodes.add(node);
98 return node;
99 default:
100 throw new ArgumentError("Invalid position ${where}");
101 }
102 }
103
104 Element insertAdjacentElement(String where, Element element)
105 => this._insertAdjacentNode(where, element);
106
107 void insertAdjacentText(String where, String text) {
108 this._insertAdjacentNode(where, new Text(text));
109 }
110
111 void insertAdjacentHtml(String where, String text) {
112 this._insertAdjacentNode(where, new DocumentFragment.html(text));
113 }
114
115 void append(Element element) { 71 void append(Element element) {
116 this.children.add(element); 72 this.children.add(element);
117 } 73 }
118 74
119 void appendText(String text) { 75 void appendText(String text) {
120 this.insertAdjacentText('beforeend', text); 76 this.nodes.add(new Text(text));
121 } 77 }
122 78
123 void appendHtml(String text) { 79 void appendHtml(String text) {
124 this.insertAdjacentHtml('beforeend', text); 80 this.nodes.add(new DocumentFragment.html(text));
125 }
126
127 // If we can come up with a semi-reasonable default value for an Element
128 // getter, we'll use it. In general, these return the same values as an
129 // element that has no parent.
130 String get contentEditable => "false";
131 bool get isContentEditable => false;
132 bool get draggable => false;
133 bool get hidden => false;
134 bool get spellcheck => false;
135 bool get translate => false;
136 int get tabIndex => -1;
137 String get id => "";
138 String get title => "";
139 String get tagName => "";
140 String get webkitdropzone => "";
141 String get webkitRegionOverflow => "";
142 Element get $m_firstElementChild {
143 if (children.length > 0) {
144 return children[0];
145 }
146 return null;
147 }
148 Element get $m_lastElementChild => children.last;
149 Element get nextElementSibling => null;
150 Element get previousElementSibling => null;
151 Element get offsetParent => null;
152 Element get parent => null;
153 Map<String, String> get attributes => const {};
154 CssClassSet get classes => new _FrozenCssClassSet();
155 Map<String, String> get dataAttributes => const {};
156 CssStyleDeclaration get style => new Element.tag('div').style;
157 Future<CssStyleDeclaration> get computedStyle =>
158 _emptyStyleFuture();
159 Future<CssStyleDeclaration> getComputedStyle(String pseudoElement) =>
160 _emptyStyleFuture();
161
162 // Imperative Element methods are made into no-ops, as they are on parentless
163 // elements.
164 void blur() {}
165 void focus() {}
166 void click() {}
167 void scrollByLines(int lines) {}
168 void scrollByPages(int pages) {}
169 void scrollIntoView([bool centerIfNeeded]) {}
170 void webkitRequestFullScreen(int flags) {}
171 void webkitRequestFullscreen() {}
172
173 // Setters throw errors rather than being no-ops because we aren't going to
174 // retain the values that were set, and erroring out seems clearer.
175 void set attributes(Map<String, String> value) {
176 throw new UnsupportedError(
177 "Attributes can't be set for document fragments.");
178 }
179
180 void set classes(Collection<String> value) {
181 throw new UnsupportedError(
182 "Classes can't be set for document fragments.");
183 }
184
185 void set dataAttributes(Map<String, String> value) {
186 throw new UnsupportedError(
187 "Data attributes can't be set for document fragments.");
188 }
189
190 void set contentEditable(String value) {
191 throw new UnsupportedError(
192 "Content editable can't be set for document fragments.");
193 }
194
195 String get dir {
196 throw new UnsupportedError(
197 "Document fragments don't support text direction.");
198 }
199
200 void set dir(String value) {
201 throw new UnsupportedError(
202 "Document fragments don't support text direction.");
203 }
204
205 void set draggable(bool value) {
206 throw new UnsupportedError(
207 "Draggable can't be set for document fragments.");
208 }
209
210 void set hidden(bool value) {
211 throw new UnsupportedError(
212 "Hidden can't be set for document fragments.");
213 }
214
215 void set id(String value) {
216 throw new UnsupportedError(
217 "ID can't be set for document fragments.");
218 }
219
220 String get lang {
221 throw new UnsupportedError(
222 "Document fragments don't support language.");
223 }
224
225 void set lang(String value) {
226 throw new UnsupportedError(
227 "Document fragments don't support language.");
228 }
229
230 void set scrollLeft(int value) {
231 throw new UnsupportedError(
232 "Document fragments don't support scrolling.");
233 }
234
235 void set scrollTop(int value) {
236 throw new UnsupportedError(
237 "Document fragments don't support scrolling.");
238 }
239
240 void set spellcheck(bool value) {
241 throw new UnsupportedError(
242 "Spellcheck can't be set for document fragments.");
243 }
244
245 void set translate(bool value) {
246 throw new UnsupportedError(
247 "Spellcheck can't be set for document fragments.");
248 }
249
250 void set tabIndex(int value) {
251 throw new UnsupportedError(
252 "Tab index can't be set for document fragments.");
253 }
254
255 void set title(String value) {
256 throw new UnsupportedError(
257 "Title can't be set for document fragments.");
258 }
259
260 void set webkitdropzone(String value) {
261 throw new UnsupportedError(
262 "WebKit drop zone can't be set for document fragments.");
263 }
264
265 void set webkitRegionOverflow(String value) {
266 throw new UnsupportedError(
267 "WebKit region overflow can't be set for document fragments.");
268 } 81 }
269 82
270 $!MEMBERS 83 $!MEMBERS
271 } 84 }
OLDNEW
« no previous file with comments | « tests/html/documentfragment_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698