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

Side by Side Diff: pkg/custom_element/lib/custom_element.dart

Issue 22253002: fix packages for latest SDK changes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/mdv/lib/mdv.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /** 5 /**
6 * Custom Elements let authors define their own elements. Authors associate code 6 * Custom Elements let authors define their own elements. Authors associate code
7 * with custom tag names, and then use those custom tag names as they would any 7 * with custom tag names, and then use those custom tag names as they would any
8 * standard tag. See <www.polymer-project.org/platform/custom-elements.html> 8 * standard tag. See <www.polymer-project.org/platform/custom-elements.html>
9 * for more information. 9 * for more information.
10 */ 10 */
(...skipping 13 matching lines...) Expand all
24 * 24 *
25 * Registers a custom HTML element with [localName] and the associated 25 * Registers a custom HTML element with [localName] and the associated
26 * constructor. This will ensure the element is detected and 26 * constructor. This will ensure the element is detected and
27 * 27 *
28 * See the specification at: 28 * See the specification at:
29 * <https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html> 29 * <https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html>
30 */ 30 */
31 void registerCustomElement(String localName, CustomElement create()) { 31 void registerCustomElement(String localName, CustomElement create()) {
32 if (_customElements == null) { 32 if (_customElements == null) {
33 _customElements = {}; 33 _customElements = {};
34 CustomElement.templateCreated.add(initCustomElements); 34 mdv.instanceCreated.add(initCustomElements);
35 // TODO(jmesserly): use MutationObserver to watch for inserts? 35 // TODO(jmesserly): use MutationObserver to watch for inserts?
36 } 36 }
37 37
38 if (!isCustomTag(localName)) { 38 if (!isCustomTag(localName)) {
39 throw new ArgumentError('$localName is not a valid custom element name, ' 39 throw new ArgumentError('$localName is not a valid custom element name, '
40 'it should have at least one dash and not be a reserved name.'); 40 'it should have at least one dash and not be a reserved name.');
41 } 41 }
42 42
43 if (_customElements.containsKey(localName)) { 43 if (_customElements.containsKey(localName)) {
44 throw new ArgumentError('custom element $localName already registered.'); 44 throw new ArgumentError('custom element $localName already registered.');
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 createShadowRoot([String componentName]) { 152 createShadowRoot([String componentName]) {
153 var root = host.createShadowRoot(); 153 var root = host.createShadowRoot();
154 if (componentName != null) { 154 if (componentName != null) {
155 _generatedRoots[componentName] = root; 155 _generatedRoots[componentName] = root;
156 } 156 }
157 return root; 157 return root;
158 } 158 }
159 159
160 getShadowRoot(String componentName) => _generatedRoots[componentName]; 160 getShadowRoot(String componentName) => _generatedRoots[componentName];
161 161
162
163 /**
164 * *Warning*: This is an implementation helper for Custom Elements and
165 * should not be used in your code.
166 *
167 * Clones the template, instantiates custom elements and hooks events, then
168 * returns it.
169 */
170 DocumentFragment cloneTemplate(DocumentFragment shadowTemplate) {
171 var result = shadowTemplate.clone(true);
172 // TODO(jmesserly): should bindModel ensure this happens?
173 TemplateElement.bootstrap(result);
174 if (_templateCreated != null) {
175 for (var callback in _templateCreated) callback(result);
176 }
177 return result;
178 }
179
180 // TODO(jmesserly): ideally this would be a stream, but they don't allow
181 // reentrancy.
182 static Set<DocumentFragmentCreated> _templateCreated;
183
184 /**
185 * *Warning*: This is an implementation helper for Custom Elements and
186 * should not be used in your code.
187 *
188 * This event is fired whenever a template is instantiated via
189 * [cloneTemplate] or via [Element.createInstance]
190 */
191 // TODO(jmesserly): This is a hack, and is neccesary for the polyfill
192 // because custom elements are not upgraded during clone()
193 static Set<DocumentFragmentCreated> get templateCreated {
194 if (_templateCreated == null) {
195 _templateCreated = new Set<DocumentFragmentCreated>();
196 mdv.instanceCreated.listen((value) {
197 for (var callback in _templateCreated) callback(value);
198 });
199 }
200 return _templateCreated;
201 }
202 /** 162 /**
203 * Invoked when this component gets created. 163 * Invoked when this component gets created.
204 * Note that [root] will be a [ShadowRoot] if the browser supports Shadow DOM. 164 * Note that [root] will be a [ShadowRoot] if the browser supports Shadow DOM.
205 */ 165 */
206 void created() {} 166 void created() {}
207 167
208 /** Invoked when this component gets inserted in the DOM tree. */ 168 /** Invoked when this component gets inserted in the DOM tree. */
209 void inserted() {} 169 void inserted() {}
210 170
211 /** Invoked when this component is removed from the DOM tree. */ 171 /** Invoked when this component is removed from the DOM tree. */
(...skipping 11 matching lines...) Expand all
223 } 183 }
224 184
225 get templateInstance => host.templateInstance; 185 get templateInstance => host.templateInstance;
226 get isTemplate => host.isTemplate; 186 get isTemplate => host.isTemplate;
227 get ref => host.ref; 187 get ref => host.ref;
228 get content => host.content; 188 get content => host.content;
229 DocumentFragment createInstance(model, [BindingDelegate delegate]) => 189 DocumentFragment createInstance(model, [BindingDelegate delegate]) =>
230 host.createInstance(model, delegate); 190 host.createInstance(model, delegate);
231 createBinding(String name, model, String path) => 191 createBinding(String name, model, String path) =>
232 host.createBinding(name, model, path); 192 host.createBinding(name, model, path);
233 void bind(String name, model, String path) => host.bind(name, model, path); 193 bind(String name, model, String path) => host.bind(name, model, path);
234 void unbind(String name) => host.unbind(name); 194 void unbind(String name) => host.unbind(name);
235 void unbindAll() => host.unbindAll(); 195 void unbindAll() => host.unbindAll();
236 get bindings => host.bindings; 196 get bindings => host.bindings;
237 BindingDelegate get bindingDelegate => host.bindingDelegate; 197 BindingDelegate get bindingDelegate => host.bindingDelegate;
238 set bindingDelegate(BindingDelegate value) { host.bindingDelegate = value; } 198 set bindingDelegate(BindingDelegate value) { host.bindingDelegate = value; }
239 199
240 // TODO(jmesserly): this forwarding is temporary until Dart supports 200 // TODO(jmesserly): this forwarding is temporary until Dart supports
241 // subclassing Elements. 201 // subclassing Elements.
242 // TODO(jmesserly): we were missing the setter for title, are other things 202 // TODO(jmesserly): we were missing the setter for title, are other things
243 // missing setters? 203 // missing setters?
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 Stream<TouchEvent> get onTouchStart => host.onTouchStart; 612 Stream<TouchEvent> get onTouchStart => host.onTouchStart;
653 Stream<TransitionEvent> get onTransitionEnd => host.onTransitionEnd; 613 Stream<TransitionEvent> get onTransitionEnd => host.onTransitionEnd;
654 614
655 // TODO(sigmund): do the normal forwarding when dartbug.com/7919 is fixed. 615 // TODO(sigmund): do the normal forwarding when dartbug.com/7919 is fixed.
656 Stream<WheelEvent> get onMouseWheel { 616 Stream<WheelEvent> get onMouseWheel {
657 throw new UnsupportedError('onMouseWheel is not supported'); 617 throw new UnsupportedError('onMouseWheel is not supported');
658 } 618 }
659 } 619 }
660 620
661 621
662 typedef DocumentFragmentCreated(DocumentFragment fragment);
663
664 Map<String, Function> _customElements; 622 Map<String, Function> _customElements;
665 623
666 void _initCustomElement(Element node, CustomElement ctor()) { 624 void _initCustomElement(Element node, CustomElement ctor()) {
667 CustomElement element = ctor(); 625 CustomElement element = ctor();
668 element.host = node; 626 element.host = node;
669 627
670 // TODO(jmesserly): replace lifecycle stuff with a proper polyfill. 628 // TODO(jmesserly): replace lifecycle stuff with a proper polyfill.
671 element.created(); 629 element.created();
672 630
673 _registerLifecycleInsert(element); 631 _registerLifecycleInsert(element);
(...skipping 22 matching lines...) Expand all
696 for (var removed in record.removedNodes) { 654 for (var removed in record.removedNodes) {
697 if (identical(node, removed)) { 655 if (identical(node, removed)) {
698 observer.disconnect(); 656 observer.disconnect();
699 element.removed(); 657 element.removed();
700 return; 658 return;
701 } 659 }
702 } 660 }
703 } 661 }
704 }).observe(element.parentNode, childList: true); 662 }).observe(element.parentNode, childList: true);
705 } 663 }
OLDNEW
« no previous file with comments | « no previous file | pkg/mdv/lib/mdv.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698