Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: tools/dom/scripts/systemhtml.py

Issue 2705213003: Refined types for most HtmlElement factory constructors (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/dom/scripts/htmldartgenerator.py ('k') | tools/dom/scripts/systemnative.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
466 # ------------------------------------------------------------------------------ 479 # ------------------------------------------------------------------------------
467 480
468 class HtmlDartInterfaceGenerator(object): 481 class HtmlDartInterfaceGenerator(object):
469 """Generates dart interface and implementation for the DOM IDL interface.""" 482 """Generates dart interface and implementation for the DOM IDL interface."""
470 483
471 def __init__(self, options, library_emitter, event_generator, interface, 484 def __init__(self, options, library_emitter, event_generator, interface,
472 backend): 485 backend):
473 self._renamer = options.renamer 486 self._renamer = options.renamer
474 self._database = options.database 487 self._database = options.database
475 self._template_loader = options.templates 488 self._template_loader = options.templates
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 return (js_support_checks.get(self._interface.doc_js_name) + 810 return (js_support_checks.get(self._interface.doc_js_name) +
798 " && (new %sElement.tag('%s') is %s)" % (lib_prefix, 811 " && (new %sElement.tag('%s') is %s)" % (lib_prefix,
799 constructors[self._interface.doc_js_name], 812 constructors[self._interface.doc_js_name],
800 self._renamer.RenameInterface(self._interface))) 813 self._renamer.RenameInterface(self._interface)))
801 return js_support_checks.get(self._interface.doc_js_name) 814 return js_support_checks.get(self._interface.doc_js_name)
802 815
803 def GenerateCustomFactory(self, constructor_info): 816 def GenerateCustomFactory(self, constructor_info):
804 # Custom factory will be taken from the template. 817 # Custom factory will be taken from the template.
805 return self._interface.doc_js_name in _js_custom_constructors 818 return self._interface.doc_js_name in _js_custom_constructors
806 819
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
807 def IsConstructorArgumentOptional(self, argument): 840 def IsConstructorArgumentOptional(self, argument):
808 return argument.optional 841 return argument.optional
809 842
810 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): 843 def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
811 index = len(arguments) 844 index = len(arguments)
812 arguments = constructor_info.ParametersAsArgumentList(index) 845 arguments = constructor_info.ParametersAsArgumentList(index)
813 if arguments: 846 if arguments:
814 arguments = ', ' + arguments 847 arguments = ', ' + arguments
815 self._members_emitter.Emit( 848 self._members_emitter.Emit(
816 " static $INTERFACE_NAME $NAME($PARAMETERS) => " 849 " static $INTERFACE_NAME $NAME($PARAMETERS) => "
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 1377
1345 def AddFile(self, basename, library_name, path): 1378 def AddFile(self, basename, library_name, path):
1346 self._libraries[library_name].AddFile(path) 1379 self._libraries[library_name].AddFile(path)
1347 1380
1348 def AddTypeEntry(self, library_name, idl_name, dart_name): 1381 def AddTypeEntry(self, library_name, idl_name, dart_name):
1349 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) 1382 self._libraries[library_name].AddTypeEntry(idl_name, dart_name)
1350 1383
1351 def Emit(self, emitter, auxiliary_dir): 1384 def Emit(self, emitter, auxiliary_dir):
1352 for lib in self._libraries.values(): 1385 for lib in self._libraries.values():
1353 lib.Emit(emitter, auxiliary_dir) 1386 lib.Emit(emitter, auxiliary_dir)
OLDNEW
« no previous file with comments | « tools/dom/scripts/htmldartgenerator.py ('k') | tools/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698