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

Side by Side Diff: sdk/lib/html/scripts/systemhtml.py

Issue 11293292: Add constructors for SVG elements and remove static factory providers for html elements. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | sdk/lib/html/templates/html/impl/factoryprovider_SvgElements.darttemplate » ('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 os 10 import os
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 # TODO(sra): maybe remove all the argument complexity and use cascades. 53 # TODO(sra): maybe remove all the argument complexity and use cascades.
54 # 54 #
55 # var c = new CanvasElement(width: 100, height: 70); 55 # var c = new CanvasElement(width: 100, height: 70);
56 # var c = new CanvasElement()..width = 100..height = 70; 56 # var c = new CanvasElement()..width = 100..height = 70;
57 # 57 #
58 class ElementConstructorInfo(object): 58 class ElementConstructorInfo(object):
59 def __init__(self, name=None, tag=None, 59 def __init__(self, name=None, tag=None,
60 params=[], opt_params=[], 60 params=[], opt_params=[],
61 factory_provider_name='_Elements'): 61 factory_provider_name='_Elements'):
62 self.name = name # The constructor name 'h1' in 'HeadingElement.h1' 62 self.name = name # The constructor name 'h1' in 'HeadingElement.h1'
63 self.tag = tag or name # The HTML tag 63 self.tag = tag or name # The HTML or SVG tag
64 self.params = params 64 self.params = params
65 self.opt_params = opt_params 65 self.opt_params = opt_params
66 self.factory_provider_name = factory_provider_name 66 self.factory_provider_name = factory_provider_name
67 67
68 def ConstructorInfo(self, interface_name): 68 def ConstructorInfo(self, interface_name):
69 info = OperationInfo() 69 info = OperationInfo()
70 info.overloads = None 70 info.overloads = None
71 info.declared_name = interface_name 71 info.declared_name = interface_name
72 info.name = interface_name 72 info.name = interface_name
73 info.constructor_name = self.name 73 info.constructor_name = self.name
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 'TableElement': 'table', 141 'TableElement': 'table',
142 'TableRowElement': 'tr', 142 'TableRowElement': 'tr',
143 #'TableSectionElement' <thead> <tbody> <tfoot> 143 #'TableSectionElement' <thead> <tbody> <tfoot>
144 'TextAreaElement': 'textarea', 144 'TextAreaElement': 'textarea',
145 'TitleElement': 'title', 145 'TitleElement': 'title',
146 'TrackElement': 'track', 146 'TrackElement': 'track',
147 'UListElement': 'ul', 147 'UListElement': 'ul',
148 'VideoElement': 'video' 148 'VideoElement': 'video'
149 } 149 }
150 150
151 def HtmlElementConstructorInfos(typename): 151 _svg_element_constructors = {
152 'SVGAElement': 'a',
153 'SVGAnimateColorElement': 'animateColor',
154 'SVGAnimateElement': 'animate',
155 'SVGAnimateMotionElement': 'animateMotion',
156 'SVGAnimateTransformElement': 'animateTransform',
157 'SVGAnimationElement': 'animation',
158 'SVGCircleElement': 'circle',
159 'SVGClipPathElement': 'clipPath',
160 'SVGCursorElement': 'cursor',
161 'SVGDefsElement': 'defs',
162 'SVGDescElement': 'desc',
163 'SVGEllipseElement': 'ellipse',
164 'SVGFilterElement': 'filter',
165 'SVGFontElement': 'font',
166 'SVGFontFaceElement': 'font-face',
167 'SVGFontFaceFormatElement': 'font-face-format',
168 'SVGFontFaceNameElement': 'font-face-name',
169 'SVGFontFaceSrcElement': 'font-face-src',
170 'SVGFontFaceUriElement': 'font-face-uri',
171 'SVGForeignObjectElement': 'foreignObject',
172 'SVGGlyphElement': 'glyph',
173 'SVGGElement': 'g',
174 'SVGHKernElement': 'hkern',
175 'SVGImageElement': 'image',
176 'SVGLinearGradientElement': 'linearGradient',
177 'SVGLineElement': 'line',
178 'SVGMarkerElement': 'marker',
179 'SVGMaskElement': 'mask',
180 'SVGMPathElement': 'mpath',
181 'SVGPathElement': 'path',
182 'SVGPatternElement': 'pattern',
183 'SVGPolygonElement': 'polygon',
184 'SVGPolylineElement': 'polyline',
185 'SVGRadialGradientElement': 'radialGradient',
186 'SVGRectElement': 'rect',
187 'SVGScriptElement': 'script',
188 'SVGSetElement': 'set',
189 'SVGStopElement': 'stop',
190 'SVGStyleElement': 'style',
191 'SVGSwitchElement': 'switch',
192 'SVGSymbolElement': 'symbol',
193 'SVGTextElement': 'text',
194 'SVGTitleElement': 'title',
195 'SVGTRefElement': 'tref',
196 'SVGTSpanElement': 'tspan',
197 'SVGUseElement': 'use',
198 'SVGViewElement': 'view',
199 'SVGVKernElement': 'vkern',
200 # TODO(efortuna): The following still need to be added to this list. Currently
201 # they can only be added via SVGElement.tag('tag name'):
202 # SVGAltGlyphDefElement, SVGAltGlyphElement, SVGAltGlyphItemElement,
203 # SVGComponentTransferFunctionElement, SVGFEBlendElement,
204 # SVGFEColorMatrixElement, SVGFEComponentTransferElement,
205 # SVGFECompositeElement, SVGFEConvolveMatrixElement,
206 # SVGFEDiffuseLightingElement, SVGFEDisplacementMapElement,
207 # SVGFEDistantLightElement, SVGFEDropShadowElement, SVGFEFloodElement,
208 # SVGFEFuncAElement, SVGFEFuncBElement, SVGFEFuncGElement, SVGFEFuncRElement,
209 # SVGFEGaussianBlurElement, SVGFEImageElement, SVGFEMergeElement,
210 # SVGFEMergeNodeElement, SVGFEMorphologyElement, SVGFEOffsetElement,
211 # SVGFEPointLightElement, SVGFESpecularLightingElement, SVGFESpotLightElement,
212 # SVGFETileElement, SVGFETurbulenceElement, SVGGlyphElement,
213 # SVGGlyphRefElement, SVGGradientElement, SVGMetadataElement,
214 # SVGMissingGlyphElement, SVGTextContentElement, SVGTextPathElement,
215 # SVGTextPositioningElement
216 }
217
218 def ElementConstructorInfos(typename, element_constructors,
219 factory_provider_name='_Elements'):
152 """Returns list of ElementConstructorInfos about the convenience constructors 220 """Returns list of ElementConstructorInfos about the convenience constructors
153 for an Element.""" 221 for an Element or SvgElement."""
154 # TODO(sra): Handle multiple and named constructors. 222 # TODO(sra): Handle multiple and named constructors.
155 if typename not in _html_element_constructors: 223 if typename not in element_constructors:
156 return [] 224 return []
157 infos = _html_element_constructors[typename] 225 infos = element_constructors[typename]
158 if isinstance(infos, str): 226 if isinstance(infos, str):
159 infos = ElementConstructorInfo(tag=infos) 227 infos = ElementConstructorInfo(tag=infos,
228 factory_provider_name=factory_provider_name)
160 if not isinstance(infos, list): 229 if not isinstance(infos, list):
161 infos = [infos] 230 infos = [infos]
162 return infos 231 return infos
163 232
164 def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name, 233 def EmitElementFactoryConstructors(emitter, infos, typename, class_name,
165 rename_type): 234 rename_type, isHtmlElement):
235 """Emits convenience factory contructors for HtmlElements and SvgElements."""
166 for info in infos: 236 for info in infos:
167 constructor_info = info.ConstructorInfo(typename) 237 constructor_info = info.ConstructorInfo(typename)
238 emitted_string = '\n static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n'
239 if isHtmlElement:
240 emitted_string += ' $CLASS _e = document.$dom_createElement("$TAG");\n'
241 else:
242 emitted_string += (
243 ' final Element _e =\n'
blois 2012/11/15 18:09:16 Change final Element _e and $CLASS _e to var e.
244 ' document.$dom_createElementNS('
245 '"http://www.w3.org/2000/svg", "$TAG");\n')
246 emitted_string += (
247 '$!INITS'
248 ' return _e;\n'
249 ' }\n')
168 250
169 inits = emitter.Emit( 251 inits = emitter.Emit(
170 '\n' 252 emitted_string,
171 ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n'
172 ' $CLASS _e = document.$dom_createElement("$TAG");\n'
173 '$!INITS'
174 ' return _e;\n'
175 ' }\n',
176 RETURN_TYPE=rename_type(constructor_info.type_name), 253 RETURN_TYPE=rename_type(constructor_info.type_name),
177 CONSTRUCTOR=constructor_info.ConstructorFactoryName(rename_type), 254 CONSTRUCTOR=constructor_info.ConstructorFactoryName(rename_type),
178 CLASS=class_name, 255 CLASS=class_name,
179 TAG=info.tag, 256 TAG=info.tag,
180 PARAMS=constructor_info.ParametersDeclaration( 257 PARAMS=constructor_info.ParametersDeclaration(
181 rename_type, force_optional=True)) 258 rename_type, force_optional=True))
182 for param in constructor_info.param_infos: 259 for param in constructor_info.param_infos:
183 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) 260 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name)
184 261
185 # ------------------------------------------------------------------------------ 262 # ------------------------------------------------------------------------------
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 else: 310 else:
234 constructor_info = AnalyzeConstructor(self._interface) 311 constructor_info = AnalyzeConstructor(self._interface)
235 if constructor_info: 312 if constructor_info:
236 constructors.append(constructor_info) 313 constructors.append(constructor_info)
237 factory_provider = '_' + interface_name + 'FactoryProvider' 314 factory_provider = '_' + interface_name + 'FactoryProvider'
238 factory_provider_emitter = self._library_emitter.FileEmitter( 315 factory_provider_emitter = self._library_emitter.FileEmitter(
239 '_%sFactoryProvider' % interface_name, self._library_name) 316 '_%sFactoryProvider' % interface_name, self._library_name)
240 self._backend.EmitFactoryProvider( 317 self._backend.EmitFactoryProvider(
241 constructor_info, factory_provider, factory_provider_emitter) 318 constructor_info, factory_provider, factory_provider_emitter)
242 319
243 infos = HtmlElementConstructorInfos(interface_name) 320 isHtmlElement = True
321 infos = ElementConstructorInfos(interface_name, _html_element_constructors)
blois 2012/11/15 18:09:16 Can we instead do a map of constructor infos, and
322 if not infos:
323 isHtmlElement = False
324 infos = ElementConstructorInfos(interface_name, _svg_element_constructors,
325 factory_provider_name='_SvgElements')
244 if infos: 326 if infos:
327 if isHtmlElement:
328 element_str = '_Elements'
329 else:
330 element_str = '_SvgElements'
245 template = self._template_loader.Load( 331 template = self._template_loader.Load(
246 'factoryprovider_Elements.darttemplate') 332 'factoryprovider%s.darttemplate' % element_str)
247 EmitHtmlElementFactoryConstructors( 333 EmitElementFactoryConstructors(
blois 2012/11/15 18:09:16 Can we eliminate this completely?
248 self._library_emitter.FileEmitter('_Elements', self._library_name, 334 self._library_emitter.FileEmitter(element_str, self._library_name,
249 template), 335 template),
250 infos, 336 infos,
251 self._interface.id, 337 self._interface.id,
252 self._interface_type_info.implementation_name(), 338 self._interface_type_info.implementation_name(),
253 self._DartType) 339 self._DartType, isHtmlElement)
254 340
255 for info in infos: 341 for info in infos:
256 constructors.append(info.ConstructorInfo(self._interface.id)) 342 constructors.append(info.ConstructorInfo(self._interface.id))
257 if factory_provider: 343 if factory_provider:
258 assert factory_provider == info.factory_provider_name 344 assert factory_provider == info.factory_provider_name
259 else: 345 else:
260 factory_provider = info.factory_provider_name 346 factory_provider = info.factory_provider_name
261 347
262 implementation_emitter = self._ImplementationEmitter() 348 implementation_emitter = self._ImplementationEmitter()
263 349
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 'svg': DartLibrary('svg', template_loader, library_type, output_dir), 1012 'svg': DartLibrary('svg', template_loader, library_type, output_dir),
927 'html': DartLibrary('html', template_loader, library_type, output_dir), 1013 'html': DartLibrary('html', template_loader, library_type, output_dir),
928 } 1014 }
929 1015
930 def AddFile(self, basename, library_name, path): 1016 def AddFile(self, basename, library_name, path):
931 self._libraries[library_name].AddFile(path) 1017 self._libraries[library_name].AddFile(path)
932 1018
933 def Emit(self, emitter, auxiliary_dir): 1019 def Emit(self, emitter, auxiliary_dir):
934 for lib in self._libraries.values(): 1020 for lib in self._libraries.values():
935 lib.Emit(emitter, auxiliary_dir) 1021 lib.Emit(emitter, auxiliary_dir)
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/html/templates/html/impl/factoryprovider_SvgElements.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698