Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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() | |
| 43 ..allowSvg(); | |
|
Jennifer Messerly
2013/08/17 06:07:07
remove newline?
blois
2013/08/19 22:02:09
Done.
| |
| 44 } | |
| 45 | |
| 46 final match = _START_TAG_REGEXP.firstMatch(svg); | |
| 47 var parentElement; | |
| 48 if (match != null && match.group(1).toLowerCase() == 'svg') { | |
| 49 parentElement = document.body; | |
| 50 } else { | |
| 51 parentElement = new SvgSvgElement(); | |
| 52 } | |
| 53 var fragment = parentElement.createFragment(svg, validator: validator, | |
| 54 treeSanitizer: treeSanitizer); | |
| 55 return fragment.nodes.where((e) => e is SvgElement).single; | |
| 56 } | |
| 38 | 57 |
| 39 _AttributeClassSet _cssClassSet; | 58 _AttributeClassSet _cssClassSet; |
| 40 CssClassSet get classes { | 59 CssClassSet get classes { |
| 41 if (_cssClassSet == null) { | 60 if (_cssClassSet == null) { |
| 42 _cssClassSet = new _AttributeClassSet(this); | 61 _cssClassSet = new _AttributeClassSet(this); |
| 43 } | 62 } |
| 44 return _cssClassSet; | 63 return _cssClassSet; |
| 45 } | 64 } |
| 46 | 65 |
| 47 List<Element> get children => new FilteredElementList<Element>(this); | 66 List<Element> get children => new FilteredElementList<Element>(this); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 59 return container.innerHtml; | 78 return container.innerHtml; |
| 60 } | 79 } |
| 61 | 80 |
| 62 String get innerHtml { | 81 String get innerHtml { |
| 63 final container = new Element.tag("div"); | 82 final container = new Element.tag("div"); |
| 64 final SvgElement cloned = this.clone(true); | 83 final SvgElement cloned = this.clone(true); |
| 65 container.children.addAll(cloned.children); | 84 container.children.addAll(cloned.children); |
| 66 return container.innerHtml; | 85 return container.innerHtml; |
| 67 } | 86 } |
| 68 | 87 |
| 69 void set innerHtml(String svg) { | 88 DocumentFragment createFragment(String svg, |
| 70 final container = new Element.tag("div"); | 89 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) { |
| 71 // Wrap the SVG string in <svg> so that SvgElements are created, rather than | 90 |
| 72 // HTMLElements. | 91 if (treeSanitizer == null) { |
| 73 container.innerHtml = '<svg version="1.1">$svg</svg>'; | 92 if (validator == null) { |
| 74 this.children = container.children[0].children; | 93 validator = new NodeValidatorBuilder.common() |
| 94 ..allowSvg(); | |
| 95 } | |
| 96 treeSanitizer = new NodeTreeSanitizer(validator); | |
| 97 } | |
| 98 | |
| 99 // We create a fragment which will parse in the HTML parser | |
| 100 var html = '<svg version="1.1">$svg</svg>'; | |
| 101 var fragment = document.body.createFragment(html, | |
| 102 treeSanitizer: treeSanitizer); | |
| 103 | |
| 104 var svgFragment = new DocumentFragment(); | |
| 105 // The root is the <svg/> element, need to pull out the contents. | |
| 106 var root = fragment.nodes.single; | |
| 107 while (root.firstChild != null) { | |
| 108 svgFragment.append(root.firstChild); | |
| 109 } | |
| 110 return svgFragment; | |
| 75 } | 111 } |
| 76 | 112 |
| 77 // Unsupported methods inherited from Element. | 113 // Unsupported methods inherited from Element. |
| 78 | 114 |
| 79 @DomName('Element.insertAdjacentText') | 115 @DomName('Element.insertAdjacentText') |
| 80 void insertAdjacentText(String where, String text) { | 116 void insertAdjacentText(String where, String text) { |
| 81 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG."); | 117 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG."); |
| 82 } | 118 } |
| 83 | 119 |
| 84 @DomName('Element.insertAdjacentHTML') | 120 @DomName('Element.insertAdjacentHTML') |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 104 * Checks to see if the SVG element type is supported by the current platform. | 140 * Checks to see if the SVG element type is supported by the current platform. |
| 105 * | 141 * |
| 106 * The tag should be a valid SVG element tag name. | 142 * The tag should be a valid SVG element tag name. |
| 107 */ | 143 */ |
| 108 static bool isTagSupported(String tag) { | 144 static bool isTagSupported(String tag) { |
| 109 var e = new $CLASSNAME.tag(tag); | 145 var e = new $CLASSNAME.tag(tag); |
| 110 return e is $CLASSNAME && !(e is UnknownElement); | 146 return e is $CLASSNAME && !(e is UnknownElement); |
| 111 } | 147 } |
| 112 $!MEMBERS | 148 $!MEMBERS |
| 113 } | 149 } |
| OLD | NEW |