OLD | NEW |
(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 _ElementImpl _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 interface Element extends Node, NodeSelector default _ElementFactoryProvider { |
| 252 // TODO(jacobr): switch back to: |
| 253 // interface Element extends Node, NodeSelector, ElementTraversal default _Eleme
ntImpl { |
| 254 Element.html(String html); |
| 255 Element.tag(String tag); |
| 256 |
| 257 Map<String, String> get attributes(); |
| 258 void set attributes(Map<String, String> value); |
| 259 |
| 260 /** |
| 261 * @domName querySelectorAll, getElementsByClassName, getElementsByTagName, |
| 262 * getElementsByTagNameNS |
| 263 */ |
| 264 ElementList queryAll(String selectors); |
| 265 |
| 266 // TODO(jacobr): remove these methods and let them be generated automatically |
| 267 // once dart supports defining fields with the same name in an interface and |
| 268 // its parent interface. |
| 269 String get title(); |
| 270 void set title(String value); |
| 271 |
| 272 /** |
| 273 * @domName childElementCount, firstElementChild, lastElementChild, |
| 274 * children, Node.nodes.add |
| 275 */ |
| 276 ElementList get elements(); |
| 277 |
| 278 // TODO: The type of value should be Collection<Element>. See http://b/5392897 |
| 279 void set elements(value); |
| 280 |
| 281 /** @domName className, classList */ |
| 282 Set<String> get classes(); |
| 283 |
| 284 // TODO: The type of value should be Collection<String>. See http://b/5392897 |
| 285 void set classes(value); |
| 286 |
| 287 Map<String, String> get dataAttributes(); |
| 288 void set dataAttributes(Map<String, String> value); |
| 289 |
| 290 /** |
| 291 * @domName getClientRects, getBoundingClientRect, clientHeight, clientWidth, |
| 292 * clientTop, clientLeft, offsetHeight, offsetWidth, offsetTop, offsetLeft, |
| 293 * scrollHeight, scrollWidth, scrollTop, scrollLeft |
| 294 */ |
| 295 Future<ElementRect> get rect(); |
| 296 |
| 297 /** @domName Window.getComputedStyle */ |
| 298 Future<CSSStyleDeclaration> get computedStyle(); |
| 299 |
| 300 /** @domName Window.getComputedStyle */ |
| 301 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement); |
| 302 |
| 303 Element clone(bool deep); |
| 304 |
| 305 Element get parent(); |
| 306 |
| 307 |
| 308 static final int ALLOW_KEYBOARD_INPUT = 1; |
| 309 |
| 310 final int _childElementCount; |
| 311 |
| 312 final HTMLCollection _children; |
| 313 |
| 314 final DOMTokenList classList; |
| 315 |
| 316 String _className; |
| 317 |
| 318 final int _clientHeight; |
| 319 |
| 320 final int _clientLeft; |
| 321 |
| 322 final int _clientTop; |
| 323 |
| 324 final int _clientWidth; |
| 325 |
| 326 String contentEditable; |
| 327 |
| 328 String dir; |
| 329 |
| 330 bool draggable; |
| 331 |
| 332 final Element _firstElementChild; |
| 333 |
| 334 bool hidden; |
| 335 |
| 336 String id; |
| 337 |
| 338 String innerHTML; |
| 339 |
| 340 final bool isContentEditable; |
| 341 |
| 342 String lang; |
| 343 |
| 344 final Element lastElementChild; |
| 345 |
| 346 final Element nextElementSibling; |
| 347 |
| 348 final int _offsetHeight; |
| 349 |
| 350 final int _offsetLeft; |
| 351 |
| 352 final Element offsetParent; |
| 353 |
| 354 final int _offsetTop; |
| 355 |
| 356 final int _offsetWidth; |
| 357 |
| 358 final String outerHTML; |
| 359 |
| 360 final Element previousElementSibling; |
| 361 |
| 362 final int _scrollHeight; |
| 363 |
| 364 int _scrollLeft; |
| 365 |
| 366 int _scrollTop; |
| 367 |
| 368 final int _scrollWidth; |
| 369 |
| 370 bool spellcheck; |
| 371 |
| 372 final CSSStyleDeclaration style; |
| 373 |
| 374 int tabIndex; |
| 375 |
| 376 final String tagName; |
| 377 |
| 378 final String webkitRegionOverflow; |
| 379 |
| 380 String webkitdropzone; |
| 381 |
| 382 ElementEvents get on(); |
| 383 |
| 384 void blur(); |
| 385 |
| 386 void click(); |
| 387 |
| 388 void focus(); |
| 389 |
| 390 String _getAttribute(String name); |
| 391 |
| 392 ClientRect _getBoundingClientRect(); |
| 393 |
| 394 ClientRectList _getClientRects(); |
| 395 |
| 396 bool _hasAttribute(String name); |
| 397 |
| 398 Element insertAdjacentElement(String where, Element element); |
| 399 |
| 400 void insertAdjacentHTML(String where, String html); |
| 401 |
| 402 void insertAdjacentText(String where, String text); |
| 403 |
| 404 Element query(String selectors); |
| 405 |
| 406 NodeList _querySelectorAll(String selectors); |
| 407 |
| 408 void _removeAttribute(String name); |
| 409 |
| 410 void scrollByLines(int lines); |
| 411 |
| 412 void scrollByPages(int pages); |
| 413 |
| 414 void scrollIntoView([bool centerIfNeeded]); |
| 415 |
| 416 void _setAttribute(String name, String value); |
| 417 |
| 418 bool matchesSelector(String selectors); |
| 419 |
| 420 void webkitRequestFullScreen(int flags); |
| 421 |
| 422 } |
| 423 |
| 424 interface ElementEvents extends Events { |
| 425 |
| 426 EventListenerList get abort(); |
| 427 |
| 428 EventListenerList get beforeCopy(); |
| 429 |
| 430 EventListenerList get beforeCut(); |
| 431 |
| 432 EventListenerList get beforePaste(); |
| 433 |
| 434 EventListenerList get blur(); |
| 435 |
| 436 EventListenerList get change(); |
| 437 |
| 438 EventListenerList get click(); |
| 439 |
| 440 EventListenerList get contextMenu(); |
| 441 |
| 442 EventListenerList get copy(); |
| 443 |
| 444 EventListenerList get cut(); |
| 445 |
| 446 EventListenerList get doubleClick(); |
| 447 |
| 448 EventListenerList get drag(); |
| 449 |
| 450 EventListenerList get dragEnd(); |
| 451 |
| 452 EventListenerList get dragEnter(); |
| 453 |
| 454 EventListenerList get dragLeave(); |
| 455 |
| 456 EventListenerList get dragOver(); |
| 457 |
| 458 EventListenerList get dragStart(); |
| 459 |
| 460 EventListenerList get drop(); |
| 461 |
| 462 EventListenerList get error(); |
| 463 |
| 464 EventListenerList get focus(); |
| 465 |
| 466 EventListenerList get fullscreenChange(); |
| 467 |
| 468 EventListenerList get fullscreenError(); |
| 469 |
| 470 EventListenerList get input(); |
| 471 |
| 472 EventListenerList get invalid(); |
| 473 |
| 474 EventListenerList get keyDown(); |
| 475 |
| 476 EventListenerList get keyPress(); |
| 477 |
| 478 EventListenerList get keyUp(); |
| 479 |
| 480 EventListenerList get load(); |
| 481 |
| 482 EventListenerList get mouseDown(); |
| 483 |
| 484 EventListenerList get mouseMove(); |
| 485 |
| 486 EventListenerList get mouseOut(); |
| 487 |
| 488 EventListenerList get mouseOver(); |
| 489 |
| 490 EventListenerList get mouseUp(); |
| 491 |
| 492 EventListenerList get mouseWheel(); |
| 493 |
| 494 EventListenerList get paste(); |
| 495 |
| 496 EventListenerList get reset(); |
| 497 |
| 498 EventListenerList get scroll(); |
| 499 |
| 500 EventListenerList get search(); |
| 501 |
| 502 EventListenerList get select(); |
| 503 |
| 504 EventListenerList get selectStart(); |
| 505 |
| 506 EventListenerList get submit(); |
| 507 |
| 508 EventListenerList get touchCancel(); |
| 509 |
| 510 EventListenerList get touchEnd(); |
| 511 |
| 512 EventListenerList get touchLeave(); |
| 513 |
| 514 EventListenerList get touchMove(); |
| 515 |
| 516 EventListenerList get touchStart(); |
| 517 |
| 518 EventListenerList get transitionEnd(); |
| 519 } |
OLD | NEW |