| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 /****************************************************************************** | 349 /****************************************************************************** |
| 350 ********** ********** | 350 ********** ********** |
| 351 ********** JS Interop Support ********** | 351 ********** JS Interop Support ********** |
| 352 ********** ********** | 352 ********** ********** |
| 353 ******************************************************************************/ | 353 ******************************************************************************/ |
| 354 | 354 |
| 355 // List of known tagName to DartClass for custom elements, used for upgrade. | 355 // List of known tagName to DartClass for custom elements, used for upgrade. |
| 356 var _knownCustomElements = new Map<String, Type>(); | 356 var _knownCustomElements = new Map<String, Type>(); |
| 357 | 357 |
| 358 void _addCustomElementType(String tagName, Type dartClass) { |
| 359 _knownCustomElements[tagName] = dartClass; |
| 360 } |
| 361 |
| 362 Type _getCustomElementType(object) => _knownCustomElements[_getCustomElementName
(object)]; |
| 363 |
| 358 // Return the tag name or is attribute of the custom element or data binding. | 364 // Return the tag name or is attribute of the custom element or data binding. |
| 359 String _getCustomElementName(element) { | 365 String _getCustomElementName(element) { |
| 360 var jsObject; | 366 var jsObject; |
| 361 var tag = ""; | 367 var tag = ""; |
| 362 var runtimeType = element.runtimeType; | 368 var runtimeType = element.runtimeType; |
| 363 if (runtimeType == HtmlElement) { | 369 if (runtimeType == HtmlElement) { |
| 364 tag = element.localName; | 370 tag = element.localName; |
| 365 } else if (runtimeType == TemplateElement) { | 371 } else if (runtimeType == TemplateElement) { |
| 366 // Data binding with a Dart class. | 372 // Data binding with a Dart class. |
| 367 tag = element.attributes['is']; | 373 tag = element.attributes['is']; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. | 429 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. |
| 424 // or it's a simple type. | 430 // or it's a simple type. |
| 425 return jsObject; | 431 return jsObject; |
| 426 } | 432 } |
| 427 | 433 |
| 428 var wrapper = js.getDartHtmlWrapperFor(jsObject); | 434 var wrapper = js.getDartHtmlWrapperFor(jsObject); |
| 429 // if we have a wrapper and and it's an upgraded custom element return the D
art instance. | 435 // if we have a wrapper and and it's an upgraded custom element return the D
art instance. |
| 430 if (wrapper != null) { | 436 if (wrapper != null) { |
| 431 if (wrapper.runtimeType == HtmlElement && !wrapper._isBadUpgrade) { | 437 if (wrapper.runtimeType == HtmlElement && !wrapper._isBadUpgrade) { |
| 432 // We're a Dart instance but we need to upgrade. | 438 // We're a Dart instance but we need to upgrade. |
| 433 var tagName = _getCustomElementName(wrapper); | 439 var customElementClass = _getCustomElementType(wrapper); |
| 434 var customElementClass = _knownCustomElements[tagName]; | |
| 435 if (customElementClass != null) { | 440 if (customElementClass != null) { |
| 436 var dartClass_instance; | 441 var dartClass_instance; |
| 437 try { | 442 try { |
| 438 dartClass_instance = _blink.Blink_Utils.constructElement(customEleme
ntClass, jsObject); | 443 dartClass_instance = _blink.Blink_Utils.constructElement(customEleme
ntClass, jsObject); |
| 439 } finally { | 444 } finally { |
| 440 dartClass_instance.blink_jsObject = jsObject; | 445 dartClass_instance.blink_jsObject = jsObject; |
| 441 jsObject['dart_class'] = dartClass_instance; | 446 jsObject['dart_class'] = dartClass_instance; |
| 442 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); | 447 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); |
| 443 return dartClass_instance; | 448 return dartClass_instance; |
| 444 } | 449 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 js.setDartHtmlWrapperFor(jsObject, jsObject); | 481 js.setDartHtmlWrapperFor(jsObject, jsObject); |
| 477 return jsObject; | 482 return jsObject; |
| 478 } | 483 } |
| 479 | 484 |
| 480 var dartClass_instance; | 485 var dartClass_instance; |
| 481 if (jsObject.hasProperty('dart_class')) { | 486 if (jsObject.hasProperty('dart_class')) { |
| 482 // Got a dart_class (it's a custom element) use it it's already set up | 487 // Got a dart_class (it's a custom element) use it it's already set up |
| 483 // make sure it's upgraded. | 488 // make sure it's upgraded. |
| 484 dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']); | 489 dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']); |
| 485 } else { | 490 } else { |
| 486 var tagName = _getCustomElementName(jsObject); | 491 var customElementClass = _getCustomElementType(jsObject); |
| 487 var customElementClass = _knownCustomElements[tagName]; | |
| 488 // Custom Element to upgrade. | 492 // Custom Element to upgrade. |
| 489 if (jsTypeName == 'HTMLElement' && customElementClass != null) { | 493 if (jsTypeName == 'HTMLElement' && customElementClass != null) { |
| 490 try { | 494 try { |
| 491 dartClass_instance = _blink.Blink_Utils.constructElement(customElement
Class, jsObject); | 495 dartClass_instance = _blink.Blink_Utils.constructElement(customElement
Class, jsObject); |
| 492 } finally { | 496 } finally { |
| 493 dartClass_instance.blink_jsObject = jsObject; | 497 dartClass_instance.blink_jsObject = jsObject; |
| 494 jsObject['dart_class'] = dartClass_instance; | 498 jsObject['dart_class'] = dartClass_instance; |
| 495 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); | 499 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); |
| 496 } | 500 } |
| 497 } else { | 501 } else { |
| 498 // TODO(terry): Verify with jakemacd that this is right? | 502 // TODO(terry): Verify with jakemacd that this is right? |
| 499 // If we every get an auto-binding we're matching previous non-JS Intero
p | 503 // If we every get an auto-binding we're matching previous non-JS Intero
p |
| 500 // did to return a TemplateElement. | 504 // did to return a TemplateElement. |
| 501 if (jsTypeName == 'auto-binding') { | 505 if (jsTypeName == 'auto-binding') { |
| 502 jsTypeName = "HTMLTemplateElement"; | 506 jsTypeName = "HTMLTemplateElement"; |
| 503 } | 507 } |
| 504 | 508 |
| 505 var func = getHtmlCreateFunction(jsTypeName); | 509 var func = getHtmlCreateFunction(jsTypeName); |
| 510 if (func == null) { |
| 511 // One last ditch effort could be a JS custom element. |
| 512 if (jsObject.toString() == "[object HTMLElement]") { |
| 513 func = getHtmlCreateFunction("HTMLElement"); |
| 514 } |
| 515 } |
| 506 if (func != null) { | 516 if (func != null) { |
| 507 dartClass_instance = func(); | 517 dartClass_instance = func(); |
| 508 dartClass_instance.blink_jsObject = jsObject; | 518 dartClass_instance.blink_jsObject = jsObject; |
| 509 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); | 519 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); |
| 510 } | 520 } |
| 511 } | 521 } |
| 512 } | 522 } |
| 513 // TODO(jacobr): cache that this is not a dart:html JS class. | 523 // TODO(jacobr): cache that this is not a dart:html JS class. |
| 514 return dartClass_instance; | 524 return dartClass_instance; |
| 515 } catch(e, stacktrace){ | 525 } catch(e, stacktrace){ |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 return null; | 632 return null; |
| 623 } | 633 } |
| 624 } | 634 } |
| 625 | 635 |
| 626 // Upgrade a Dart HtmlElement to the user's Dart custom element class. | 636 // Upgrade a Dart HtmlElement to the user's Dart custom element class. |
| 627 _upgradeHtmlElement(dartInstance) { | 637 _upgradeHtmlElement(dartInstance) { |
| 628 // Only try upgrading HtmlElement (Dart class) if there is a failure then | 638 // Only try upgrading HtmlElement (Dart class) if there is a failure then |
| 629 // don't try it again - one failure is enough. | 639 // don't try it again - one failure is enough. |
| 630 if (dartInstance.runtimeType == HtmlElement && !dartInstance._isBadUpgrade) { | 640 if (dartInstance.runtimeType == HtmlElement && !dartInstance._isBadUpgrade) { |
| 631 // Must be exactly HtmlElement not something derived from it. | 641 // Must be exactly HtmlElement not something derived from it. |
| 632 var jsObject = dartInstance.blink_jsObject; | 642 |
| 633 var tagName = _getCustomElementName(dartInstance); | 643 var customElementClass = _getCustomElementType(dartInstance); |
| 634 var customElementClass = _knownCustomElements[tagName]; | 644 |
| 635 // Custom Element to upgrade. | 645 // Custom Element to upgrade. |
| 636 if (customElementClass != null) { | 646 if (customElementClass != null) { |
| 647 var jsObject = dartInstance.blink_jsObject; |
| 637 try { | 648 try { |
| 638 dartInstance = _blink.Blink_Utils.constructElement(customElementClass, j
sObject); | 649 dartInstance = _blink.Blink_Utils.constructElement(customElementClass, j
sObject); |
| 639 } catch (e) { | 650 } catch (e) { |
| 640 dartInstance._badUpgrade(); | 651 dartInstance._badUpgrade(); |
| 641 } finally { | 652 } finally { |
| 642 dartInstance.blink_jsObject = jsObject; | 653 dartInstance.blink_jsObject = jsObject; |
| 643 jsObject['dart_class'] = dartInstance; | 654 jsObject['dart_class'] = dartInstance; |
| 644 js.setDartHtmlWrapperFor(jsObject, dartInstance); | 655 js.setDartHtmlWrapperFor(jsObject, dartInstance); |
| 645 } | 656 } |
| 646 } | 657 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 | 765 |
| 755 unwrap_jso(dartClass_instance) => dartClass_instance; | 766 unwrap_jso(dartClass_instance) => dartClass_instance; |
| 756 wrap_jso(jsObject) => jsObject; | 767 wrap_jso(jsObject) => jsObject; |
| 757 make_dart_rectangle(r) => r; | 768 make_dart_rectangle(r) => r; |
| 758 convertDartToNative_Dictionary(Map dict) => dict; | 769 convertDartToNative_Dictionary(Map dict) => dict; |
| 759 List convertDartToNative_StringArray(List<String> input) => input; | 770 List convertDartToNative_StringArray(List<String> input) => input; |
| 760 convertDartToNative_List(List input) => input; | 771 convertDartToNative_List(List input) => input; |
| 761 createCustomUpgrader(Type customElementClass, $this) => $this; | 772 createCustomUpgrader(Type customElementClass, $this) => $this; |
| 762 | 773 |
| 763 $endif | 774 $endif |
| OLD | NEW |