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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/templates/html/dartium/html_dartium.darttemplate
diff --git a/tools/dom/templates/html/dartium/html_dartium.darttemplate b/tools/dom/templates/html/dartium/html_dartium.darttemplate
index 2fde7a039794ee680599f376b60ac370c3df8cc4..bb286402efe2af2cd13c1147b710fc85606c67dd 100644
--- a/tools/dom/templates/html/dartium/html_dartium.darttemplate
+++ b/tools/dom/templates/html/dartium/html_dartium.darttemplate
@@ -353,7 +353,36 @@ Function _getSvgFunction(String key) {
******************************************************************************/
// List of known tagName to DartClass for custom elements, used for upgrade.
-var _knownCustomeElements = new Map<String, Type>();
+var _knownCustomElements = new Map<String, Type>();
+
+// Return the tag name or is attribute of the custom element or data binding.
+String _getCustomElementName(element) {
+ var jsObject;
+ var tag = "";
+ var runtimeType = element.runtimeType;
+ if (runtimeType == HtmlElement) {
+ tag = element.localName;
+ } else if (runtimeType == TemplateElement) {
+ // Data binding with a Dart class.
+ tag = element.attributes['is'];
+ } else if (runtimeType == js.JsObjectImpl) {
+ // It's a Polymer core element (written in JS).
+ // Make sure it's an element anything else we can ignore.
+ if (element.hasProperty('nodeType') && element['nodeType'] == 1) {
+ if (js.JsNative.callMethod(element, 'hasAttribute', ['is'])) {
+ // It's data binding use the is attribute.
+ tag = js.JsNative.callMethod(element, 'getAttribute', ['is']);
+ } else {
+ // It's a custom element we want the local name.
+ tag = element['localName'];
+ }
+ }
+ } else {
+ throw new UnsupportedError('Element is incorrect type. Got ${runtimeType}, expected HtmlElement/HtmlTemplate/JsObjectImpl.');
+ }
+
+ return tag;
+}
Rectangle make_dart_rectangle(r) =>
r == null ? null : new Rectangle(
@@ -396,11 +425,26 @@ wrap_jso(jsObject) {
return jsObject;
}
- // TODO(alanknight): With upgraded custom elements this causes a failure because
- // we need a new wrapper after the type changes. We could possibly invalidate this
- // if the constructor name didn't match?
var wrapper = js.getDartHtmlWrapperFor(jsObject);
+ // if we have a wrapper and and it's an upgraded custom element return the Dart instance.
if (wrapper != null) {
+ if (wrapper.runtimeType == HtmlElement && !wrapper._isBadUpgrade) {
+ // We're a Dart instance but we need to upgrade.
+ var tagName = _getCustomElementName(wrapper);
+ var customElementClass = _knownCustomElements[tagName];
+ if (customElementClass != null) {
+ var dartClass_instance;
+ try {
+ dartClass_instance = _blink.Blink_Utils.constructElement(customElementClass, jsObject);
+ } finally {
+ dartClass_instance.blink_jsObject = jsObject;
+ jsObject['dart_class'] = dartClass_instance;
+ js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
+ return dartClass_instance;
+ }
+ }
+ }
+
return wrapper;
}
@@ -439,8 +483,8 @@ wrap_jso(jsObject) {
// make sure it's upgraded.
dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']);
} else {
- var localName = jsObject['localName'];
- var customElementClass = _knownCustomeElements[localName];
+ var tagName = _getCustomElementName(jsObject);
+ var customElementClass = _knownCustomElements[tagName];
// Custom Element to upgrade.
if (jsTypeName == 'HTMLElement' && customElementClass != null) {
try {
@@ -451,6 +495,13 @@ wrap_jso(jsObject) {
js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
}
} else {
+ // TODO(terry): Verify with jakemacd that this is right?
+ // If we every get an auto-binding we're matching previous non-JS Interop
+ // did to return a TemplateElement.
+ if (jsTypeName == 'auto-binding') {
+ jsTypeName = "HTMLTemplateElement";
+ }
+
var func = getHtmlCreateFunction(jsTypeName);
if (func != null) {
dartClass_instance = func();
@@ -579,8 +630,8 @@ _upgradeHtmlElement(dartInstance) {
if (dartInstance.runtimeType == HtmlElement && !dartInstance._isBadUpgrade) {
// Must be exactly HtmlElement not something derived from it.
var jsObject = dartInstance.blink_jsObject;
- var localName = dartInstance.localName;
- var customElementClass = _knownCustomeElements[localName];
+ var tagName = _getCustomElementName(dartInstance);
+ var customElementClass = _knownCustomElements[tagName];
// Custom Element to upgrade.
if (customElementClass != null) {
try {
« 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