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

Side by Side Diff: Source/build/scripts/make_element_factory.py

Issue 35423004: Move SVGNames to Python (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add comment Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/build/scripts/make_qualified_names.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/env python 1 #!/usr/bin/env python
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 18 matching lines...) Expand all
29 29
30 import sys 30 import sys
31 31
32 import in_generator 32 import in_generator
33 import template_expander 33 import template_expander
34 import name_utilities 34 import name_utilities
35 35
36 from make_qualified_names import MakeQualifiedNamesWriter 36 from make_qualified_names import MakeQualifiedNamesWriter
37 37
38 38
39 def _interface(tag):
40 if tag['interfaceName']:
41 return tag['interfaceName']
42 name = name_utilities.upper_first(tag['name'])
43 # FIXME: We shouldn't hard-code HTML here.
44 if name == 'HTML':
45 name = 'Html'
46 return 'HTML%sElement' % name
47
48
49 def _js_interface(tag):
50 if tag['JSInterfaceName']:
51 return tag['JSInterfaceName']
52 return _interface(tag)
53
54
55 def _has_js_interface(tag):
56 return not tag['mapToTagName'] and not tag['noConstructor'] and _js_interfac e(tag) != 'HTMLElement'
57
58
59 class MakeElementFactoryWriter(MakeQualifiedNamesWriter): 39 class MakeElementFactoryWriter(MakeQualifiedNamesWriter):
60 defaults = dict(MakeQualifiedNamesWriter.default_parameters, **{ 40 defaults = dict(MakeQualifiedNamesWriter.default_parameters, **{
61 'JSInterfaceName': None, 41 'JSInterfaceName': None,
62 'constructorNeedsCreatedByParser': None, 42 'constructorNeedsCreatedByParser': None,
63 'constructorNeedsFormElement': None, 43 'constructorNeedsFormElement': None,
64 'contextConditional': None, 44 'contextConditional': None,
65 'interfaceName': None, 45 'interfaceName': None,
66 'mapToTagName': None, 46 'mapToTagName': None,
67 'noConstructor': None, 47 'noConstructor': None,
68 'wrapperOnlyIfMediaIsAvailable': None, 48 'wrapperOnlyIfMediaIsAvailable': None,
69 }) 49 })
70 default_parameters = dict(MakeQualifiedNamesWriter.default_parameters, **{ 50 default_parameters = dict(MakeQualifiedNamesWriter.default_parameters, **{
71 'fallbackInterfaceName': None, 51 'fallbackInterfaceName': '',
52 'fallbackJSInterfaceName': '',
72 }) 53 })
73 filters = dict(MakeQualifiedNamesWriter.filters, **{ 54 filters = MakeQualifiedNamesWriter.filters
74 'interface': _interface,
75 'js_interface': _js_interface,
76 'has_js_interface': _has_js_interface,
77 })
78 55
79 def __init__(self, in_file_paths, enabled_conditions): 56 def __init__(self, in_file_paths, enabled_conditions):
80 super(MakeElementFactoryWriter, self).__init__(in_file_paths, enabled_co nditions) 57 super(MakeElementFactoryWriter, self).__init__(in_file_paths, enabled_co nditions)
81 58
82 # FIXME: When we start using these element factories, we'll want to 59 # FIXME: When we start using these element factories, we'll want to
83 # remove the "new" prefix and also have our base class generate 60 # remove the "new" prefix and also have our base class generate
84 # *Names.h and *Names.cpp. 61 # *Names.h and *Names.cpp.
85 self._outputs.update({ 62 self._outputs.update({
86 (self.namespace + 'ElementFactory.h'): self.generate_factory_header, 63 (self.namespace + 'ElementFactory.h'): self.generate_factory_header,
87 (self.namespace + 'ElementFactory.cpp'): self.generate_factory_imple mentation, 64 (self.namespace + 'ElementFactory.cpp'): self.generate_factory_imple mentation,
88 ('V8' + self.namespace + 'ElementWrapperFactory.h'): self.generate_w rapper_factory_header, 65 ('V8' + self.namespace + 'ElementWrapperFactory.h'): self.generate_w rapper_factory_header,
89 ('V8' + self.namespace + 'ElementWrapperFactory.cpp'): self.generate _wrapper_factory_implementation, 66 ('V8' + self.namespace + 'ElementWrapperFactory.cpp'): self.generate _wrapper_factory_implementation,
90 }) 67 })
91 68
69 fallback_interface = self.tags_in_file.parameters['fallbackInterfaceName '].strip('"')
70 fallback_js_interface = self.tags_in_file.parameters['fallbackJSInterfac eName'].strip('"') or fallback_interface
71
92 for tag in self._template_context['tags']: 72 for tag in self._template_context['tags']:
93 tag['js_interface'] = _js_interface(tag) if _has_js_interface(tag) e lse None 73 tag['has_js_interface'] = self._has_js_interface(tag)
74 tag['js_interface'] = self._js_interface(tag)
75 tag['interface'] = self._interface(tag)
94 76
95 self._template_context.update({ 77 self._template_context.update({
96 'fallback_interface': self.tags_in_file.parameters['fallbackInterfac eName'].strip('"'), 78 'fallback_interface': fallback_interface,
79 'fallback_js_interface': fallback_js_interface,
97 }) 80 })
98 81
99 @template_expander.use_jinja('ElementFactory.h.tmpl', filters=filters) 82 @template_expander.use_jinja('ElementFactory.h.tmpl', filters=filters)
100 def generate_factory_header(self): 83 def generate_factory_header(self):
101 return self._template_context 84 return self._template_context
102 85
103 @template_expander.use_jinja('ElementFactory.cpp.tmpl', filters=filters) 86 @template_expander.use_jinja('ElementFactory.cpp.tmpl', filters=filters)
104 def generate_factory_implementation(self): 87 def generate_factory_implementation(self):
105 return self._template_context 88 return self._template_context
106 89
107 @template_expander.use_jinja('ElementWrapperFactory.h.tmpl', filters=filters ) 90 @template_expander.use_jinja('ElementWrapperFactory.h.tmpl', filters=filters )
108 def generate_wrapper_factory_header(self): 91 def generate_wrapper_factory_header(self):
109 return self._template_context 92 return self._template_context
110 93
111 @template_expander.use_jinja('ElementWrapperFactory.cpp.tmpl', filters=filte rs) 94 @template_expander.use_jinja('ElementWrapperFactory.cpp.tmpl', filters=filte rs)
112 def generate_wrapper_factory_implementation(self): 95 def generate_wrapper_factory_implementation(self):
113 return self._template_context 96 return self._template_context
114 97
98 def _interface(self, tag):
99 if tag['interfaceName']:
100 return tag['interfaceName']
101 name = name_utilities.upper_first(tag['name'])
102 # FIXME: We shouldn't hard-code HTML here.
103 if name == 'HTML':
104 name = 'Html'
105 dash = name.find('-')
106 while dash != -1:
107 name = name[:dash] + name[dash + 1].upper() + name[dash + 2:]
108 dash = name.find('-')
109 return '%s%sElement' % (self.namespace, name)
110
111 def _js_interface(self, tag):
112 if tag['JSInterfaceName']:
113 return tag['JSInterfaceName']
114 return self._interface(tag)
115
116 def _has_js_interface(self, tag):
117 return not tag['mapToTagName'] and not tag['noConstructor'] and self._js _interface(tag) != ('%sElement' % self.namespace)
118
115 119
116 if __name__ == "__main__": 120 if __name__ == "__main__":
117 in_generator.Maker(MakeElementFactoryWriter).main(sys.argv) 121 in_generator.Maker(MakeElementFactoryWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | Source/build/scripts/make_qualified_names.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698