OLD | NEW |
---|---|
1 <!-- | 1 <!-- |
2 // Copyright 2015 The Chromium Authors. All rights reserved. | 2 // Copyright 2015 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 --> | 5 --> |
6 <script> | 6 <script> |
7 import "dart:mirrors"; | 7 import "dart:mirrors"; |
8 import "dart:sky"; | 8 import "dart:sky"; |
9 | 9 |
10 class _Registration { | 10 class _Registration { |
(...skipping 29 matching lines...) Expand all Loading... | |
40 // Invoke attributeChanged callback when element is first created too. | 40 // Invoke attributeChanged callback when element is first created too. |
41 for (Attr attribute in getAttributes()) | 41 for (Attr attribute in getAttributes()) |
42 attributeChangedCallback(attribute.name, null, attribute.value); | 42 attributeChangedCallback(attribute.name, null, attribute.value); |
43 } | 43 } |
44 | 44 |
45 attachedCallback() { | 45 attachedCallback() { |
46 if (shadowRoot == null) { | 46 if (shadowRoot == null) { |
47 var registration = _registery[tagName]; | 47 var registration = _registery[tagName]; |
48 if (registration.template != null) { | 48 if (registration.template != null) { |
49 ShadowRoot shadow = ensureShadowRoot(); | 49 ShadowRoot shadow = ensureShadowRoot(); |
50 var tree = registration.template.content.cloneNode(deep:true); | 50 shadow.appendChild(_cloneDeep(registration.template.content)); |
abarth-chromium
2015/02/21 09:15:49
Custom elements don't quite work properly with the
abarth-chromium
2015/02/21 09:15:49
Custom elements don't quite work properly with the
esprehn
2015/02/21 09:57:13
We should use importNode, which clones you into th
| |
51 shadow.appendChild(tree); | |
52 shadowRootReady(); | 51 shadowRootReady(); |
53 } | 52 } |
54 } | 53 } |
55 attached(); | 54 attached(); |
56 } | 55 } |
57 | 56 |
58 detachedCallback() { | 57 detachedCallback() { |
59 detached(); | 58 detached(); |
60 } | 59 } |
61 | 60 |
62 attributeChangedCallback(name, oldValue, newValue) { | 61 attributeChangedCallback(name, oldValue, newValue) { |
63 attributeChanged(name, oldValue, newValue); | 62 attributeChanged(name, oldValue, newValue); |
64 } | 63 } |
64 | |
65 Node _clone(Node node) { | |
66 if (node is Element) { | |
67 Element result = document.createElement(node.tagName); | |
68 result.setAttributes(node.getAttributes()); | |
69 return result; | |
70 } | |
71 return node.cloneNode(deep: false); | |
72 } | |
73 | |
74 Node _cloneDeep(Node node) { | |
75 Node result = _clone(node); | |
76 if (node is ParentNode) { | |
77 ParentNode parent = node as ParentNode; | |
78 for (Node child = parent.firstChild; child != null; child = child.nextSibl ing) | |
79 result.appendChild(_cloneDeep(child)); | |
80 } | |
81 return result; | |
82 } | |
esprehn
2015/02/21 09:57:13
This is duplicating what importNode already does.
| |
65 } | 83 } |
66 | 84 |
67 void register(Element script, Type type) { | 85 void register(Element script, Type type) { |
68 Element definition = script.parentNode; | 86 Element definition = script.parentNode; |
69 | 87 |
70 if (definition.tagName != 'sky-element') | 88 if (definition.tagName != 'sky-element') |
71 throw new UnsupportedError('register() calls must be inside a <sky-element>. '); | 89 throw new UnsupportedError('register() calls must be inside a <sky-element>. '); |
72 | 90 |
73 ClassMirror mirror = reflectClass(type); | 91 ClassMirror mirror = reflectClass(type); |
74 if (!mirror.isSubclassOf(reflectClass(SkyElement))) | 92 if (!mirror.isSubclassOf(reflectClass(SkyElement))) |
75 throw new UnsupportedError('@Tagname can only be used on descendants of SkyE lement'); | 93 throw new UnsupportedError('@Tagname can only be used on descendants of SkyE lement'); |
76 | 94 |
77 String tagName = _getTagName(type); | 95 String tagName = _getTagName(type); |
78 Element template = definition.querySelector('template'); | 96 Element template = definition.querySelector('template'); |
79 | 97 |
80 document.registerElement(tagName, type); | 98 document.registerElement(tagName, type); |
81 _registery[tagName] = new _Registration(template); | 99 _registery[tagName] = new _Registration(template); |
82 } | 100 } |
83 </script> | 101 </script> |
OLD | NEW |