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

Side by Side Diff: tools/dom/templates/html/dartium/html_dartium.darttemplate

Issue 1403623002: Fixed upgrading and data binding (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged Created 5 years, 2 months 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
OLDNEW
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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 346 }
347 347
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 _knownCustomeElements = new Map<String, Type>(); 356 var _knownCustomElements = new Map<String, Type>();
357
358 // Return the tag name or is attribute of the custom element or data binding.
359 String _getCustomElementName(element) {
360 var jsObject;
361 var tag = "";
362 var runtimeType = element.runtimeType;
363 if (runtimeType == HtmlElement) {
364 tag = element.localName;
365 } else if (runtimeType == TemplateElement) {
366 // Data binding with a Dart class.
367 tag = element.attributes['is'];
368 } else if (runtimeType == js.JsObjectImpl) {
369 // It's a Polymer core element (written in JS).
370 // Make sure it's an element anything else we can ignore.
371 if (element.hasProperty('nodeType') && element['nodeType'] == 1) {
372 if (js.JsNative.callMethod(element, 'hasAttribute', ['is'])) {
373 // It's data binding use the is attribute.
374 tag = js.JsNative.callMethod(element, 'getAttribute', ['is']);
375 } else {
376 // It's a custom element we want the local name.
377 tag = element['localName'];
378 }
379 }
380 } else {
381 throw new UnsupportedError('Element is incorrect type. Got ${runtimeType}, e xpected HtmlElement/HtmlTemplate/JsObjectImpl.');
382 }
383
384 return tag;
385 }
357 386
358 Rectangle make_dart_rectangle(r) => 387 Rectangle make_dart_rectangle(r) =>
359 r == null ? null : new Rectangle( 388 r == null ? null : new Rectangle(
360 js.JsNative.getProperty(r, 'left'), 389 js.JsNative.getProperty(r, 'left'),
361 js.JsNative.getProperty(r, 'top'), 390 js.JsNative.getProperty(r, 'top'),
362 js.JsNative.getProperty(r, 'width'), 391 js.JsNative.getProperty(r, 'width'),
363 js.JsNative.getProperty(r, 'height')); 392 js.JsNative.getProperty(r, 'height'));
364 393
365 /// An abstract class for all DOM objects we wrap in dart:html and related 394 /// An abstract class for all DOM objects we wrap in dart:html and related
366 /// libraries. 395 /// libraries.
(...skipping 22 matching lines...) Expand all
389 * on the Dart class and return the created Dart class. 418 * on the Dart class and return the created Dart class.
390 */ 419 */
391 wrap_jso(jsObject) { 420 wrap_jso(jsObject) {
392 try { 421 try {
393 if (jsObject is! js.JsObject || jsObject == null) { 422 if (jsObject is! js.JsObject || jsObject == null) {
394 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. 423 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
395 // or it's a simple type. 424 // or it's a simple type.
396 return jsObject; 425 return jsObject;
397 } 426 }
398 427
399 // TODO(alanknight): With upgraded custom elements this causes a failure bec ause
400 // we need a new wrapper after the type changes. We could possibly invalidat e this
401 // if the constructor name didn't match?
402 var wrapper = js.getDartHtmlWrapperFor(jsObject); 428 var wrapper = js.getDartHtmlWrapperFor(jsObject);
429 // if we have a wrapper and and it's an upgraded custom element return the D art instance.
403 if (wrapper != null) { 430 if (wrapper != null) {
431 if (wrapper.runtimeType == HtmlElement && !wrapper._isBadUpgrade) {
432 // We're a Dart instance but we need to upgrade.
433 var tagName = _getCustomElementName(wrapper);
434 var customElementClass = _knownCustomElements[tagName];
435 if (customElementClass != null) {
436 var dartClass_instance;
437 try {
438 dartClass_instance = _blink.Blink_Utils.constructElement(customEleme ntClass, jsObject);
439 } finally {
440 dartClass_instance.blink_jsObject = jsObject;
441 jsObject['dart_class'] = dartClass_instance;
442 js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
443 return dartClass_instance;
444 }
445 }
446 }
447
404 return wrapper; 448 return wrapper;
405 } 449 }
406 450
407 if (jsObject is js.JsArray) { 451 if (jsObject is js.JsArray) {
408 var wrappingList = new _DartHtmlWrappingList(jsObject); 452 var wrappingList = new _DartHtmlWrappingList(jsObject);
409 js.setDartHtmlWrapperFor(jsObject, wrappingList); 453 js.setDartHtmlWrapperFor(jsObject, wrappingList);
410 return wrappingList; 454 return wrappingList;
411 } 455 }
412 456
413 // Try the most general type conversions on it. 457 // Try the most general type conversions on it.
(...skipping 18 matching lines...) Expand all
432 js.setDartHtmlWrapperFor(jsObject, jsObject); 476 js.setDartHtmlWrapperFor(jsObject, jsObject);
433 return jsObject; 477 return jsObject;
434 } 478 }
435 479
436 var dartClass_instance; 480 var dartClass_instance;
437 if (jsObject.hasProperty('dart_class')) { 481 if (jsObject.hasProperty('dart_class')) {
438 // Got a dart_class (it's a custom element) use it it's already set up 482 // Got a dart_class (it's a custom element) use it it's already set up
439 // make sure it's upgraded. 483 // make sure it's upgraded.
440 dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']); 484 dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']);
441 } else { 485 } else {
442 var localName = jsObject['localName']; 486 var tagName = _getCustomElementName(jsObject);
443 var customElementClass = _knownCustomeElements[localName]; 487 var customElementClass = _knownCustomElements[tagName];
444 // Custom Element to upgrade. 488 // Custom Element to upgrade.
445 if (jsTypeName == 'HTMLElement' && customElementClass != null) { 489 if (jsTypeName == 'HTMLElement' && customElementClass != null) {
446 try { 490 try {
447 dartClass_instance = _blink.Blink_Utils.constructElement(customElement Class, jsObject); 491 dartClass_instance = _blink.Blink_Utils.constructElement(customElement Class, jsObject);
448 } finally { 492 } finally {
449 dartClass_instance.blink_jsObject = jsObject; 493 dartClass_instance.blink_jsObject = jsObject;
450 jsObject['dart_class'] = dartClass_instance; 494 jsObject['dart_class'] = dartClass_instance;
451 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); 495 js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
452 } 496 }
453 } else { 497 } else {
498 // 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
500 // did to return a TemplateElement.
501 if (jsTypeName == 'auto-binding') {
502 jsTypeName = "HTMLTemplateElement";
503 }
504
454 var func = getHtmlCreateFunction(jsTypeName); 505 var func = getHtmlCreateFunction(jsTypeName);
455 if (func != null) { 506 if (func != null) {
456 dartClass_instance = func(); 507 dartClass_instance = func();
457 dartClass_instance.blink_jsObject = jsObject; 508 dartClass_instance.blink_jsObject = jsObject;
458 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); 509 js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
459 } 510 }
460 } 511 }
461 } 512 }
462 // TODO(jacobr): cache that this is not a dart:html JS class. 513 // TODO(jacobr): cache that this is not a dart:html JS class.
463 return dartClass_instance; 514 return dartClass_instance;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 623 }
573 } 624 }
574 625
575 // Upgrade a Dart HtmlElement to the user's Dart custom element class. 626 // Upgrade a Dart HtmlElement to the user's Dart custom element class.
576 _upgradeHtmlElement(dartInstance) { 627 _upgradeHtmlElement(dartInstance) {
577 // Only try upgrading HtmlElement (Dart class) if there is a failure then 628 // Only try upgrading HtmlElement (Dart class) if there is a failure then
578 // don't try it again - one failure is enough. 629 // don't try it again - one failure is enough.
579 if (dartInstance.runtimeType == HtmlElement && !dartInstance._isBadUpgrade) { 630 if (dartInstance.runtimeType == HtmlElement && !dartInstance._isBadUpgrade) {
580 // Must be exactly HtmlElement not something derived from it. 631 // Must be exactly HtmlElement not something derived from it.
581 var jsObject = dartInstance.blink_jsObject; 632 var jsObject = dartInstance.blink_jsObject;
582 var localName = dartInstance.localName; 633 var tagName = _getCustomElementName(dartInstance);
583 var customElementClass = _knownCustomeElements[localName]; 634 var customElementClass = _knownCustomElements[tagName];
584 // Custom Element to upgrade. 635 // Custom Element to upgrade.
585 if (customElementClass != null) { 636 if (customElementClass != null) {
586 try { 637 try {
587 dartInstance = _blink.Blink_Utils.constructElement(customElementClass, j sObject); 638 dartInstance = _blink.Blink_Utils.constructElement(customElementClass, j sObject);
588 } catch (e) { 639 } catch (e) {
589 dartInstance._badUpgrade(); 640 dartInstance._badUpgrade();
590 } finally { 641 } finally {
591 dartInstance.blink_jsObject = jsObject; 642 dartInstance.blink_jsObject = jsObject;
592 jsObject['dart_class'] = dartInstance; 643 jsObject['dart_class'] = dartInstance;
593 js.setDartHtmlWrapperFor(jsObject, dartInstance); 644 js.setDartHtmlWrapperFor(jsObject, dartInstance);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 754
704 unwrap_jso(dartClass_instance) => dartClass_instance; 755 unwrap_jso(dartClass_instance) => dartClass_instance;
705 wrap_jso(jsObject) => jsObject; 756 wrap_jso(jsObject) => jsObject;
706 make_dart_rectangle(r) => r; 757 make_dart_rectangle(r) => r;
707 convertDartToNative_Dictionary(Map dict) => dict; 758 convertDartToNative_Dictionary(Map dict) => dict;
708 List convertDartToNative_StringArray(List<String> input) => input; 759 List convertDartToNative_StringArray(List<String> input) => input;
709 convertDartToNative_List(List input) => input; 760 convertDartToNative_List(List input) => input;
710 createCustomUpgrader(Type customElementClass, $this) => $this; 761 createCustomUpgrader(Type customElementClass, $this) => $this;
711 762
712 $endif 763 $endif
OLDNEW
« no previous file with comments | « tools/dom/src/dartium_CustomElementSupport.dart ('k') | tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698