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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/html/templates/html/impl/factoryprovider_SvgElements.darttemplate » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,109 @@
'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',
+ 'SVGSVGElement': 'svg',
+ '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'
blois 2012/11/15 01:35:49 Should just be able to use _SVGElementFactoryProvi
Emily Fortuna 2012/11/15 01:36:51 See below for the SVG cases. This is for the HtmlE
+ else:
+ emitted_string += (
+ ' final Element _e =\n'
+ ' 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 +318,26 @@
self._backend.EmitFactoryProvider(
constructor_info, factory_provider, factory_provider_emitter)
- infos = HtmlElementConstructorInfos(interface_name)
+ isHtmlElement = True
+ infos = ElementConstructorInfos(interface_name, _html_element_constructors)
+ 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'
blois 2012/11/15 01:35:49 We should be able to just get rid of these factory
template = self._template_loader.Load(
- 'factoryprovider_Elements.darttemplate')
- EmitHtmlElementFactoryConstructors(
- self._library_emitter.FileEmitter('_Elements', self._library_name,
+ 'factoryprovider%s.darttemplate' % element_str)
+ EmitElementFactoryConstructors(
+ 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))
« 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