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

Side by Side Diff: client/html/generated/html/interface/Element.dart

Issue 9403004: Wrapperless dart:html generator (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review fixes Created 8 years, 10 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // WARNING: Do not edit - generated code.
6
7 /**
8 * Provides a Map abstraction on top of data-* attributes, similar to the
9 * dataSet in the old DOM.
10 */
11 class _DataAttributeMap implements Map<String, String> {
12
13 final Map<String, String> _attributes;
14
15 _DataAttributeMap(this._attributes);
16
17 // interface Map
18
19 // TODO: Use lazy iterator when it is available on Map.
20 bool containsValue(String value) => getValues().some((v) => v == value);
21
22 bool containsKey(String key) => _attributes.containsKey(_attr(key));
23
24 String operator [](String key) => _attributes[_attr(key)];
25
26 void operator []=(String key, String value) {
27 _attributes[_attr(key)] = value;
28 }
29
30 String putIfAbsent(String key, String ifAbsent()) {
31 if (!containsKey(key)) {
32 return this[key] = ifAbsent();
33 }
34 return this[key];
35 }
36
37 String remove(String key) => _attributes.remove(_attr(key));
38
39 void clear() {
40 // Needs to operate on a snapshot since we are mutatiting the collection.
41 for (String key in getKeys()) {
42 remove(key);
43 }
44 }
45
46 void forEach(void f(String key, String value)) {
47 _attributes.forEach((String key, String value) {
48 if (_matches(key)) {
49 f(_strip(key), value);
50 }
51 });
52 }
53
54 Collection<String> getKeys() {
55 final keys = new List<String>();
56 _attributes.forEach((String key, String value) {
57 if (_matches(key)) {
58 keys.add(_strip(key));
59 }
60 });
61 return keys;
62 }
63
64 Collection<String> getValues() {
65 final values = new List<String>();
66 _attributes.forEach((String key, String value) {
67 if (_matches(key)) {
68 values.add(value);
69 }
70 });
71 return values;
72 }
73
74 int get length() => getKeys().length;
75
76 // TODO: Use lazy iterator when it is available on Map.
77 bool isEmpty() => length == 0;
78
79 // Helpers.
80 String _attr(String key) => 'data-$key';
81 bool _matches(String key) => key.startsWith('data-');
82 String _strip(String key) => key.substring(5);
83 }
84
85 class _CssClassSet implements Set<String> {
86
87 final _ElementJs _element;
88
89 _CssClassSet(this._element);
90
91 String toString() {
92 return _formatSet(_read());
93 }
94
95 // interface Iterable - BEGIN
96 Iterator<String> iterator() {
97 return _read().iterator();
98 }
99 // interface Iterable - END
100
101 // interface Collection - BEGIN
102 void forEach(void f(String element)) {
103 _read().forEach(f);
104 }
105
106 Collection map(f(String element)) {
107 return _read().map(f);
108 }
109
110 Collection<String> filter(bool f(String element)) {
111 return _read().filter(f);
112 }
113
114 bool every(bool f(String element)) {
115 return _read().every(f);
116 }
117
118 bool some(bool f(String element)) {
119 return _read().some(f);
120 }
121
122 bool isEmpty() {
123 return _read().isEmpty();
124 }
125
126 int get length() {
127 return _read().length;
128 }
129 // interface Collection - END
130
131 // interface Set - BEGIN
132 bool contains(String value) {
133 return _read().contains(value);
134 }
135
136 void add(String value) {
137 // TODO - figure out if we need to do any validation here
138 // or if the browser natively does enough
139 _modify((s) => s.add(value));
140 }
141
142 bool remove(String value) {
143 Set<String> s = _read();
144 bool result = s.remove(value);
145 _write(s);
146 return result;
147 }
148
149 void addAll(Collection<String> collection) {
150 // TODO - see comment above about validation
151 _modify((s) => s.addAll(collection));
152 }
153
154 void removeAll(Collection<String> collection) {
155 _modify((s) => s.removeAll(collection));
156 }
157
158 bool isSubsetOf(Collection<String> collection) {
159 return _read().isSubsetOf(collection);
160 }
161
162 bool containsAll(Collection<String> collection) {
163 return _read().containsAll(collection);
164 }
165
166 Set<String> intersection(Collection<String> other) {
167 return _read().intersection(other);
168 }
169
170 void clear() {
171 _modify((s) => s.clear());
172 }
173 // interface Set - END
174
175 /**
176 * Helper method used to modify the set of css classes on this element.
177 *
178 * f - callback with:
179 * s - a Set of all the css class name currently on this element.
180 *
181 * After f returns, the modified set is written to the
182 * className property of this element.
183 */
184 void _modify( f(Set<String> s)) {
185 Set<String> s = _read();
186 f(s);
187 _write(s);
188 }
189
190 /**
191 * Read the class names from the Element class property,
192 * and put them into a set (duplicates are discarded).
193 */
194 Set<String> _read() {
195 // TODO(mattsh) simplify this once split can take regex.
196 Set<String> s = new Set<String>();
197 for (String name in _className().split(' ')) {
198 String trimmed = name.trim();
199 if (!trimmed.isEmpty()) {
200 s.add(trimmed);
201 }
202 }
203 return s;
204 }
205
206 /**
207 * Read the class names as a space-separated string. This is meant to be
208 * overridden by subclasses.
209 */
210 String _className() => _element._className;
211
212 /**
213 * Join all the elements of a set into one string and write
214 * back to the element.
215 */
216 void _write(Set s) {
217 _element._className = _formatSet(s);
218 }
219
220 String _formatSet(Set<String> s) {
221 // TODO(mattsh) should be able to pass Set to String.joins http:/b/5398605
222 List list = new List.from(s);
223 return Strings.join(list, ' ');
224 }
225 }
226
227 interface ElementList extends List<Element> {
228 // TODO(jacobr): add element batch manipulation methods.
229 ElementList filter(bool f(Element element));
230
231 ElementList getRange(int start, int length);
232
233 Element get first();
234 // TODO(jacobr): add insertAt
235 }
236
237 /**
238 * All your element measurement needs in one place
239 */
240 interface ElementRect {
241 // Relative to offsetParent
242 ClientRect get client();
243 ClientRect get offset();
244 ClientRect get scroll();
245 // In global coords
246 ClientRect get bounding();
247 // In global coords
248 List<ClientRect> get clientRects();
249 }
250
251 // TODO(jacobr): referencing _ElementJs here is problematic when we need
252 // to support wrappers as well.
253 interface Element extends Node, NodeSelector default _ElementJs {
254 // TODO(jacobr): switch back to:
255 // interface Element extends Node, NodeSelector, ElementTraversal default _Eleme ntJs {
256 Element.html(String html);
257 Element.tag(String tag);
258
259 Map<String, String> get attributes();
260 void set attributes(Map<String, String> value);
261
262 // TODO(jacobr): remove these methods and let them be generated automatically
263 // once dart supports defining fields with the same name in an interface and
264 // its parent interface.
265 String get title();
266 void set title(String value);
267
268 ElementList get elements();
269
270 // TODO: The type of value should be Collection<Element>. See http://b/5392897
271 void set elements(value);
272
273 Element query(String selectors);
274
275 ElementList queryAll(String selectors);
276
277 Set<String> get classes();
278
279 // TODO: The type of value should be Collection<String>. See http://b/5392897
280 void set classes(value);
281
282 Map<String, String> get dataAttributes();
283 void set dataAttributes(Map<String, String> value);
284
285 bool matchesSelector([String selectors]);
286
287 Future<ElementRect> get rect();
288
289 Future<CSSStyleDeclaration> get computedStyle();
290
291 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement);
292
293 Element clone(bool deep);
294
295
296 Element get parent();
297
298
299 static final int ALLOW_KEYBOARD_INPUT = 1;
300
301 final int childElementCount;
302
303 final HTMLCollection children;
304
305 final DOMTokenList classList;
306
307 final String className;
308
309 final int clientHeight;
310
311 final int clientLeft;
312
313 final int clientTop;
314
315 final int clientWidth;
316
317 String contentEditable;
318
319 String dir;
320
321 bool draggable;
322
323 final Element firstElementChild;
324
325 bool hidden;
326
327 String id;
328
329 String innerHTML;
330
331 final bool isContentEditable;
332
333 String lang;
334
335 final Element lastElementChild;
336
337 final Element nextElementSibling;
338
339 final int offsetHeight;
340
341 final int offsetLeft;
342
343 final Element offsetParent;
344
345 final int offsetTop;
346
347 final int offsetWidth;
348
349 final String outerHTML;
350
351 final Element previousElementSibling;
352
353 final int scrollHeight;
354
355 int scrollLeft;
356
357 int scrollTop;
358
359 final int scrollWidth;
360
361 bool spellcheck;
362
363 final CSSStyleDeclaration style;
364
365 int tabIndex;
366
367 final String tagName;
368
369 String webkitdropzone;
370
371 ElementEvents get on();
372
373 void blur();
374
375 void focus();
376
377 ClientRect getBoundingClientRect();
378
379 ClientRectList getClientRects();
380
381 NodeList getElementsByClassName(String name);
382
383 NodeList getElementsByTagName(String name);
384
385 NodeList getElementsByTagNameNS(String namespaceURI, String localName);
386
387 Element insertAdjacentElement(String where, Element element);
388
389 void insertAdjacentHTML(String where, String html);
390
391 void insertAdjacentText(String where, String text);
392
393 Element querySelector(String selectors);
394
395 NodeList querySelectorAll(String selectors);
396
397 void scrollByLines(int lines);
398
399 void scrollByPages(int pages);
400
401 void scrollIntoView([bool alignWithTop]);
402
403 void scrollIntoViewIfNeeded([bool centerIfNeeded]);
404
405 bool webkitMatchesSelector(String selectors);
406
407 void webkitRequestFullScreen(int flags);
408
409 }
410
411 interface ElementEvents extends Events {
412
413 EventListenerList get abort();
414
415 EventListenerList get beforeCopy();
416
417 EventListenerList get beforeCut();
418
419 EventListenerList get beforePaste();
420
421 EventListenerList get blur();
422
423 EventListenerList get change();
424
425 EventListenerList get click();
426
427 EventListenerList get contextMenu();
428
429 EventListenerList get copy();
430
431 EventListenerList get cut();
432
433 EventListenerList get doubleClick();
434
435 EventListenerList get drag();
436
437 EventListenerList get dragEnd();
438
439 EventListenerList get dragEnter();
440
441 EventListenerList get dragLeave();
442
443 EventListenerList get dragOver();
444
445 EventListenerList get dragStart();
446
447 EventListenerList get drop();
448
449 EventListenerList get error();
450
451 EventListenerList get focus();
452
453 EventListenerList get fullScreenChange();
454
455 EventListenerList get fullScreenError();
456
457 EventListenerList get input();
458
459 EventListenerList get invalid();
460
461 EventListenerList get keyDown();
462
463 EventListenerList get keyPress();
464
465 EventListenerList get keyUp();
466
467 EventListenerList get load();
468
469 EventListenerList get mouseDown();
470
471 EventListenerList get mouseMove();
472
473 EventListenerList get mouseOut();
474
475 EventListenerList get mouseOver();
476
477 EventListenerList get mouseUp();
478
479 EventListenerList get mouseWheel();
480
481 EventListenerList get paste();
482
483 EventListenerList get reset();
484
485 EventListenerList get scroll();
486
487 EventListenerList get search();
488
489 EventListenerList get select();
490
491 EventListenerList get selectStart();
492
493 EventListenerList get submit();
494
495 EventListenerList get touchCancel();
496
497 EventListenerList get touchEnd();
498
499 EventListenerList get touchLeave();
500
501 EventListenerList get touchMove();
502
503 EventListenerList get touchStart();
504
505 EventListenerList get transitionEnd();
506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698