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

Unified Diff: tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate

Issue 17706003: update MDV impl (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 7 years, 6 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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate b/tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate
index 1aba301acaa2bd5a2de28040e91baaa5191e2a4f..600e12cb7305f37e287fe6dad714a2f45db14f2b 100644
--- a/tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate
+++ b/tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate
@@ -141,25 +141,40 @@ $!MEMBERS
// == true check because it starts as a null field.
if (template._templateIsDecorated == true) return false;
- template._templateIsDecorated = true;
-
_injectStylesheet();
- // Create content
- if (template is! TemplateElement) {
- var doc = _getTemplateContentsOwner(template.document);
- template._templateContent = doc.createDocumentFragment();
- }
+ var templateElement = template;
+ var isNative = templateElement is TemplateElement;
+ var bootstrapContents = isNative;
+ var liftContents = !isNative;
+ var liftRoot = false;
+
+ if (!isNative && templateElement._isAttributeTemplate) {
+ if (instanceRef != null) {
+ // TODO(jmesserly): this is just an assert in MDV.
+ throw new ArgumentError('instanceRef should not be supplied for '
+ 'attribute templates.');
+ }
+ templateElement = _extractTemplateFromAttributeTemplate(template);
+ isNative = templateElement is TemplateElement;
+ liftRoot = true;
+ }
- if (instanceRef != null) {
- template._templateInstanceRef = instanceRef;
- return true; // content is empty.
+ templateElement._templateIsDecorated = true;
+
+ if (!isNative) {
+ var doc = _getTemplateContentsOwner(templateElement.document);
+ templateElement._templateContent = doc.createDocumentFragment();
}
- if (template is TemplateElement) {
- bootstrap(template.content);
- } else {
- _liftNonNativeChildrenIntoContent(template);
+ if (instanceRef != null) {
+ // template is contained within an instance, its direct content must be
+ // empty
+ templateElement._templateInstanceRef = instanceRef;
+ } else if (liftContents) {
+ _liftNonNativeChildrenIntoContent(templateElement, template, liftRoot);
+ } else if (bootstrapContents) {
+ bootstrap(templateElement.content);
}
return true;
@@ -183,54 +198,52 @@ $!MEMBERS
return d;
}
- static Element _cloneAndSeperateAttributeTemplate(Element templateElement) {
- var clone = templateElement.clone(false);
- var attributes = templateElement.attributes;
- for (var name in attributes.keys.toList()) {
+ // For non-template browsers, the parser will disallow <template> in certain
+ // locations, so we allow "attribute templates" which combine the template
+ // element with the top-level container node of the content, e.g.
+ //
+ // <tr template repeat="{{ foo }}"" class="bar"><td>Bar</td></tr>
+ //
+ // becomes
+ //
+ // <template repeat="{{ foo }}">
+ // + #document-fragment
+ // + <tr class="bar">
+ // + <td>Bar</td>
+ //
+ static Element _extractTemplateFromAttributeTemplate(Element el) {
+ var template = el.document.$dom_createElement('template');
+ el.parentNode.insertBefore(template, el);
+
+ for (var name in el.attributes.keys.toList()) {
switch (name) {
case 'template':
+ el.attributes.remove(name);
+ break;
case 'repeat':
case 'bind':
case 'ref':
- clone.attributes.remove(name);
- break;
- default:
- attributes.remove(name);
+ template.attributes[name] = el.attributes.remove(name);
break;
}
}
- return clone;
+ return template;
}
- static void _liftNonNativeChildrenIntoContent(Element templateElement) {
- var content = templateElement.content;
+ static void _liftNonNativeChildrenIntoContent(Element template, Element el,
+ bool useRoot) {
- if (!templateElement._isAttributeTemplate) {
- var child;
- while ((child = templateElement.firstChild) != null) {
- content.append(child);
- }
+ var content = template.content;
+ if (useRoot) {
+ content.append(el);
return;
}
- // For attribute templates we copy the whole thing into the content and
- // we move the non template attributes into the content.
- //
- // <tr foo template>
- //
- // becomes
- //
- // <tr template>
- // + #document-fragment
- // + <tr foo>
- //
- var newRoot = _cloneAndSeperateAttributeTemplate(templateElement);
var child;
- while ((child = templateElement.firstChild) != null) {
- newRoot.append(child);
+ while ((child = el.firstChild) != null) {
+ content.append(child);
}
- content.append(newRoot);
}
/**
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698