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

Side by Side Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 11348255: Adding docs to Element. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
1 library html; 1 library html;
2 2
3 import 'dart:collection'; 3 import 'dart:collection';
4 import 'dart:html_common'; 4 import 'dart:html_common';
5 import 'dart:indexed_db'; 5 import 'dart:indexed_db';
6 import 'dart:isolate'; 6 import 'dart:isolate';
7 import 'dart:json'; 7 import 'dart:json';
8 import 'dart:svg' as svg; 8 import 'dart:svg' as svg;
9 import 'dart:web_audio' as web_audio; 9 import 'dart:web_audio' as web_audio;
10 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 10 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
(...skipping 7333 matching lines...) Expand 10 before | Expand all | Expand 10 after
7344 } 7344 }
7345 return s; 7345 return s;
7346 } 7346 }
7347 7347
7348 void writeClasses(Set<String> s) { 7348 void writeClasses(Set<String> s) {
7349 List list = new List.from(s); 7349 List list = new List.from(s);
7350 _element.$dom_className = Strings.join(list, ' '); 7350 _element.$dom_className = Strings.join(list, ' ');
7351 } 7351 }
7352 } 7352 }
7353 7353
7354 /// @domName Element 7354 /**
7355 * An abstract class which all HTML elements extend.
7356 */
7355 abstract class Element extends Node implements ElementTraversal native "*Element " { 7357 abstract class Element extends Node implements ElementTraversal native "*Element " {
7356 7358
7359 /**
7360 * Creates an HTML element from a valid fragment of HTML.
7361 *
7362 * The [html] fragment must represent valid HTML with a single element root,
7363 * which will be parsed and returned.
7364 *
7365 * Important: the contents of [html] should not contain any user-supplied
7366 * data. Without strict data validation it is impossible to prevent script
7367 * injection exploits.
7368 *
7369 * It is instead recommended that elements be constructed via [Element.tag]
7370 * and text be added via [text].
7371 *
7372 * var element = new Element.html('<div class="foo">content</div>');
7373 */
7357 factory Element.html(String html) => 7374 factory Element.html(String html) =>
7358 _ElementFactoryProvider.createElement_html(html); 7375 _ElementFactoryProvider.createElement_html(html);
7376
7377 /**
7378 * Creates the HTML element specified by the tag name.
7379 *
7380 * This is similar to [Document.createElement].
7381 * [tag] should be a valid HTML tag name. If [tag] is an unknown tag then
7382 * this will create an [UnknownElement].
7383 * var divElement = new Element.tag('div');
7384 * print(divElement is DivElement); // 'true'
7385 * var myElement = new Element.tag('unknownTag');
7386 * print(myElement is UnknownElement); // 'true'
7387 * For standard elements it is more preferable to use the type constructors:
7388 * var element = new DivElement();
7389 */
7359 factory Element.tag(String tag) => 7390 factory Element.tag(String tag) =>
7360 _ElementFactoryProvider.createElement_tag(tag); 7391 _ElementFactoryProvider.createElement_tag(tag);
7361 7392
7362 /** 7393 /**
7363 * @domName Element.hasAttribute, Element.getAttribute, Element.setAttribute, 7394 * All attributes on this element.
7364 * Element.removeAttribute 7395 *
7396 * Any modifications to the attribute map will automatically be applied to
7397 * this element.
7398 *
7399 * This only includes attributes which are not in a namespace
7400 * (such as xlink:href), additional attributes can be accessed via
7401 * [getNamespacedAttributes].
7365 */ 7402 */
7366 Map<String, String> get attributes => new _ElementAttributeMap(this); 7403 Map<String, String> get attributes => new _ElementAttributeMap(this);
7367 7404
7368 void set attributes(Map<String, String> value) { 7405 void set attributes(Map<String, String> value) {
7369 Map<String, String> attributes = this.attributes; 7406 Map<String, String> attributes = this.attributes;
7370 attributes.clear(); 7407 attributes.clear();
7371 for (String key in value.keys) { 7408 for (String key in value.keys) {
7372 attributes[key] = value[key]; 7409 attributes[key] = value[key];
7373 } 7410 }
7374 } 7411 }
(...skipping 13 matching lines...) Expand all
7388 this.children = value; 7425 this.children = value;
7389 } 7426 }
7390 7427
7391 /** 7428 /**
7392 * Deprecated, use [children] instead. 7429 * Deprecated, use [children] instead.
7393 */ 7430 */
7394 @deprecated 7431 @deprecated
7395 List<Element> get elements => this.children; 7432 List<Element> get elements => this.children;
7396 7433
7397 /** 7434 /**
7398 * @domName childElementCount, firstElementChild, lastElementChild, 7435 * List of the direct children of this element.
7399 * children, Node.nodes.add 7436 *
7437 * This collection can be used to add and remove elements from the document.
7438 * var item = new DivElement();
7439 * item.text = 'Something';
7440 * document.body.children.add(item) // Item is now displayed on the page.
7441 * for (var element in document.body.children) {
7442 * element.style.background = 'red'; // Turns every child of body red.
7443 * }
7400 */ 7444 */
7401 List<Element> get children => new _ChildrenElementList._wrap(this); 7445 List<Element> get children => new _ChildrenElementList._wrap(this);
7402 7446
7403 void set children(List<Element> value) { 7447 void set children(List<Element> value) {
7404 // Copy list first since we don't want liveness during iteration. 7448 // Copy list first since we don't want liveness during iteration.
7405 List copy = new List.from(value); 7449 List copy = new List.from(value);
7406 var children = this.children; 7450 var children = this.children;
7407 children.clear(); 7451 children.clear();
7408 children.addAll(copy); 7452 children.addAll(copy);
7409 } 7453 }
7410 7454
7455 /**
7456 * Finds the first descendant element of this element that matches the
7457 * specified group of selectors.
7458 *
7459 * [selectors] should be a string using CSS selector syntax.
7460 * Get the first descendant with the class 'classname':
7461 * var element = element.query('.className');
7462 * Get the element with id 'id':
7463 * var element = element.query('#id');
7464 * Get the first descendant [ImageElement]:
7465 * var img = element.query('img');
7466 *
7467 * See also:
7468 *
7469 * * [CSS Selectors](http://docs.webplatform.org/wiki/css/selectors)
7470 */
7411 Element query(String selectors) => $dom_querySelector(selectors); 7471 Element query(String selectors) => $dom_querySelector(selectors);
7412 7472
7473 /**
7474 * Finds all descendent elements of this element that match the specified
7475 * group of selectors.
7476 *
7477 * [selectors] should be a string using CSS selector syntax.
7478 * var items = element.query('.itemClassName');
7479 */
7413 List<Element> queryAll(String selectors) => 7480 List<Element> queryAll(String selectors) =>
7414 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); 7481 new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
7415 7482
7416 /** @domName className, classList */ 7483 /**
7484 * The set of CSS classes applied to this element.
7485 *
7486 * This set makes it easy to add, remove or toggle the classes applied to
7487 * this element.
7488 * element.classes.add('selected');
7489 * element.classes.toggle('isOnline');
7490 * element.classes.remove('selected');
7491 */
7417 CssClassSet get classes => new _ElementCssClassSet(this); 7492 CssClassSet get classes => new _ElementCssClassSet(this);
7418 7493
7419 void set classes(Collection<String> value) { 7494 void set classes(Collection<String> value) {
7420 CssClassSet classSet = classes; 7495 CssClassSet classSet = classes;
7421 classSet.clear(); 7496 classSet.clear();
7422 classSet.addAll(value); 7497 classSet.addAll(value);
7423 } 7498 }
7424 7499
7500 /**
7501 * Allows access to all custom data attributes (data-*) set on this element.
7502 *
7503 * The keys for the map must follow these rules:
7504 *
7505 * * The name must not begin with `xml`.
7506 * * The name cannot contain a semi-colon (`;`).
7507 * * The name cannot contain any capital letters.
7508 *
7509 * Any keys from markup will be converted to camel-cased keys in the map.
7510 * For example, HTML specified as:
7511 * <div data-my-random-value='value'></div>div
Kathy Walrath 2012/12/12 19:16:06 </div>div -> </div> ?
blois 2012/12/12 19:46:29 Done.
7512 * Would be accessed in Dart as:
7513 * var value = element.dataAttributes['myRandomValue'];
7514 *
7515 * See also:
7516 *
7517 * * [Custom data attributes](http://www.w3.org/TR/html5/global-attributes.htm l#custom-data-attribute)
7518 */
7425 Map<String, String> get dataAttributes => 7519 Map<String, String> get dataAttributes =>
7426 new _DataAttributeMap(attributes); 7520 new _DataAttributeMap(attributes);
7427 7521
7428 void set dataAttributes(Map<String, String> value) { 7522 void set dataAttributes(Map<String, String> value) {
7429 final dataAttributes = this.dataAttributes; 7523 final dataAttributes = this.dataAttributes;
7430 dataAttributes.clear(); 7524 dataAttributes.clear();
7431 for (String key in value.keys) { 7525 for (String key in value.keys) {
7432 dataAttributes[key] = value[key]; 7526 dataAttributes[key] = value[key];
7433 } 7527 }
7434 } 7528 }
7435 7529
7436 /** 7530 /**
7437 * Gets a map for manipulating the attributes of a particular namespace. 7531 * Gets a map for manipulating the attributes of a particular namespace.
7532 *
7438 * This is primarily useful for SVG attributes such as xref:link. 7533 * This is primarily useful for SVG attributes such as xref:link.
7439 */ 7534 */
7440 Map<String, String> getNamespacedAttributes(String namespace) { 7535 Map<String, String> getNamespacedAttributes(String namespace) {
7441 return new _NamespacedAttributeMap(this, namespace); 7536 return new _NamespacedAttributeMap(this, namespace);
7442 } 7537 }
7443 7538
7444 /** @domName Window.getComputedStyle */ 7539 /**
7540 * The set of all CSS values applied to this element, including inherited
7541 * and default values.
7542 *
7543 * The computedStyle contains the values which are inherited from other
Kathy Walrath 2012/12/12 19:16:06 which -> that the values -> values?
blois 2012/12/12 19:46:29 Done.
7544 * sources, such as parent elements or stylesheets. This differs from the
7545 * [style] property which contains the values specified directly on this
Kathy Walrath 2012/12/12 19:16:06 which -> , which (in general, you should either h
blois 2012/12/12 19:46:29 Done.
7546 * element,
Kathy Walrath 2012/12/12 19:16:06 element, -> element. (period)
blois 2012/12/12 19:46:29 Done.
blois 2012/12/12 19:46:29 Done.
7547 *
7548 * See also:
7549 *
7550 * * [CSS Inheritance and Cascade](http://docs.webplatform.org/wiki/tutorials/ inheritance_and_cascade)
7551 */
7445 Future<CssStyleDeclaration> get computedStyle { 7552 Future<CssStyleDeclaration> get computedStyle {
7446 // TODO(jacobr): last param should be null, see b/5045788 7553 // TODO(jacobr): last param should be null, see b/5045788
7447 return getComputedStyle(''); 7554 return getComputedStyle('');
7448 } 7555 }
7449 7556
7450 /** @domName Window.getComputedStyle */ 7557 /**
7558 * This returns the computed styles for pseudo-elements such as
Kathy Walrath 2012/12/12 19:16:06 This returns -> Returns
blois 2012/12/12 19:46:29 Done.
7559 * `::after, ::before, ::marker, ::line-marker`.
7560 *
7561 * See also:
7562 *
7563 * * [Pseudo-elements](http://docs.webplatform.org/wiki/css/selectors/pseudo-e lements)
7564 */
7451 Future<CssStyleDeclaration> getComputedStyle(String pseudoElement) { 7565 Future<CssStyleDeclaration> getComputedStyle(String pseudoElement) {
7452 return _createMeasurementFuture( 7566 return _createMeasurementFuture(
7453 () => window.$dom_getComputedStyle(this, pseudoElement), 7567 () => window.$dom_getComputedStyle(this, pseudoElement),
7454 new Completer<CssStyleDeclaration>()); 7568 new Completer<CssStyleDeclaration>());
7455 } 7569 }
7456 7570
7457 /** 7571 /**
7458 * Adds the specified element to after the last child of this. 7572 * Adds the specified element to after the last child of this.
Kathy Walrath 2012/12/12 19:16:06 this -> this element (seems more natural)
blois 2012/12/12 19:46:29 Done.
7459 */ 7573 */
7460 void append(Element e) { 7574 void append(Element e) {
7461 this.children.add(e); 7575 this.children.add(e);
7462 } 7576 }
7463 7577
7464 /** 7578 /**
7465 * Adds the specified text as a text node after the last child of this. 7579 * Adds the specified text as a text node after the last child of this.
Kathy Walrath 2012/12/12 19:16:06 this -> this element
blois 2012/12/12 19:46:29 Done.
7466 */ 7580 */
7467 void appendText(String text) { 7581 void appendText(String text) {
7468 this.insertAdjacentText('beforeend', text); 7582 this.insertAdjacentText('beforeend', text);
7469 } 7583 }
7470 7584
7471 /** 7585 /**
7472 * Parses the specified text as HTML and adds the resulting node after the 7586 * Parses the specified text as HTML and adds the resulting node after the
7473 * last child of this. 7587 * last child of this.
Kathy Walrath 2012/12/12 19:16:06 this -> this element
blois 2012/12/12 19:46:29 Done.
7474 */ 7588 */
7475 void appendHtml(String text) { 7589 void appendHtml(String text) {
7476 this.insertAdjacentHtml('beforeend', text); 7590 this.insertAdjacentHtml('beforeend', text);
7477 } 7591 }
7478 7592
7479 // Hooks to support custom WebComponents. 7593 // Hooks to support custom WebComponents.
7480 /** 7594 /**
7481 * Experimental support for [web components][wc]. This field stores a 7595 * Experimental support for [web components][wc]. This field stores a
7482 * reference to the component implementation. It was inspired by Mozilla's 7596 * reference to the component implementation. It was inspired by Mozilla's
7483 * [x-tags][] project. Please note: in the future it may be possible to 7597 * [x-tags][] project. Please note: in the future it may be possible to
7484 * `extend Element` from your class, in which case this field will be 7598 * `extend Element` from your class, in which case this field will be
7485 * deprecated and will simply return this [Element] object. 7599 * deprecated and will simply return this [Element] object.
7486 * 7600 *
7487 * [wc]: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html 7601 * [wc]: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html
7488 * [x-tags]: http://x-tags.org/ 7602 * [x-tags]: http://x-tags.org/
7489 */ 7603 */
7490 @Creates('Null') // Set from Dart code; does not instantiate a native type. 7604 @Creates('Null') // Set from Dart code; does not instantiate a native type.
7491 var xtag; 7605 var xtag;
7492 7606
7493 // TODO(vsm): Implement noSuchMethod or similar for dart2js. 7607 // TODO(vsm): Implement noSuchMethod or similar for dart2js.
7494 7608
7495 /** @domName Element.insertAdjacentText */ 7609 /**
7610 * Creates a text node and inserts it into the DOM at the specified location.
7611 *
7612 * The [where] parameter indicates where to insert [text]:
7613 *
7614 * * `beforeBegin` Immediately before this element.
Kathy Walrath 2012/12/12 19:16:06 These bullets seem like they wouldn't look right i
blois 2012/12/12 19:46:29 Done.
7615 * * `afterBegin` As the first child of this element.
7616 * * `beforeEnd` As the last child of this element.
7617 * * `afterEnd` Immediately after this element.
7618 *
7619 * See also:
7620 *
7621 * * [insertAdjacentHtml]
7622 */
7496 void insertAdjacentText(String where, String text) { 7623 void insertAdjacentText(String where, String text) {
7497 if (JS('bool', '!!#.insertAdjacentText', this)) { 7624 if (JS('bool', '!!#.insertAdjacentText', this)) {
7498 _insertAdjacentText(where, text); 7625 _insertAdjacentText(where, text);
7499 } else { 7626 } else {
7500 _insertAdjacentNode(where, new Text(text)); 7627 _insertAdjacentNode(where, new Text(text));
7501 } 7628 }
7502 } 7629 }
7503 7630
7504 @JSName('insertAdjacentText') 7631 @JSName('insertAdjacentText')
7505 void _insertAdjacentText(String where, String text) native; 7632 void _insertAdjacentText(String where, String text) native;
7506 7633
7507 /** @domName Element.insertAdjacentHTML */ 7634 /**
7635 * Parses text as an HTML fragment and inserts it into the DOM at the
7636 * specified location.
7637 *
7638 * The [where] parameter indicates where to insert the HTML fragment:
7639 *
7640 * * `beforeBegin` Immediately before this element.
7641 * * `afterBegin` As the first child of this element.
7642 * * `beforeEnd` As the last child of this element.
7643 * * `afterEnd` Immediately after this element.
7644 *
7645 * var html = '<div class="something">content</div>';
7646 * // Inserts as the first child
7647 * document.body.insertAdjacentHtml('afterBegin', html);
7648 * var createdElement = document.body.children[0];
7649 * print(createdElement.classes[0]); // Prints 'something'
Kathy Walrath 2012/12/12 19:16:06 Perhaps this method should be the one that the mai
blois 2012/12/12 19:46:29 Done.
7650 */
7508 void insertAdjacentHtml(String where, String text) { 7651 void insertAdjacentHtml(String where, String text) {
7509 if (JS('bool', '!!#.insertAdjacentHtml', this)) { 7652 if (JS('bool', '!!#.insertAdjacentHtml', this)) {
7510 _insertAdjacentHtml(where, text); 7653 _insertAdjacentHtml(where, text);
7511 } else { 7654 } else {
7512 _insertAdjacentNode(where, new DocumentFragment.html(text)); 7655 _insertAdjacentNode(where, new DocumentFragment.html(text));
7513 } 7656 }
7514 } 7657 }
7515 7658
7516 @JSName('insertAdjacentHTML') 7659 @JSName('insertAdjacentHTML')
7517 void _insertAdjacentHTML(String where, String text) native; 7660 void _insertAdjacentHTML(String where, String text) native;
7518 7661
7519 /** @domName Element.insertAdjacentHTML */ 7662 /**
7663 * Inserts [element] into the DOM at the specified location.
7664 *
7665 * The [where] parameter indicates where to insert [element]:
7666 *
7667 * * `beforeBegin` Immediately before this element.
7668 * * `afterBegin` As the first child of this element.
7669 * * `beforeEnd` As the last child of this element.
7670 * * `afterEnd` Immediately after this element.
7671 *
7672 * See also:
7673 *
7674 * * [insertAdjacentHtml]
7675 */
7520 Element insertAdjacentElement(String where, Element element) { 7676 Element insertAdjacentElement(String where, Element element) {
7521 if (JS('bool', '!!#.insertAdjacentElement', this)) { 7677 if (JS('bool', '!!#.insertAdjacentElement', this)) {
7522 _insertAdjacentElement(where, element); 7678 _insertAdjacentElement(where, element);
7523 } else { 7679 } else {
7524 _insertAdjacentNode(where, element); 7680 _insertAdjacentNode(where, element);
7525 } 7681 }
7526 return element; 7682 return element;
7527 } 7683 }
7528 7684
7529 @JSName('insertAdjacentElement') 7685 @JSName('insertAdjacentElement')
(...skipping 18173 matching lines...) Expand 10 before | Expand all | Expand 10 after
25703 T next() { 25859 T next() {
25704 if (!hasNext) { 25860 if (!hasNext) {
25705 throw new StateError("No more elements"); 25861 throw new StateError("No more elements");
25706 } 25862 }
25707 return _array[_pos++]; 25863 return _array[_pos++];
25708 } 25864 }
25709 25865
25710 final List<T> _array; 25866 final List<T> _array;
25711 int _pos; 25867 int _pos;
25712 } 25868 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | sdk/lib/html/templates/html/impl/impl_Element.darttemplate » ('J')

Powered by Google App Engine
This is Rietveld 408576698