OLD | NEW |
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 /// *Warning* this class is experimental and subject to change. | 7 /// *Warning* this class is experimental and subject to change. |
8 /// | 8 /// |
9 /// The data associated with a polymer-element declaration, if it is backed | 9 /// The data associated with a polymer-element declaration, if it is backed |
10 /// by a Dart class instead of a JavaScript prototype. | 10 /// by a Dart class instead of a JavaScript prototype. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (attrs != null) { | 179 if (attrs != null) { |
180 // names='a b c' or names='a,b,c' | 180 // names='a b c' or names='a,b,c' |
181 // record each name for publishing | 181 // record each name for publishing |
182 for (var attr in attrs.split(_ATTRIBUTES_REGEX)) { | 182 for (var attr in attrs.split(_ATTRIBUTES_REGEX)) { |
183 // remove excess ws | 183 // remove excess ws |
184 attr = attr.trim(); | 184 attr = attr.trim(); |
185 | 185 |
186 // do not override explicit entries | 186 // do not override explicit entries |
187 if (attr == '') continue; | 187 if (attr == '') continue; |
188 | 188 |
189 var property = new Symbol(attr); | 189 var property = smoke.nameToSymbol(attr); |
190 var path = new PropertyPath([property]); | 190 var path = new PropertyPath([property]); |
191 if (_publish != null && _publish.containsKey(path)) { | 191 if (_publish != null && _publish.containsKey(path)) { |
192 continue; | 192 continue; |
193 } | 193 } |
194 | 194 |
195 var decl = smoke.getDeclaration(type, property); | 195 var decl = smoke.getDeclaration(type, property); |
196 if (decl == null || decl.isMethod || decl.isFinal) { | 196 if (decl == null || decl.isMethod || decl.isFinal) { |
197 window.console.warn('property for attribute $attr of polymer-element ' | 197 window.console.warn('property for attribute $attr of polymer-element ' |
198 'name=$name not found.'); | 198 'name=$name not found.'); |
199 continue; | 199 continue; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 if (cssText == '') return null; | 343 if (cssText == '') return null; |
344 | 344 |
345 return new StyleElement() | 345 return new StyleElement() |
346 ..text = cssText | 346 ..text = cssText |
347 ..attributes[_STYLE_SCOPE_ATTRIBUTE] = '$name-$scopeDescriptor'; | 347 ..attributes[_STYLE_SCOPE_ATTRIBUTE] = '$name-$scopeDescriptor'; |
348 } | 348 } |
349 | 349 |
350 /// Fetch a list of all *Changed methods so we can observe the associated | 350 /// Fetch a list of all *Changed methods so we can observe the associated |
351 /// properties. | 351 /// properties. |
352 void inferObservers() { | 352 void inferObservers() { |
353 var options = const smoke.QueryOptions(includeFields: false, | 353 for (var decl in smoke.query(type, _changedMethodQueryOptions)) { |
354 includeProperties: false, includeMethods: true, includeInherited: true, | 354 // TODO(jmesserly): now that we have a better system, should we |
355 includeUpTo: HtmlElement); | 355 // deprecate *Changed methods? |
356 for (var decl in smoke.query(type, options)) { | 356 if (_observe == null) _observe = new HashMap(); |
357 String name = smoke.symbolToName(decl.name); | 357 var name = smoke.symbolToName(decl.name); |
358 if (name.endsWith(_OBSERVE_SUFFIX) && name != 'attributeChanged') { | 358 name = name.substring(0, name.length - 7); |
359 // TODO(jmesserly): now that we have a better system, should we | 359 _observe[new PropertyPath(name)] = [decl.name]; |
360 // deprecate *Changed methods? | |
361 if (_observe == null) _observe = new HashMap(); | |
362 name = name.substring(0, name.length - 7); | |
363 _observe[new PropertyPath(name)] = [decl.name]; | |
364 } | |
365 } | 360 } |
366 } | 361 } |
367 | 362 |
368 /// Fetch a list of all methods annotated with [ObserveProperty] so we can | 363 /// Fetch a list of all methods annotated with [ObserveProperty] so we can |
369 /// observe the associated properties. | 364 /// observe the associated properties. |
370 void explodeObservers() { | 365 void explodeObservers() { |
371 var options = const smoke.QueryOptions(includeFields: false, | 366 var options = const smoke.QueryOptions(includeFields: false, |
372 includeProperties: false, includeMethods: true, includeInherited: true, | 367 includeProperties: false, includeMethods: true, includeInherited: true, |
373 includeUpTo: HtmlElement, withAnnotations: const [ObserveProperty]); | 368 includeUpTo: HtmlElement, withAnnotations: const [ObserveProperty]); |
374 for (var decl in smoke.query(type, options)) { | 369 for (var decl in smoke.query(type, options)) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 .responseText; | 466 .responseText; |
472 } on DomException catch (e, t) { | 467 } on DomException catch (e, t) { |
473 _sheetLog.fine('failed to XHR stylesheet text href="$href" error: ' | 468 _sheetLog.fine('failed to XHR stylesheet text href="$href" error: ' |
474 '$e, trace: $t'); | 469 '$e, trace: $t'); |
475 return ''; | 470 return ''; |
476 } | 471 } |
477 } | 472 } |
478 | 473 |
479 final Logger _sheetLog = new Logger('polymer.stylesheet'); | 474 final Logger _sheetLog = new Logger('polymer.stylesheet'); |
480 | 475 |
481 const _OBSERVE_SUFFIX = 'Changed'; | 476 |
| 477 final smoke.QueryOptions _changedMethodQueryOptions = new smoke.QueryOptions( |
| 478 includeFields: false, includeProperties: false, includeMethods: true, |
| 479 includeInherited: true, includeUpTo: HtmlElement, |
| 480 matches: _isObserverMethod); |
| 481 |
| 482 bool _isObserverMethod(Symbol symbol) { |
| 483 String name = smoke.symbolToName(symbol); |
| 484 if (name == null) return false; |
| 485 return name.endsWith('Changed') && name != 'attributeChanged'; |
| 486 } |
482 | 487 |
483 // TODO(jmesserly): is this list complete? | 488 // TODO(jmesserly): is this list complete? |
484 final _eventTranslations = const { | 489 final _eventTranslations = const { |
485 // TODO(jmesserly): these three Polymer.js translations won't work in Dart, | 490 // TODO(jmesserly): these three Polymer.js translations won't work in Dart, |
486 // because we strip the webkit prefix (below). Reconcile. | 491 // because we strip the webkit prefix (below). Reconcile. |
487 'webkitanimationstart': 'webkitAnimationStart', | 492 'webkitanimationstart': 'webkitAnimationStart', |
488 'webkitanimationend': 'webkitAnimationEnd', | 493 'webkitanimationend': 'webkitAnimationEnd', |
489 'webkittransitionend': 'webkitTransitionEnd', | 494 'webkittransitionend': 'webkitTransitionEnd', |
490 | 495 |
491 'domfocusout': 'DOMFocusOut', | 496 'domfocusout': 'DOMFocusOut', |
(...skipping 24 matching lines...) Expand all Loading... |
516 | 521 |
517 // Dart note: we need this function because we have additional renames JS does | 522 // Dart note: we need this function because we have additional renames JS does |
518 // not have. The JS renames are simply case differences, whereas we have ones | 523 // not have. The JS renames are simply case differences, whereas we have ones |
519 // like doubleclick -> dblclick and stripping the webkit prefix. | 524 // like doubleclick -> dblclick and stripping the webkit prefix. |
520 String _eventNameFromType(String eventType) { | 525 String _eventNameFromType(String eventType) { |
521 final result = _reverseEventTranslations[eventType]; | 526 final result = _reverseEventTranslations[eventType]; |
522 return result != null ? result : eventType; | 527 return result != null ? result : eventType; |
523 } | 528 } |
524 | 529 |
525 final _ATTRIBUTES_REGEX = new RegExp(r'\s|,'); | 530 final _ATTRIBUTES_REGEX = new RegExp(r'\s|,'); |
OLD | NEW |