| 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 from generator import GetAnnotationsAndComments, FormatAnnotationsAndComments | 10 from generator import GetAnnotationsAndComments, FormatAnnotationsAndComments |
| 10 | 11 |
| 11 _logger = logging.getLogger('dartgenerator') | 12 _logger = logging.getLogger('dartgenerator') |
| 12 | 13 |
| 13 # Events without onEventName attributes in the IDL we want to support. | 14 # Events without onEventName attributes in the IDL we want to support. |
| 14 # We can automatically extract most event names by checking for | 15 # 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 | 16 # 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. | 17 # to manually add them here so that they are easy for users to find. |
| 17 _html_manual_events = { | 18 _html_manual_events = monitored.Dict('htmleventgenerator._html_manual_events', { |
| 18 'Element': ['touchleave', 'touchenter', 'webkitTransitionEnd'], | 19 'Element': ['touchleave', 'touchenter', 'webkitTransitionEnd'], |
| 19 'Window': ['DOMContentLoaded'] | 20 'Window': ['DOMContentLoaded'] |
| 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 = { | 26 _on_attribute_to_event_name_mapping = monitored.Dict( |
| 27 'htmleventgenerator._on_attribute_to_event_name_mapping', { |
| 26 'webkitanimationend': 'webkitAnimationEnd', | 28 'webkitanimationend': 'webkitAnimationEnd', |
| 27 'webkitanimationiteration': 'webkitAnimationIteration', | 29 'webkitanimationiteration': 'webkitAnimationIteration', |
| 28 'webkitanimationstart': 'webkitAnimationStart', | 30 'webkitanimationstart': 'webkitAnimationStart', |
| 29 'webkitspeechchange': 'webkitSpeechChange', | 31 'webkitspeechchange': 'webkitSpeechChange', |
| 30 'webkittransitionend': 'webkitTransitionEnd', | 32 'webkittransitionend': 'webkitTransitionEnd', |
| 31 } | 33 }) |
| 32 | 34 |
| 33 _html_event_types = { | 35 _html_event_types = monitored.Dict('htmleventgenerator._html_event_types', { |
| 34 '*.abort': ('abort', 'Event'), | 36 '*.abort': ('abort', 'Event'), |
| 35 '*.beforecopy': ('beforeCopy', 'Event'), | 37 '*.beforecopy': ('beforeCopy', 'Event'), |
| 36 '*.beforecut': ('beforeCut', 'Event'), | 38 '*.beforecut': ('beforeCut', 'Event'), |
| 37 '*.beforepaste': ('beforePaste', 'Event'), | 39 '*.beforepaste': ('beforePaste', 'Event'), |
| 38 '*.beforeunload': ('beforeUnload', 'Event'), | 40 '*.beforeunload': ('beforeUnload', 'Event'), |
| 39 '*.blur': ('blur', 'Event'), | 41 '*.blur': ('blur', 'Event'), |
| 40 '*.canplay': ('canPlay', 'Event'), | 42 '*.canplay': ('canPlay', 'Event'), |
| 41 '*.canplaythrough': ('canPlayThrough', 'Event'), | 43 '*.canplaythrough': ('canPlayThrough', 'Event'), |
| 42 '*.change': ('change', 'Event'), | 44 '*.change': ('change', 'Event'), |
| 43 '*.click': ('click', 'MouseEvent'), | 45 '*.click': ('click', 'MouseEvent'), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 'BatteryManager.chargingtimechange': ('chargingTimeChange', 'Event'), | 117 'BatteryManager.chargingtimechange': ('chargingTimeChange', 'Event'), |
| 116 'BatteryManager.dischargingtimechange': ('dischargingTimeChange', 'Event'), | 118 'BatteryManager.dischargingtimechange': ('dischargingTimeChange', 'Event'), |
| 117 'BatteryManager.levelchange': ('levelChange', 'Event'), | 119 'BatteryManager.levelchange': ('levelChange', 'Event'), |
| 118 'DOMApplicationCache.cached': ('cached', 'Event'), | 120 'DOMApplicationCache.cached': ('cached', 'Event'), |
| 119 'DOMApplicationCache.checking': ('checking', 'Event'), | 121 'DOMApplicationCache.checking': ('checking', 'Event'), |
| 120 'DOMApplicationCache.downloading': ('downloading', 'Event'), | 122 'DOMApplicationCache.downloading': ('downloading', 'Event'), |
| 121 'DOMApplicationCache.noupdate': ('noUpdate', 'Event'), | 123 'DOMApplicationCache.noupdate': ('noUpdate', 'Event'), |
| 122 'DOMApplicationCache.obsolete': ('obsolete', 'Event'), | 124 'DOMApplicationCache.obsolete': ('obsolete', 'Event'), |
| 123 'DOMApplicationCache.progress': ('progress', 'Event'), | 125 'DOMApplicationCache.progress': ('progress', 'Event'), |
| 124 'DOMApplicationCache.updateready': ('updateReady', 'Event'), | 126 'DOMApplicationCache.updateready': ('updateReady', 'Event'), |
| 125 'Document.cuechange': ('cueChange', 'Event'), | |
| 126 'Document.readystatechange': ('readyStateChange', 'Event'), | 127 'Document.readystatechange': ('readyStateChange', 'Event'), |
| 127 'Document.selectionchange': ('selectionChange', 'Event'), | 128 'Document.selectionchange': ('selectionChange', 'Event'), |
| 128 'Document.webkitpointerlockchange': ('pointerLockChange', 'Event'), | 129 'Document.webkitpointerlockchange': ('pointerLockChange', 'Event'), |
| 129 'Document.webkitpointerlockerror': ('pointerLockError', 'Event'), | 130 'Document.webkitpointerlockerror': ('pointerLockError', 'Event'), |
| 130 'Element.cuechange': ('cueChange', 'Event'), | |
| 131 'EventSource.open': ('open', 'Event'), | 131 'EventSource.open': ('open', 'Event'), |
| 132 'FileReader.abort': ('abort', 'ProgressEvent'), | 132 'FileReader.abort': ('abort', 'ProgressEvent'), |
| 133 'FileReader.load': ('load', 'ProgressEvent'), | 133 'FileReader.load': ('load', 'ProgressEvent'), |
| 134 'FileReader.loadend': ('loadEnd', 'ProgressEvent'), | 134 'FileReader.loadend': ('loadEnd', 'ProgressEvent'), |
| 135 'FileReader.loadstart': ('loadStart', 'ProgressEvent'), | 135 'FileReader.loadstart': ('loadStart', 'ProgressEvent'), |
| 136 'FileReader.progress': ('progress', 'ProgressEvent'), | 136 'FileReader.progress': ('progress', 'ProgressEvent'), |
| 137 'FileWriter.abort': ('abort', 'ProgressEvent'), | 137 'FileWriter.abort': ('abort', 'ProgressEvent'), |
| 138 'FileWriter.progress': ('progress', 'ProgressEvent'), | 138 'FileWriter.progress': ('progress', 'ProgressEvent'), |
| 139 'FileWriter.write': ('write', 'ProgressEvent'), | 139 'FileWriter.write': ('write', 'ProgressEvent'), |
| 140 'FileWriter.writeend': ('writeEnd', 'ProgressEvent'), | 140 'FileWriter.writeend': ('writeEnd', 'ProgressEvent'), |
| 141 'FileWriter.writestart': ('writeStart', 'ProgressEvent'), | 141 'FileWriter.writestart': ('writeStart', 'ProgressEvent'), |
| 142 'HTMLBodyElement.storage': ('storage', 'StorageEvent'), | 142 'HTMLBodyElement.storage': ('storage', 'StorageEvent'), |
| 143 'HTMLInputElement.webkitSpeechChange': ('speechChange', 'Event'), | 143 'HTMLInputElement.webkitSpeechChange': ('speechChange', 'Event'), |
| 144 'HTMLMediaElement.loadstart': ('loadStart', 'Event'), | 144 'HTMLMediaElement.loadstart': ('loadStart', 'Event'), |
| 145 'HTMLMediaElement.progress': ('progress', 'Event'), | 145 'HTMLMediaElement.progress': ('progress', 'Event'), |
| 146 'HTMLMediaElement.show': ('show', 'Event'), | 146 'HTMLMediaElement.show': ('show', 'Event'), |
| 147 'HTMLMediaElement.webkitkeyadded': ('keyAdded', 'MediaKeyEvent'), | 147 'HTMLMediaElement.webkitkeyadded': ('keyAdded', 'MediaKeyEvent'), |
| 148 'HTMLMediaElement.webkitkeyerror': ('keyError', 'MediaKeyEvent'), | 148 'HTMLMediaElement.webkitkeyerror': ('keyError', 'MediaKeyEvent'), |
| 149 'HTMLMediaElement.webkitkeymessage': ('keyMessage', 'MediaKeyEvent'), | 149 'HTMLMediaElement.webkitkeymessage': ('keyMessage', 'MediaKeyEvent'), |
| 150 'HTMLMediaElement.webkitneedkey': ('needKey', 'MediaKeyEvent'), | 150 'HTMLMediaElement.webkitneedkey': ('needKey', 'MediaKeyEvent'), |
| 151 'IDBDatabase.versionchange': ('versionChange', 'VersionChangeEvent'), | 151 'IDBDatabase.versionchange': ('versionChange', 'VersionChangeEvent'), |
| 152 'IDBOpenDBRequest.blocked': ('blocked', 'Event'), | 152 'IDBOpenDBRequest.blocked': ('blocked', 'Event'), |
| 153 'IDBOpenDBRequest.upgradeneeded': ('upgradeNeeded', 'VersionChangeEvent'), | 153 'IDBOpenDBRequest.upgradeneeded': ('upgradeNeeded', 'VersionChangeEvent'), |
| 154 'IDBRequest.success': ('success', 'Event'), | 154 'IDBRequest.success': ('success', 'Event'), |
| 155 'IDBTransaction.complete': ('complete', 'Event'), | 155 'IDBTransaction.complete': ('complete', 'Event'), |
| 156 'IDBVersionChangeRequest.blocked': ('blocked', 'Event'), | 156 'MediaStream.addtrack': ('addTrack', 'Event'), |
| 157 'MediaController.play': ('play', 'Event'), | 157 'MediaStream.removetrack': ('removeTrack', 'Event'), |
| 158 'MediaStreamTrack.mute': ('mute', 'Event'), | 158 'MediaStreamTrack.mute': ('mute', 'Event'), |
| 159 'MediaStreamTrack.unmute': ('unmute', 'Event'), | 159 'MediaStreamTrack.unmute': ('unmute', 'Event'), |
| 160 'MediaStreamTrackList.addtrack': ('addTrack', 'MediaStreamTrackEvent'), | |
| 161 'MediaStreamTrackList.removetrack': ('removeTrack', 'MediaStreamTrackEvent'), | |
| 162 'Notification.click': ('click', 'Event'), | 160 'Notification.click': ('click', 'Event'), |
| 163 'Notification.close': ('close', 'Event'), | 161 'Notification.close': ('close', 'Event'), |
| 164 'Notification.display': ('display', 'Event'), | 162 'Notification.display': ('display', 'Event'), |
| 165 'Notification.show': ('show', 'Event'), | 163 'Notification.show': ('show', 'Event'), |
| 166 'RTCDataChannel.close': ('close', 'Event'), | 164 'RTCDataChannel.close': ('close', 'Event'), |
| 167 'RTCDataChannel.open': ('open', 'Event'), | 165 'RTCDataChannel.open': ('open', 'Event'), |
| 168 'RTCPeerConnection.addstream': ('addStream', 'MediaStreamEvent'), | 166 'RTCPeerConnection.addstream': ('addStream', 'MediaStreamEvent'), |
| 169 'RTCPeerConnection.connecting': ('connecting', 'MediaStreamEvent'), | |
| 170 'RTCPeerConnection.datachannel': ('dataChannel', 'RtcDataChannelEvent'), | 167 'RTCPeerConnection.datachannel': ('dataChannel', 'RtcDataChannelEvent'), |
| 171 'RTCPeerConnection.icecandidate': ('iceCandidate', 'RtcIceCandidateEvent'), | 168 'RTCPeerConnection.icecandidate': ('iceCandidate', 'RtcIceCandidateEvent'), |
| 172 'RTCPeerConnection.icechange': ('iceChange', 'Event'), | 169 'RTCPeerConnection.icechange': ('iceChange', 'Event'), |
| 170 'RTCPeerConnection.gatheringchange': ('gatheringChange', 'Event'), |
| 173 'RTCPeerConnection.negotiationneeded': ('negotiationNeeded', 'Event'), | 171 'RTCPeerConnection.negotiationneeded': ('negotiationNeeded', 'Event'), |
| 174 'RTCPeerConnection.open': ('open', 'Event'), | |
| 175 'RTCPeerConnection.removestream': ('removeStream', 'MediaStreamEvent'), | 172 'RTCPeerConnection.removestream': ('removeStream', 'MediaStreamEvent'), |
| 176 'RTCPeerConnection.statechange': ('stateChange', 'Event'), | 173 'RTCPeerConnection.statechange': ('stateChange', 'Event'), |
| 177 'ScriptProcessorNode.audioprocess': ('audioProcess', 'AudioProcessingEvent'), | |
| 178 'SharedWorkerContext.connect': ('connect', 'Event'), | 174 'SharedWorkerContext.connect': ('connect', 'Event'), |
| 179 'SpeechRecognition.audioend': ('audioEnd', 'Event'), | 175 'SpeechRecognition.audioend': ('audioEnd', 'Event'), |
| 180 'SpeechRecognition.audiostart': ('audioStart', 'Event'), | 176 'SpeechRecognition.audiostart': ('audioStart', 'Event'), |
| 181 'SpeechRecognition.end': ('end', 'Event'), | 177 'SpeechRecognition.end': ('end', 'Event'), |
| 182 'SpeechRecognition.error': ('error', 'SpeechRecognitionError'), | 178 'SpeechRecognition.error': ('error', 'SpeechRecognitionError'), |
| 183 'SpeechRecognition.nomatch': ('noMatch', 'SpeechRecognitionEvent'), | 179 'SpeechRecognition.nomatch': ('noMatch', 'SpeechRecognitionEvent'), |
| 184 'SpeechRecognition.result': ('result', 'SpeechRecognitionEvent'), | 180 'SpeechRecognition.result': ('result', 'SpeechRecognitionEvent'), |
| 185 'SpeechRecognition.soundend': ('soundEnd', 'Event'), | 181 'SpeechRecognition.soundend': ('soundEnd', 'Event'), |
| 186 'SpeechRecognition.soundstart': ('soundStart', 'Event'), | 182 'SpeechRecognition.soundstart': ('soundStart', 'Event'), |
| 187 'SpeechRecognition.speechend': ('speechEnd', 'Event'), | 183 'SpeechRecognition.speechend': ('speechEnd', 'Event'), |
| 188 'SpeechRecognition.speechstart': ('speechStart', 'Event'), | 184 'SpeechRecognition.speechstart': ('speechStart', 'Event'), |
| 189 'SpeechRecognition.start': ('start', 'Event'), | 185 'SpeechRecognition.start': ('start', 'Event'), |
| 190 'TextTrack.cuechange': ('cueChange', 'Event'), | 186 'TextTrack.cuechange': ('cueChange', 'Event'), |
| 191 'TextTrackCue.enter': ('enter', 'Event'), | 187 'TextTrackCue.enter': ('enter', 'Event'), |
| 192 'TextTrackCue.exit': ('exit', 'Event'), | 188 'TextTrackCue.exit': ('exit', 'Event'), |
| 193 'TextTrackList.addtrack': ('addTrack', 'TrackEvent'), | 189 'TextTrackList.addtrack': ('addTrack', 'TrackEvent'), |
| 194 'WebSocket.close': ('close', 'CloseEvent'), | 190 'WebSocket.close': ('close', 'CloseEvent'), |
| 195 'WebSocket.open': ('open', 'Event'), # should be OpenEvent, but not exposed. | 191 'WebSocket.open': ('open', 'Event'), # should be OpenEvent, but not exposed. |
| 196 'Window.DOMContentLoaded': ('contentLoaded', 'Event'), | 192 'Window.DOMContentLoaded': ('contentLoaded', 'Event'), |
| 197 'Window.cuechange': ('cueChange', 'Event'), | |
| 198 'Window.devicemotion': ('deviceMotion', 'DeviceMotionEvent'), | 193 'Window.devicemotion': ('deviceMotion', 'DeviceMotionEvent'), |
| 199 'Window.deviceorientation': ('deviceOrientation', 'DeviceOrientationEvent'), | 194 'Window.deviceorientation': ('deviceOrientation', 'DeviceOrientationEvent'), |
| 200 'Window.loadstart': ('loadStart', 'Event'), | 195 'Window.loadstart': ('loadStart', 'Event'), |
| 201 'Window.pagehide': ('pageHide', 'Event'), | 196 'Window.pagehide': ('pageHide', 'Event'), |
| 202 'Window.pageshow': ('pageShow', 'Event'), | 197 'Window.pageshow': ('pageShow', 'Event'), |
| 203 'Window.progress': ('progress', 'Event'), | 198 'Window.progress': ('progress', 'Event'), |
| 204 'XMLHttpRequest.abort': ('abort', 'ProgressEvent'), | 199 'XMLHttpRequest.abort': ('abort', 'ProgressEvent'), |
| 205 'XMLHttpRequest.error': ('error', 'ProgressEvent'), | 200 'XMLHttpRequest.error': ('error', 'ProgressEvent'), |
| 206 'XMLHttpRequest.load': ('load', 'ProgressEvent'), | 201 'XMLHttpRequest.load': ('load', 'ProgressEvent'), |
| 207 'XMLHttpRequest.loadend': ('loadEnd', 'ProgressEvent'), | 202 'XMLHttpRequest.loadend': ('loadEnd', 'ProgressEvent'), |
| 208 'XMLHttpRequest.loadstart': ('loadStart', 'ProgressEvent'), | 203 'XMLHttpRequest.loadstart': ('loadStart', 'ProgressEvent'), |
| 209 'XMLHttpRequest.progress': ('progress', 'ProgressEvent'), | 204 'XMLHttpRequest.progress': ('progress', 'ProgressEvent'), |
| 210 'XMLHttpRequest.readystatechange': ('readyStateChange', 'ProgressEvent'), | 205 'XMLHttpRequest.readystatechange': ('readyStateChange', 'ProgressEvent'), |
| 211 'XMLHttpRequestUpload.abort': ('abort', 'ProgressEvent'), | 206 'XMLHttpRequestUpload.abort': ('abort', 'ProgressEvent'), |
| 212 'XMLHttpRequestUpload.error': ('error', 'ProgressEvent'), | 207 'XMLHttpRequestUpload.error': ('error', 'ProgressEvent'), |
| 213 'XMLHttpRequestUpload.load': ('load', 'ProgressEvent'), | 208 'XMLHttpRequestUpload.load': ('load', 'ProgressEvent'), |
| 214 'XMLHttpRequestUpload.loadend': ('loadEnd', 'ProgressEvent'), | 209 'XMLHttpRequestUpload.loadend': ('loadEnd', 'ProgressEvent'), |
| 215 'XMLHttpRequestUpload.loadstart': ('loadStart', 'ProgressEvent'), | 210 'XMLHttpRequestUpload.loadstart': ('loadStart', 'ProgressEvent'), |
| 216 'XMLHttpRequestUpload.progress': ('progress', 'ProgressEvent'), | 211 'XMLHttpRequestUpload.progress': ('progress', 'ProgressEvent'), |
| 217 } | 212 }) |
| 218 | 213 |
| 219 # These classes require an explicit declaration for the "on" method even though | 214 # These classes require an explicit declaration for the "on" method even though |
| 220 # they don't declare any unique events, because the concrete class hierarchy | 215 # they don't declare any unique events, because the concrete class hierarchy |
| 221 # doesn't match the interface hierarchy. | 216 # doesn't match the interface hierarchy. |
| 222 _html_explicit_event_classes = set(['DocumentFragment']) | 217 _html_explicit_event_classes = set(['DocumentFragment']) |
| 223 | 218 |
| 224 class HtmlEventGenerator(object): | 219 class HtmlEventGenerator(object): |
| 225 | 220 |
| 226 def __init__(self, database, renamer, template_loader): | 221 def __init__(self, database, renamer, template_loader): |
| 227 self._event_classes = set() | 222 self._event_classes = set() |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 """ | 352 """ |
| 358 key = '%s.%s' % (html_interface_name, dom_event_name) | 353 key = '%s.%s' % (html_interface_name, dom_event_name) |
| 359 if key in _html_event_types: | 354 if key in _html_event_types: |
| 360 return _html_event_types[key] | 355 return _html_event_types[key] |
| 361 key = '*.%s' % dom_event_name | 356 key = '*.%s' % dom_event_name |
| 362 if key in _html_event_types: | 357 if key in _html_event_types: |
| 363 return _html_event_types[key] | 358 return _html_event_types[key] |
| 364 _logger.warn('Cannot resolve event type for %s.%s' % | 359 _logger.warn('Cannot resolve event type for %s.%s' % |
| 365 (html_interface_name, dom_event_name)) | 360 (html_interface_name, dom_event_name)) |
| 366 return None | 361 return None |
| OLD | NEW |