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 /// Use this annotation to publish a property as an attribute. | 7 /// Use this annotation to publish a property as an attribute. |
8 /// | 8 /// |
9 /// You can also use [PublishedProperty] to provide additional information, | 9 /// You can also use [PublishedProperty] to provide additional information, |
10 /// such as automatically syncing the property back to the attribute. | 10 /// such as automatically syncing the property back to the attribute. |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 /// | 345 /// |
346 /// If this class is a superclass, calling `super.created()` is sufficient. | 346 /// If this class is a superclass, calling `super.created()` is sufficient. |
347 void polymerCreated() { | 347 void polymerCreated() { |
348 var t = nodeBind(this).templateInstance; | 348 var t = nodeBind(this).templateInstance; |
349 if (t != null && t.model != null) { | 349 if (t != null && t.model != null) { |
350 window.console.warn('Attributes on $_name were data bound ' | 350 window.console.warn('Attributes on $_name were data bound ' |
351 'prior to Polymer upgrading the element. This may result in ' | 351 'prior to Polymer upgrading the element. This may result in ' |
352 'incorrect binding types.'); | 352 'incorrect binding types.'); |
353 } | 353 } |
354 prepareElement(); | 354 prepareElement(); |
355 if (!isTemplateStagingDocument(ownerDocument)) { | 355 |
| 356 // TODO(sorvell): replace when ShadowDOMPolyfill issue is corrected |
| 357 // https://github.com/Polymer/ShadowDOM/issues/420 |
| 358 if (!isTemplateStagingDocument(ownerDocument) || _hasShadowDomPolyfill) { |
356 makeElementReady(); | 359 makeElementReady(); |
357 } | 360 } |
358 } | 361 } |
359 | 362 |
360 /// *Deprecated* use [shadowRoots] instead. | 363 /// *Deprecated* use [shadowRoots] instead. |
361 @deprecated | 364 @deprecated |
362 ShadowRoot getShadowRoot(String customTagName) => shadowRoots[customTagName]; | 365 ShadowRoot getShadowRoot(String customTagName) => shadowRoots[customTagName]; |
363 | 366 |
364 void prepareElement() { | 367 void prepareElement() { |
365 if (_elementPrepared) { | 368 if (_elementPrepared) { |
366 window.console.warn('Element already prepared: $_name'); | 369 window.console.warn('Element already prepared: $_name'); |
367 return; | 370 return; |
368 } | 371 } |
369 _initJsObject(); | 372 _initJsObject(); |
370 // Dart note: get the corresponding <polymer-element> declaration. | 373 // Dart note: get the corresponding <polymer-element> declaration. |
371 _element = _getDeclaration(_name); | 374 _element = _getDeclaration(_name); |
372 // install property storage | 375 // install property storage |
373 createPropertyObserver(); | 376 createPropertyObserver(); |
| 377 // TODO (sorvell): temporarily open observer when created |
374 openPropertyObserver(); | 378 openPropertyObserver(); |
375 // install boilerplate attributes | 379 // install boilerplate attributes |
376 copyInstanceAttributes(); | 380 copyInstanceAttributes(); |
377 // process input attributes | 381 // process input attributes |
378 takeAttributes(); | 382 takeAttributes(); |
379 // add event listeners | 383 // add event listeners |
380 addHostListeners(); | 384 addHostListeners(); |
381 } | 385 } |
382 | 386 |
383 /// Initialize JS interop for this element. For now we just initialize the | 387 /// Initialize JS interop for this element. For now we just initialize the |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 root.append(dom); | 517 root.append(dom); |
514 // perform post-construction initialization tasks on shadow root | 518 // perform post-construction initialization tasks on shadow root |
515 shadowRootReady(root); | 519 shadowRootReady(root); |
516 // return the created shadow root | 520 // return the created shadow root |
517 return root; | 521 return root; |
518 } | 522 } |
519 | 523 |
520 void shadowRootReady(Node root) { | 524 void shadowRootReady(Node root) { |
521 // locate nodes with id and store references to them in this.$ hash | 525 // locate nodes with id and store references to them in this.$ hash |
522 marshalNodeReferences(root); | 526 marshalNodeReferences(root); |
| 527 |
| 528 // set up polymer gestures |
| 529 if (_PolymerGestures != null) { |
| 530 _PolymerGestures.callMethod('register', [root]); |
| 531 } |
523 } | 532 } |
524 | 533 |
525 /// Locate nodes with id and store references to them in [$] hash. | 534 /// Locate nodes with id and store references to them in [$] hash. |
526 void marshalNodeReferences(Node root) { | 535 void marshalNodeReferences(Node root) { |
527 if (root == null) return; | 536 if (root == null) return; |
528 for (var n in (root as dynamic).querySelectorAll('[id]')) { | 537 for (var n in (root as dynamic).querySelectorAll('[id]')) { |
529 $[n.id] = n; | 538 $[n.id] = n; |
530 } | 539 } |
531 } | 540 } |
532 | 541 |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 if (events.isEmpty) return; | 1019 if (events.isEmpty) return; |
1011 | 1020 |
1012 _eventsLog.fine(() => '[$_name] addHostListeners: $events'); | 1021 _eventsLog.fine(() => '[$_name] addHostListeners: $events'); |
1013 | 1022 |
1014 // NOTE: host events look like bindings but really are not; | 1023 // NOTE: host events look like bindings but really are not; |
1015 // (1) we don't want the attribute to be set and (2) we want to support | 1024 // (1) we don't want the attribute to be set and (2) we want to support |
1016 // multiple event listeners ('host' and 'instance') and Node.bind | 1025 // multiple event listeners ('host' and 'instance') and Node.bind |
1017 // by default supports 1 thing being bound. | 1026 // by default supports 1 thing being bound. |
1018 events.forEach((type, methodName) { | 1027 events.forEach((type, methodName) { |
1019 // Dart note: the getEventHandler method is on our PolymerExpressions. | 1028 // Dart note: the getEventHandler method is on our PolymerExpressions. |
1020 _PolymerGestures.callMethod( | 1029 on[type].listen(element.syntax.getEventHandler(this, this, methodName)); |
1021 'addEventListener', | |
1022 [this, type, Zone.current.bindUnaryCallback( | |
1023 element.syntax.getEventHandler(this, this, methodName))]); | |
1024 }); | 1030 }); |
1025 } | 1031 } |
1026 | 1032 |
1027 /// Calls [methodOrCallback] with [args] if it is a closure, otherwise, treat | 1033 /// Calls [methodOrCallback] with [args] if it is a closure, otherwise, treat |
1028 /// it as a method name in [object], and invoke it. | 1034 /// it as a method name in [object], and invoke it. |
1029 void dispatchMethod(object, callbackOrMethod, List args) { | 1035 void dispatchMethod(object, callbackOrMethod, List args) { |
1030 _eventsLog.info(() => '>>> [$_name]: dispatch $callbackOrMethod'); | 1036 _eventsLog.info(() => '>>> [$_name]: dispatch $callbackOrMethod'); |
1031 | 1037 |
1032 if (callbackOrMethod is Function) { | 1038 if (callbackOrMethod is Function) { |
1033 int maxArgs = smoke.maxArgs(callbackOrMethod); | 1039 int maxArgs = smoke.maxArgs(callbackOrMethod); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 installScopeCssText('$cssText', scope, name); | 1166 installScopeCssText('$cssText', scope, name); |
1161 } | 1167 } |
1162 } | 1168 } |
1163 | 1169 |
1164 void installScopeCssText(String cssText, [Node scope, String name]) { | 1170 void installScopeCssText(String cssText, [Node scope, String name]) { |
1165 if (scope == null) scope = findStyleScope(); | 1171 if (scope == null) scope = findStyleScope(); |
1166 if (name == null) name = ''; | 1172 if (name == null) name = ''; |
1167 | 1173 |
1168 if (scope == null) return; | 1174 if (scope == null) return; |
1169 | 1175 |
1170 if (_hasShadowDomPolyfill) { | 1176 if (_ShadowCss != null) { |
1171 cssText = _shimCssText(cssText, scope is ShadowRoot ? scope.host : null); | 1177 cssText = _shimCssText(cssText, scope is ShadowRoot ? scope.host : null); |
1172 } | 1178 } |
1173 var style = element.cssTextToScopeStyle(cssText, | 1179 var style = element.cssTextToScopeStyle(cssText, |
1174 _STYLE_CONTROLLER_SCOPE); | 1180 _STYLE_CONTROLLER_SCOPE); |
1175 applyStyleToScope(style, scope); | 1181 applyStyleToScope(style, scope); |
1176 // cache that this style has been applied | 1182 // cache that this style has been applied |
1177 styleCacheForScope(scope).add('$_name$name'); | 1183 styleCacheForScope(scope).add('$_name$name'); |
1178 } | 1184 } |
1179 | 1185 |
1180 Node findStyleScope([node]) { | 1186 Node findStyleScope([node]) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 final Logger _eventsLog = new Logger('polymer.events'); | 1350 final Logger _eventsLog = new Logger('polymer.events'); |
1345 final Logger _unbindLog = new Logger('polymer.unbind'); | 1351 final Logger _unbindLog = new Logger('polymer.unbind'); |
1346 final Logger _bindLog = new Logger('polymer.bind'); | 1352 final Logger _bindLog = new Logger('polymer.bind'); |
1347 final Logger _watchLog = new Logger('polymer.watch'); | 1353 final Logger _watchLog = new Logger('polymer.watch'); |
1348 final Logger _readyLog = new Logger('polymer.ready'); | 1354 final Logger _readyLog = new Logger('polymer.ready'); |
1349 | 1355 |
1350 final Expando _eventHandledTable = new Expando<Set<Node>>(); | 1356 final Expando _eventHandledTable = new Expando<Set<Node>>(); |
1351 | 1357 |
1352 final JsObject _PolymerGestures = js.context['PolymerGestures']; | 1358 final JsObject _PolymerGestures = js.context['PolymerGestures']; |
1353 | 1359 |
OLD | NEW |