OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // DO NOT EDIT | 5 // DO NOT EDIT |
6 // Auto-generated dart:html library. | 6 // Auto-generated dart:html library. |
7 | 7 |
8 /** | 8 /** |
9 * HTML elements and other resources for web-based applications that need to | 9 * HTML elements and other resources for web-based applications that need to |
10 * interact with the browser and the DOM (Document Object Model). | 10 * interact with the browser and the DOM (Document Object Model). |
(...skipping 19 matching lines...) Expand all Loading... |
30 * on Github. | 30 * on Github. |
31 */ | 31 */ |
32 library dart.dom.html; | 32 library dart.dom.html; |
33 | 33 |
34 import 'dart:async'; | 34 import 'dart:async'; |
35 import 'dart:collection'; | 35 import 'dart:collection'; |
36 import 'dart:_internal' hide Symbol, deprecated; | 36 import 'dart:_internal' hide Symbol, deprecated; |
37 import 'dart:html_common'; | 37 import 'dart:html_common'; |
38 import 'dart:indexed_db'; | 38 import 'dart:indexed_db'; |
39 import 'dart:indexed_db' show indexed_dbBlinkMap; | 39 import 'dart:indexed_db' show indexed_dbBlinkMap; |
| 40 import 'dart:indexed_db' show indexed_dbBlinkFunctionMap; |
40 import 'dart:isolate'; | 41 import 'dart:isolate'; |
41 import 'dart:js' as js; | 42 import 'dart:js' as js; |
42 import "dart:convert"; | 43 import "dart:convert"; |
43 import 'dart:math'; | 44 import 'dart:math'; |
44 // TODO(vsm): Remove this when we can do the proper checking in | 45 // TODO(vsm): Remove this when we can do the proper checking in |
45 // native code for custom elements. | 46 // native code for custom elements. |
46 import 'dart:mirrors'; | 47 import 'dart:mirrors'; |
47 import 'dart:nativewrappers'; | 48 import 'dart:nativewrappers'; |
48 import 'dart:typed_data'; | 49 import 'dart:typed_data'; |
49 import 'dart:web_gl' as gl; | 50 import 'dart:web_gl' as gl; |
50 import 'dart:web_gl' show web_glBlinkMap; | 51 import 'dart:web_gl' show web_glBlinkMap; |
| 52 import 'dart:web_gl' show web_glBlinkFunctionMap; |
51 import 'dart:web_sql'; | 53 import 'dart:web_sql'; |
52 // Not actually used, but imported since dart:html can generate these objects. | 54 // Not actually used, but imported since dart:html can generate these objects. |
53 import 'dart:svg' as svg; | 55 import 'dart:svg' as svg; |
54 import 'dart:svg' show svgBlinkMap; | 56 import 'dart:svg' show svgBlinkMap; |
| 57 import 'dart:svg' show svgBlinkFunctionMap; |
55 import 'dart:svg' show Matrix; | 58 import 'dart:svg' show Matrix; |
56 import 'dart:svg' show SvgSvgElement; | 59 import 'dart:svg' show SvgSvgElement; |
57 import 'dart:web_audio' as web_audio; | 60 import 'dart:web_audio' as web_audio; |
58 import 'dart:web_audio' show web_audioBlinkMap; | 61 import 'dart:web_audio' show web_audioBlinkMap; |
| 62 import 'dart:web_audio' show web_audioBlinkFunctionMap; |
59 import 'dart:_blink' as _blink; | 63 import 'dart:_blink' as _blink; |
60 | 64 |
61 export 'dart:math' show Rectangle, Point; | 65 export 'dart:math' show Rectangle, Point; |
62 | 66 |
63 $!GENERATED_DART_FILES | 67 $!GENERATED_DART_FILES |
64 | 68 |
65 // Issue 14721, order important for WrappedEvent. | 69 // Issue 14721, order important for WrappedEvent. |
66 part '$AUXILIARY_DIR/AttributeMap.dart'; | 70 part '$AUXILIARY_DIR/AttributeMap.dart'; |
67 part '$AUXILIARY_DIR/CanvasImageSource.dart'; | 71 part '$AUXILIARY_DIR/CanvasImageSource.dart'; |
68 part '$AUXILIARY_DIR/CrossFrameTypes.dart'; | 72 part '$AUXILIARY_DIR/CrossFrameTypes.dart'; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 * [Window] object, which is accessible only to that `<iframe>`. | 108 * [Window] object, which is accessible only to that `<iframe>`. |
105 * | 109 * |
106 * See also: | 110 * See also: |
107 * | 111 * |
108 * * [Window](https://developer.mozilla.org/en-US/docs/Web/API/window) from MD
N. | 112 * * [Window](https://developer.mozilla.org/en-US/docs/Web/API/window) from MD
N. |
109 */ | 113 */ |
110 Window get window { | 114 Window get window { |
111 if (_window != null) { | 115 if (_window != null) { |
112 return _window; | 116 return _window; |
113 } | 117 } |
| 118 $if DARTIUM |
| 119 $if JSINTEROP |
| 120 _window = wrap_jso(js.context['window']); |
| 121 $else |
114 _window = _Utils.window(); | 122 _window = _Utils.window(); |
| 123 $endif |
| 124 $endif |
115 return _window; | 125 return _window; |
116 } | 126 } |
117 | 127 |
118 HtmlDocument _document; | 128 HtmlDocument _document; |
119 | 129 |
120 /** | 130 /** |
121 * Root node for all content in a web page. | 131 * Root node for all content in a web page. |
122 */ | 132 */ |
123 HtmlDocument get document { | 133 HtmlDocument get document { |
124 if (_document != null) { | 134 if (_document != null) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 242 } |
233 return null; | 243 return null; |
234 } | 244 } |
235 | 245 |
236 Type _getSvgType(String key) { | 246 Type _getSvgType(String key) { |
237 if (svgBlinkMap.containsKey(key)) { | 247 if (svgBlinkMap.containsKey(key)) { |
238 return svgBlinkMap[key](); | 248 return svgBlinkMap[key](); |
239 } | 249 } |
240 return null; | 250 return null; |
241 } | 251 } |
| 252 |
| 253 |
| 254 $if JSINTEROP |
| 255 // FIXME: Can we make this private? |
| 256 final htmlBlinkFunctionMap = { |
| 257 $!TYPE_FUNCTION_MAP |
| 258 }; |
| 259 |
| 260 // TODO(terry): We may want to move this elsewhere if html becomes |
| 261 // a package to avoid dartium depending on pkg:html. |
| 262 getHtmlCreateFunction(String key) { |
| 263 var result; |
| 264 |
| 265 // TODO(vsm): Add Cross Frame and JS types here as well. |
| 266 |
| 267 // Check the html library. |
| 268 result = _getHtmlFunction(key); |
| 269 if (result != null) { |
| 270 return result; |
| 271 } |
| 272 |
| 273 // Check the web gl library. |
| 274 result = _getWebGlFunction(key); |
| 275 if (result != null) { |
| 276 return result; |
| 277 } |
| 278 |
| 279 // Check the indexed db library. |
| 280 result = _getIndexDbFunction(key); |
| 281 if (result != null) { |
| 282 return result; |
| 283 } |
| 284 |
| 285 // Check the web audio library. |
| 286 result = _getWebAudioFunction(key); |
| 287 if (result != null) { |
| 288 return result; |
| 289 } |
| 290 |
| 291 // Check the web sql library. |
| 292 result = _getWebSqlFunction(key); |
| 293 if (result != null) { |
| 294 return result; |
| 295 } |
| 296 |
| 297 // Check the svg library. |
| 298 result = _getSvgFunction(key); |
| 299 if (result != null) { |
| 300 return result; |
| 301 } |
| 302 |
| 303 return null; |
| 304 } |
| 305 |
| 306 Type _getHtmlFunction(String key) { |
| 307 if (htmlBlinkFunctionMap.containsKey(key)) { |
| 308 return htmlBlinkFunctionMap[key](); |
| 309 } |
| 310 return null; |
| 311 } |
| 312 |
| 313 Type _getWebGlFunction(String key) { |
| 314 if (web_glBlinkFunctionMap.containsKey(key)) { |
| 315 return web_glBlinkFunctionMap[key](); |
| 316 } |
| 317 return null; |
| 318 } |
| 319 |
| 320 Type _getIndexDbFunction(String key) { |
| 321 if (indexed_dbBlinkFunctionMap.containsKey(key)) { |
| 322 return indexed_dbBlinkFunctionMap[key](); |
| 323 } |
| 324 return null; |
| 325 } |
| 326 |
| 327 Type _getWebAudioFunction(String key) { |
| 328 if (web_audioBlinkFunctionMap.containsKey(key)) { |
| 329 return web_audioBlinkFunctionMap[key](); |
| 330 } |
| 331 return null; |
| 332 } |
| 333 |
| 334 Type _getWebSqlFunction(String key) { |
| 335 if (web_sqlBlinkFunctionMap.containsKey(key)) { |
| 336 return web_sqlBlinkFunctionMap[key](); |
| 337 } |
| 338 return null; |
| 339 } |
| 340 |
| 341 Type _getSvgFunction(String key) { |
| 342 if (svgBlinkFunctionMap.containsKey(key)) { |
| 343 return svgBlinkFunctionMap[key](); |
| 344 } |
| 345 return null; |
| 346 } |
| 347 |
| 348 |
| 349 /****************************************************************************** |
| 350 ********** ********** |
| 351 ********** JS Interop Support ********** |
| 352 ********** ********** |
| 353 ******************************************************************************/ |
| 354 |
| 355 Rectangle make_dart_rectangle(r) => new Rectangle(r['top'], r['left'], r['width'
], r['height']); |
| 356 |
| 357 |
| 358 /** Expando for JsObject, used by every Dart class associated with a Javascript |
| 359 * class (e.g., DOM, WebAudio, etc.). |
| 360 */ |
| 361 |
| 362 /** |
| 363 * Return the JsObject associated with a Dart class [dartClass_instance]. |
| 364 */ |
| 365 js.JsObject unwrap_jso(dartClass_instance) { |
| 366 try { |
| 367 if (dartClass_instance != null) |
| 368 return dartClass_instance is! Function ? dartClass_instance.blink_jsOb
ject : dartClass_instance; |
| 369 else |
| 370 return null; |
| 371 // return dartClass_instance.dartium_expando[dartClass_instance.expandoJsOb
ject]; |
| 372 } catch(NoSuchMethodException) { |
| 373 // No blink_jsObject then return the dartClass_instance is probably an |
| 374 // array that was already converted to a Dart class e.g., Uint8ClampedList
. |
| 375 return dartClass_instance; |
| 376 } |
| 377 } |
| 378 |
| 379 /** |
| 380 * Create Dart class that maps to the JS Type, add the JsObject as an expando |
| 381 * on the Dart class and return the created Dart class. |
| 382 */ |
| 383 wrap_jso(jsObject) { |
| 384 try { |
| 385 // debug_or_assert("jsObject != null", jsObject != null); |
| 386 if (jsObject is! js.JsObject) { |
| 387 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. |
| 388 return jsObject; |
| 389 } |
| 390 var constructor = jsObject['constructor']; |
| 391 debug_or_assert("constructor != null", constructor != null); |
| 392 var jsTypeName = constructor['name']; |
| 393 debug_or_assert("constructor != null && jsTypeName.length > 0", constructor !=
null && jsTypeName.length > 0); |
| 394 var func = getHtmlCreateFunction(jsTypeName); |
| 395 debug_or_assert("func != null name = ${jsTypeName}", func != null); |
| 396 var dartClass_instance = func(); |
| 397 dartClass_instance.blink_jsObject = jsObject; |
| 398 // dartClass_instance.dartium_expando[dartClass_instance.expandoJsObject] = jsO
bject; |
| 399 return dartClass_instance; |
| 400 } catch(e, stacktrace){ |
| 401 if (e is DebugAssertException) |
| 402 window.console.log("${e.message}\n ${stacktrace}"); |
| 403 else |
| 404 window.console.log("${stacktrace}"); |
| 405 } |
| 406 } |
| 407 |
| 408 class DebugAssertException implements Exception { |
| 409 String message; |
| 410 DebugAssertException(this.message); |
| 411 } |
| 412 |
| 413 debug_or_assert(message, expression) { |
| 414 if (!expression) { |
| 415 throw new DebugAssertException("$message"); |
| 416 } |
| 417 } |
| 418 |
| 419 // Wrap JsObject node list to return a List<node>. |
| 420 List<Node> wrap_jso_list(jso_nodes) { |
| 421 List<Node> nodes = new List<Node>(); |
| 422 var collectionLen = jso_nodes['length']; |
| 423 for (var i = 0; i < collectionLen; i++) { |
| 424 nodes.add(wrap_jso(jso_nodes.callMethod('item', [i]))); |
| 425 } |
| 426 var frozen_nodes = new _FrozenElementList._wrap(nodes); |
| 427 frozen_nodes.dartClass_instance = jso_nodes; |
| 428 return frozen_nodes; |
| 429 } |
| 430 $else |
| 431 unwrap_jso(dartClass_instance) => dartClass_instance; |
| 432 wrap_jso(jsObject) => jsObject; |
| 433 wrap_jso_list(jso_nodes) => jso_nodes; |
| 434 make_dart_rectangle(r) => r; |
| 435 $endif |
OLD | NEW |