| 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 logging | 10 import logging |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 'WebGLRenderingContext': "JS('bool', '!!(window.WebGLRenderingContext)')", | 456 'WebGLRenderingContext': "JS('bool', '!!(window.WebGLRenderingContext)')", |
| 457 'WebSocket': "JS('bool', 'typeof window.WebSocket != \"undefined\"')", | 457 'WebSocket': "JS('bool', 'typeof window.WebSocket != \"undefined\"')", |
| 458 'Worker': "JS('bool', '(typeof window.Worker != \"undefined\")')", | 458 'Worker': "JS('bool', '(typeof window.Worker != \"undefined\")')", |
| 459 'XSLTProcessor': "JS('bool', '!!(window.XSLTProcessor)')", | 459 'XSLTProcessor': "JS('bool', '!!(window.XSLTProcessor)')", |
| 460 }.items() + | 460 }.items() + |
| 461 dict((key, | 461 dict((key, |
| 462 SvgSupportStr(_svg_element_constructors[key]) if key.startswith('SVG') | 462 SvgSupportStr(_svg_element_constructors[key]) if key.startswith('SVG') |
| 463 else ElemSupportStr(_html_element_constructors[key])) for key in | 463 else ElemSupportStr(_html_element_constructors[key])) for key in |
| 464 _js_support_checks_basic_element_with_constructors + | 464 _js_support_checks_basic_element_with_constructors + |
| 465 _js_support_checks_additional_element).items()) | 465 _js_support_checks_additional_element).items()) |
| 466 | |
| 467 | |
| 468 # JavaScript element class names of elements for which createElement does not | |
| 469 # always return exactly the right element, either because it might not be | |
| 470 # supported, or some browser does something weird. | |
| 471 _js_unreliable_element_factories = set( | |
| 472 _js_support_checks_basic_element_with_constructors + | |
| 473 _js_support_checks_additional_element + | |
| 474 [ | |
| 475 'HTMLEmbedElement', | |
| 476 'HTMLObjectElement', | |
| 477 ]) | |
| 478 | |
| 479 # ------------------------------------------------------------------------------ | 466 # ------------------------------------------------------------------------------ |
| 480 | 467 |
| 481 class HtmlDartInterfaceGenerator(object): | 468 class HtmlDartInterfaceGenerator(object): |
| 482 """Generates dart interface and implementation for the DOM IDL interface.""" | 469 """Generates dart interface and implementation for the DOM IDL interface.""" |
| 483 | 470 |
| 484 def __init__(self, options, library_emitter, event_generator, interface, | 471 def __init__(self, options, library_emitter, event_generator, interface, |
| 485 backend): | 472 backend): |
| 486 self._renamer = options.renamer | 473 self._renamer = options.renamer |
| 487 self._database = options.database | 474 self._database = options.database |
| 488 self._template_loader = options.templates | 475 self._template_loader = options.templates |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 return (js_support_checks.get(self._interface.doc_js_name) + | 797 return (js_support_checks.get(self._interface.doc_js_name) + |
| 811 " && (new %sElement.tag('%s') is %s)" % (lib_prefix, | 798 " && (new %sElement.tag('%s') is %s)" % (lib_prefix, |
| 812 constructors[self._interface.doc_js_name], | 799 constructors[self._interface.doc_js_name], |
| 813 self._renamer.RenameInterface(self._interface))) | 800 self._renamer.RenameInterface(self._interface))) |
| 814 return js_support_checks.get(self._interface.doc_js_name) | 801 return js_support_checks.get(self._interface.doc_js_name) |
| 815 | 802 |
| 816 def GenerateCustomFactory(self, constructor_info): | 803 def GenerateCustomFactory(self, constructor_info): |
| 817 # Custom factory will be taken from the template. | 804 # Custom factory will be taken from the template. |
| 818 return self._interface.doc_js_name in _js_custom_constructors | 805 return self._interface.doc_js_name in _js_custom_constructors |
| 819 | 806 |
| 820 def MakeFactoryCall(self, factory, method, arguments, constructor_info): | |
| 821 if factory is 'document' and method is 'createElement' \ | |
| 822 and not ',' in arguments \ | |
| 823 and not self._HasUnreliableFactoryConstructor(): | |
| 824 return emitter.Format( | |
| 825 "JS('returns:$INTERFACE_NAME;creates:$INTERFACE_NAME;new:true'," | |
| 826 " '#.$METHOD(#)', $FACTORY, $ARGUMENTS)", | |
| 827 INTERFACE_NAME=self._interface_type_info.interface_name(), | |
| 828 FACTORY=factory, | |
| 829 METHOD=method, | |
| 830 ARGUMENTS=arguments) | |
| 831 return emitter.Format( | |
| 832 '$FACTORY.$METHOD($ARGUMENTS)', | |
| 833 FACTORY=factory, | |
| 834 METHOD=method, | |
| 835 ARGUMENTS=arguments) | |
| 836 | |
| 837 def _HasUnreliableFactoryConstructor(self): | |
| 838 return self._interface.doc_js_name in _js_unreliable_element_factories | |
| 839 | |
| 840 def IsConstructorArgumentOptional(self, argument): | 807 def IsConstructorArgumentOptional(self, argument): |
| 841 return argument.optional | 808 return argument.optional |
| 842 | 809 |
| 843 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): | 810 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): |
| 844 index = len(arguments) | 811 index = len(arguments) |
| 845 arguments = constructor_info.ParametersAsArgumentList(index) | 812 arguments = constructor_info.ParametersAsArgumentList(index) |
| 846 if arguments: | 813 if arguments: |
| 847 arguments = ', ' + arguments | 814 arguments = ', ' + arguments |
| 848 self._members_emitter.Emit( | 815 self._members_emitter.Emit( |
| 849 " static $INTERFACE_NAME $NAME($PARAMETERS) => " | 816 " static $INTERFACE_NAME $NAME($PARAMETERS) => " |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 | 1344 |
| 1378 def AddFile(self, basename, library_name, path): | 1345 def AddFile(self, basename, library_name, path): |
| 1379 self._libraries[library_name].AddFile(path) | 1346 self._libraries[library_name].AddFile(path) |
| 1380 | 1347 |
| 1381 def AddTypeEntry(self, library_name, idl_name, dart_name): | 1348 def AddTypeEntry(self, library_name, idl_name, dart_name): |
| 1382 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) | 1349 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) |
| 1383 | 1350 |
| 1384 def Emit(self, emitter, auxiliary_dir): | 1351 def Emit(self, emitter, auxiliary_dir): |
| 1385 for lib in self._libraries.values(): | 1352 for lib in self._libraries.values(): |
| 1386 lib.Emit(emitter, auxiliary_dir) | 1353 lib.Emit(emitter, auxiliary_dir) |
| OLD | NEW |