| 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 /// Code from declaration/events.js | 5 /// Code from declaration/events.js |
| 6 part of polymer; | 6 part of polymer; |
| 7 | 7 |
| 8 /// An extension of [polymer_expressions.PolymerExpressions] that adds support | 8 /// An extension of [polymer_expressions.PolymerExpressions] that adds support |
| 9 /// for binding events using `on-eventName` using [PolymerEventBindings]. | 9 /// for binding events using `on-eventName` using [PolymerEventBindings]. |
| 10 // TODO(jmesserly): the JS layering is a bit odd, with polymer-dev implementing | 10 // TODO(jmesserly): the JS layering is a bit odd, with polymer-dev implementing |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 /// A mixin for a [BindingDelegate] to add Polymer event support. | 47 /// A mixin for a [BindingDelegate] to add Polymer event support. |
| 48 /// This is included in [PolymerExpressions]. | 48 /// This is included in [PolymerExpressions]. |
| 49 abstract class PolymerEventBindings { | 49 abstract class PolymerEventBindings { |
| 50 /// Finds the event controller for this node. | 50 /// Finds the event controller for this node. |
| 51 Element findController(Node node) { | 51 Element findController(Node node) { |
| 52 while (node.parentNode != null) { | 52 while (node.parentNode != null) { |
| 53 if (node is Polymer && node.eventController != null) { | 53 if (node is Polymer && node.eventController != null) { |
| 54 return node.eventController; | 54 return node.eventController; |
| 55 } else if (node is Element) { |
| 56 // If it is a normal element, js polymer element, or dart wrapper to a |
| 57 // js polymer element, then we try js interop. |
| 58 var eventController = |
| 59 new JsObject.fromBrowserObject(node)['eventController']; |
| 60 if (eventController != null) return eventController; |
| 55 } | 61 } |
| 56 node = node.parentNode; | 62 node = node.parentNode; |
| 57 } | 63 } |
| 58 return node is ShadowRoot ? node.host : null; | 64 return node is ShadowRoot ? node.host : null; |
| 59 } | 65 } |
| 60 | 66 |
| 61 EventListener getEventHandler(controller, target, String method) => (e) { | 67 EventListener getEventHandler(controller, target, String method) => (e) { |
| 62 if (controller == null || controller is! Polymer) { | 68 if (controller == null || controller is! Polymer) { |
| 63 controller = findController(target); | 69 controller = findController(target); |
| 64 } | 70 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return map; | 169 return map; |
| 164 }(); | 170 }(); |
| 165 | 171 |
| 166 // Dart note: we need this function because we have additional renames JS does | 172 // Dart note: we need this function because we have additional renames JS does |
| 167 // not have. The JS renames are simply case differences, whereas we have ones | 173 // not have. The JS renames are simply case differences, whereas we have ones |
| 168 // like doubleclick -> dblclick and stripping the webkit prefix. | 174 // like doubleclick -> dblclick and stripping the webkit prefix. |
| 169 String _eventNameFromType(String eventType) { | 175 String _eventNameFromType(String eventType) { |
| 170 final result = _reverseEventTranslations[eventType]; | 176 final result = _reverseEventTranslations[eventType]; |
| 171 return result != null ? result : eventType; | 177 return result != null ? result : eventType; |
| 172 } | 178 } |
| OLD | NEW |