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

Side by Side Diff: tools/dom/templates/html/impl/impl_SVGElement.darttemplate

Issue 16374007: First rev of Safe DOM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of $LIBRARYNAME; 5 part of $LIBRARYNAME;
6 6
7 class _AttributeClassSet extends CssClassSetImpl { 7 class _AttributeClassSet extends CssClassSetImpl {
8 final Element _element; 8 final Element _element;
9 9
10 _AttributeClassSet(this._element); 10 _AttributeClassSet(this._element);
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 return s; 25 return s;
26 } 26 }
27 27
28 void writeClasses(Set s) { 28 void writeClasses(Set s) {
29 _element.attributes['class'] = s.join(' '); 29 _element.attributes['class'] = s.join(' ');
30 } 30 }
31 } 31 }
32 32
33 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 33 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
34 static final _START_TAG_REGEXP = new RegExp('<(\\w+)');
35
34 factory $CLASSNAME.tag(String tag) => 36 factory $CLASSNAME.tag(String tag) =>
35 _$(CLASSNAME)FactoryProvider.create$(CLASSNAME)_tag(tag); 37 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
36 factory $CLASSNAME.svg(String svg) => 38 factory $CLASSNAME.svg(String svg,
37 _$(CLASSNAME)FactoryProvider.create$(CLASSNAME)_svg(svg); 39 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
40
41 if (validator == null && treeSanitizer == null) {
42 validator = new NodeValidatorBuilder.common()..allowSvg();
43 }
44
45 final match = _START_TAG_REGEXP.firstMatch(svg);
46 var parentElement;
47 if (match != null && match.group(1).toLowerCase() == 'svg') {
48 parentElement = document.body;
49 } else {
50 parentElement = new SvgSvgElement();
51 }
52 var fragment = parentElement.createFragment(svg, validator: validator,
53 treeSanitizer: treeSanitizer);
54 return fragment.nodes.where((e) => e is SvgElement).single;
55 }
38 56
39 _AttributeClassSet _cssClassSet; 57 _AttributeClassSet _cssClassSet;
40 CssClassSet get classes { 58 CssClassSet get classes {
41 if (_cssClassSet == null) { 59 if (_cssClassSet == null) {
42 _cssClassSet = new _AttributeClassSet(this); 60 _cssClassSet = new _AttributeClassSet(this);
43 } 61 }
44 return _cssClassSet; 62 return _cssClassSet;
45 } 63 }
46 64
47 List<Element> get children => new FilteredElementList<Element>(this); 65 List<Element> get children => new FilteredElementList<Element>(this);
(...skipping 11 matching lines...) Expand all
59 return container.innerHtml; 77 return container.innerHtml;
60 } 78 }
61 79
62 String get innerHtml { 80 String get innerHtml {
63 final container = new Element.tag("div"); 81 final container = new Element.tag("div");
64 final SvgElement cloned = this.clone(true); 82 final SvgElement cloned = this.clone(true);
65 container.children.addAll(cloned.children); 83 container.children.addAll(cloned.children);
66 return container.innerHtml; 84 return container.innerHtml;
67 } 85 }
68 86
69 void set innerHtml(String svg) { 87 void set innerHtml(String value) {
70 final container = new Element.tag("div"); 88 this.setInnerHtml(value);
71 // Wrap the SVG string in <svg> so that SvgElements are created, rather than 89 }
72 // HTMLElements. 90
73 container.innerHtml = '<svg version="1.1">$svg</svg>'; 91 DocumentFragment createFragment(String svg,
74 this.children = container.children[0].children; 92 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
93
94 if (treeSanitizer == null) {
95 if (validator == null) {
96 validator = new NodeValidatorBuilder.common()
97 ..allowSvg();
98 }
99 treeSanitizer = new NodeTreeSanitizer(validator);
100 }
101
102 // We create a fragment which will parse in the HTML parser
103 var html = '<svg version="1.1">$svg</svg>';
104 var fragment = document.body.createFragment(html,
105 treeSanitizer: treeSanitizer);
106
107 var svgFragment = new DocumentFragment();
108 // The root is the <svg/> element, need to pull out the contents.
109 var root = fragment.nodes.single;
110 while (root.firstChild != null) {
111 svgFragment.append(root.firstChild);
112 }
113 return svgFragment;
75 } 114 }
76 115
77 // Unsupported methods inherited from Element. 116 // Unsupported methods inherited from Element.
78 117
79 @DomName('Element.insertAdjacentText') 118 @DomName('Element.insertAdjacentText')
80 void insertAdjacentText(String where, String text) { 119 void insertAdjacentText(String where, String text) {
81 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG."); 120 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG.");
82 } 121 }
83 122
84 @DomName('Element.insertAdjacentHTML') 123 @DomName('Element.insertAdjacentHTML')
(...skipping 19 matching lines...) Expand all
104 * Checks to see if the SVG element type is supported by the current platform. 143 * Checks to see if the SVG element type is supported by the current platform.
105 * 144 *
106 * The tag should be a valid SVG element tag name. 145 * The tag should be a valid SVG element tag name.
107 */ 146 */
108 static bool isTagSupported(String tag) { 147 static bool isTagSupported(String tag) {
109 var e = new $CLASSNAME.tag(tag); 148 var e = new $CLASSNAME.tag(tag);
110 return e is $CLASSNAME && !(e is UnknownElement); 149 return e is $CLASSNAME && !(e is UnknownElement);
111 } 150 }
112 $!MEMBERS 151 $!MEMBERS
113 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698