OLD | NEW |
1 /** | 1 /** |
2 * HTML elements and other resources for web-based applications that need to | 2 * HTML elements and other resources for web-based applications that need to |
3 * interact with the browser and the DOM (Document Object Model). | 3 * interact with the browser and the DOM (Document Object Model). |
4 * | 4 * |
5 * This library includes DOM element types, CSS styling, local storage, | 5 * This library includes DOM element types, CSS styling, local storage, |
6 * media, speech, events, and more. | 6 * media, speech, events, and more. |
7 * To get started, | 7 * To get started, |
8 * check out the [Element] class, the base class for many of the HTML | 8 * check out the [Element] class, the base class for many of the HTML |
9 * DOM types. | 9 * DOM types. |
10 * | 10 * |
11 * ## Other resources | 11 * ## Other resources |
12 * | 12 * |
13 * * If you've never written a web app before, try our | 13 * * If you've never written a web app before, try our |
14 * tutorials—[A Game of Darts](http://dartlang.org/docs/tutorials). | 14 * tutorials—[A Game of Darts](http://dartlang.org/docs/tutorials). |
15 * | 15 * |
16 * * To see some web-based Dart apps in action and to play with the code, | 16 * * To see some web-based Dart apps in action and to play with the code, |
17 * download | 17 * download |
18 * [Dart Editor](http://www.dartlang.org/#get-started) | 18 * [Dart Editor](http://www.dartlang.org/#get-started) |
19 * and run its built-in examples. | 19 * and run its built-in examples. |
20 * | 20 * |
21 * * For even more examples, see | 21 * * For even more examples, see |
22 * [Dart HTML5 Samples](https://github.com/dart-lang/dart-html5-samples) | 22 * [Dart HTML5 Samples](https://github.com/dart-lang/dart-html5-samples) |
23 * on Github. | 23 * on Github. |
24 */ | 24 */ |
25 library dart.dom.html; | 25 library dart.dom.html; |
26 | 26 |
| 27 import 'dart:_runtime' show global_; |
27 import 'dart:async'; | 28 import 'dart:async'; |
28 import 'dart:collection'; | 29 import 'dart:collection'; |
29 import 'dart:_internal' hide Symbol; | 30 import 'dart:_internal' hide Symbol; |
30 import 'dart:html_common'; | 31 import 'dart:html_common'; |
31 import 'dart:isolate'; | 32 import 'dart:isolate'; |
32 import "dart:convert"; | 33 import "dart:convert"; |
33 import 'dart:math'; | 34 import 'dart:math'; |
34 import 'dart:_native_typed_data'; | 35 import 'dart:_native_typed_data'; |
35 import 'dart:typed_data'; | 36 import 'dart:typed_data'; |
36 import 'dart:_isolate_helper' show IsolateNatives; | 37 import 'dart:_isolate_helper' show IsolateNatives; |
(...skipping 4883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4920 /** | 4921 /** |
4921 * Parses the specified text as HTML and adds the resulting node after the | 4922 * Parses the specified text as HTML and adds the resulting node after the |
4922 * last child of this document fragment. | 4923 * last child of this document fragment. |
4923 */ | 4924 */ |
4924 void appendHtml(String text, {NodeValidator validator, | 4925 void appendHtml(String text, {NodeValidator validator, |
4925 NodeTreeSanitizer, treeSanitizer}) { | 4926 NodeTreeSanitizer, treeSanitizer}) { |
4926 this.append(new DocumentFragment.html(text, validator: validator, | 4927 this.append(new DocumentFragment.html(text, validator: validator, |
4927 treeSanitizer: treeSanitizer)); | 4928 treeSanitizer: treeSanitizer)); |
4928 } | 4929 } |
4929 | 4930 |
4930 /** | 4931 /** |
4931 * Alias for [querySelector]. Note this function is deprecated because its | 4932 * Alias for [querySelector]. Note this function is deprecated because its |
4932 * semantics will be changing in the future. | 4933 * semantics will be changing in the future. |
4933 */ | 4934 */ |
4934 @deprecated | 4935 @deprecated |
4935 @Experimental() | 4936 @Experimental() |
4936 @DomName('DocumentFragment.querySelector') | 4937 @DomName('DocumentFragment.querySelector') |
4937 Element query(String relativeSelectors) { | 4938 Element query(String relativeSelectors) { |
4938 return querySelector(relativeSelectors); | 4939 return querySelector(relativeSelectors); |
4939 } | 4940 } |
4940 | 4941 |
4941 /** | 4942 /** |
4942 * Alias for [querySelectorAll]. Note this function is deprecated because its | 4943 * Alias for [querySelectorAll]. Note this function is deprecated because its |
4943 * semantics will be changing in the future. | 4944 * semantics will be changing in the future. |
4944 */ | 4945 */ |
4945 @deprecated | 4946 @deprecated |
4946 @Experimental() | 4947 @Experimental() |
4947 @DomName('DocumentFragment.querySelectorAll') | 4948 @DomName('DocumentFragment.querySelectorAll') |
4948 ElementList<Element> queryAll(String relativeSelectors) { | 4949 ElementList<Element> queryAll(String relativeSelectors) { |
4949 return querySelectorAll(relativeSelectors); | 4950 return querySelectorAll(relativeSelectors); |
4950 } | 4951 } |
4951 // To suppress missing implicit constructor warnings. | 4952 // To suppress missing implicit constructor warnings. |
(...skipping 2646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7598 * Normally events should be created via their constructors, if available. | 7599 * Normally events should be created via their constructors, if available. |
7599 * | 7600 * |
7600 * var e = new Event.type('MouseEvent', 'mousedown', true, true); | 7601 * var e = new Event.type('MouseEvent', 'mousedown', true, true); |
7601 */ | 7602 */ |
7602 factory Event.eventType(String type, String name, {bool canBubble: true, | 7603 factory Event.eventType(String type, String name, {bool canBubble: true, |
7603 bool cancelable: true}) { | 7604 bool cancelable: true}) { |
7604 final Event e = document._createEvent(type); | 7605 final Event e = document._createEvent(type); |
7605 e._initEvent(name, canBubble, cancelable); | 7606 e._initEvent(name, canBubble, cancelable); |
7606 return e; | 7607 return e; |
7607 } | 7608 } |
7608 | 7609 |
7609 /** The CSS selector involved with event delegation. */ | 7610 /** The CSS selector involved with event delegation. */ |
7610 String _selector; | 7611 String _selector; |
7611 | 7612 |
7612 /** | 7613 /** |
7613 * A pointer to the element whose CSS selector matched within which an event | 7614 * A pointer to the element whose CSS selector matched within which an event |
7614 * was fired. If this Event was not associated with any Event delegation, | 7615 * was fired. If this Event was not associated with any Event delegation, |
7615 * accessing this value will throw an [UnsupportedError]. | 7616 * accessing this value will throw an [UnsupportedError]. |
7616 */ | 7617 */ |
7617 Element get matchingTarget { | 7618 Element get matchingTarget { |
7618 if (_selector == null) { | 7619 if (_selector == null) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7833 Events(this._ptr); | 7834 Events(this._ptr); |
7834 | 7835 |
7835 Stream operator [](String type) { | 7836 Stream operator [](String type) { |
7836 return new _EventStream(_ptr, type, false); | 7837 return new _EventStream(_ptr, type, false); |
7837 } | 7838 } |
7838 } | 7839 } |
7839 | 7840 |
7840 class ElementEvents extends Events { | 7841 class ElementEvents extends Events { |
7841 /* Raw event target. */ | 7842 /* Raw event target. */ |
7842 static final webkitEvents = { | 7843 static final webkitEvents = { |
7843 'animationend' : 'webkitAnimationEnd', | 7844 'animationend' : 'webkitAnimationEnd', |
7844 'animationiteration' : 'webkitAnimationIteration', | 7845 'animationiteration' : 'webkitAnimationIteration', |
7845 'animationstart' : 'webkitAnimationStart', | 7846 'animationstart' : 'webkitAnimationStart', |
7846 'fullscreenchange' : 'webkitfullscreenchange', | 7847 'fullscreenchange' : 'webkitfullscreenchange', |
7847 'fullscreenerror' : 'webkitfullscreenerror', | 7848 'fullscreenerror' : 'webkitfullscreenerror', |
7848 'keyadded' : 'webkitkeyadded', | 7849 'keyadded' : 'webkitkeyadded', |
7849 'keyerror' : 'webkitkeyerror', | 7850 'keyerror' : 'webkitkeyerror', |
7850 'keymessage' : 'webkitkeymessage', | 7851 'keymessage' : 'webkitkeymessage', |
7851 'needkey' : 'webkitneedkey', | 7852 'needkey' : 'webkitneedkey', |
7852 'pointerlockchange' : 'webkitpointerlockchange', | 7853 'pointerlockchange' : 'webkitpointerlockchange', |
7853 'pointerlockerror' : 'webkitpointerlockerror', | 7854 'pointerlockerror' : 'webkitpointerlockerror', |
7854 'resourcetimingbufferfull' : 'webkitresourcetimingbufferfull', | 7855 'resourcetimingbufferfull' : 'webkitresourcetimingbufferfull', |
7855 'transitionend': 'webkitTransitionEnd', | 7856 'transitionend': 'webkitTransitionEnd', |
7856 'speechchange' : 'webkitSpeechChange' | 7857 'speechchange' : 'webkitSpeechChange' |
7857 }; | 7858 }; |
7858 | 7859 |
7859 ElementEvents(Element ptr) : super(ptr); | 7860 ElementEvents(Element ptr) : super(ptr); |
7860 | 7861 |
7861 Stream operator [](String type) { | 7862 Stream operator [](String type) { |
7862 if (webkitEvents.keys.contains(type.toLowerCase())) { | 7863 if (webkitEvents.keys.contains(type.toLowerCase())) { |
7863 if (Device.isWebKit) { | 7864 if (Device.isWebKit) { |
7864 return new _ElementEventStreamImpl( | 7865 return new _ElementEventStreamImpl( |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8674 responseType: responseType, | 8675 responseType: responseType, |
8675 requestHeaders: requestHeaders, sendData: formData, | 8676 requestHeaders: requestHeaders, sendData: formData, |
8676 onProgress: onProgress); | 8677 onProgress: onProgress); |
8677 } | 8678 } |
8678 | 8679 |
8679 /** | 8680 /** |
8680 * Creates and sends a URL request for the specified [url]. | 8681 * Creates and sends a URL request for the specified [url]. |
8681 * | 8682 * |
8682 * By default `request` will perform an HTTP GET request, but a different | 8683 * By default `request` will perform an HTTP GET request, but a different |
8683 * method (`POST`, `PUT`, `DELETE`, etc) can be used by specifying the | 8684 * method (`POST`, `PUT`, `DELETE`, etc) can be used by specifying the |
8684 * [method] parameter. (See also [HttpRequest.postFormData] for `POST` | 8685 * [method] parameter. (See also [HttpRequest.postFormData] for `POST` |
8685 * requests only. | 8686 * requests only. |
8686 * | 8687 * |
8687 * The Future is completed when the response is available. | 8688 * The Future is completed when the response is available. |
8688 * | 8689 * |
8689 * If specified, `sendData` will send data in the form of a [ByteBuffer], | 8690 * If specified, `sendData` will send data in the form of a [ByteBuffer], |
8690 * [Blob], [Document], [String], or [FormData] along with the HttpRequest. | 8691 * [Blob], [Document], [String], or [FormData] along with the HttpRequest. |
8691 * | 8692 * |
8692 * If specified, [responseType] sets the desired response format for the | 8693 * If specified, [responseType] sets the desired response format for the |
8693 * request. By default it is [String], but can also be 'arraybuffer', 'blob', | 8694 * request. By default it is [String], but can also be 'arraybuffer', 'blob', |
8694 * 'document', 'json', or 'text'. See also [HttpRequest.responseType] | 8695 * 'document', 'json', or 'text'. See also [HttpRequest.responseType] |
8695 * for more information. | 8696 * for more information. |
8696 * | 8697 * |
8697 * The [withCredentials] parameter specified that credentials such as a cookie | 8698 * The [withCredentials] parameter specified that credentials such as a cookie |
8698 * (already) set in the header or | 8699 * (already) set in the header or |
8699 * [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2) | 8700 * [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2) |
8700 * should be specified for the request. Details to keep in mind when using | 8701 * should be specified for the request. Details to keep in mind when using |
8701 * credentials: | 8702 * credentials: |
8702 * | 8703 * |
8703 * * Using credentials is only useful for cross-origin requests. | 8704 * * Using credentials is only useful for cross-origin requests. |
8704 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca
rd (*). | 8705 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca
rd (*). |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8767 xhr.onLoad.listen((e) { | 8768 xhr.onLoad.listen((e) { |
8768 var accepted = xhr.status >= 200 && xhr.status < 300; | 8769 var accepted = xhr.status >= 200 && xhr.status < 300; |
8769 var fileUri = xhr.status == 0; // file:// URIs have status of 0. | 8770 var fileUri = xhr.status == 0; // file:// URIs have status of 0. |
8770 var notModified = xhr.status == 304; | 8771 var notModified = xhr.status == 304; |
8771 // Redirect status is specified up to 307, but others have been used in | 8772 // Redirect status is specified up to 307, but others have been used in |
8772 // practice. Notably Google Drive uses 308 Resume Incomplete for | 8773 // practice. Notably Google Drive uses 308 Resume Incomplete for |
8773 // resumable uploads, and it's also been used as a redirect. The | 8774 // resumable uploads, and it's also been used as a redirect. The |
8774 // redirect case will be handled by the browser before it gets to us, | 8775 // redirect case will be handled by the browser before it gets to us, |
8775 // so if we see it we should pass it through to the user. | 8776 // so if we see it we should pass it through to the user. |
8776 var unknownRedirect = xhr.status > 307 && xhr.status < 400; | 8777 var unknownRedirect = xhr.status > 307 && xhr.status < 400; |
8777 | 8778 |
8778 if (accepted || fileUri || notModified || unknownRedirect) { | 8779 if (accepted || fileUri || notModified || unknownRedirect) { |
8779 completer.complete(xhr); | 8780 completer.complete(xhr); |
8780 } else { | 8781 } else { |
8781 completer.completeError(e); | 8782 completer.completeError(e); |
8782 } | 8783 } |
8783 }); | 8784 }); |
8784 | 8785 |
8785 xhr.onError.listen(completer.completeError); | 8786 xhr.onError.listen(completer.completeError); |
8786 | 8787 |
8787 if (sendData != null) { | 8788 if (sendData != null) { |
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10627 * The [type] of the event identifies what kind of interaction occurred. | 10628 * The [type] of the event identifies what kind of interaction occurred. |
10628 * | 10629 * |
10629 * See also: | 10630 * See also: |
10630 * | 10631 * |
10631 * * [KeyboardEvent](https://developer.mozilla.org/en/DOM/KeyboardEvent) at MDN. | 10632 * * [KeyboardEvent](https://developer.mozilla.org/en/DOM/KeyboardEvent) at MDN. |
10632 */ | 10633 */ |
10633 @DomName('KeyboardEvent') | 10634 @DomName('KeyboardEvent') |
10634 @Native("KeyboardEvent") | 10635 @Native("KeyboardEvent") |
10635 class KeyboardEvent extends UIEvent { | 10636 class KeyboardEvent extends UIEvent { |
10636 | 10637 |
10637 /** | 10638 /** |
10638 * Programmatically create a KeyboardEvent. | 10639 * Programmatically create a KeyboardEvent. |
10639 * | 10640 * |
10640 * Due to browser differences, keyCode, charCode, or keyIdentifier values | 10641 * Due to browser differences, keyCode, charCode, or keyIdentifier values |
10641 * cannot be specified in this base level constructor. This constructor | 10642 * cannot be specified in this base level constructor. This constructor |
10642 * enables the user to programmatically create and dispatch a [KeyboardEvent], | 10643 * enables the user to programmatically create and dispatch a [KeyboardEvent], |
10643 * but it will not contain any particular key content. For programmatically | 10644 * but it will not contain any particular key content. For programmatically |
10644 * creating keyboard events with specific key value contents, see the custom | 10645 * creating keyboard events with specific key value contents, see the custom |
10645 * Event [KeyEvent]. | 10646 * Event [KeyEvent]. |
10646 */ | 10647 */ |
10647 factory KeyboardEvent(String type, | 10648 factory KeyboardEvent(String type, |
10648 {Window view, bool canBubble: true, bool cancelable: true, | 10649 {Window view, bool canBubble: true, bool cancelable: true, |
10649 int keyLocation: 1, bool ctrlKey: false, | 10650 int keyLocation: 1, bool ctrlKey: false, |
10650 bool altKey: false, bool shiftKey: false, bool metaKey: false}) { | 10651 bool altKey: false, bool shiftKey: false, bool metaKey: false}) { |
10651 if (view == null) { | 10652 if (view == null) { |
10652 view = window; | 10653 view = window; |
10653 } | 10654 } |
10654 KeyboardEvent e = document._createEvent("KeyboardEvent"); | 10655 KeyboardEvent e = document._createEvent("KeyboardEvent"); |
10655 e._initKeyboardEvent(type, canBubble, cancelable, view, "", | 10656 e._initKeyboardEvent(type, canBubble, cancelable, view, "", |
(...skipping 7914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18570 // for details. All rights reserved. Use of this source code is governed by a | 18571 // for details. All rights reserved. Use of this source code is governed by a |
18571 // BSD-style license that can be found in the LICENSE file. | 18572 // BSD-style license that can be found in the LICENSE file. |
18572 | 18573 |
18573 | 18574 |
18574 // Iterator for arrays with fixed size. | 18575 // Iterator for arrays with fixed size. |
18575 class FixedSizeListIterator<T> implements Iterator<T> { | 18576 class FixedSizeListIterator<T> implements Iterator<T> { |
18576 final List<T> _array; | 18577 final List<T> _array; |
18577 final int _length; // Cache array length for faster access. | 18578 final int _length; // Cache array length for faster access. |
18578 int _position; | 18579 int _position; |
18579 T _current; | 18580 T _current; |
18580 | 18581 |
18581 FixedSizeListIterator(List<T> array) | 18582 FixedSizeListIterator(List<T> array) |
18582 : _array = array, | 18583 : _array = array, |
18583 _position = -1, | 18584 _position = -1, |
18584 _length = array.length; | 18585 _length = array.length; |
18585 | 18586 |
18586 bool moveNext() { | 18587 bool moveNext() { |
18587 int nextPosition = _position + 1; | 18588 int nextPosition = _position + 1; |
18588 if (nextPosition < _length) { | 18589 if (nextPosition < _length) { |
18589 _current = _array[nextPosition]; | 18590 _current = _array[nextPosition]; |
18590 _position = nextPosition; | 18591 _position = nextPosition; |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19029 @Experimental() // untriaged | 19030 @Experimental() // untriaged |
19030 int get location => throw new UnimplementedError(); | 19031 int get location => throw new UnimplementedError(); |
19031 @Experimental() // untriaged | 19032 @Experimental() // untriaged |
19032 bool get repeat => throw new UnimplementedError(); | 19033 bool get repeat => throw new UnimplementedError(); |
19033 dynamic get _get_view => throw new UnimplementedError(); | 19034 dynamic get _get_view => throw new UnimplementedError(); |
19034 } | 19035 } |
19035 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 19036 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
19036 // for details. All rights reserved. Use of this source code is governed by a | 19037 // for details. All rights reserved. Use of this source code is governed by a |
19037 // BSD-style license that can be found in the LICENSE file. | 19038 // BSD-style license that can be found in the LICENSE file. |
19038 | 19039 |
19039 | |
19040 class Platform { | 19040 class Platform { |
19041 /** | 19041 /** |
19042 * Returns true if dart:typed_data types are supported on this | 19042 * Returns true if dart:typed_data types are supported on this |
19043 * browser. If false, using these types will generate a runtime | 19043 * browser. If false, using these types will generate a runtime |
19044 * error. | 19044 * error. |
19045 */ | 19045 */ |
19046 static final supportsTypedData = JS('bool', '!!(window.ArrayBuffer)'); | 19046 static final supportsTypedData = JS('bool', '!!($global_.ArrayBuffer)'); |
19047 | 19047 |
19048 /** | 19048 /** |
19049 * Returns true if SIMD types in dart:typed_data types are supported | 19049 * Returns true if SIMD types in dart:typed_data types are supported |
19050 * on this browser. If false, using these types will generate a runtime | 19050 * on this browser. If false, using these types will generate a runtime |
19051 * error. | 19051 * error. |
19052 */ | 19052 */ |
19053 static final supportsSimd = false; | 19053 static final supportsSimd = false; |
19054 } | 19054 } |
19055 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 19055 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
19056 // for details. All rights reserved. Use of this source code is governed by a | 19056 // for details. All rights reserved. Use of this source code is governed by a |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19548 * Each web page loaded in the browser has its own [Window], which is a | 19548 * Each web page loaded in the browser has its own [Window], which is a |
19549 * container for the web page. | 19549 * container for the web page. |
19550 * | 19550 * |
19551 * If the web page has any `<iframe>` elements, then each `<iframe>` has its own | 19551 * If the web page has any `<iframe>` elements, then each `<iframe>` has its own |
19552 * [Window] object, which is accessible only to that `<iframe>`. | 19552 * [Window] object, which is accessible only to that `<iframe>`. |
19553 * | 19553 * |
19554 * See also: | 19554 * See also: |
19555 * | 19555 * |
19556 * * [Window](https://developer.mozilla.org/en-US/docs/Web/API/window) from MD
N. | 19556 * * [Window](https://developer.mozilla.org/en-US/docs/Web/API/window) from MD
N. |
19557 */ | 19557 */ |
19558 Window get window => wrap_jso(JS('', 'window')); | 19558 |
| 19559 final Window window = wrap_jso(JS('', '$global_')); |
19559 | 19560 |
19560 /** | 19561 /** |
19561 * Root node for all content in a web page. | 19562 * Root node for all content in a web page. |
19562 */ | 19563 */ |
19563 HtmlDocument get document => wrap_jso(JS('HtmlDocument', 'document')); | 19564 HtmlDocument get document => wrap_jso(JS('HtmlDocument', 'document')); |
19564 | 19565 |
19565 // Workaround for tags like <cite> that lack their own Element subclass -- | 19566 // Workaround for tags like <cite> that lack their own Element subclass -- |
19566 // Dart issue 1990. | 19567 // Dart issue 1990. |
19567 @Native("HTMLElement") | 19568 @Native("HTMLElement") |
19568 class HtmlElement extends Element { | 19569 class HtmlElement extends Element { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19791 } | 19792 } |
19792 return null; | 19793 return null; |
19793 } | 19794 } |
19794 | 19795 |
19795 Function _getHtmlFunction(String key) { | 19796 Function _getHtmlFunction(String key) { |
19796 if (htmlBlinkFunctionMap.containsKey(key)) { | 19797 if (htmlBlinkFunctionMap.containsKey(key)) { |
19797 return htmlBlinkFunctionMap[key](); | 19798 return htmlBlinkFunctionMap[key](); |
19798 } | 19799 } |
19799 return null; | 19800 return null; |
19800 } | 19801 } |
19801 | |
OLD | NEW |