Index: sdk/lib/html/scripts/systemhtml.py |
=================================================================== |
--- sdk/lib/html/scripts/systemhtml.py (revision 14920) |
+++ sdk/lib/html/scripts/systemhtml.py (working copy) |
@@ -60,7 +60,7 @@ |
params=[], opt_params=[], |
factory_provider_name='_Elements'): |
self.name = name # The constructor name 'h1' in 'HeadingElement.h1' |
- self.tag = tag or name # The HTML tag |
+ self.tag = tag or name # The HTML or SVG tag |
self.params = params |
self.opt_params = opt_params |
self.factory_provider_name = factory_provider_name |
@@ -148,31 +148,108 @@ |
'VideoElement': 'video' |
} |
-def HtmlElementConstructorInfos(typename): |
+_svg_element_constructors = { |
+ 'SVGAElement': 'a', |
+ 'SVGAnimateColorElement': 'animateColor', |
+ 'SVGAnimateElement': 'animate', |
+ 'SVGAnimateMotionElement': 'animateMotion', |
+ 'SVGAnimateTransformElement': 'animateTransform', |
+ 'SVGAnimationElement': 'animation', |
+ 'SVGCircleElement': 'circle', |
+ 'SVGClipPathElement': 'clipPath', |
+ 'SVGCursorElement': 'cursor', |
+ 'SVGDefsElement': 'defs', |
+ 'SVGDescElement': 'desc', |
+ 'SVGEllipseElement': 'ellipse', |
+ 'SVGFilterElement': 'filter', |
+ 'SVGFontElement': 'font', |
+ 'SVGFontFaceElement': 'font-face', |
+ 'SVGFontFaceFormatElement': 'font-face-format', |
+ 'SVGFontFaceNameElement': 'font-face-name', |
+ 'SVGFontFaceSrcElement': 'font-face-src', |
+ 'SVGFontFaceUriElement': 'font-face-uri', |
+ 'SVGForeignObjectElement': 'foreignObject', |
+ 'SVGGlyphElement': 'glyph', |
+ 'SVGGElement': 'g', |
+ 'SVGHKernElement': 'hkern', |
+ 'SVGImageElement': 'image', |
+ 'SVGLinearGradientElement': 'linearGradient', |
+ 'SVGLineElement': 'line', |
+ 'SVGMarkerElement': 'marker', |
+ 'SVGMaskElement': 'mask', |
+ 'SVGMPathElement': 'mpath', |
+ 'SVGPathElement': 'path', |
+ 'SVGPatternElement': 'pattern', |
+ 'SVGPolygonElement': 'polygon', |
+ 'SVGPolylineElement': 'polyline', |
+ 'SVGRadialGradientElement': 'radialGradient', |
+ 'SVGRectElement': 'rect', |
+ 'SVGScriptElement': 'script', |
+ 'SVGSetElement': 'set', |
+ 'SVGStopElement': 'stop', |
+ 'SVGStyleElement': 'style', |
+ 'SVGSwitchElement': 'switch', |
+ 'SVGSymbolElement': 'symbol', |
+ 'SVGTextElement': 'text', |
+ 'SVGTitleElement': 'title', |
+ 'SVGTRefElement': 'tref', |
+ 'SVGTSpanElement': 'tspan', |
+ 'SVGUseElement': 'use', |
+ 'SVGViewElement': 'view', |
+ 'SVGVKernElement': 'vkern', |
+ # TODO(efortuna): The following still need to be added to this list. Currently |
+ # they can only be added via SVGElement.tag('tag name'): |
+ # SVGAltGlyphDefElement, SVGAltGlyphElement, SVGAltGlyphItemElement, |
+ # SVGComponentTransferFunctionElement, SVGFEBlendElement, |
+ # SVGFEColorMatrixElement, SVGFEComponentTransferElement, |
+ # SVGFECompositeElement, SVGFEConvolveMatrixElement, |
+ # SVGFEDiffuseLightingElement, SVGFEDisplacementMapElement, |
+ # SVGFEDistantLightElement, SVGFEDropShadowElement, SVGFEFloodElement, |
+ # SVGFEFuncAElement, SVGFEFuncBElement, SVGFEFuncGElement, SVGFEFuncRElement, |
+ # SVGFEGaussianBlurElement, SVGFEImageElement, SVGFEMergeElement, |
+ # SVGFEMergeNodeElement, SVGFEMorphologyElement, SVGFEOffsetElement, |
+ # SVGFEPointLightElement, SVGFESpecularLightingElement, SVGFESpotLightElement, |
+ # SVGFETileElement, SVGFETurbulenceElement, SVGGlyphElement, |
+ # SVGGlyphRefElement, SVGGradientElement, SVGMetadataElement, |
+ # SVGMissingGlyphElement, SVGTextContentElement, SVGTextPathElement, |
+ # SVGTextPositioningElement |
+} |
+ |
+def ElementConstructorInfos(typename, element_constructors, |
+ factory_provider_name='_Elements'): |
"""Returns list of ElementConstructorInfos about the convenience constructors |
- for an Element.""" |
+ for an Element or SvgElement.""" |
# TODO(sra): Handle multiple and named constructors. |
- if typename not in _html_element_constructors: |
+ if typename not in element_constructors: |
return [] |
- infos = _html_element_constructors[typename] |
+ infos = element_constructors[typename] |
if isinstance(infos, str): |
- infos = ElementConstructorInfo(tag=infos) |
+ infos = ElementConstructorInfo(tag=infos, |
+ factory_provider_name=factory_provider_name) |
if not isinstance(infos, list): |
infos = [infos] |
return infos |
-def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name, |
- rename_type): |
+def EmitElementFactoryConstructors(emitter, infos, typename, class_name, |
+ rename_type, isHtmlElement): |
+ """Emits convenience factory contructors for HtmlElements and SvgElements.""" |
for info in infos: |
constructor_info = info.ConstructorInfo(typename) |
+ emitted_string = '\n static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n' |
+ if isHtmlElement: |
+ emitted_string += ' $CLASS _e = document.$dom_createElement("$TAG");\n' |
+ else: |
+ emitted_string += ( |
+ ' final Element _e =\n' |
blois
2012/11/15 18:09:16
Change final Element _e and $CLASS _e to var e.
|
+ ' document.$dom_createElementNS(' |
+ '"http://www.w3.org/2000/svg", "$TAG");\n') |
+ emitted_string += ( |
+ '$!INITS' |
+ ' return _e;\n' |
+ ' }\n') |
inits = emitter.Emit( |
- '\n' |
- ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n' |
- ' $CLASS _e = document.$dom_createElement("$TAG");\n' |
- '$!INITS' |
- ' return _e;\n' |
- ' }\n', |
+ emitted_string, |
RETURN_TYPE=rename_type(constructor_info.type_name), |
CONSTRUCTOR=constructor_info.ConstructorFactoryName(rename_type), |
CLASS=class_name, |
@@ -240,17 +317,26 @@ |
self._backend.EmitFactoryProvider( |
constructor_info, factory_provider, factory_provider_emitter) |
- infos = HtmlElementConstructorInfos(interface_name) |
+ isHtmlElement = True |
+ infos = ElementConstructorInfos(interface_name, _html_element_constructors) |
blois
2012/11/15 18:09:16
Can we instead do a map of constructor infos, and
|
+ if not infos: |
+ isHtmlElement = False |
+ infos = ElementConstructorInfos(interface_name, _svg_element_constructors, |
+ factory_provider_name='_SvgElements') |
if infos: |
+ if isHtmlElement: |
+ element_str = '_Elements' |
+ else: |
+ element_str = '_SvgElements' |
template = self._template_loader.Load( |
- 'factoryprovider_Elements.darttemplate') |
- EmitHtmlElementFactoryConstructors( |
- self._library_emitter.FileEmitter('_Elements', self._library_name, |
+ 'factoryprovider%s.darttemplate' % element_str) |
+ EmitElementFactoryConstructors( |
blois
2012/11/15 18:09:16
Can we eliminate this completely?
|
+ self._library_emitter.FileEmitter(element_str, self._library_name, |
template), |
infos, |
self._interface.id, |
self._interface_type_info.implementation_name(), |
- self._DartType) |
+ self._DartType, isHtmlElement) |
for info in infos: |
constructors.append(info.ConstructorInfo(self._interface.id)) |