Chromium Code Reviews| 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 /** | 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. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 } | 149 } |
| 150 return false; | 150 return false; |
| 151 } | 151 } |
| 152 | 152 |
| 153 void register(String name, String extendee) { | 153 void register(String name, String extendee) { |
| 154 // build prototype combining extendee, Polymer base, and named api | 154 // build prototype combining extendee, Polymer base, and named api |
| 155 buildType(name, extendee); | 155 buildType(name, extendee); |
| 156 | 156 |
| 157 // back reference declaration element | 157 // back reference declaration element |
| 158 // TODO(sjmiles): replace `element` with `elementElement` or `declaration` | 158 // TODO(sjmiles): replace `element` with `elementElement` or `declaration` |
| 159 _declarations[_type] = this; | 159 _declarations[name] = this; |
| 160 | 160 |
| 161 // more declarative features | 161 // more declarative features |
| 162 desugar(); | 162 desugar(); |
| 163 | 163 |
| 164 // TODO(sorvell): install a helper method this.resolvePath to aid in | 164 // TODO(sorvell): install a helper method this.resolvePath to aid in |
| 165 // setting resource paths. e.g. | 165 // setting resource paths. e.g. |
| 166 // this.$.image.src = this.resolvePath('images/foo.png') | 166 // this.$.image.src = this.resolvePath('images/foo.png') |
| 167 // Potentially remove when spec bug is addressed. | 167 // Potentially remove when spec bug is addressed. |
| 168 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=21407 | 168 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=21407 |
| 169 // TODO(jmesserly): resolvePath not ported, see first comment in this class. | 169 // TODO(jmesserly): resolvePath not ported, see first comment in this class. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 185 * | 185 * |
| 186 * *Note*: unlike the JavaScript version, we do not have to metaprogram the | 186 * *Note*: unlike the JavaScript version, we do not have to metaprogram the |
| 187 * prototype, which simplifies this method. | 187 * prototype, which simplifies this method. |
| 188 */ | 188 */ |
| 189 void buildType(String name, String extendee) { | 189 void buildType(String name, String extendee) { |
| 190 // get our custom type | 190 // get our custom type |
| 191 _type = _getRegisteredType(name); | 191 _type = _getRegisteredType(name); |
| 192 | 192 |
| 193 // get basal prototype | 193 // get basal prototype |
| 194 _supertype = _getRegisteredType(extendee); | 194 _supertype = _getRegisteredType(extendee); |
| 195 if (supertype != null) _super = _getDeclaration(supertype); | 195 if (_supertype != null) _super = _getDeclaration(extendee); |
| 196 | 196 |
| 197 var cls = reflectClass(_type); | 197 var cls = reflectClass(_type); |
| 198 | 198 |
| 199 // transcribe `attributes` declarations onto own prototype's `publish` | 199 // transcribe `attributes` declarations onto own prototype's `publish` |
| 200 publishAttributes(cls, _super); | 200 publishAttributes(cls, _super); |
| 201 | 201 |
| 202 publishProperties(type); | 202 publishProperties(type); |
| 203 | 203 |
| 204 inferObservers(cls); | 204 inferObservers(cls); |
| 205 | 205 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 | 514 |
| 515 void _notifyType(String name) { | 515 void _notifyType(String name) { |
| 516 var waiting = _waitType.remove(name); | 516 var waiting = _waitType.remove(name); |
| 517 if (waiting != null) waiting.registerWhenReady(); | 517 if (waiting != null) waiting.registerWhenReady(); |
| 518 } | 518 } |
| 519 | 519 |
| 520 /// elements waiting for super, by name | 520 /// elements waiting for super, by name |
| 521 final Map _waitSuper = new Map<String, List<PolymerDeclaration>>(); | 521 final Map _waitSuper = new Map<String, List<PolymerDeclaration>>(); |
| 522 | 522 |
| 523 void _notifySuper(String name) { | 523 void _notifySuper(String name) { |
| 524 _registered.add(name); | |
|
Siggi Cherem (dart-lang)
2013/10/24 02:25:08
(IIUC _notifySuper is called after the call to reg
| |
| 525 var waiting = _waitSuper.remove(name); | 524 var waiting = _waitSuper.remove(name); |
| 526 if (waiting != null) { | 525 if (waiting != null) { |
| 527 for (var w in waiting) { | 526 for (var w in waiting) { |
| 528 w.registerWhenReady(); | 527 w.registerWhenReady(); |
| 529 } | 528 } |
| 530 } | 529 } |
| 531 } | 530 } |
| 532 | 531 |
| 533 /// track document.register'ed tag names | 532 /// track document.register'ed tag names and their declarations |
| 534 final Set _registered = new Set<String>(); | 533 final Map _declarations = new Map<String, PolymerDeclaration>(); |
| 535 | 534 |
| 536 bool _isRegistered(name) => _registered.contains(name); | 535 bool _isRegistered(String name) => _declarations.containsKey(name); |
| 537 | 536 PolymerDeclaration _getDeclaration(String name) => _declarations[name]; |
| 538 final Map _declarations = new Map<Type, PolymerDeclaration>(); | |
| 539 | |
| 540 PolymerDeclaration _getDeclaration(Type type) => _declarations[type]; | |
| 541 | 537 |
| 542 final _objectType = reflectClass(Object); | 538 final _objectType = reflectClass(Object); |
| 543 | 539 |
| 544 Map _getProperties(ClassMirror cls, Map props, bool matches(metadata)) { | 540 Map _getProperties(ClassMirror cls, Map props, bool matches(metadata)) { |
| 545 for (var field in cls.variables.values) { | 541 for (var field in cls.variables.values) { |
| 546 if (field.isFinal || field.isStatic || field.isPrivate) continue; | 542 if (field.isFinal || field.isStatic || field.isPrivate) continue; |
| 547 | 543 |
| 548 for (var meta in field.metadata) { | 544 for (var meta in field.metadata) { |
| 549 if (matches(meta.reflectee)) { | 545 if (matches(meta.reflectee)) { |
| 550 if (props == null) props = {}; | 546 if (props == null) props = {}; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 return map; | 661 return map; |
| 666 }(); | 662 }(); |
| 667 | 663 |
| 668 // Dart note: we need this function because we have additional renames JS does | 664 // Dart note: we need this function because we have additional renames JS does |
| 669 // not have. The JS renames are simply case differences, whereas we have ones | 665 // not have. The JS renames are simply case differences, whereas we have ones |
| 670 // like doubleclick -> dblclick and stripping the webkit prefix. | 666 // like doubleclick -> dblclick and stripping the webkit prefix. |
| 671 String _eventNameFromType(String eventType) { | 667 String _eventNameFromType(String eventType) { |
| 672 final result = _reverseEventTranslations[eventType]; | 668 final result = _reverseEventTranslations[eventType]; |
| 673 return result != null ? result : eventType; | 669 return result != null ? result : eventType; |
| 674 } | 670 } |
| OLD | NEW |