Chromium Code Reviews| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 'write': 'write', | 180 'write': 'write', |
| 181 'writeend': 'writeEnd', | 181 'writeend': 'writeEnd', |
| 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 # These classes are not really proper events targets, even though the IDL claims | |
| 191 # they are. We don't make these the dart-style event names since they're not | |
| 192 # really events -- the user uses them the same way they would use any other | |
| 193 # event in JavaScript -- by assigning an event handler function. | |
| 194 use_idl_event_style = set(['ScriptProcessorNode']) | |
|
blois
2012/12/07 23:40:00
The name seems a bit odd- this is basically the co
Emily Fortuna
2012/12/07 23:58:22
No. The items in "use_idl_event_style" have attr.t
| |
| 195 | |
| 190 class HtmlEventGenerator(object): | 196 class HtmlEventGenerator(object): |
| 191 | 197 |
| 192 def __init__(self, database, renamer, template_loader): | 198 def __init__(self, database, renamer, template_loader): |
| 193 self._event_classes = set() | 199 self._event_classes = set() |
| 194 self._database = database | 200 self._database = database |
| 195 self._renamer = renamer | 201 self._renamer = renamer |
| 196 self._template_loader = template_loader | 202 self._template_loader = template_loader |
| 197 | 203 |
| 198 def ProcessInterface(self, interface, html_interface_name, custom_events, | 204 def ProcessInterface(self, interface, html_interface_name, custom_events, |
| 199 events_implementation_emitter): | 205 events_implementation_emitter): |
| 200 event_names = set([attr.id[2:] for attr in interface.attributes | 206 event_names = set([attr.id[2:] for attr in interface.attributes |
| 201 if attr.type.id == 'EventListener']) | 207 if attr.type.id == 'EventListener']) |
| 202 | 208 |
| 203 # Document and DocumentFragment actually derive from Element, so omit | 209 # Document and DocumentFragment actually derive from Element, so omit |
| 204 # any events which are duplicated with that. | 210 # any events which are duplicated with that. |
| 205 if interface.id == 'Document' or interface.id == 'DocumentFragment': | 211 if interface.id == 'Document' or interface.id == 'DocumentFragment': |
| 206 element_interface = self._database.GetInterface('Element') | 212 element_interface = self._database.GetInterface('Element') |
| 207 for attr in element_interface.attributes: | 213 for attr in element_interface.attributes: |
| 208 if attr.type.id == 'EventListener' and attr.id[2:] in event_names: | 214 if attr.type.id == 'EventListener' and attr.id[2:] in event_names: |
| 209 event_names.remove(attr.id[2:]) | 215 event_names.remove(attr.id[2:]) |
| 210 | 216 |
| 211 if not event_names and interface.id not in _html_explicit_event_classes: | 217 if interface.id in use_idl_event_style or ( |
| 218 not event_names and interface.id not in _html_explicit_event_classes): | |
| 212 return None | 219 return None |
| 213 | 220 |
| 214 self._event_classes.add(interface.id) | 221 self._event_classes.add(interface.id) |
| 215 events_class_name = html_interface_name + 'Events' | 222 events_class_name = html_interface_name + 'Events' |
| 216 parent_events_class_name = self._GetParentEventsClassName(interface) | 223 parent_events_class_name = self._GetParentEventsClassName(interface) |
| 217 | 224 |
| 218 if not event_names: | 225 if not event_names: |
| 219 return parent_events_class_name | 226 return parent_events_class_name |
| 220 | 227 |
| 221 template_file = 'impl_%s.darttemplate' % events_class_name | 228 template_file = 'impl_%s.darttemplate' % events_class_name |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 parent_events_class_name = 'Events' | 271 parent_events_class_name = 'Events' |
| 265 interfaces_with_events = set() | 272 interfaces_with_events = set() |
| 266 for parent in self._database.Hierarchy(interface): | 273 for parent in self._database.Hierarchy(interface): |
| 267 if parent != interface and parent.id in self._event_classes: | 274 if parent != interface and parent.id in self._event_classes: |
| 268 parent_name = self._renamer.RenameInterface(parent) | 275 parent_name = self._renamer.RenameInterface(parent) |
| 269 parent_events_class_name = parent_name + 'Events' | 276 parent_events_class_name = parent_name + 'Events' |
| 270 interfaces_with_events.add(parent) | 277 interfaces_with_events.add(parent) |
| 271 if len(interfaces_with_events) > 1: | 278 if len(interfaces_with_events) > 1: |
| 272 raise Exception('Only one parent event class allowed ' + interface.id) | 279 raise Exception('Only one parent event class allowed ' + interface.id) |
| 273 return parent_events_class_name | 280 return parent_events_class_name |
| OLD | NEW |