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 os | 10 import os |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 'TableRowElement': 'tr', | 143 'TableRowElement': 'tr', |
144 #'TableSectionElement' <thead> <tbody> <tfoot> | 144 #'TableSectionElement' <thead> <tbody> <tfoot> |
145 'TextAreaElement': 'textarea', | 145 'TextAreaElement': 'textarea', |
146 'TitleElement': 'title', | 146 'TitleElement': 'title', |
147 'TrackElement': 'track', | 147 'TrackElement': 'track', |
148 'UListElement': 'ul', | 148 'UListElement': 'ul', |
149 'VideoElement': 'video' | 149 'VideoElement': 'video' |
150 } | 150 } |
151 | 151 |
152 _svg_element_constructors = { | 152 _svg_element_constructors = { |
153 'SVGAElement': 'a', | 153 'AElement': 'a', |
154 'SVGAnimateColorElement': 'animateColor', | 154 'AnimateColorElement': 'animateColor', |
155 'SVGAnimateElement': 'animate', | 155 'AnimateElement': 'animate', |
156 'SVGAnimateMotionElement': 'animateMotion', | 156 'AnimateMotionElement': 'animateMotion', |
157 'SVGAnimateTransformElement': 'animateTransform', | 157 'AnimateTransformElement': 'animateTransform', |
158 'SVGAnimationElement': 'animation', | 158 'AnimationElement': 'animation', |
159 'SVGCircleElement': 'circle', | 159 'CircleElement': 'circle', |
160 'SVGClipPathElement': 'clipPath', | 160 'ClipPathElement': 'clipPath', |
161 'SVGCursorElement': 'cursor', | 161 'CursorElement': 'cursor', |
162 'SVGDefsElement': 'defs', | 162 'DefsElement': 'defs', |
163 'SVGDescElement': 'desc', | 163 'DescElement': 'desc', |
164 'SVGEllipseElement': 'ellipse', | 164 'EllipseElement': 'ellipse', |
165 'SVGFilterElement': 'filter', | 165 'FilterElement': 'filter', |
166 'SVGFontElement': 'font', | 166 'FontElement': 'font', |
167 'SVGFontFaceElement': 'font-face', | 167 'FontFaceElement': 'font-face', |
168 'SVGFontFaceFormatElement': 'font-face-format', | 168 'FontFaceFormatElement': 'font-face-format', |
169 'SVGFontFaceNameElement': 'font-face-name', | 169 'FontFaceNameElement': 'font-face-name', |
170 'SVGFontFaceSrcElement': 'font-face-src', | 170 'FontFaceSrcElement': 'font-face-src', |
171 'SVGFontFaceUriElement': 'font-face-uri', | 171 'FontFaceUriElement': 'font-face-uri', |
172 'SVGForeignObjectElement': 'foreignObject', | 172 'ForeignObjectElement': 'foreignObject', |
173 'SVGGlyphElement': 'glyph', | 173 'GlyphElement': 'glyph', |
174 'SVGGElement': 'g', | 174 'GElement': 'g', |
175 'SVGHKernElement': 'hkern', | 175 'HKernElement': 'hkern', |
176 'SVGImageElement': 'image', | 176 'ImageElement': 'image', |
177 'SVGLinearGradientElement': 'linearGradient', | 177 'LinearGradientElement': 'linearGradient', |
178 'SVGLineElement': 'line', | 178 'LineElement': 'line', |
179 'SVGMarkerElement': 'marker', | 179 'MarkerElement': 'marker', |
180 'SVGMaskElement': 'mask', | 180 'MaskElement': 'mask', |
181 'SVGMPathElement': 'mpath', | 181 'MPathElement': 'mpath', |
182 'SVGPathElement': 'path', | 182 'PathElement': 'path', |
183 'SVGPatternElement': 'pattern', | 183 'PatternElement': 'pattern', |
184 'SVGPolygonElement': 'polygon', | 184 'PolygonElement': 'polygon', |
185 'SVGPolylineElement': 'polyline', | 185 'PolylineElement': 'polyline', |
186 'SVGRadialGradientElement': 'radialGradient', | 186 'RadialGradientElement': 'radialGradient', |
187 'SVGRectElement': 'rect', | 187 'RectElement': 'rect', |
188 'SVGScriptElement': 'script', | 188 'ScriptElement': 'script', |
189 'SVGSetElement': 'set', | 189 'SetElement': 'set', |
190 'SVGStopElement': 'stop', | 190 'StopElement': 'stop', |
191 'SVGStyleElement': 'style', | 191 'StyleElement': 'style', |
192 'SVGSwitchElement': 'switch', | 192 'SwitchElement': 'switch', |
193 'SVGSymbolElement': 'symbol', | 193 'SymbolElement': 'symbol', |
194 'SVGTextElement': 'text', | 194 'TextElement': 'text', |
195 'SVGTitleElement': 'title', | 195 'TitleElement': 'title', |
196 'SVGTRefElement': 'tref', | 196 'TRefElement': 'tref', |
197 'SVGTSpanElement': 'tspan', | 197 'TSpanElement': 'tspan', |
198 'SVGUseElement': 'use', | 198 'UseElement': 'use', |
199 'SVGViewElement': 'view', | 199 'ViewElement': 'view', |
200 'SVGVKernElement': 'vkern', | 200 'VKernElement': 'vkern', |
201 } | 201 } |
202 | 202 |
203 _element_constructors = { | 203 _element_constructors = { |
204 'html': _html_element_constructors, | 204 'html': _html_element_constructors, |
205 'svg': _svg_element_constructors | 205 'svg': _svg_element_constructors |
206 } | 206 } |
207 | 207 |
208 _factory_ctr_strings = { | 208 _factory_ctr_strings = { |
209 'html': { | 209 'html': { |
210 'provider_name': 'document', | 210 'provider_name': 'document', |
211 'constructor_name': '$dom_createElement' | 211 'constructor_name': '$dom_createElement' |
212 }, | 212 }, |
213 'svg': { | 213 'svg': { |
214 'provider_name': '_SVGElementFactoryProvider', | 214 'provider_name': '_SvgElementFactoryProvider', |
215 'constructor_name': 'createSVGElement_tag', | 215 'constructor_name': 'createSvgElement_tag', |
216 }, | 216 }, |
217 } | 217 } |
218 | 218 |
219 def ElementConstructorInfos(typename, element_constructors, | 219 def ElementConstructorInfos(typename, element_constructors, |
220 factory_provider_name='_Elements'): | 220 factory_provider_name='_Elements'): |
221 """Returns list of ElementConstructorInfos about the convenience constructors | 221 """Returns list of ElementConstructorInfos about the convenience constructors |
222 for an Element or SvgElement.""" | 222 for an Element or SvgElement.""" |
223 # TODO(sra): Handle multiple and named constructors. | 223 # TODO(sra): Handle multiple and named constructors. |
224 if typename not in element_constructors: | 224 if typename not in element_constructors: |
225 return [] | 225 return [] |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 constructor_info, factory_provider, factory_provider_emitter) | 291 constructor_info, factory_provider, factory_provider_emitter) |
292 | 292 |
293 # HTML Elements and SVG Elements have convenience constructors. | 293 # HTML Elements and SVG Elements have convenience constructors. |
294 infos = ElementConstructorInfos(interface_name, | 294 infos = ElementConstructorInfos(interface_name, |
295 _element_constructors[self._library_name], factory_provider_name= | 295 _element_constructors[self._library_name], factory_provider_name= |
296 _factory_ctr_strings[self._library_name]['provider_name']) | 296 _factory_ctr_strings[self._library_name]['provider_name']) |
297 | 297 |
298 if infos: | 298 if infos: |
299 factory_constructor_name = _factory_ctr_strings[ | 299 factory_constructor_name = _factory_ctr_strings[ |
300 self._library_name]['constructor_name'] | 300 self._library_name]['constructor_name'] |
301 | 301 |
302 for info in infos: | 302 for info in infos: |
303 constructors.append(info.ConstructorInfo(self._interface.id)) | 303 constructors.append(info.ConstructorInfo(self._interface.id)) |
304 if factory_provider: | 304 if factory_provider: |
305 assert factory_provider == info.factory_provider_name | 305 assert factory_provider == info.factory_provider_name |
306 else: | 306 else: |
307 factory_provider = info.factory_provider_name | 307 factory_provider = info.factory_provider_name |
308 | 308 |
309 implementation_emitter = self._ImplementationEmitter() | 309 implementation_emitter = self._ImplementationEmitter() |
310 | 310 |
311 base_type_info = None | 311 base_type_info = None |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 # ------------------------------------------------------------------------------ | 913 # ------------------------------------------------------------------------------ |
914 | 914 |
915 class DartLibraryEmitter(): | 915 class DartLibraryEmitter(): |
916 def __init__(self, multiemitter, dart_sources_dir, dart_libraries): | 916 def __init__(self, multiemitter, dart_sources_dir, dart_libraries): |
917 self._multiemitter = multiemitter | 917 self._multiemitter = multiemitter |
918 self._dart_sources_dir = dart_sources_dir | 918 self._dart_sources_dir = dart_sources_dir |
919 self._path_to_emitter = {} | 919 self._path_to_emitter = {} |
920 self._dart_libraries = dart_libraries | 920 self._dart_libraries = dart_libraries |
921 | 921 |
922 def FileEmitter(self, basename, library_name, template=None): | 922 def FileEmitter(self, basename, library_name, template=None): |
923 path = os.path.join(self._dart_sources_dir, '%s.dart' % basename) | 923 aux_dir = os.path.join(self._dart_sources_dir, library_name) |
| 924 path = os.path.join(aux_dir, '%s.dart' % basename) |
924 if not path in self._path_to_emitter: | 925 if not path in self._path_to_emitter: |
925 emitter = self._multiemitter.FileEmitter(path) | 926 emitter = self._multiemitter.FileEmitter(path) |
926 if not template is None: | 927 if not template is None: |
927 emitter = emitter.Emit(template) | 928 emitter = emitter.Emit(template) |
928 self._path_to_emitter[path] = emitter | 929 self._path_to_emitter[path] = emitter |
929 | 930 |
930 self._dart_libraries.AddFile(basename, library_name, path) | 931 self._dart_libraries.AddFile(basename, library_name, path) |
931 return self._path_to_emitter[path] | 932 return self._path_to_emitter[path] |
932 | 933 |
933 def EmitLibraries(self, auxiliary_dir): | 934 def EmitLibraries(self, auxiliary_dir): |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 'svg': DartLibrary('svg', template_loader, library_type, output_dir), | 970 'svg': DartLibrary('svg', template_loader, library_type, output_dir), |
970 'html': DartLibrary('html', template_loader, library_type, output_dir), | 971 'html': DartLibrary('html', template_loader, library_type, output_dir), |
971 } | 972 } |
972 | 973 |
973 def AddFile(self, basename, library_name, path): | 974 def AddFile(self, basename, library_name, path): |
974 self._libraries[library_name].AddFile(path) | 975 self._libraries[library_name].AddFile(path) |
975 | 976 |
976 def Emit(self, emitter, auxiliary_dir): | 977 def Emit(self, emitter, auxiliary_dir): |
977 for lib in self._libraries.values(): | 978 for lib in self._libraries.values(): |
978 lib.Emit(emitter, auxiliary_dir) | 979 lib.Emit(emitter, auxiliary_dir) |
OLD | NEW |