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

Side by Side Diff: sdk/lib/svg/dart2js/svg_dart2js.dart

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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | sdk/lib/svg/dartium/svg_dartium.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 library dart.dom.svg; 1 library dart.dom.svg;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:collection'; 4 import 'dart:collection';
5 import 'dart:_collection-dev' hide deprecated; 5 import 'dart:_collection-dev' hide deprecated;
6 import 'dart:html'; 6 import 'dart:html';
7 import 'dart:html_common'; 7 import 'dart:html_common';
8 import 'dart:_js_helper' show Creates, Returns, JavaScriptIndexingBehavior, JSNa me; 8 import 'dart:_js_helper' show Creates, Returns, JavaScriptIndexingBehavior, JSNa me;
9 import 'dart:_foreign_helper' show JS; 9 import 'dart:_foreign_helper' show JS;
10 import 'dart:_interceptors' show Interceptor; 10 import 'dart:_interceptors' show Interceptor;
11 // DO NOT EDIT - unless you are editing documentation as per: 11 // DO NOT EDIT - unless you are editing documentation as per:
12 // https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation 12 // https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation
13 // Auto-generated dart:svg library. 13 // Auto-generated dart:svg library.
14 14
15 15
16 16
17 17
18 18
19 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 19 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
20 // for details. All rights reserved. Use of this source code is governed by a 20 // for details. All rights reserved. Use of this source code is governed by a
21 // BSD-style license that can be found in the LICENSE file. 21 // BSD-style license that can be found in the LICENSE file.
22 22
23 23
24 final _START_TAG_REGEXP = new RegExp('<(\\w+)');
25
26 class _SvgElementFactoryProvider { 24 class _SvgElementFactoryProvider {
27 static SvgElement createSvgElement_tag(String tag) { 25 static SvgElement createSvgElement_tag(String tag) {
28 final Element temp = 26 final Element temp =
29 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag); 27 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
30 return temp; 28 return temp;
31 } 29 }
32
33 static SvgElement createSvgElement_svg(String svg) {
34 Element parentTag;
35 final match = _START_TAG_REGEXP.firstMatch(svg);
36 if (match != null && match.group(1).toLowerCase() == 'svg') {
37 parentTag = new Element.tag('div');
38 } else {
39 parentTag = new SvgSvgElement();
40 }
41
42 parentTag.innerHtml = svg;
43 if (parentTag.children.length == 1) return parentTag.children.removeLast();
44
45 throw new ArgumentError(
46 'SVG had ${parentTag.children.length} '
47 'top-level children but 1 expected');
48 }
49 }
50
51 class _SvgSvgElementFactoryProvider {
52 static SvgSvgElement createSvgSvgElement() {
53 final el = new SvgElement.tag("svg");
54 // The SVG spec requires the version attribute to match the spec version
55 el.attributes['version'] = "1.1";
56 return el;
57 }
58 } 30 }
59 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 31 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
60 // for details. All rights reserved. Use of this source code is governed by a 32 // for details. All rights reserved. Use of this source code is governed by a
61 // BSD-style license that can be found in the LICENSE file. 33 // BSD-style license that can be found in the LICENSE file.
62 34
63 35
64 @DocsEditable() 36 @DocsEditable()
65 @DomName('SVGAElement') 37 @DomName('SVGAElement')
66 @Unstable() 38 @Unstable()
67 class AElement extends GraphicsElement implements UriReference, ExternalResource sRequired native "SVGAElement" { 39 class AElement extends GraphicsElement implements UriReference, ExternalResource sRequired native "SVGAElement" {
(...skipping 4682 matching lines...) Expand 10 before | Expand all | Expand 10 after
4750 } 4722 }
4751 4723
4752 void writeClasses(Set s) { 4724 void writeClasses(Set s) {
4753 _element.attributes['class'] = s.join(' '); 4725 _element.attributes['class'] = s.join(' ');
4754 } 4726 }
4755 } 4727 }
4756 4728
4757 @DomName('SVGElement') 4729 @DomName('SVGElement')
4758 @Unstable() 4730 @Unstable()
4759 class SvgElement extends Element native "SVGElement" { 4731 class SvgElement extends Element native "SVGElement" {
4732 static final _START_TAG_REGEXP = new RegExp('<(\\w+)');
4733
4760 factory SvgElement.tag(String tag) => 4734 factory SvgElement.tag(String tag) =>
4761 _SvgElementFactoryProvider.createSvgElement_tag(tag); 4735 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
4762 factory SvgElement.svg(String svg) => 4736 factory SvgElement.svg(String svg,
4763 _SvgElementFactoryProvider.createSvgElement_svg(svg); 4737 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
4738
4739 if (validator == null && treeSanitizer == null) {
4740 validator = new NodeValidatorBuilder.common()..allowSvg();
4741 }
4742
4743 final match = _START_TAG_REGEXP.firstMatch(svg);
4744 var parentElement;
4745 if (match != null && match.group(1).toLowerCase() == 'svg') {
4746 parentElement = document.body;
4747 } else {
4748 parentElement = new SvgSvgElement();
4749 }
4750 var fragment = parentElement.createFragment(svg, validator: validator,
4751 treeSanitizer: treeSanitizer);
4752 return fragment.nodes.where((e) => e is SvgElement).single;
4753 }
4764 4754
4765 _AttributeClassSet _cssClassSet; 4755 _AttributeClassSet _cssClassSet;
4766 CssClassSet get classes { 4756 CssClassSet get classes {
4767 if (_cssClassSet == null) { 4757 if (_cssClassSet == null) {
4768 _cssClassSet = new _AttributeClassSet(this); 4758 _cssClassSet = new _AttributeClassSet(this);
4769 } 4759 }
4770 return _cssClassSet; 4760 return _cssClassSet;
4771 } 4761 }
4772 4762
4773 List<Element> get children => new FilteredElementList<Element>(this); 4763 List<Element> get children => new FilteredElementList<Element>(this);
(...skipping 11 matching lines...) Expand all
4785 return container.innerHtml; 4775 return container.innerHtml;
4786 } 4776 }
4787 4777
4788 String get innerHtml { 4778 String get innerHtml {
4789 final container = new Element.tag("div"); 4779 final container = new Element.tag("div");
4790 final SvgElement cloned = this.clone(true); 4780 final SvgElement cloned = this.clone(true);
4791 container.children.addAll(cloned.children); 4781 container.children.addAll(cloned.children);
4792 return container.innerHtml; 4782 return container.innerHtml;
4793 } 4783 }
4794 4784
4795 void set innerHtml(String svg) { 4785 void set innerHtml(String value) {
4796 final container = new Element.tag("div"); 4786 this.setInnerHtml(value);
4797 // Wrap the SVG string in <svg> so that SvgElements are created, rather than 4787 }
4798 // HTMLElements. 4788
4799 container.innerHtml = '<svg version="1.1">$svg</svg>'; 4789 DocumentFragment createFragment(String svg,
4800 this.children = container.children[0].children; 4790 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
4791
4792 if (treeSanitizer == null) {
4793 if (validator == null) {
4794 validator = new NodeValidatorBuilder.common()
4795 ..allowSvg();
4796 }
4797 treeSanitizer = new NodeTreeSanitizer(validator);
4798 }
4799
4800 // We create a fragment which will parse in the HTML parser
4801 var html = '<svg version="1.1">$svg</svg>';
4802 var fragment = document.body.createFragment(html,
4803 treeSanitizer: treeSanitizer);
4804
4805 var svgFragment = new DocumentFragment();
4806 // The root is the <svg/> element, need to pull out the contents.
4807 var root = fragment.nodes.single;
4808 while (root.firstChild != null) {
4809 svgFragment.append(root.firstChild);
4810 }
4811 return svgFragment;
4801 } 4812 }
4802 4813
4803 // Unsupported methods inherited from Element. 4814 // Unsupported methods inherited from Element.
4804 4815
4805 @DomName('Element.insertAdjacentText') 4816 @DomName('Element.insertAdjacentText')
4806 void insertAdjacentText(String where, String text) { 4817 void insertAdjacentText(String where, String text) {
4807 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG."); 4818 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG.");
4808 } 4819 }
4809 4820
4810 @DomName('Element.insertAdjacentHTML') 4821 @DomName('Element.insertAdjacentHTML')
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4869 4880
4870 } 4881 }
4871 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 4882 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
4872 // for details. All rights reserved. Use of this source code is governed by a 4883 // for details. All rights reserved. Use of this source code is governed by a
4873 // BSD-style license that can be found in the LICENSE file. 4884 // BSD-style license that can be found in the LICENSE file.
4874 4885
4875 4886
4876 @DomName('SVGSVGElement') 4887 @DomName('SVGSVGElement')
4877 @Unstable() 4888 @Unstable()
4878 class SvgSvgElement extends GraphicsElement implements FitToViewBox, ExternalRes ourcesRequired, ZoomAndPan native "SVGSVGElement" { 4889 class SvgSvgElement extends GraphicsElement implements FitToViewBox, ExternalRes ourcesRequired, ZoomAndPan native "SVGSVGElement" {
4879 factory SvgSvgElement() => _SvgSvgElementFactoryProvider.createSvgSvgElement() ; 4890 factory SvgSvgElement() {
4891 final el = new SvgElement.tag("svg");
4892 // The SVG spec requires the version attribute to match the spec version
4893 el.attributes['version'] = "1.1";
4894 return el;
4895 }
4880 4896
4881 // To suppress missing implicit constructor warnings. 4897 // To suppress missing implicit constructor warnings.
4882 factory SvgSvgElement._() { throw new UnsupportedError("Not supported"); } 4898 factory SvgSvgElement._() { throw new UnsupportedError("Not supported"); }
4883 4899
4884 @DomName('SVGSVGElement.contentScriptType') 4900 @DomName('SVGSVGElement.contentScriptType')
4885 @DocsEditable() 4901 @DocsEditable()
4886 String contentScriptType; 4902 String contentScriptType;
4887 4903
4888 @DomName('SVGSVGElement.contentStyleType') 4904 @DomName('SVGSVGElement.contentStyleType')
4889 @DocsEditable() 4905 @DocsEditable()
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
6174 @DomName('SVGVKernElement') 6190 @DomName('SVGVKernElement')
6175 @Unstable() 6191 @Unstable()
6176 abstract class _SVGVKernElement extends SvgElement native "SVGVKernElement" { 6192 abstract class _SVGVKernElement extends SvgElement native "SVGVKernElement" {
6177 // To suppress missing implicit constructor warnings. 6193 // To suppress missing implicit constructor warnings.
6178 factory _SVGVKernElement._() { throw new UnsupportedError("Not supported"); } 6194 factory _SVGVKernElement._() { throw new UnsupportedError("Not supported"); }
6179 6195
6180 @DomName('SVGVKernElement.SVGVKernElement') 6196 @DomName('SVGVKernElement.SVGVKernElement')
6181 @DocsEditable() 6197 @DocsEditable()
6182 factory _SVGVKernElement() => _SvgElementFactoryProvider.createSvgElement_tag( "vkern"); 6198 factory _SVGVKernElement() => _SvgElementFactoryProvider.createSvgElement_tag( "vkern");
6183 } 6199 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | sdk/lib/svg/dartium/svg_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698