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

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

Issue 44573005: Update polymer to commit b7200854b2441a22ce89f6563963f36c50f5150d (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
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 * **Warning**: this class is experiental and subject to change. 8 * **Warning**: this class is experiental and subject to change.
9 * 9 *
10 * The implementation for the `polymer-element` element. 10 * The implementation for the `polymer-element` element.
11 * 11 *
12 * Normally you do not need to use this class directly, see [PolymerElement]. 12 * Normally you do not need to use this class directly, see [PolymerElement].
13 */ 13 */
14 class PolymerDeclaration extends HtmlElement { 14 class PolymerDeclaration extends HtmlElement {
15 static const _TAG = 'polymer-element'; 15 static const _TAG = 'polymer-element';
16 16
17 factory PolymerDeclaration() => new Element.tag(_TAG); 17 factory PolymerDeclaration() => new Element.tag(_TAG);
18 // Fully ported from revision: 18 // Fully ported from revision:
19 // https://github.com/Polymer/polymer/blob/00e2982c78fcd396adaebff3118e94029a2 b9fb0 19 // https://github.com/Polymer/polymer/blob/b7200854b2441a22ce89f6563963f36c50f 5150d
20 // 20 //
21 // src/declaration/attributes.js 21 // src/declaration/attributes.js
22 // src/declaration/events.js 22 // src/declaration/events.js
23 // src/declaration/polymer-element.js 23 // src/declaration/polymer-element.js
24 // src/declaration/properties.js 24 // src/declaration/properties.js
25 // src/declaration/prototype.js (note: most code not needed in Dart) 25 // src/declaration/prototype.js (note: most code not needed in Dart)
26 // src/declaration/styles.js 26 // src/declaration/styles.js
27 // 27 //
28 // Not yet ported: 28 // Not yet ported:
29 // src/declaration/path.js - blocked on HTMLImports.getDocumentUrl 29 // src/declaration/path.js - blocked on HTMLImports.getDocumentUrl
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // inherit publishing meta-data 199 // inherit publishing meta-data
200 // x-platform fixup 200 // x-platform fixup
201 } 201 }
202 202
203 /** Implement various declarative features. */ 203 /** Implement various declarative features. */
204 void desugar(name, extendee) { 204 void desugar(name, extendee) {
205 // compile list of attributes to copy to instances 205 // compile list of attributes to copy to instances
206 accumulateInstanceAttributes(); 206 accumulateInstanceAttributes();
207 // parse on-* delegates declared on `this` element 207 // parse on-* delegates declared on `this` element
208 parseHostEvents(); 208 parseHostEvents();
209 // parse on-* delegates declared in templates
210 parseLocalEvents();
211 // install external stylesheets as if they are inline 209 // install external stylesheets as if they are inline
212 installSheets(); 210 installSheets();
213 211
214 // TODO(sorvell): install a helper method this.resolvePath to aid in 212 // TODO(sorvell): install a helper method this.resolvePath to aid in
215 // setting resource paths. e.g. 213 // setting resource paths. e.g.
216 // this.$.image.src = this.resolvePath('images/foo.png') 214 // this.$.image.src = this.resolvePath('images/foo.png')
217 // Potentially remove when spec bug is addressed. 215 // Potentially remove when spec bug is addressed.
218 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=21407 216 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=21407
219 // TODO(jmesserly): resolvePath not ported, see first comment in this class. 217 // TODO(jmesserly): resolvePath not ported, see first comment in this class.
220 218
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 304 }
307 305
308 /** Extracts events from the element tag attributes. */ 306 /** Extracts events from the element tag attributes. */
309 void parseHostEvents() { 307 void parseHostEvents() {
310 addAttributeDelegates(_eventDelegates); 308 addAttributeDelegates(_eventDelegates);
311 } 309 }
312 310
313 void addAttributeDelegates(Map<String, String> delegates) { 311 void addAttributeDelegates(Map<String, String> delegates) {
314 attributes.forEach((name, value) { 312 attributes.forEach((name, value) {
315 if (_hasEventPrefix(name)) { 313 if (_hasEventPrefix(name)) {
316 delegates[_removeEventPrefix(name)] = value; 314 delegates[_removeEventPrefix(name)] =
315 value.replaceAll('{{', '').replaceAll('}}', '').trim();
Jennifer Messerly 2013/10/25 22:00:41 in JavaScript they're just replacing the first occ
Siggi Cherem (dart-lang) 2013/10/26 00:02:35 Done.
317 } 316 }
318 }); 317 });
319 } 318 }
320 319
321 /** Extracts events under the element's <template>. */
322 void parseLocalEvents() {
323 for (var t in this.queryAll('template')) {
324 final events = new Set<String>();
325 // acquire delegates from entire subtree at t
326 accumulateTemplatedEvents(t, events);
327 if (events.isNotEmpty) {
328 // store delegate information directly on template
329 if (_templateDelegates == null) {
330 _templateDelegates = new Expando<Set<String>>();
331 }
332 _templateDelegates[t] = events;
333 }
334 }
335 }
336
337 void accumulateTemplatedEvents(Element node, Set<String> events) {
338 if (node.localName == 'template') {
339 accumulateChildEvents(templateBind(node).content, events);
340 }
341 }
342
343 void accumulateChildEvents(node, Set<String> events) {
344 assert(node is Element || node is DocumentFragment);
345 for (var n in node.children) {
346 accumulateEvents(n, events);
347 }
348 }
349
350 void accumulateEvents(Element node, Set<String> events) {
351 accumulateAttributeEvents(node, events);
352 accumulateChildEvents(node, events);
353 accumulateTemplatedEvents(node, events);
354 }
355
356 void accumulateAttributeEvents(Element node, Set<String> events) {
357 for (var name in node.attributes.keys) {
358 if (_hasEventPrefix(name)) {
359 accumulateEvent(_removeEventPrefix(name), events);
360 }
361 }
362 }
363
364 void accumulateEvent(String name, Set<String> events) {
365 var translated = _eventTranslations[name];
366 events.add(translated != null ? translated : name);
367 }
368
369 String urlToPath(String url) { 320 String urlToPath(String url) {
370 if (url == null) return ''; 321 if (url == null) return '';
371 return (url.split('/')..removeLast()..add('')).join('/'); 322 return (url.split('/')..removeLast()..add('')).join('/');
372 } 323 }
373 324
374 /** 325 /**
375 * Install external stylesheets loaded in <element> elements into the 326 * Install external stylesheets loaded in <element> elements into the
376 * element's template. 327 * element's template.
377 */ 328 */
378 void installSheets() { 329 void installSheets() {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 return map; 594 return map;
644 }(); 595 }();
645 596
646 // Dart note: we need this function because we have additional renames JS does 597 // Dart note: we need this function because we have additional renames JS does
647 // not have. The JS renames are simply case differences, whereas we have ones 598 // not have. The JS renames are simply case differences, whereas we have ones
648 // like doubleclick -> dblclick and stripping the webkit prefix. 599 // like doubleclick -> dblclick and stripping the webkit prefix.
649 String _eventNameFromType(String eventType) { 600 String _eventNameFromType(String eventType) {
650 final result = _reverseEventTranslations[eventType]; 601 final result = _reverseEventTranslations[eventType];
651 return result != null ? result : eventType; 602 return result != null ? result : eventType;
652 } 603 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698