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 shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 import os | 10 import os |
(...skipping 23 matching lines...) Expand all Loading... |
34 'WheelEvent.wheelDeltaX', | 34 'WheelEvent.wheelDeltaX', |
35 'WheelEvent.wheelDeltaY', | 35 'WheelEvent.wheelDeltaY', |
36 'Window.cancelAnimationFrame', | 36 'Window.cancelAnimationFrame', |
37 'Window.document', | 37 'Window.document', |
38 'Window.indexedDB', | 38 'Window.indexedDB', |
39 'Window.location', | 39 'Window.location', |
40 'Window.open', | 40 'Window.open', |
41 'Window.requestAnimationFrame', | 41 'Window.requestAnimationFrame', |
42 'Window.webkitCancelAnimationFrame', | 42 'Window.webkitCancelAnimationFrame', |
43 'Window.webkitRequestAnimationFrame', | 43 'Window.webkitRequestAnimationFrame', |
| 44 'WorkerContext.indexedDB', |
44 ]) | 45 ]) |
45 | 46 |
46 | 47 |
47 # Classes that offer only static methods, and therefore we should suppress | 48 # Classes that offer only static methods, and therefore we should suppress |
48 # constructor creation. | 49 # constructor creation. |
49 _static_classes = set(['Url']) | 50 _static_classes = set(['Url']) |
50 | 51 |
51 # Information for generating element constructors. | 52 # Information for generating element constructors. |
52 # | 53 # |
53 # TODO(sra): maybe remove all the argument complexity and use cascades. | 54 # TODO(sra): maybe remove all the argument complexity and use cascades. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 'TitleElement': 'title', | 196 'TitleElement': 'title', |
196 'TRefElement': 'tref', | 197 'TRefElement': 'tref', |
197 'TSpanElement': 'tspan', | 198 'TSpanElement': 'tspan', |
198 'UseElement': 'use', | 199 'UseElement': 'use', |
199 'ViewElement': 'view', | 200 'ViewElement': 'view', |
200 'VKernElement': 'vkern', | 201 'VKernElement': 'vkern', |
201 } | 202 } |
202 | 203 |
203 _element_constructors = { | 204 _element_constructors = { |
204 'html': _html_element_constructors, | 205 'html': _html_element_constructors, |
| 206 'indexed_db': {}, |
205 'svg': _svg_element_constructors, | 207 'svg': _svg_element_constructors, |
206 'web_audio': {}, | 208 'web_audio': {}, |
207 } | 209 } |
208 | 210 |
209 _factory_ctr_strings = { | 211 _factory_ctr_strings = { |
210 'html': { | 212 'html': { |
211 'provider_name': 'document', | 213 'provider_name': 'document', |
212 'constructor_name': '$dom_createElement' | 214 'constructor_name': '$dom_createElement' |
213 }, | 215 }, |
| 216 'indexed_db': { |
| 217 'provider_name': 'document', |
| 218 'constructor_name': '$dom_createElement' |
| 219 }, |
214 'svg': { | 220 'svg': { |
215 'provider_name': '_SvgElementFactoryProvider', | 221 'provider_name': '_SvgElementFactoryProvider', |
216 'constructor_name': 'createSvgElement_tag', | 222 'constructor_name': 'createSvgElement_tag', |
217 }, | 223 }, |
218 'web_audio': { | 224 'web_audio': { |
219 'provider_name': 'document', | 225 'provider_name': 'document', |
220 'constructor_name': '$dom_createElement' | 226 'constructor_name': '$dom_createElement' |
221 }, | 227 }, |
222 } | 228 } |
223 | 229 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 self.GenerateInterface() | 268 self.GenerateInterface() |
263 | 269 |
264 def GenerateCallback(self): | 270 def GenerateCallback(self): |
265 """Generates a typedef for the callback interface.""" | 271 """Generates a typedef for the callback interface.""" |
266 handlers = [operation for operation in self._interface.operations | 272 handlers = [operation for operation in self._interface.operations |
267 if operation.id == 'handleEvent'] | 273 if operation.id == 'handleEvent'] |
268 info = AnalyzeOperation(self._interface, handlers) | 274 info = AnalyzeOperation(self._interface, handlers) |
269 code = self._library_emitter.FileEmitter(self._interface.id, | 275 code = self._library_emitter.FileEmitter(self._interface.id, |
270 self._library_name) | 276 self._library_name) |
271 code.Emit(self._template_loader.Load('callback.darttemplate')) | 277 code.Emit(self._template_loader.Load('callback.darttemplate')) |
| 278 |
| 279 typedef_name = self._renamer.RenameInterface(self._interface) |
272 code.Emit('typedef void $NAME($PARAMS);\n', | 280 code.Emit('typedef void $NAME($PARAMS);\n', |
273 NAME=self._interface.id, | 281 NAME=self._interface.id, |
274 PARAMS=info.ParametersDeclaration(self._DartType)) | 282 PARAMS=info.ParametersDeclaration(self._DartType)) |
275 self._backend.GenerateCallback(info) | 283 self._backend.GenerateCallback(info) |
276 | 284 |
277 def GenerateInterface(self): | 285 def GenerateInterface(self): |
278 interface_name = self._interface_type_info.interface_name() | 286 interface_name = self._interface_type_info.interface_name() |
279 | 287 |
280 factory_provider = None | 288 factory_provider = None |
281 if interface_name in interface_factories: | 289 if interface_name in interface_factories: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 template = self._template_loader.Load('factoryprovider.darttemplate') | 451 template = self._template_loader.Load('factoryprovider.darttemplate') |
444 | 452 |
445 interface_name = self._interface_type_info.interface_name() | 453 interface_name = self._interface_type_info.interface_name() |
446 arguments = constructor_info.ParametersAsArgumentList() | 454 arguments = constructor_info.ParametersAsArgumentList() |
447 comma = ',' if arguments else '' | 455 comma = ',' if arguments else '' |
448 emitter.Emit( | 456 emitter.Emit( |
449 template, | 457 template, |
450 FACTORYPROVIDER=factory_provider, | 458 FACTORYPROVIDER=factory_provider, |
451 CONSTRUCTOR=interface_name, | 459 CONSTRUCTOR=interface_name, |
452 PARAMETERS=constructor_info.ParametersDeclaration(self._DartType), | 460 PARAMETERS=constructor_info.ParametersDeclaration(self._DartType), |
453 NAMED_CONSTRUCTOR=constructor_info.name or interface_name, | 461 NAMED_CONSTRUCTOR=constructor_info.name or self._interface.doc_js_name, |
454 ARGUMENTS=arguments, | 462 ARGUMENTS=arguments, |
455 PRE_ARGUMENTS_COMMA=comma, | 463 PRE_ARGUMENTS_COMMA=comma, |
456 ARGUMENTS_PATTERN=','.join(['#'] * len(constructor_info.param_infos))) | 464 ARGUMENTS_PATTERN=','.join(['#'] * len(constructor_info.param_infos))) |
457 | 465 |
458 def SecondaryContext(self, interface): | 466 def SecondaryContext(self, interface): |
459 if interface is not self._current_secondary_parent: | 467 if interface is not self._current_secondary_parent: |
460 self._current_secondary_parent = interface | 468 self._current_secondary_parent = interface |
461 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 469 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
462 | 470 |
463 def AddIndexer(self, element_type): | 471 def AddIndexer(self, element_type): |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 for library_name in libraries: | 989 for library_name in libraries: |
982 self._libraries[library_name] = DartLibrary( | 990 self._libraries[library_name] = DartLibrary( |
983 library_name, template_loader, library_type, output_dir) | 991 library_name, template_loader, library_type, output_dir) |
984 | 992 |
985 def AddFile(self, basename, library_name, path): | 993 def AddFile(self, basename, library_name, path): |
986 self._libraries[library_name].AddFile(path) | 994 self._libraries[library_name].AddFile(path) |
987 | 995 |
988 def Emit(self, emitter, auxiliary_dir): | 996 def Emit(self, emitter, auxiliary_dir): |
989 for lib in self._libraries.values(): | 997 for lib in self._libraries.values(): |
990 lib.Emit(emitter, auxiliary_dir) | 998 lib.Emit(emitter, auxiliary_dir) |
OLD | NEW |