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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 * See also: | 110 * See also: |
111 * | 111 * |
112 * * [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. |
113 */ | 113 */ |
114 Window get window { | 114 Window get window { |
115 if (_window != null) { | 115 if (_window != null) { |
116 return _window; | 116 return _window; |
117 } | 117 } |
118 $if DARTIUM | 118 $if DARTIUM |
119 $if JSINTEROP | 119 $if JSINTEROP |
120 _window = wrap_jso(js.context['window']); | 120 _window = wrap_jso(js.JsNative.getProperty(js.context, 'window')); |
121 $else | 121 $else |
122 _window = _Utils.window(); | 122 _window = _Utils.window(); |
123 $endif | 123 $endif |
124 $endif | 124 $endif |
125 return _window; | 125 return _window; |
126 } | 126 } |
127 | 127 |
128 HtmlDocument _document; | 128 HtmlDocument _document; |
129 | 129 |
130 /** | 130 /** |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 /****************************************************************************** | 348 /****************************************************************************** |
349 ********** ********** | 349 ********** ********** |
350 ********** JS Interop Support ********** | 350 ********** JS Interop Support ********** |
351 ********** ********** | 351 ********** ********** |
352 ******************************************************************************/ | 352 ******************************************************************************/ |
353 | 353 |
354 // List of known tagName to DartClass for custom elements, used for upgrade. | 354 // List of known tagName to DartClass for custom elements, used for upgrade. |
355 var _knownCustomeElements = new Map<String, Type>(); | 355 var _knownCustomeElements = new Map<String, Type>(); |
356 | 356 |
357 Rectangle make_dart_rectangle(r) => | 357 Rectangle make_dart_rectangle(r) => |
358 r == null ? null : new Rectangle(r['left'], r['top'], r['width'], r['height'
]); | 358 r == null ? null : new Rectangle( |
| 359 js.JsNative.getProperty(r, 'left'), |
| 360 js.JsNative.getProperty(r, 'top'), |
| 361 js.JsNative.getProperty(r, 'width'), |
| 362 js.JsNative.getProperty(r, 'height')); |
359 | 363 |
360 // Need a default constructor for constructing classes with mixins that are | 364 // Need a default constructor for constructing classes with mixins that are |
361 // also extending NativeFieldWrapperClass2. Defining JsoNativeFieldWrapper | 365 // also extending NativeFieldWrapperClass2. Defining JsoNativeFieldWrapper |
362 // extending NativeFieldWrapperClass2 creates a default constructor. | 366 // extending NativeFieldWrapperClass2 creates a default constructor. |
363 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {} | 367 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {} |
364 | 368 |
365 // Flag to disable JS interop asserts. Setting to false will speed up the | 369 // Flag to disable JS interop asserts. Setting to false will speed up the |
366 // wrap_jso calls. | 370 // wrap_jso calls. |
367 bool __interop_checks = true; | 371 bool __interop_checks = true; |
368 | 372 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 406 } |
403 | 407 |
404 // Try the most general type conversions on it. | 408 // Try the most general type conversions on it. |
405 // TODO(alanknight): We may be able to do better. This maintains identity, | 409 // TODO(alanknight): We may be able to do better. This maintains identity, |
406 // which is useful, but expensive. And if we nest something that only | 410 // which is useful, but expensive. And if we nest something that only |
407 // this conversion handles, how does that work? e.g. a list of maps of eleme
nts. | 411 // this conversion handles, how does that work? e.g. a list of maps of eleme
nts. |
408 var converted = convertNativeToDart_SerializedScriptValue(jsObject); | 412 var converted = convertNativeToDart_SerializedScriptValue(jsObject); |
409 if (!identical(converted, jsObject)) { | 413 if (!identical(converted, jsObject)) { |
410 return converted; | 414 return converted; |
411 } | 415 } |
412 var constructor = jsObject['constructor']; | 416 |
| 417 var constructor = js.JsNative.getProperty(jsObject, 'constructor'); |
413 if (__interop_checks) { | 418 if (__interop_checks) { |
414 debug_or_assert("constructor != null", constructor != null); | 419 debug_or_assert("constructor != null", constructor != null); |
415 } | 420 } |
416 var jsTypeName = constructor['name']; | 421 var jsTypeName = js.JsNative.getProperty(constructor, 'name'); |
417 if (__interop_checks) { | 422 if (__interop_checks) { |
418 debug_or_assert("constructor != null && jsTypeName.length > 0", constructo
r != null && jsTypeName.length > 0); | 423 debug_or_assert("constructor != null && jsTypeName.length > 0", constructo
r != null && jsTypeName.length > 0); |
419 } | 424 } |
420 | 425 |
421 var dartClass_instance; | 426 var dartClass_instance; |
422 if (jsObject.hasProperty('dart_class')) { | 427 if (jsObject.hasProperty('dart_class')) { |
423 // Got a dart_class (it's a custom element) use it it's already set up | 428 // Got a dart_class (it's a custom element) use it it's already set up |
424 // make sure it's upgraded. | 429 // make sure it's upgraded. |
425 dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']); | 430 dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']); |
426 } else { | 431 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
437 } | 442 } |
438 } else { | 443 } else { |
439 var func = getHtmlCreateFunction(jsTypeName); | 444 var func = getHtmlCreateFunction(jsTypeName); |
440 if (func != null) { | 445 if (func != null) { |
441 dartClass_instance = func(); | 446 dartClass_instance = func(); |
442 dartClass_instance.blink_jsObject = jsObject; | 447 dartClass_instance.blink_jsObject = jsObject; |
443 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); | 448 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); |
444 } | 449 } |
445 } | 450 } |
446 } | 451 } |
| 452 // TODO(jacobr): cache that this is not a dart:html JS class. |
447 return dartClass_instance; | 453 return dartClass_instance; |
448 } catch(e, stacktrace){ | 454 } catch(e, stacktrace){ |
449 if (__interop_checks) { | 455 if (__interop_checks) { |
450 if (e is DebugAssertException) | 456 if (e is DebugAssertException) |
451 window.console.log("${e.message}\n ${stacktrace}"); | 457 window.console.log("${e.message}\n ${stacktrace}"); |
452 else | 458 else |
453 window.console.log("${stacktrace}"); | 459 window.console.log("${stacktrace}"); |
454 } | 460 } |
455 } | 461 } |
456 | 462 |
457 return null; | 463 return null; |
458 } | 464 } |
459 | 465 |
460 /** | 466 /** |
| 467 * Create Dart class that maps to the JS Type, add the JsObject as an expando |
| 468 * on the Dart class and return the created Dart class. |
| 469 */ |
| 470 wrap_jso_no_SerializedScriptvalue(jsObject) { |
| 471 try { |
| 472 if (jsObject is! js.JsObject || jsObject == null) { |
| 473 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. |
| 474 // or it's a simple type. |
| 475 return jsObject; |
| 476 } |
| 477 |
| 478 // TODO(alanknight): With upgraded custom elements this causes a failure bec
ause |
| 479 // we need a new wrapper after the type changes. We could possibly invalidat
e this |
| 480 // if the constructor name didn't match? |
| 481 var wrapper = js.getDartHtmlWrapperFor(jsObject); |
| 482 if (wrapper != null) { |
| 483 return wrapper; |
| 484 } |
| 485 |
| 486 if (jsObject is js.JsArray) { |
| 487 var wrappingList = new _DartHtmlWrappingList(jsObject); |
| 488 js.setDartHtmlWrapperFor(jsObject, wrappingList); |
| 489 return wrappingList; |
| 490 } |
| 491 |
| 492 var constructor = js.JsNative.getProperty(jsObject, 'constructor'); |
| 493 if (__interop_checks) { |
| 494 debug_or_assert("constructor != null", constructor != null); |
| 495 } |
| 496 var jsTypeName = js.JsNative.getProperty(constructor, 'name'); |
| 497 if (__interop_checks) { |
| 498 debug_or_assert("constructor != null && jsTypeName.length > 0", constructo
r != null && jsTypeName.length > 0); |
| 499 } |
| 500 |
| 501 var func = getHtmlCreateFunction(jsTypeName); |
| 502 if (func != null) { |
| 503 var dartClass_instance = func(); |
| 504 dartClass_instance.blink_jsObject = jsObject; |
| 505 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); |
| 506 return dartClass_instance; |
| 507 } |
| 508 return jsObject; |
| 509 } catch(e, stacktrace){ |
| 510 if (__interop_checks) { |
| 511 if (e is DebugAssertException) |
| 512 window.console.log("${e.message}\n ${stacktrace}"); |
| 513 else |
| 514 window.console.log("${stacktrace}"); |
| 515 } |
| 516 } |
| 517 |
| 518 return null; |
| 519 } |
| 520 |
| 521 /** |
461 * Create Dart class that maps to the JS Type that is the JS type being | 522 * Create Dart class that maps to the JS Type that is the JS type being |
462 * extended using JS interop createCallback (we need the base type of the | 523 * extended using JS interop createCallback (we need the base type of the |
463 * custom element) not the Dart created constructor. | 524 * custom element) not the Dart created constructor. |
464 */ | 525 */ |
465 wrap_jso_custom_element(jsObject) { | 526 wrap_jso_custom_element(jsObject) { |
466 try { | 527 try { |
467 if (jsObject is! js.JsObject) { | 528 if (jsObject is! js.JsObject) { |
468 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. | 529 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. |
469 return jsObject; | 530 return jsObject; |
470 } | 531 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 603 |
543 _knownListeners.putIfAbsent(thisHashCode, () => new Map<int, js.JsFunction>())
; | 604 _knownListeners.putIfAbsent(thisHashCode, () => new Map<int, js.JsFunction>())
; |
544 _knownListeners[thisHashCode].putIfAbsent(listenerHashCode, () => | 605 _knownListeners[thisHashCode].putIfAbsent(listenerHashCode, () => |
545 new js.JsFunction.withThis((theObject, event) => listener(wrap_jso(event))))
; | 606 new js.JsFunction.withThis((theObject, event) => listener(wrap_jso(event))))
; |
546 | 607 |
547 return _knownListeners[thisHashCode][listenerHashCode]; | 608 return _knownListeners[thisHashCode][listenerHashCode]; |
548 } | 609 } |
549 | 610 |
550 Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) { | 611 Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) { |
551 var result = new Map(); | 612 var result = new Map(); |
552 var keys = js.context['Object'].callMethod('keys', [jsObject]); | 613 var keys = js.JsNative.callMethod(js.JsNative.getProperty(js.context, 'Object'
), 'keys', [jsObject]); |
553 for (var key in keys) { | 614 for (var key in keys) { |
554 result[key] = wrap_jso(jsObject[key]); | 615 result[key] = wrap_jso(js.JsNative.getProperty(jsObject, key)); |
555 } | 616 } |
556 return result; | 617 return result; |
557 } | 618 } |
558 | 619 |
559 // Converts a flat Dart map into a JavaScript object with properties this is | 620 // Converts a flat Dart map into a JavaScript object with properties this is |
560 // is the Dartium only version it uses dart:js. | 621 // is the Dartium only version it uses dart:js. |
561 // TODO(alanknight): This could probably be unified with the dart2js conversions | 622 // TODO(alanknight): This could probably be unified with the dart2js conversions |
562 // code in html_common and be more general. | 623 // code in html_common and be more general. |
563 convertDartToNative_Dictionary(Map dict) { | 624 convertDartToNative_Dictionary(Map dict) { |
564 if (dict == null) return null; | 625 if (dict == null) return null; |
565 var jsObject = new js.JsObject(js.context['Object']); | 626 var jsObject = new js.JsObject(js.JsNative.getProperty(js.context, 'Object')); |
566 dict.forEach((String key, value) { | 627 dict.forEach((String key, value) { |
567 if (value is List) { | 628 if (value is List) { |
568 var jsArray = new js.JsArray(); | 629 var jsArray = new js.JsArray(); |
569 value.forEach((elem) { | 630 value.forEach((elem) { |
570 jsArray.add(elem is Map ? convertDartToNative_Dictionary(elem): elem); | 631 jsArray.add(elem is Map ? convertDartToNative_Dictionary(elem): elem); |
571 }); | 632 }); |
572 jsObject[key] = jsArray; | 633 jsObject[key] = jsArray; |
573 } else { | 634 } else { |
574 jsObject[key] = value; | 635 jsObject[key] = value; |
575 } | 636 } |
576 }); | 637 }); |
577 return jsObject; | 638 return jsObject; |
578 } | 639 } |
579 | 640 |
580 // Converts a Dart list into a JsArray. For the Dartium version only. | 641 // Converts a Dart list into a JsArray. For the Dartium version only. |
581 convertDartToNative_List(List input) => new js.JsArray()..addAll(input); | 642 convertDartToNative_List(List input) => new js.JsArray()..addAll(input); |
582 | 643 |
583 // Conversion function place holder (currently not used in dart2js or dartium). | 644 // Conversion function place holder (currently not used in dart2js or dartium). |
584 List convertDartToNative_StringArray(List<String> input) => input; | 645 List convertDartToNative_StringArray(List<String> input) => input; |
585 | 646 |
586 /** | 647 /** |
587 * Wraps a JsArray and will call wrap_jso on its entries. | 648 * Wraps a JsArray and will call wrap_jso on its entries. |
588 */ | 649 */ |
589 class _DartHtmlWrappingList extends ListBase { | 650 class _DartHtmlWrappingList extends ListBase implements NativeFieldWrapperClass2
{ |
590 _DartHtmlWrappingList(this._basicList); | 651 _DartHtmlWrappingList(this.blink_jsObject); |
591 | 652 |
592 final js.JsArray _basicList; | 653 final js.JsArray blink_jsObject; |
593 | 654 |
594 operator [](int index) => wrap_jso(_basicList[index]); | 655 operator [](int index) => wrap_jso(js.JsNative.getArrayIndex(blink_jsObject, i
ndex)); |
595 | 656 |
596 operator []=(int index, value) => _basicList[index] = unwrap_jso(value); | 657 operator []=(int index, value) => blink_jsObject[index] = value; |
597 | 658 |
598 int get length => _basicList.length; | 659 int get length => blink_jsObject.length; |
599 int set length(int newLength) => _basicList.length = newLength; | 660 int set length(int newLength) => blink_jsObject.length = newLength; |
600 } | 661 } |
601 | 662 |
602 /** | 663 /** |
603 * Upgrade the JS HTMLElement to the Dart class. Used by Dart's Polymer. | 664 * Upgrade the JS HTMLElement to the Dart class. Used by Dart's Polymer. |
604 */ | 665 */ |
605 createCustomUpgrader(Type customElementClass, $this) { | 666 createCustomUpgrader(Type customElementClass, $this) { |
606 var dartClass; | 667 var dartClass; |
607 try { | 668 try { |
608 dartClass = _blink.Blink_Utils.constructElement(customElementClass, $this); | 669 dartClass = _blink.Blink_Utils.constructElement(customElementClass, $this); |
609 } catch (e) { | 670 } catch (e) { |
610 throw e; | 671 throw e; |
611 } finally { | 672 } finally { |
612 // Need to remember the Dart class that was created for this custom so | 673 // Need to remember the Dart class that was created for this custom so |
613 // return it and setup the blink_jsObject to the $this that we'll be working | 674 // return it and setup the blink_jsObject to the $this that we'll be working |
614 // with as we talk to blink. | 675 // with as we talk to blink. |
615 $this['dart_class'] = dartClass; | 676 js.setDartHtmlWrapperFor($this, dartClass); |
616 } | 677 } |
617 | 678 |
618 return dartClass; | 679 return dartClass; |
619 } | 680 } |
620 | 681 |
621 $else | 682 $else |
622 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {} | 683 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {} |
623 | 684 |
624 unwrap_jso(dartClass_instance) => dartClass_instance; | 685 unwrap_jso(dartClass_instance) => dartClass_instance; |
625 wrap_jso(jsObject) => jsObject; | 686 wrap_jso(jsObject) => jsObject; |
626 make_dart_rectangle(r) => r; | 687 make_dart_rectangle(r) => r; |
627 convertDartToNative_Dictionary(Map dict) => dict; | 688 convertDartToNative_Dictionary(Map dict) => dict; |
628 List convertDartToNative_StringArray(List<String> input) => input; | 689 List convertDartToNative_StringArray(List<String> input) => input; |
629 convertDartToNative_List(List input) => input; | 690 convertDartToNative_List(List input) => input; |
630 createCustomUpgrader(Type customElementClass, $this) => $this; | 691 createCustomUpgrader(Type customElementClass, $this) => $this; |
631 | 692 |
632 $endif | 693 $endif |
OLD | NEW |