-
Notifications
You must be signed in to change notification settings - Fork 27.3k
fix(render): create svg elements with the right namespace #4949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,92 @@ import {createRenderView, NodeFactory} from '../view_factory'; | |
| import {DefaultRenderView, DefaultRenderFragmentRef, DefaultProtoViewRef} from '../view'; | ||
| import {camelCaseToDashCase} from './util'; | ||
|
|
||
| // TODO(tbosch): solve SVG properly once https://github.com/angular/angular/issues/4417 is done | ||
| const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink'; | ||
| const SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; | ||
| const SVG_ELEMENT_NAMES = CONST_EXPR({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| 'altGlyph': true, | ||
| 'altGlyphDef': true, | ||
| 'altGlyphItem': true, | ||
| 'animate': true, | ||
| 'animateColor': true, | ||
| 'animateMotion': true, | ||
| 'animateTransform': true, | ||
| 'circle': true, | ||
| 'clipPath': true, | ||
| 'color-profile': true, | ||
| 'cursor': true, | ||
| 'defs': true, | ||
| 'desc': true, | ||
| 'ellipse': true, | ||
| 'feBlend': true, | ||
| 'feColorMatrix': true, | ||
| 'feComponentTransfer': true, | ||
| 'feComposite': true, | ||
| 'feConvolveMatrix': true, | ||
| 'feDiffuseLighting': true, | ||
| 'feDisplacementMap': true, | ||
| 'feDistantLight': true, | ||
| 'feFlood': true, | ||
| 'feFuncA': true, | ||
| 'feFuncB': true, | ||
| 'feFuncG': true, | ||
| 'feFuncR': true, | ||
| 'feGaussianBlur': true, | ||
| 'feImage': true, | ||
| 'feMerge': true, | ||
| 'feMergeNode': true, | ||
| 'feMorphology': true, | ||
| 'feOffset': true, | ||
| 'fePointLight': true, | ||
| 'feSpecularLighting': true, | ||
| 'feSpotLight': true, | ||
| 'feTile': true, | ||
| 'feTurbulence': true, | ||
| 'filter': true, | ||
| 'font': true, | ||
| 'font-face': true, | ||
| 'font-face-format': true, | ||
| 'font-face-name': true, | ||
| 'font-face-src': true, | ||
| 'font-face-uri': true, | ||
| 'foreignObject': true, | ||
| 'g': true, | ||
| 'glyph': true, | ||
| 'glyphRef': true, | ||
| 'hkern': true, | ||
| 'image': true, | ||
| 'line': true, | ||
| 'linearGradient': true, | ||
| 'marker': true, | ||
| 'mask': true, | ||
| 'metadata': true, | ||
| 'missing-glyph': true, | ||
| 'mpath': true, | ||
| 'path': true, | ||
| 'pattern': true, | ||
| 'polygon': true, | ||
| 'polyline': true, | ||
| 'radialGradient': true, | ||
| 'rect': true, | ||
| 'set': true, | ||
| 'stop': true, | ||
| 'style': true, | ||
| 'svg': true, | ||
| 'switch': true, | ||
| 'symbol': true, | ||
| 'text': true, | ||
| 'textPath': true, | ||
| 'title': true, | ||
| 'tref': true, | ||
| 'tspan': true, | ||
| 'use': true, | ||
| 'view': true, | ||
| 'vkern': true | ||
| }); | ||
|
|
||
| const SVG_ATTR_NAMESPACES = CONST_EXPR({'href': XLINK_NAMESPACE}); | ||
|
|
||
| export abstract class DomRenderer extends Renderer implements NodeFactory<Node> { | ||
| abstract registerComponentTemplate(templateId: number, commands: RenderTemplateCmd[], | ||
| styles: string[], nativeShadow: boolean); | ||
|
|
@@ -271,17 +357,25 @@ export class DomRenderer_ extends DomRenderer { | |
| wtfLeave(s); | ||
| } | ||
| createElement(name: string, attrNameAndValues: string[]): Node { | ||
| var el = DOM.createElement(name); | ||
| this._setAttributes(el, attrNameAndValues); | ||
| var isSvg = SVG_ELEMENT_NAMES[name] == true; | ||
| var el = isSvg ? DOM.createElementNS(SVG_NAMESPACE, name) : DOM.createElement(name); | ||
| this._setAttributes(el, attrNameAndValues, isSvg); | ||
| return el; | ||
| } | ||
| mergeElement(existing: Node, attrNameAndValues: string[]) { | ||
| DOM.clearNodes(existing); | ||
| this._setAttributes(existing, attrNameAndValues); | ||
| this._setAttributes(existing, attrNameAndValues, false); | ||
| } | ||
| private _setAttributes(node: Node, attrNameAndValues: string[]) { | ||
| private _setAttributes(node: Node, attrNameAndValues: string[], isSvg: boolean) { | ||
| for (var attrIdx = 0; attrIdx < attrNameAndValues.length; attrIdx += 2) { | ||
| DOM.setAttribute(node, attrNameAndValues[attrIdx], attrNameAndValues[attrIdx + 1]); | ||
| var attrName = attrNameAndValues[attrIdx]; | ||
| var attrValue = attrNameAndValues[attrIdx + 1]; | ||
| var attrNs = isSvg ? SVG_ATTR_NAMESPACES[attrName] : null; | ||
| if (isPresent(attrNs)) { | ||
| DOM.setAttributeNS(node, XLINK_NAMESPACE, attrName, attrValue); | ||
| } else { | ||
| DOM.setAttribute(node, attrName, attrValue); | ||
| } | ||
| } | ||
| } | ||
| createRootContentInsertionPoint(): Node { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the class is abstract, no need to throw (other places should also be modified)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vicb: could you please file an issue for this? There are lots of places where we need to clean this up. For now Tobias' change is fine. The P1 goal is to roll out pre-compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then I need to implement it in all sub classes...