Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library html; | 1 library html; |
| 2 | 2 |
| 3 import 'dart:isolate'; | 3 import 'dart:isolate'; |
| 4 import 'dart:json'; | 4 import 'dart:json'; |
| 5 import 'dart:svg' as svg; | 5 import 'dart:svg' as svg; |
| 6 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 6 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 7 // for details. All rights reserved. Use of this source code is governed by a | 7 // for details. All rights reserved. Use of this source code is governed by a |
| 8 // BSD-style license that can be found in the LICENSE file. | 8 // BSD-style license that can be found in the LICENSE file. |
| 9 | 9 |
| 10 // DO NOT EDIT | 10 // DO NOT EDIT |
| (...skipping 7318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7329 } | 7329 } |
| 7330 return s; | 7330 return s; |
| 7331 } | 7331 } |
| 7332 | 7332 |
| 7333 void writeClasses(Set<String> s) { | 7333 void writeClasses(Set<String> s) { |
| 7334 List list = new List.from(s); | 7334 List list = new List.from(s); |
| 7335 _element.$dom_className = Strings.join(list, ' '); | 7335 _element.$dom_className = Strings.join(list, ' '); |
| 7336 } | 7336 } |
| 7337 } | 7337 } |
| 7338 | 7338 |
| 7339 /** | |
| 7340 * The base class of all components for an HTML document. | |
| 7341 */ | |
| 7339 abstract class Element extends Node implements ElementTraversal native "*Element " { | 7342 abstract class Element extends Node implements ElementTraversal native "*Element " { |
| 7340 | 7343 |
| 7344 /** | |
| 7345 * Creates an HTML Element from a valid fragment of HTML. | |
|
Kathy Walrath
2012/11/27 21:53:42
Add a blank line after. (Do this globally.)
Also,
blois
2012/12/12 01:03:44
Done.
| |
| 7346 * The [html] fragment must represent valid HTML with a single element root, | |
| 7347 * which will be parsed and returned. | |
| 7348 * | |
| 7349 * Important: the contents of [html] should not contain any user-supplied | |
| 7350 * data. Without strict data validation it is impossible to prevent script | |
| 7351 * injection exploits. | |
| 7352 * | |
| 7353 * It is instead recommended that elements be constructed via [Element.tag] | |
| 7354 * and text be added via [text]. | |
| 7355 */ | |
| 7341 factory Element.html(String html) => | 7356 factory Element.html(String html) => |
| 7342 _ElementFactoryProvider.createElement_html(html); | 7357 _ElementFactoryProvider.createElement_html(html); |
| 7358 | |
| 7359 /** | |
| 7360 * Creates the HTML element specified by the tag name. | |
| 7361 * This is similar to document.createElement. | |
| 7362 * [tag] should be a valid HTML tag name. If [tag] is an unknown tag then | |
| 7363 * this will create an [UnknownElement]. | |
| 7364 * var element = new Element.tag('div'); | |
| 7365 * For standard elements it is more preferable to use the type constructors: | |
| 7366 * var element = new DivElement(); | |
| 7367 */ | |
| 7343 factory Element.tag(String tag) => | 7368 factory Element.tag(String tag) => |
| 7344 _ElementFactoryProvider.createElement_tag(tag); | 7369 _ElementFactoryProvider.createElement_tag(tag); |
| 7345 | 7370 |
| 7346 /** | 7371 /** |
| 7347 * @domName Element.hasAttribute, Element.getAttribute, Element.setAttribute, | 7372 * Provides access to all attributes on this element. |
| 7348 * Element.removeAttribute | 7373 * This only includes attributes in the default namespace, additional |
| 7374 * attributes can be accessed via [getNamespacedAttributes]. | |
| 7375 * Any modifications to the map will automatically be applied to this | |
| 7376 * element. | |
| 7349 */ | 7377 */ |
| 7350 Map<String, String> get attributes => new _ElementAttributeMap(this); | 7378 Map<String, String> get attributes => new _ElementAttributeMap(this); |
| 7351 | 7379 |
| 7352 void set attributes(Map<String, String> value) { | 7380 void set attributes(Map<String, String> value) { |
| 7353 Map<String, String> attributes = this.attributes; | 7381 Map<String, String> attributes = this.attributes; |
| 7354 attributes.clear(); | 7382 attributes.clear(); |
| 7355 for (String key in value.keys) { | 7383 for (String key in value.keys) { |
| 7356 attributes[key] = value[key]; | 7384 attributes[key] = value[key]; |
| 7357 } | 7385 } |
| 7358 } | 7386 } |
| 7359 | 7387 |
| 7360 /** | 7388 /** |
| 7361 * Deprecated, use innerHtml instead. | 7389 * Deprecated, use innerHtml instead. |
| 7362 */ | 7390 */ |
| 7363 String get innerHTML => this.innerHtml; | 7391 String get innerHTML => this.innerHtml; |
| 7364 void set innerHTML(String value) { | 7392 void set innerHTML(String value) { |
| 7365 this.innerHtml = value; | 7393 this.innerHtml = value; |
| 7366 } | 7394 } |
| 7367 | 7395 |
| 7368 void set elements(Collection<Element> value) { | 7396 void set elements(Collection<Element> value) { |
| 7369 this.children = value; | 7397 this.children = value; |
| 7370 } | 7398 } |
| 7371 | 7399 |
| 7372 /** | 7400 /** |
| 7373 * Deprecated, use [children] instead. | 7401 * Deprecated, use [children] instead. |
| 7374 */ | 7402 */ |
| 7375 List<Element> get elements => this.children; | 7403 List<Element> get elements => this.children; |
| 7376 | 7404 |
| 7377 /** | 7405 /** |
| 7378 * @domName childElementCount, firstElementChild, lastElementChild, | 7406 * List of the direct children of this element. |
| 7379 * children, Node.nodes.add | 7407 * This collection can be used to add and remove elements from the document. |
| 7380 */ | 7408 */ |
| 7381 List<Element> get children => new _ChildrenElementList._wrap(this); | 7409 List<Element> get children => new _ChildrenElementList._wrap(this); |
| 7382 | 7410 |
| 7383 void set children(Collection<Element> value) { | 7411 void set children(Collection<Element> value) { |
| 7384 // Copy list first since we don't want liveness during iteration. | 7412 // Copy list first since we don't want liveness during iteration. |
| 7385 List copy = new List.from(value); | 7413 List copy = new List.from(value); |
| 7386 var children = this.children; | 7414 var children = this.children; |
| 7387 children.clear(); | 7415 children.clear(); |
| 7388 children.addAll(copy); | 7416 children.addAll(copy); |
| 7389 } | 7417 } |
| 7390 | 7418 |
| 7419 /** | |
| 7420 * Finds the first descendent element of this element that matches the | |
| 7421 * specified group of selectors. | |
| 7422 * [selectors] should be a string using CSS selector syntax. | |
| 7423 * var element = element.query('.className'); | |
| 7424 * var element = element.query('#id'); | |
| 7425 */ | |
| 7391 Element query(String selectors) => $dom_querySelector(selectors); | 7426 Element query(String selectors) => $dom_querySelector(selectors); |
| 7392 | 7427 |
| 7428 /** | |
| 7429 * Finds all descendent elements of this element that match the specified | |
| 7430 * group of selectors. | |
| 7431 * [selectors] should be a string using CSS selector syntax. | |
| 7432 * var items = element.query('.itemClassName'); | |
| 7433 */ | |
| 7393 List<Element> queryAll(String selectors) => | 7434 List<Element> queryAll(String selectors) => |
| 7394 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); | 7435 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); |
| 7395 | 7436 |
| 7396 /** @domName className, classList */ | 7437 /** |
| 7438 * The set of CSS classes applied to this element. | |
| 7439 * This set makes it easy to add, remove or toggle the classes applied to | |
| 7440 * this element. | |
| 7441 * element.classes.add('selected'); | |
| 7442 * element.classes.toggle('isOnline'); | |
| 7443 * element.classes.remove('selected'); | |
| 7444 */ | |
| 7397 CssClassSet get classes => new _ElementCssClassSet(this); | 7445 CssClassSet get classes => new _ElementCssClassSet(this); |
| 7398 | 7446 |
| 7399 void set classes(Collection<String> value) { | 7447 void set classes(Collection<String> value) { |
| 7400 CssClassSet classSet = classes; | 7448 CssClassSet classSet = classes; |
| 7401 classSet.clear(); | 7449 classSet.clear(); |
| 7402 classSet.addAll(value); | 7450 classSet.addAll(value); |
| 7403 } | 7451 } |
| 7404 | 7452 |
| 7453 /** | |
| 7454 * Allows access to all custom data attributes (data-*) set on this element. | |
| 7455 * The keys for the map must follow these rules: | |
|
Kathy Walrath
2012/11/27 21:53:42
Add blank lines before and after this line.
(Bulle
blois
2012/12/12 01:03:44
Done.
| |
| 7456 * * The name must not begin with `xml`. | |
| 7457 * * The name cannot contain a semi-colon (`;`). | |
| 7458 * * The name cannot contain any capitol letters. | |
| 7459 * | |
| 7460 * Any keys from markup will be converted to camel-cased keys in the map | |
| 7461 * This means that a key of 'camel-cased-name' would be converted to | |
| 7462 * 'camelCasedName'. | |
| 7463 */ | |
| 7405 Map<String, String> get dataAttributes => | 7464 Map<String, String> get dataAttributes => |
| 7406 new _DataAttributeMap(attributes); | 7465 new _DataAttributeMap(attributes); |
| 7407 | 7466 |
| 7408 void set dataAttributes(Map<String, String> value) { | 7467 void set dataAttributes(Map<String, String> value) { |
| 7409 final dataAttributes = this.dataAttributes; | 7468 final dataAttributes = this.dataAttributes; |
| 7410 dataAttributes.clear(); | 7469 dataAttributes.clear(); |
| 7411 for (String key in value.keys) { | 7470 for (String key in value.keys) { |
| 7412 dataAttributes[key] = value[key]; | 7471 dataAttributes[key] = value[key]; |
| 7413 } | 7472 } |
| 7414 } | 7473 } |
| 7415 | 7474 |
| 7416 /** | 7475 /** |
| 7417 * Gets a map for manipulating the attributes of a particular namespace. | 7476 * Gets a map for manipulating the attributes of a particular namespace. |
| 7418 * This is primarily useful for SVG attributes such as xref:link. | 7477 * This is primarily useful for SVG attributes such as xref:link. |
| 7419 */ | 7478 */ |
| 7420 Map<String, String> getNamespacedAttributes(String namespace) { | 7479 Map<String, String> getNamespacedAttributes(String namespace) { |
| 7421 return new _NamespacedAttributeMap(this, namespace); | 7480 return new _NamespacedAttributeMap(this, namespace); |
| 7422 } | 7481 } |
| 7423 | 7482 |
| 7424 /** @domName Window.getComputedStyle */ | 7483 /** |
| 7484 * Gets the final set of all CSS values applied to this element, including | |
| 7485 * inherited and default values. | |
| 7486 * As opposed to the [style] property which contains the values specified | |
| 7487 * directly on this element, computedStyle contains the values which are | |
| 7488 * inherited from other sources, such as parent elements or stylesheets. | |
| 7489 */ | |
| 7425 Future<CSSStyleDeclaration> get computedStyle { | 7490 Future<CSSStyleDeclaration> get computedStyle { |
| 7426 // TODO(jacobr): last param should be null, see b/5045788 | 7491 // TODO(jacobr): last param should be null, see b/5045788 |
| 7427 return getComputedStyle(''); | 7492 return getComputedStyle(''); |
| 7428 } | 7493 } |
| 7429 | 7494 |
| 7430 /** @domName Window.getComputedStyle */ | 7495 /** |
| 7496 * Gets the computed style of a pseudoElement of this element. | |
| 7497 * Similar to [computedStyle] but this targets pseudo-elements such as | |
| 7498 * `::after, ::before, ::marker, ::line-marker`. | |
| 7499 */ | |
| 7431 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) { | 7500 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) { |
| 7432 return _createMeasurementFuture( | 7501 return _createMeasurementFuture( |
| 7433 () => window.$dom_getComputedStyle(this, pseudoElement), | 7502 () => window.$dom_getComputedStyle(this, pseudoElement), |
| 7434 new Completer<CSSStyleDeclaration>()); | 7503 new Completer<CSSStyleDeclaration>()); |
| 7435 } | 7504 } |
| 7436 | 7505 |
| 7437 /** | 7506 /** |
| 7438 * Adds the specified text as a text node after the last child of this. | 7507 * Adds the specified text as a text node after the last child of this. |
| 7439 */ | 7508 */ |
| 7440 void addText(String text) { | 7509 void addText(String text) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 7458 * deprecated and will simply return this [Element] object. | 7527 * deprecated and will simply return this [Element] object. |
| 7459 * | 7528 * |
| 7460 * [wc]: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html | 7529 * [wc]: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html |
| 7461 * [x-tags]: http://x-tags.org/ | 7530 * [x-tags]: http://x-tags.org/ |
| 7462 */ | 7531 */ |
| 7463 @Creates('Null') // Set from Dart code; does not instantiate a native type. | 7532 @Creates('Null') // Set from Dart code; does not instantiate a native type. |
| 7464 var xtag; | 7533 var xtag; |
| 7465 | 7534 |
| 7466 // TODO(vsm): Implement noSuchMethod or similar for dart2js. | 7535 // TODO(vsm): Implement noSuchMethod or similar for dart2js. |
| 7467 | 7536 |
| 7468 /** @domName Element.insertAdjacentText */ | 7537 /** |
| 7538 * Creates a text node and inserts it into the DOM at the specified location. | |
| 7539 * The [where] parameter indicates: | |
| 7540 * * `beforeBegin` Immediately before this element. | |
| 7541 * * `afterBegin` As the first child of this element. | |
| 7542 * * `beforeEnd` As the last child of this element. | |
| 7543 * * `afterEnd` Immediately after this element. | |
| 7544 */ | |
| 7469 void insertAdjacentText(String where, String text) { | 7545 void insertAdjacentText(String where, String text) { |
| 7470 if (JS('bool', '!!#.insertAdjacentText', this)) { | 7546 if (JS('bool', '!!#.insertAdjacentText', this)) { |
| 7471 _insertAdjacentText(where, text); | 7547 _insertAdjacentText(where, text); |
| 7472 } else { | 7548 } else { |
| 7473 _insertAdjacentNode(where, new Text(text)); | 7549 _insertAdjacentNode(where, new Text(text)); |
| 7474 } | 7550 } |
| 7475 } | 7551 } |
| 7476 | 7552 |
| 7477 void _insertAdjacentText(String where, String text) | 7553 void _insertAdjacentText(String where, String text) |
| 7478 native 'insertAdjacentText'; | 7554 native 'insertAdjacentText'; |
| 7479 | 7555 |
| 7480 /** @domName Element.insertAdjacentHTML */ | 7556 /** |
| 7557 * Parses [text] as an HTML fragment and inserts it into the DOM at the | |
| 7558 * specified location. | |
| 7559 * The [where] parameter indicates: | |
|
Kathy Walrath
2012/11/27 21:53:42
indicates -> indicates where to insert the HTML fr
blois
2012/12/12 01:03:44
Done.
| |
| 7560 * * `beforeBegin` Immediately before this element. | |
| 7561 * * `afterBegin` As the first child of this element. | |
| 7562 * * `beforeEnd` As the last child of this element. | |
| 7563 * * `afterEnd` Immediately after this element. | |
| 7564 */ | |
| 7481 void insertAdjacentHtml(String where, String text) { | 7565 void insertAdjacentHtml(String where, String text) { |
| 7482 if (JS('bool', '!!#.insertAdjacentHtml', this)) { | 7566 if (JS('bool', '!!#.insertAdjacentHtml', this)) { |
| 7483 _insertAdjacentHtml(where, text); | 7567 _insertAdjacentHtml(where, text); |
| 7484 } else { | 7568 } else { |
| 7485 _insertAdjacentNode(where, new DocumentFragment.html(text)); | 7569 _insertAdjacentNode(where, new DocumentFragment.html(text)); |
| 7486 } | 7570 } |
| 7487 } | 7571 } |
| 7488 | 7572 |
| 7489 void _insertAdjacentHtml(String where, String text) | 7573 void _insertAdjacentHtml(String where, String text) |
| 7490 native 'insertAdjacentHTML'; | 7574 native 'insertAdjacentHTML'; |
| 7491 | 7575 |
| 7492 /** @domName Element.insertAdjacentHTML */ | 7576 /** |
| 7577 * Inserts [element] into the DOM at the specified location. | |
| 7578 * The [where] parameter indicates: | |
| 7579 * * `beforeBegin` Immediately before this element. | |
| 7580 * * `afterBegin` As the first child of this element. | |
| 7581 * * `beforeEnd` As the last child of this element. | |
| 7582 * * `afterEnd` Immediately after this element. | |
| 7583 */ | |
|
Kathy Walrath
2012/11/27 21:53:42
You need a blank line before the bulleted list. Ho
blois
2012/12/12 01:03:44
Done.
| |
| 7493 Element insertAdjacentElement(String where, Element element) { | 7584 Element insertAdjacentElement(String where, Element element) { |
| 7494 if (JS('bool', '!!#.insertAdjacentElement', this)) { | 7585 if (JS('bool', '!!#.insertAdjacentElement', this)) { |
| 7495 _insertAdjacentElement(where, element); | 7586 _insertAdjacentElement(where, element); |
| 7496 } else { | 7587 } else { |
| 7497 _insertAdjacentNode(where, element); | 7588 _insertAdjacentNode(where, element); |
| 7498 } | 7589 } |
| 7499 return element; | 7590 return element; |
| 7500 } | 7591 } |
| 7501 | 7592 |
| 7502 void _insertAdjacentElement(String where, Element element) | 7593 void _insertAdjacentElement(String where, Element element) |
| (...skipping 17562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 25065 if (length < 0) throw new ArgumentError('length'); | 25156 if (length < 0) throw new ArgumentError('length'); |
| 25066 if (start < 0) throw new RangeError.value(start); | 25157 if (start < 0) throw new RangeError.value(start); |
| 25067 int end = start + length; | 25158 int end = start + length; |
| 25068 if (end > a.length) throw new RangeError.value(end); | 25159 if (end > a.length) throw new RangeError.value(end); |
| 25069 for (int i = start; i < end; i++) { | 25160 for (int i = start; i < end; i++) { |
| 25070 accumulator.add(a[i]); | 25161 accumulator.add(a[i]); |
| 25071 } | 25162 } |
| 25072 return accumulator; | 25163 return accumulator; |
| 25073 } | 25164 } |
| 25074 } | 25165 } |
| OLD | NEW |