| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides functionality to generate dart:html event classes.""" | 6 """This module provides functionality to generate dart:html event classes.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 | 9 |
| 10 _logger = logging.getLogger('dartgenerator') | 10 _logger = logging.getLogger('dartgenerator') |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 'writestart': 'writeStart' | 182 'writestart': 'writeStart' |
| 183 } | 183 } |
| 184 | 184 |
| 185 # These classes require an explicit declaration for the "on" method even though | 185 # These classes require an explicit declaration for the "on" method even though |
| 186 # they don't declare any unique events, because the concrete class hierarchy | 186 # they don't declare any unique events, because the concrete class hierarchy |
| 187 # doesn't match the interface hierarchy. | 187 # doesn't match the interface hierarchy. |
| 188 _html_explicit_event_classes = set(['DocumentFragment']) | 188 _html_explicit_event_classes = set(['DocumentFragment']) |
| 189 | 189 |
| 190 class HtmlEventGenerator(object): | 190 class HtmlEventGenerator(object): |
| 191 | 191 |
| 192 def __init__(self, database, template_loader): | 192 def __init__(self, database, renamer, template_loader): |
| 193 self._event_classes = set() | 193 self._event_classes = set() |
| 194 self._database = database | 194 self._database = database |
| 195 self._renamer = renamer |
| 195 self._template_loader = template_loader | 196 self._template_loader = template_loader |
| 196 | 197 |
| 197 def ProcessInterface(self, interface, html_interface_name, custom_events, | 198 def ProcessInterface(self, interface, html_interface_name, custom_events, |
| 198 events_implementation_emitter): | 199 events_implementation_emitter): |
| 199 event_names = set([attr.id[2:] for attr in interface.attributes | 200 event_names = set([attr.id[2:] for attr in interface.attributes |
| 200 if attr.type.id == 'EventListener']) | 201 if attr.type.id == 'EventListener']) |
| 201 | 202 |
| 202 # Document and DocumentFragment actually derive from Element, so omit | 203 # Document and DocumentFragment actually derive from Element, so omit |
| 203 # any events which are duplicated with that. | 204 # any events which are duplicated with that. |
| 204 if interface.id == 'Document' or interface.id == 'DocumentFragment': | 205 if interface.id == 'Document' or interface.id == 'DocumentFragment': |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 def _GetParentEventsClassName(self, interface): | 258 def _GetParentEventsClassName(self, interface): |
| 258 # Ugly hack as we don't specify that Document and DocumentFragment inherit | 259 # Ugly hack as we don't specify that Document and DocumentFragment inherit |
| 259 # from Element in our IDL. | 260 # from Element in our IDL. |
| 260 if interface.id == 'Document' or interface.id == 'DocumentFragment': | 261 if interface.id == 'Document' or interface.id == 'DocumentFragment': |
| 261 return 'ElementEvents' | 262 return 'ElementEvents' |
| 262 | 263 |
| 263 parent_events_class_name = 'Events' | 264 parent_events_class_name = 'Events' |
| 264 interfaces_with_events = set() | 265 interfaces_with_events = set() |
| 265 for parent in self._database.Hierarchy(interface): | 266 for parent in self._database.Hierarchy(interface): |
| 266 if parent != interface and parent.id in self._event_classes: | 267 if parent != interface and parent.id in self._event_classes: |
| 267 parent_events_class_name = parent.id + 'Events' | 268 parent_name = self._renamer.RenameInterface(parent) |
| 269 parent_events_class_name = parent_name + 'Events' |
| 268 interfaces_with_events.add(parent) | 270 interfaces_with_events.add(parent) |
| 269 if len(interfaces_with_events) > 1: | 271 if len(interfaces_with_events) > 1: |
| 270 raise Exception('Only one parent event class allowed ' + interface.id) | 272 raise Exception('Only one parent event class allowed ' + interface.id) |
| 271 return parent_events_class_name | 273 return parent_events_class_name |
| OLD | NEW |