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

Side by Side Diff: pkg/polymer/lib/src/instance.dart

Issue 32903004: simple fix: loosen type annotations for ShadowRoot (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 part of polymer; 5 part of polymer;
6 6
7 /** 7 /**
8 * Use this annotation to publish a field as an attribute. For example: 8 * Use this annotation to publish a field as an attribute. For example:
9 * 9 *
10 * class MyPlaybackElement extends PolymerElement { 10 * class MyPlaybackElement extends PolymerElement {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 parseDeclaration(declaration); 176 parseDeclaration(declaration);
177 } 177 }
178 } 178 }
179 179
180 /** 180 /**
181 * Parse input `<polymer-element>` as needed, override for custom behavior. 181 * Parse input `<polymer-element>` as needed, override for custom behavior.
182 */ 182 */
183 void parseDeclaration(Element elementElement) { 183 void parseDeclaration(Element elementElement) {
184 var root = shadowFromTemplate(fetchTemplate(elementElement)); 184 var root = shadowFromTemplate(fetchTemplate(elementElement));
185 185
186 // Dart note: this is extra code compared to Polymer to support 186 // Dart note: the following code is to support the getShadowRoot method.
187 // the getShadowRoot method. 187 if (root is! ShadowRoot) return;
188 if (root == null) return;
189 188
190 var name = elementElement.attributes['name']; 189 var name = elementElement.attributes['name'];
191 if (name == null) return; 190 if (name == null) return;
192 _shadowRoots[name] = root; 191 _shadowRoots[name] = root;
193 } 192 }
194 193
195 /** 194 /**
196 * Return a shadow-root template (if desired), override for custom behavior. 195 * Return a shadow-root template (if desired), override for custom behavior.
197 */ 196 */
198 Element fetchTemplate(Element elementElement) => 197 Element fetchTemplate(Element elementElement) =>
199 elementElement.query('template'); 198 elementElement.query('template');
200 199
201 /** Utility function that creates a shadow root from a `<template>`. */ 200 /**
201 * Utility function that creates a shadow root from a `<template>`.
202 *
203 * The base implementation will return a [ShadowRoot], but you can replace it
204 * with your own code and skip ShadowRoot creation. In that case, you should
205 * return `null`.
206 *
207 * In your overridden method, you can use [instanceTemplate] to stamp the
208 * template and initialize data binding, and [shadowRootReady] to intialize
209 * other Polymer features like event handlers. It is fine to call
210 * shadowRootReady with a node something other than a ShadowRoot; for example,
211 * with this Node.
212 */
202 ShadowRoot shadowFromTemplate(Element template) { 213 ShadowRoot shadowFromTemplate(Element template) {
203 if (template == null) return null; 214 if (template == null) return null;
204 // cache elder shadow root (if any) 215 // cache elder shadow root (if any)
205 var elderRoot = this.shadowRoot; 216 var elderRoot = this.shadowRoot;
206 // make a shadow root 217 // make a shadow root
207 var root = createShadowRoot(); 218 var root = createShadowRoot();
208 219
209 // Provides ability to traverse from ShadowRoot to the host. 220 // Provides ability to traverse from ShadowRoot to the host.
210 // TODO(jmessery): remove once we have this ability on the DOM. 221 // TODO(jmessery): remove once we have this ability on the DOM.
211 _shadowHost[root] = this; 222 _shadowHost[root] = this;
212 223
213 // migrate flag(s)( 224 // migrate flag(s)(
214 root.applyAuthorStyles = applyAuthorStyles; 225 root.applyAuthorStyles = applyAuthorStyles;
215 root.resetStyleInheritance = resetStyleInheritance; 226 root.resetStyleInheritance = resetStyleInheritance;
216 // stamp template 227 // stamp template
217 // which includes parsing and applying MDV bindings before being 228 // which includes parsing and applying MDV bindings before being
218 // inserted (to avoid {{}} in attribute values) 229 // inserted (to avoid {{}} in attribute values)
219 // e.g. to prevent <img src="images/{{icon}}"> from generating a 404. 230 // e.g. to prevent <img src="images/{{icon}}"> from generating a 404.
220 var dom = instanceTemplate(template); 231 var dom = instanceTemplate(template);
221 // append to shadow dom 232 // append to shadow dom
222 root.append(dom); 233 root.append(dom);
223 // perform post-construction initialization tasks on shadow root 234 // perform post-construction initialization tasks on shadow root
224 shadowRootReady(root, template); 235 shadowRootReady(root, template);
225 // return the created shadow root 236 // return the created shadow root
226 return root; 237 return root;
227 } 238 }
228 239
229 void shadowRootReady(ShadowRoot root, Element template) { 240 void shadowRootReady(Node root, Element template) {
230 // locate nodes with id and store references to them in this.$ hash 241 // locate nodes with id and store references to them in this.$ hash
231 marshalNodeReferences(root); 242 marshalNodeReferences(root);
232 // add local events of interest... 243 // add local events of interest...
233 addInstanceListeners(root, template); 244 addInstanceListeners(root, template);
234 // TODO(jmesserly): port this 245 // TODO(jmesserly): port this
235 // set up pointer gestures 246 // set up pointer gestures
236 // PointerGestures.register(root); 247 // PointerGestures.register(root);
237 } 248 }
238 249
239 /** Locate nodes with id and store references to them in [$] hash. */ 250 /** Locate nodes with id and store references to them in [$] hash. */
240 void marshalNodeReferences(ShadowRoot root) { 251 void marshalNodeReferences(Node root) {
241 if (root == null) return; 252 if (root == null) return;
242 for (var n in root.queryAll('[id]')) { 253 for (var n in root.queryAll('[id]')) {
243 $[n.id] = n; 254 $[n.id] = n;
244 } 255 }
245 } 256 }
246 257
247 void attributeChanged(String name, String oldValue, String newValue) { 258 void attributeChanged(String name, String oldValue, String newValue) {
248 if (name != 'class' && name != 'style') { 259 if (name != 'class' && name != 'style') {
249 attributeToProperty(name, newValue); 260 attributeToProperty(name, newValue);
250 } 261 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 var events = _declaration._eventDelegates; 592 var events = _declaration._eventDelegates;
582 if (events.isEmpty) return; 593 if (events.isEmpty) return;
583 594
584 if (_eventsLog.isLoggable(Level.FINE)) { 595 if (_eventsLog.isLoggable(Level.FINE)) {
585 _eventsLog.fine('[$localName] addHostListeners: $events'); 596 _eventsLog.fine('[$localName] addHostListeners: $events');
586 } 597 }
587 addNodeListeners(this, events.keys, hostEventListener); 598 addNodeListeners(this, events.keys, hostEventListener);
588 } 599 }
589 600
590 /** Attach event listeners inside a shadow [root]. */ 601 /** Attach event listeners inside a shadow [root]. */
591 void addInstanceListeners(ShadowRoot root, Element template) { 602 void addInstanceListeners(Node root, Element template) {
592 var templateDelegates = _declaration._templateDelegates; 603 var templateDelegates = _declaration._templateDelegates;
593 if (templateDelegates == null) return; 604 if (templateDelegates == null) return;
594 var events = templateDelegates[template]; 605 var events = templateDelegates[template];
595 if (events == null) return; 606 if (events == null) return;
596 607
597 if (_eventsLog.isLoggable(Level.FINE)) { 608 if (_eventsLog.isLoggable(Level.FINE)) {
598 _eventsLog.fine('[$localName] addInstanceListeners: $events'); 609 _eventsLog.fine('[$localName] addInstanceListeners: $events');
599 } 610 }
600 addNodeListeners(root, events, instanceEventListener); 611 addNodeListeners(root, events, instanceEventListener);
601 } 612 }
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 /** 952 /**
942 * Base class for PolymerElements deriving from HtmlElement. 953 * Base class for PolymerElements deriving from HtmlElement.
943 * 954 *
944 * See [Polymer]. 955 * See [Polymer].
945 */ 956 */
946 class PolymerElement extends HtmlElement with Polymer, Observable { 957 class PolymerElement extends HtmlElement with Polymer, Observable {
947 PolymerElement.created() : super.created() { 958 PolymerElement.created() : super.created() {
948 polymerCreated(); 959 polymerCreated();
949 } 960 }
950 } 961 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698