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

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

Issue 2718713003: Redo "Refined types for most HtmlElement factory constructors" (Closed)
Patch Set: ShadowElement() is unreliable Created 3 years, 9 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 'HTMLShadowElement',
478 'HTMLTemplateElement',
479 ])
480
466 # ------------------------------------------------------------------------------ 481 # ------------------------------------------------------------------------------
467 482
468 class HtmlDartInterfaceGenerator(object): 483 class HtmlDartInterfaceGenerator(object):
469 """Generates dart interface and implementation for the DOM IDL interface.""" 484 """Generates dart interface and implementation for the DOM IDL interface."""
470 485
471 def __init__(self, options, library_emitter, event_generator, interface, 486 def __init__(self, options, library_emitter, event_generator, interface,
472 backend): 487 backend):
473 self._renamer = options.renamer 488 self._renamer = options.renamer
474 self._database = options.database 489 self._database = options.database
475 self._template_loader = options.templates 490 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) + 812 return (js_support_checks.get(self._interface.doc_js_name) +
798 " && (new %sElement.tag('%s') is %s)" % (lib_prefix, 813 " && (new %sElement.tag('%s') is %s)" % (lib_prefix,
799 constructors[self._interface.doc_js_name], 814 constructors[self._interface.doc_js_name],
800 self._renamer.RenameInterface(self._interface))) 815 self._renamer.RenameInterface(self._interface)))
801 return js_support_checks.get(self._interface.doc_js_name) 816 return js_support_checks.get(self._interface.doc_js_name)
802 817
803 def GenerateCustomFactory(self, constructor_info): 818 def GenerateCustomFactory(self, constructor_info):
804 # Custom factory will be taken from the template. 819 # Custom factory will be taken from the template.
805 return self._interface.doc_js_name in _js_custom_constructors 820 return self._interface.doc_js_name in _js_custom_constructors
806 821
822 def MakeFactoryCall(self, factory, method, arguments, constructor_info):
823 if factory is 'document' and method is 'createElement' \
824 and not ',' in arguments \
825 and not self._HasUnreliableFactoryConstructor():
826 return emitter.Format(
827 "JS('returns:$INTERFACE_NAME;creates:$INTERFACE_NAME;new:true',"
828 " '#.$METHOD(#)', $FACTORY, $ARGUMENTS)",
829 INTERFACE_NAME=self._interface_type_info.interface_name(),
830 FACTORY=factory,
831 METHOD=method,
832 ARGUMENTS=arguments)
833 return emitter.Format(
834 '$FACTORY.$METHOD($ARGUMENTS)',
835 FACTORY=factory,
836 METHOD=method,
837 ARGUMENTS=arguments)
838
839 def _HasUnreliableFactoryConstructor(self):
840 return self._interface.doc_js_name in _js_unreliable_element_factories
841
807 def IsConstructorArgumentOptional(self, argument): 842 def IsConstructorArgumentOptional(self, argument):
808 return argument.optional 843 return argument.optional
809 844
810 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): 845 def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
811 index = len(arguments) 846 index = len(arguments)
812 arguments = constructor_info.ParametersAsArgumentList(index) 847 arguments = constructor_info.ParametersAsArgumentList(index)
813 if arguments: 848 if arguments:
814 arguments = ', ' + arguments 849 arguments = ', ' + arguments
815 self._members_emitter.Emit( 850 self._members_emitter.Emit(
816 " static $INTERFACE_NAME $NAME($PARAMETERS) => " 851 " static $INTERFACE_NAME $NAME($PARAMETERS) => "
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 1379
1345 def AddFile(self, basename, library_name, path): 1380 def AddFile(self, basename, library_name, path):
1346 self._libraries[library_name].AddFile(path) 1381 self._libraries[library_name].AddFile(path)
1347 1382
1348 def AddTypeEntry(self, library_name, idl_name, dart_name): 1383 def AddTypeEntry(self, library_name, idl_name, dart_name):
1349 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) 1384 self._libraries[library_name].AddTypeEntry(idl_name, dart_name)
1350 1385
1351 def Emit(self, emitter, auxiliary_dir): 1386 def Emit(self, emitter, auxiliary_dir):
1352 for lib in self._libraries.values(): 1387 for lib in self._libraries.values():
1353 lib.Emit(emitter, auxiliary_dir) 1388 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