| 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 import monitored | 9 import monitored |
| 10 | 10 |
| 11 _logger = logging.getLogger('dartgenerator') | 11 _logger = logging.getLogger('dartgenerator') |
| 12 | 12 |
| 13 # Events without onEventName attributes in the IDL we want to support. | 13 # Events without onEventName attributes in the IDL we want to support. |
| 14 # We can automatically extract most event names by checking for | 14 # We can automatically extract most event names by checking for |
| 15 # onEventName methods in the IDL but some events aren't listed so we need | 15 # onEventName methods in the IDL but some events aren't listed so we need |
| 16 # to manually add them here so that they are easy for users to find. | 16 # to manually add them here so that they are easy for users to find. |
| 17 _html_manual_events = monitored.Dict('htmleventgenerator._html_manual_events', { | 17 _html_manual_events = monitored.Dict('htmleventgenerator._html_manual_events', { |
| 18 'Element': ['touchleave', 'touchenter', 'transitionend'], | 18 'Element': ['ontouchleave', 'ontouchenter', 'ontransitionend'], |
| 19 'Window': ['DOMContentLoaded'] | 19 'HTMLCanvasElement': ['onwebglcontextlost', 'onwebglcontextrestored'], |
| 20 'Window': ['onDOMContentLoaded'] |
| 20 }) | 21 }) |
| 21 | 22 |
| 22 # These event names must be camel case when attaching event listeners | 23 # These event names must be camel case when attaching event listeners |
| 23 # using addEventListener even though the onEventName properties in the DOM for | 24 # using addEventListener even though the onEventName properties in the DOM for |
| 24 # them are not camel case. | 25 # them are not camel case. |
| 25 _on_attribute_to_event_name_mapping = monitored.Dict( | 26 _on_attribute_to_event_name_mapping = monitored.Dict( |
| 26 'htmleventgenerator._on_attribute_to_event_name_mapping', { | 27 'htmleventgenerator._on_attribute_to_event_name_mapping', { |
| 27 'webkitanimationend': 'webkitAnimationEnd', | 28 'webkitanimationend': 'webkitAnimationEnd', |
| 28 'webkitanimationiteration': 'webkitAnimationIteration', | 29 'webkitanimationiteration': 'webkitAnimationIteration', |
| 29 'webkitanimationstart': 'webkitAnimationStart', | 30 'webkitanimationstart': 'webkitAnimationStart', |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 'FileWriter.abort': ('abort', 'ProgressEvent'), | 134 'FileWriter.abort': ('abort', 'ProgressEvent'), |
| 134 'FileWriter.progress': ('progress', 'ProgressEvent'), | 135 'FileWriter.progress': ('progress', 'ProgressEvent'), |
| 135 'FileWriter.write': ('write', 'ProgressEvent'), | 136 'FileWriter.write': ('write', 'ProgressEvent'), |
| 136 'FileWriter.writeend': ('writeEnd', 'ProgressEvent'), | 137 'FileWriter.writeend': ('writeEnd', 'ProgressEvent'), |
| 137 'FileWriter.writestart': ('writeStart', 'ProgressEvent'), | 138 'FileWriter.writestart': ('writeStart', 'ProgressEvent'), |
| 138 'FontLoader.load': ('load', 'CssFontFaceLoadEvent'), | 139 'FontLoader.load': ('load', 'CssFontFaceLoadEvent'), |
| 139 'FontLoader.loading': ('loading', 'CssFontFaceLoadEvent'), | 140 'FontLoader.loading': ('loading', 'CssFontFaceLoadEvent'), |
| 140 'FontLoader.loadingdone': ('loadingDone', 'CssFontFaceLoadEvent'), | 141 'FontLoader.loadingdone': ('loadingDone', 'CssFontFaceLoadEvent'), |
| 141 'FontLoader.loadstart': ('loadStart', 'CssFontFaceLoadEvent'), | 142 'FontLoader.loadstart': ('loadStart', 'CssFontFaceLoadEvent'), |
| 142 'HTMLBodyElement.storage': ('storage', 'StorageEvent'), | 143 'HTMLBodyElement.storage': ('storage', 'StorageEvent'), |
| 144 'HTMLCanvasElement.webglcontextlost': ('webGlContextLost', 'gl.ContextEvent'), |
| 145 'HTMLCanvasElement.webglcontextrestored': ('webGlContextRestored', 'gl.Context
Event'), |
| 143 'HTMLInputElement.webkitSpeechChange': ('speechChange', 'Event'), | 146 'HTMLInputElement.webkitSpeechChange': ('speechChange', 'Event'), |
| 144 'HTMLFormElement.autocomplete': ('autocomplete', 'Event'), | 147 'HTMLFormElement.autocomplete': ('autocomplete', 'Event'), |
| 145 'HTMLFormElement.autocompleteerror': ('autocompleteError', 'AutocompleteErrorE
vent'), | 148 'HTMLFormElement.autocompleteerror': ('autocompleteError', 'AutocompleteErrorE
vent'), |
| 146 'HTMLMediaElement.loadstart': ('loadStart', 'Event'), | 149 'HTMLMediaElement.loadstart': ('loadStart', 'Event'), |
| 147 'HTMLMediaElement.progress': ('progress', 'Event'), | 150 'HTMLMediaElement.progress': ('progress', 'Event'), |
| 148 'HTMLMediaElement.show': ('show', 'Event'), | 151 'HTMLMediaElement.show': ('show', 'Event'), |
| 149 'HTMLMediaElement.webkitkeyadded': ('keyAdded', 'MediaKeyEvent'), | 152 'HTMLMediaElement.webkitkeyadded': ('keyAdded', 'MediaKeyEvent'), |
| 150 'HTMLMediaElement.webkitkeyerror': ('keyError', 'MediaKeyEvent'), | 153 'HTMLMediaElement.webkitkeyerror': ('keyError', 'MediaKeyEvent'), |
| 151 'HTMLMediaElement.webkitkeymessage': ('keyMessage', 'MediaKeyEvent'), | 154 'HTMLMediaElement.webkitkeymessage': ('keyMessage', 'MediaKeyEvent'), |
| 152 'HTMLMediaElement.webkitneedkey': ('needKey', 'MediaKeyEvent'), | 155 'HTMLMediaElement.webkitneedkey': ('needKey', 'MediaKeyEvent'), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 " $(ANNOTATIONS)Stream<$TYPE> get $(NAME) => " | 296 " $(ANNOTATIONS)Stream<$TYPE> get $(NAME) => " |
| 294 "$PROVIDER.forTarget(this);\n", | 297 "$PROVIDER.forTarget(this);\n", |
| 295 ANNOTATIONS=annotations, | 298 ANNOTATIONS=annotations, |
| 296 NAME=getter_name, | 299 NAME=getter_name, |
| 297 PROVIDER=provider, | 300 PROVIDER=provider, |
| 298 TYPE=event_type) | 301 TYPE=event_type) |
| 299 | 302 |
| 300 def _GetEvents(self, interface, custom_events): | 303 def _GetEvents(self, interface, custom_events): |
| 301 """ Gets a list of all of the events for the specified interface. | 304 """ Gets a list of all of the events for the specified interface. |
| 302 """ | 305 """ |
| 303 events = set([attr for attr in interface.attributes | 306 html_interface_name = interface.doc_js_name |
| 307 |
| 308 events = set([attr.id for attr in interface.attributes |
| 304 if attr.type.id == 'EventListener']) | 309 if attr.type.id == 'EventListener']) |
| 305 if not events and interface.id not in _html_explicit_event_classes: | 310 |
| 311 if html_interface_name in _html_manual_events: |
| 312 events.update(_html_manual_events[html_interface_name]) |
| 313 |
| 314 if not events and interface.id not in _html_explicit_event_classes : |
| 306 return None | 315 return None |
| 307 | 316 |
| 308 html_interface_name = interface.doc_js_name | |
| 309 | |
| 310 dom_event_names = set() | 317 dom_event_names = set() |
| 311 for event in events: | 318 for event in events: |
| 312 dom_name = event.id[2:] | 319 dom_name = event[2:] |
| 313 dom_name = _on_attribute_to_event_name_mapping.get(dom_name, dom_name) | 320 dom_name = _on_attribute_to_event_name_mapping.get(dom_name, dom_name) |
| 314 dom_event_names.add(dom_name) | 321 dom_event_names.add(dom_name) |
| 315 if html_interface_name in _html_manual_events: | |
| 316 dom_event_names.update(_html_manual_events[html_interface_name]) | |
| 317 | 322 |
| 318 events = [] | 323 events = [] |
| 319 for dom_name in sorted(dom_event_names): | 324 for dom_name in sorted(dom_event_names): |
| 320 event_info = self._FindEventInfo(html_interface_name, dom_name) | 325 event_info = self._FindEventInfo(html_interface_name, dom_name) |
| 321 if not event_info: | 326 if not event_info: |
| 322 continue | 327 continue |
| 323 | 328 |
| 324 (html_name, event_type) = event_info | 329 (html_name, event_type) = event_info |
| 325 if self._IsEventSuppressed(interface, html_name, event_type): | 330 if self._IsEventSuppressed(interface, html_name, event_type): |
| 326 continue | 331 continue |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 """ | 372 """ |
| 368 key = '%s.%s' % (html_interface_name, dom_event_name) | 373 key = '%s.%s' % (html_interface_name, dom_event_name) |
| 369 if key in _html_event_types: | 374 if key in _html_event_types: |
| 370 return _html_event_types[key] | 375 return _html_event_types[key] |
| 371 key = '*.%s' % dom_event_name | 376 key = '*.%s' % dom_event_name |
| 372 if key in _html_event_types: | 377 if key in _html_event_types: |
| 373 return _html_event_types[key] | 378 return _html_event_types[key] |
| 374 _logger.warn('Cannot resolve event type for %s.%s' % | 379 _logger.warn('Cannot resolve event type for %s.%s' % |
| 375 (html_interface_name, dom_event_name)) | 380 (html_interface_name, dom_event_name)) |
| 376 return None | 381 return None |
| OLD | NEW |