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 monitored | 10 import monitored |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 self._library_name = self._renamer.GetLibraryName(self._interface) | 414 self._library_name = self._renamer.GetLibraryName(self._interface) |
415 | 415 |
416 def Generate(self): | 416 def Generate(self): |
417 if 'Callback' in self._interface.ext_attrs: | 417 if 'Callback' in self._interface.ext_attrs: |
418 self.GenerateCallback() | 418 self.GenerateCallback() |
419 else: | 419 else: |
420 self.GenerateInterface() | 420 self.GenerateInterface() |
421 | 421 |
422 def GenerateCallback(self): | 422 def GenerateCallback(self): |
423 """Generates a typedef for the callback interface.""" | 423 """Generates a typedef for the callback interface.""" |
424 info = GetCallbackInfo(self._interface) | 424 handlers = [operation for operation in self._interface.operations |
| 425 if operation.id == 'handleEvent'] |
| 426 info = AnalyzeOperation(self._interface, handlers) |
425 code = self._library_emitter.FileEmitter(self._interface.id, | 427 code = self._library_emitter.FileEmitter(self._interface.id, |
426 self._library_name) | 428 self._library_name) |
427 code.Emit(self._template_loader.Load('callback.darttemplate')) | 429 code.Emit(self._template_loader.Load('callback.darttemplate')) |
428 | 430 |
429 typedef_name = self._renamer.RenameInterface(self._interface) | 431 typedef_name = self._renamer.RenameInterface(self._interface) |
430 code.Emit('typedef void $NAME($PARAMS);\n', | 432 code.Emit('typedef void $NAME($PARAMS);\n', |
431 LIBRARYNAME='dart.dom.%s' % self._library_name, | 433 LIBRARYNAME='dart.dom.%s' % self._library_name, |
432 NAME=typedef_name, | 434 NAME=typedef_name, |
433 PARAMS=info.ParametersDeclaration(self._DartType)) | 435 PARAMS=info.ParametersDeclaration(self._DartType)) |
434 self._backend.GenerateCallback(info) | 436 self._backend.GenerateCallback(info) |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 def EmitOperation(self, info, html_name): | 853 def EmitOperation(self, info, html_name): |
852 """ | 854 """ |
853 Arguments: | 855 Arguments: |
854 info: An OperationInfo object. | 856 info: An OperationInfo object. |
855 """ | 857 """ |
856 if self._HasCustomImplementation(info.name): | 858 if self._HasCustomImplementation(info.name): |
857 return | 859 return |
858 | 860 |
859 if IsPureInterface(self._interface.id): | 861 if IsPureInterface(self._interface.id): |
860 self._AddInterfaceOperation(info, html_name) | 862 self._AddInterfaceOperation(info, html_name) |
861 elif info.callback_args: | |
862 self._AddFutureifiedOperation(info, html_name) | |
863 elif any(self._OperationRequiresConversions(op) for op in info.overloads): | 863 elif any(self._OperationRequiresConversions(op) for op in info.overloads): |
864 # Any conversions needed? | 864 # Any conversions needed? |
865 self._AddOperationWithConversions(info, html_name) | 865 self._AddOperationWithConversions(info, html_name) |
866 else: | 866 else: |
867 self._AddDirectNativeOperation(info, html_name) | 867 self._AddDirectNativeOperation(info, html_name) |
868 | 868 |
869 def _AddDirectNativeOperation(self, info, html_name): | 869 def _AddDirectNativeOperation(self, info, html_name): |
870 self._members_emitter.Emit( | 870 self._members_emitter.Emit( |
871 '\n' | 871 '\n' |
872 ' $RENAME$ANNOTATIONS$MODIFIERS$TYPE $NAME($PARAMS) native;\n', | 872 ' $RENAME$ANNOTATIONS$MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 for library_name in libraries: | 1135 for library_name in libraries: |
1136 self._libraries[library_name] = DartLibrary( | 1136 self._libraries[library_name] = DartLibrary( |
1137 library_name, template_loader, library_type, output_dir) | 1137 library_name, template_loader, library_type, output_dir) |
1138 | 1138 |
1139 def AddFile(self, basename, library_name, path): | 1139 def AddFile(self, basename, library_name, path): |
1140 self._libraries[library_name].AddFile(path) | 1140 self._libraries[library_name].AddFile(path) |
1141 | 1141 |
1142 def Emit(self, emitter, auxiliary_dir): | 1142 def Emit(self, emitter, auxiliary_dir): |
1143 for lib in self._libraries.values(): | 1143 for lib in self._libraries.values(): |
1144 lib.Emit(emitter, auxiliary_dir) | 1144 lib.Emit(emitter, auxiliary_dir) |
OLD | NEW |