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

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

Issue 1391143006: Fixed native element extension, custom events, _VMUpgrader, and data binding. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged conflicts 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, Map<Type, String>>(); 356 var _knownCustomElements = new Map<String, Map<Type, String>>();
357 357
358 void _addCustomElementType(String tagName, Type dartClass, [String extendTag]) { 358 void _addCustomElementType(String tagName, Type dartClass, [String extendTag]) {
359 _knownCustomElements[tagName] = 359 _knownCustomElements[tagName] =
360 {'type': dartClass, 'extends': extendTag != null ? extendTag : "" }; 360 {'type': dartClass, 'extends': extendTag != null ? extendTag : "" };
361 } 361 }
362 362
363 Type _getCustomElementType(object) { 363 Type _getCustomElementType(object) {
364 var entry = _knownCustomElements[_getCustomElementName(object)]; 364 var entry = _getCustomElementEntry(object);
365 if (entry != null) { 365 if (entry != null) {
366 return entry['type']; 366 return entry['type'];
367 } 367 }
368 return null; 368 return null;
369 } 369 }
370 370
371 String _getCustomElementExtends(object) { 371 String _getCustomElementExtends(object) {
372 var entry = _knownCustomElements[_getCustomElementName(object)]; 372 var entry = _getCustomElementEntry(object);
373 if (entry != null) { 373 if (entry != null) {
374 return entry['extends']; 374 return entry['extends'];
375 } 375 }
376 return null; 376 return null;
377 } 377 }
378 378
379 _getCustomElement(object) => _knownCustomElements[_getCustomElementName(object)] ; 379 _getCustomElementEntry(element) {
380 var hasAttribute = false;
381
382 var jsObject;
383 var tag = "";
384 var runtimeType = element.runtimeType;
385 if (runtimeType == HtmlElement) {
386 tag = element.localName;
387 } else if (runtimeType == TemplateElement) {
388 // Data binding with a Dart class.
389 tag = element.attributes['is'];
390 } else if (runtimeType == js.JsObjectImpl) {
391 // It's a Polymer core element (written in JS).
392 // Make sure it's an element anything else we can ignore.
393 if (element.hasProperty('nodeType') && element['nodeType'] == 1) {
394 if (js.JsNative.callMethod(element, 'hasAttribute', ['is'])) {
395 hasAttribute = true;
396 // It's data binding use the is attribute.
397 tag = js.JsNative.callMethod(element, 'getAttribute', ['is']);
398 } else {
399 // It's a custom element we want the local name.
400 tag = element['localName'];
401 }
402 }
403 } else {
404 throw new UnsupportedError('Element is incorrect type. Got ${runtimeType}, e xpected HtmlElement/HtmlTemplate/JsObjectImpl.');
405 }
406
407 var entry = _knownCustomElements[tag];
408 if (entry != null) {
409 // If there's an 'is' attribute then check if the extends tag registered
410 // matches the tag if so then return the entry that's registered for this
411 // extendsTag or if there's no 'is' tag then return the entry found.
412 if ((hasAttribute && entry['extends'] == tag) || !hasAttribute) {
413 return entry;
414 }
415 }
416
417 return null;
418 }
380 419
381 // Return the tag name or is attribute of the custom element or data binding. 420 // Return the tag name or is attribute of the custom element or data binding.
382 String _getCustomElementName(element) { 421 String _getCustomElementName(element) {
383 var jsObject; 422 var jsObject;
384 var tag = ""; 423 var tag = "";
385 var runtimeType = element.runtimeType; 424 var runtimeType = element.runtimeType;
386 if (runtimeType == HtmlElement) { 425 if (runtimeType == HtmlElement) {
387 tag = element.localName; 426 tag = element.localName;
388 } else if (runtimeType == TemplateElement) { 427 } else if (runtimeType == TemplateElement) {
389 // Data binding with a Dart class. 428 // Data binding with a Dart class.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 try { 483 try {
445 if (jsObject is! js.JsObject || jsObject == null) { 484 if (jsObject is! js.JsObject || jsObject == null) {
446 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. 485 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
447 // or it's a simple type. 486 // or it's a simple type.
448 return jsObject; 487 return jsObject;
449 } 488 }
450 489
451 var wrapper = js.getDartHtmlWrapperFor(jsObject); 490 var wrapper = js.getDartHtmlWrapperFor(jsObject);
452 // if we have a wrapper return the Dart instance. 491 // if we have a wrapper return the Dart instance.
453 if (wrapper != null) { 492 if (wrapper != null) {
454 if (wrapper.runtimeType == HtmlElement && !wrapper._isBadUpgrade) { 493 var customElementClass = _getCustomElementType(wrapper.blink_jsObject);
455 // We're a Dart instance but we need to upgrade. 494 if (wrapper.runtimeType != customElementClass && customElementClass != nul l) {
456 var customElementClass = _getCustomElementType(wrapper); 495 if (wrapper.runtimeType == HtmlElement && !wrapper._isBadUpgrade) {
457 if (customElementClass != null) { 496 // We're a Dart instance if it's HtmlElement and we have a customEleme nt
458 var dartClass_instance; 497 // class then we need to upgrade.
459 try { 498 if (customElementClass != null) {
460 dartClass_instance = _blink.Blink_Utils.constructElement(customEleme ntClass, jsObject); 499 var dartClass_instance;
461 } finally { 500 try {
462 dartClass_instance.blink_jsObject = jsObject; 501 dartClass_instance = _blink.Blink_Utils.constructElement(customEle mentClass, jsObject);
463 jsObject['dart_class'] = dartClass_instance; 502 } finally {
464 js.setDartHtmlWrapperFor(jsObject, dartClass_instance); 503 dartClass_instance.blink_jsObject = jsObject;
465 return dartClass_instance; 504 return dartClass_instance;
505 }
466 } 506 }
467 } 507 }
468 } 508 }
469 509
470 return wrapper; 510 return wrapper;
471 } 511 }
472 512
473 if (jsObject is js.JsArray) { 513 if (jsObject is js.JsArray) {
474 var wrappingList = new _DartHtmlWrappingList(jsObject); 514 var wrappingList = new _DartHtmlWrappingList(jsObject);
475 js.setDartHtmlWrapperFor(jsObject, wrappingList); 515 js.setDartHtmlWrapperFor(jsObject, wrappingList);
(...skipping 17 matching lines...) Expand all
493 return jsObject; 533 return jsObject;
494 } 534 }
495 var jsTypeName = js.JsNative.getProperty(constructor, 'name'); 535 var jsTypeName = js.JsNative.getProperty(constructor, 'name');
496 if (jsTypeName is! String || jsTypeName.length == 0) { 536 if (jsTypeName is! String || jsTypeName.length == 0) {
497 // Not an html type. 537 // Not an html type.
498 js.setDartHtmlWrapperFor(jsObject, jsObject); 538 js.setDartHtmlWrapperFor(jsObject, jsObject);
499 return jsObject; 539 return jsObject;
500 } 540 }
501 541
502 var dartClass_instance; 542 var dartClass_instance;
503 if (jsObject.hasProperty('dart_class')) { 543 var customElementClass = null;
504 // Got a dart_class (it's a custom element) use it it's already set up 544 var extendsTag = "";
505 // make sure it's upgraded. 545 var custom = _getCustomElementEntry(jsObject);
506 dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']); 546 if (custom != null) {
547 customElementClass = custom['type'];
548 extendsTag = custom['extends'];
549 }
550
551 // Custom Element to upgrade.
552 if (customElementClass != null && extendsTag == "") {
553 try {
554 dartClass_instance = _blink.Blink_Utils.constructElement(customElementCl ass, jsObject);
555 } finally {
556 dartClass_instance.blink_jsObject = jsObject;
557 js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
558 }
507 } else { 559 } else {
508 var customElementClass = null; 560 var func = getHtmlCreateFunction(jsTypeName);
509 var extendsTag = ""; 561 if (func == null) {
510 var custom = _getCustomElement(jsObject);
511 if (custom != null) {
512 customElementClass = custom['type'];
513 extendsTag = custom['extends'];
514 }
515 // Custom Element to upgrade.
516 if (jsTypeName == 'HTMLElement' && customElementClass != null && extendsTa g == "") {
517 try {
518 dartClass_instance = _blink.Blink_Utils.constructElement(customElement Class, jsObject);
519 } finally {
520 dartClass_instance.blink_jsObject = jsObject;
521 jsObject['dart_class'] = dartClass_instance;
522 js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
523 }
524 } else {
525 // TODO(terry): Verify with jakemacd that this is right?
526 // If we every get an auto-binding we're matching previous non-JS Intero p
527 // did to return a TemplateElement.
528 if (jsTypeName == 'auto-binding') { 562 if (jsTypeName == 'auto-binding') {
529 jsTypeName = "HTMLTemplateElement"; 563 func = getHtmlCreateFunction("HTMLTemplateElement");
530 } 564 } else if (jsObject.toString() == "[object HTMLElement]") {
531
532 var func = getHtmlCreateFunction(jsTypeName);
533 if (func == null) {
534 // One last ditch effort could be a JS custom element. 565 // One last ditch effort could be a JS custom element.
535 if (jsObject.toString() == "[object HTMLElement]") { 566 func = getHtmlCreateFunction("HTMLElement");
536 func = getHtmlCreateFunction("HTMLElement");
537 }
538 }
539 if (func != null) {
540 dartClass_instance = func();
541 dartClass_instance.blink_jsObject = jsObject;
542 js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
543 } 567 }
544 } 568 }
569 if (func != null) {
570 dartClass_instance = func();
571 dartClass_instance.blink_jsObject = jsObject;
572 js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
573 }
545 } 574 }
575
546 // TODO(jacobr): cache that this is not a dart:html JS class. 576 // TODO(jacobr): cache that this is not a dart:html JS class.
547 return dartClass_instance; 577 return dartClass_instance;
548 } catch(e, stacktrace){ 578 } catch(e, stacktrace){
549 if (__interop_checks) { 579 if (__interop_checks) {
550 if (e is DebugAssertException) 580 if (e is DebugAssertException)
551 window.console.log("${e.message}\n ${stacktrace}"); 581 window.console.log("${e.message}\n ${stacktrace}");
552 else 582 else
553 window.console.log("${stacktrace}"); 583 window.console.log("${stacktrace}");
554 } 584 }
555 } 585 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 697
668 // Custom Element to upgrade. 698 // Custom Element to upgrade.
669 if (customElementClass != null) { 699 if (customElementClass != null) {
670 var jsObject = dartInstance.blink_jsObject; 700 var jsObject = dartInstance.blink_jsObject;
671 try { 701 try {
672 dartInstance = _blink.Blink_Utils.constructElement(customElementClass, j sObject); 702 dartInstance = _blink.Blink_Utils.constructElement(customElementClass, j sObject);
673 } catch (e) { 703 } catch (e) {
674 dartInstance._badUpgrade(); 704 dartInstance._badUpgrade();
675 } finally { 705 } finally {
676 dartInstance.blink_jsObject = jsObject; 706 dartInstance.blink_jsObject = jsObject;
677 jsObject['dart_class'] = dartInstance;
678 js.setDartHtmlWrapperFor(jsObject, dartInstance); 707 js.setDartHtmlWrapperFor(jsObject, dartInstance);
679 } 708 }
680 } 709 }
681 } 710 }
682 711
683 return dartInstance; 712 return dartInstance;
684 } 713 }
685 714
686 class DebugAssertException implements Exception { 715 class DebugAssertException implements Exception {
687 String message; 716 String message;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 817
789 unwrap_jso(dartClass_instance) => dartClass_instance; 818 unwrap_jso(dartClass_instance) => dartClass_instance;
790 wrap_jso(jsObject) => jsObject; 819 wrap_jso(jsObject) => jsObject;
791 make_dart_rectangle(r) => r; 820 make_dart_rectangle(r) => r;
792 convertDartToNative_Dictionary(Map dict) => dict; 821 convertDartToNative_Dictionary(Map dict) => dict;
793 List convertDartToNative_StringArray(List<String> input) => input; 822 List convertDartToNative_StringArray(List<String> input) => input;
794 convertDartToNative_List(List input) => input; 823 convertDartToNative_List(List input) => input;
795 createCustomUpgrader(Type customElementClass, $this) => $this; 824 createCustomUpgrader(Type customElementClass, $this) => $this;
796 825
797 $endif 826 $endif
OLDNEW
« no previous file with comments | « tools/dom/src/dartium_CustomElementSupport.dart ('k') | tools/dom/templates/html/impl/impl_CustomEvent.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698