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

Side by Side Diff: sdk/lib/svg/dartium/svg_dartium.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/svg/dart2js/svg_dart2js.dart ('k') | tests/html/cssstyledeclaration_test.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:nativewrappers'; 8 import 'dart:nativewrappers';
9 // DO NOT EDIT 9 // DO NOT EDIT
10 // Auto-generated dart:svg library. 10 // Auto-generated dart:svg library.
11 11
12 12
13 13
14 14
15 15
16 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 16 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
17 // for details. All rights reserved. Use of this source code is governed by a 17 // for details. All rights reserved. Use of this source code is governed by a
18 // BSD-style license that can be found in the LICENSE file. 18 // BSD-style license that can be found in the LICENSE file.
19 19
20 20
21 final _START_TAG_REGEXP = new RegExp('<(\\w+)');
22
23 class _SvgElementFactoryProvider { 21 class _SvgElementFactoryProvider {
24 static SvgElement createSvgElement_tag(String tag) { 22 static SvgElement createSvgElement_tag(String tag) {
25 final Element temp = 23 final Element temp =
26 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag); 24 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
27 return temp; 25 return temp;
28 } 26 }
29
30 static SvgElement createSvgElement_svg(String svg) {
31 Element parentTag;
32 final match = _START_TAG_REGEXP.firstMatch(svg);
33 if (match != null && match.group(1).toLowerCase() == 'svg') {
34 parentTag = new Element.tag('div');
35 } else {
36 parentTag = new SvgSvgElement();
37 }
38
39 parentTag.innerHtml = svg;
40 if (parentTag.children.length == 1) return parentTag.children.removeLast();
41
42 throw new ArgumentError(
43 'SVG had ${parentTag.children.length} '
44 'top-level children but 1 expected');
45 }
46 }
47
48 class _SvgSvgElementFactoryProvider {
49 static SvgSvgElement createSvgSvgElement() {
50 final el = new SvgElement.tag("svg");
51 // The SVG spec requires the version attribute to match the spec version
52 el.attributes['version'] = "1.1";
53 return el;
54 }
55 } 27 }
56 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 28 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
57 // for details. All rights reserved. Use of this source code is governed by a 29 // for details. All rights reserved. Use of this source code is governed by a
58 // BSD-style license that can be found in the LICENSE file. 30 // BSD-style license that can be found in the LICENSE file.
59 31
60 // WARNING: Do not edit - generated code. 32 // WARNING: Do not edit - generated code.
61 33
62 34
63 @DocsEditable() 35 @DocsEditable()
64 @DomName('SVGAElement') 36 @DomName('SVGAElement')
(...skipping 5271 matching lines...) Expand 10 before | Expand all | Expand 10 after
5336 } 5308 }
5337 5309
5338 void writeClasses(Set s) { 5310 void writeClasses(Set s) {
5339 _element.attributes['class'] = s.join(' '); 5311 _element.attributes['class'] = s.join(' ');
5340 } 5312 }
5341 } 5313 }
5342 5314
5343 @DomName('SVGElement') 5315 @DomName('SVGElement')
5344 @Unstable() 5316 @Unstable()
5345 class SvgElement extends Element { 5317 class SvgElement extends Element {
5318 static final _START_TAG_REGEXP = new RegExp('<(\\w+)');
5319
5346 factory SvgElement.tag(String tag) => 5320 factory SvgElement.tag(String tag) =>
5347 _SvgElementFactoryProvider.createSvgElement_tag(tag); 5321 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
5348 factory SvgElement.svg(String svg) => 5322 factory SvgElement.svg(String svg,
5349 _SvgElementFactoryProvider.createSvgElement_svg(svg); 5323 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
5324
5325 if (validator == null && treeSanitizer == null) {
5326 validator = new NodeValidatorBuilder.common()..allowSvg();
5327 }
5328
5329 final match = _START_TAG_REGEXP.firstMatch(svg);
5330 var parentElement;
5331 if (match != null && match.group(1).toLowerCase() == 'svg') {
5332 parentElement = document.body;
5333 } else {
5334 parentElement = new SvgSvgElement();
5335 }
5336 var fragment = parentElement.createFragment(svg, validator: validator,
5337 treeSanitizer: treeSanitizer);
5338 return fragment.nodes.where((e) => e is SvgElement).single;
5339 }
5350 5340
5351 _AttributeClassSet _cssClassSet; 5341 _AttributeClassSet _cssClassSet;
5352 CssClassSet get classes { 5342 CssClassSet get classes {
5353 if (_cssClassSet == null) { 5343 if (_cssClassSet == null) {
5354 _cssClassSet = new _AttributeClassSet(this); 5344 _cssClassSet = new _AttributeClassSet(this);
5355 } 5345 }
5356 return _cssClassSet; 5346 return _cssClassSet;
5357 } 5347 }
5358 5348
5359 List<Element> get children => new FilteredElementList<Element>(this); 5349 List<Element> get children => new FilteredElementList<Element>(this);
(...skipping 11 matching lines...) Expand all
5371 return container.innerHtml; 5361 return container.innerHtml;
5372 } 5362 }
5373 5363
5374 String get innerHtml { 5364 String get innerHtml {
5375 final container = new Element.tag("div"); 5365 final container = new Element.tag("div");
5376 final SvgElement cloned = this.clone(true); 5366 final SvgElement cloned = this.clone(true);
5377 container.children.addAll(cloned.children); 5367 container.children.addAll(cloned.children);
5378 return container.innerHtml; 5368 return container.innerHtml;
5379 } 5369 }
5380 5370
5381 void set innerHtml(String svg) { 5371 void set innerHtml(String value) {
5382 final container = new Element.tag("div"); 5372 this.setInnerHtml(value);
5383 // Wrap the SVG string in <svg> so that SvgElements are created, rather than 5373 }
5384 // HTMLElements. 5374
5385 container.innerHtml = '<svg version="1.1">$svg</svg>'; 5375 DocumentFragment createFragment(String svg,
5386 this.children = container.children[0].children; 5376 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
5377
5378 if (treeSanitizer == null) {
5379 if (validator == null) {
5380 validator = new NodeValidatorBuilder.common()
5381 ..allowSvg();
5382 }
5383 treeSanitizer = new NodeTreeSanitizer(validator);
5384 }
5385
5386 // We create a fragment which will parse in the HTML parser
5387 var html = '<svg version="1.1">$svg</svg>';
5388 var fragment = document.body.createFragment(html,
5389 treeSanitizer: treeSanitizer);
5390
5391 var svgFragment = new DocumentFragment();
5392 // The root is the <svg/> element, need to pull out the contents.
5393 var root = fragment.nodes.single;
5394 while (root.firstChild != null) {
5395 svgFragment.append(root.firstChild);
5396 }
5397 return svgFragment;
5387 } 5398 }
5388 5399
5389 // Unsupported methods inherited from Element. 5400 // Unsupported methods inherited from Element.
5390 5401
5391 @DomName('Element.insertAdjacentText') 5402 @DomName('Element.insertAdjacentText')
5392 void insertAdjacentText(String where, String text) { 5403 void insertAdjacentText(String where, String text) {
5393 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG."); 5404 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG.");
5394 } 5405 }
5395 5406
5396 @DomName('Element.insertAdjacentHTML') 5407 @DomName('Element.insertAdjacentHTML')
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
5472 5483
5473 } 5484 }
5474 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 5485 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
5475 // for details. All rights reserved. Use of this source code is governed by a 5486 // for details. All rights reserved. Use of this source code is governed by a
5476 // BSD-style license that can be found in the LICENSE file. 5487 // BSD-style license that can be found in the LICENSE file.
5477 5488
5478 5489
5479 @DomName('SVGSVGElement') 5490 @DomName('SVGSVGElement')
5480 @Unstable() 5491 @Unstable()
5481 class SvgSvgElement extends GraphicsElement implements FitToViewBox, ExternalRes ourcesRequired, ZoomAndPan { 5492 class SvgSvgElement extends GraphicsElement implements FitToViewBox, ExternalRes ourcesRequired, ZoomAndPan {
5482 factory SvgSvgElement() => _SvgSvgElementFactoryProvider.createSvgSvgElement() ; 5493 factory SvgSvgElement() {
5494 final el = new SvgElement.tag("svg");
5495 // The SVG spec requires the version attribute to match the spec version
5496 el.attributes['version'] = "1.1";
5497 return el;
5498 }
5483 5499
5484 // To suppress missing implicit constructor warnings. 5500 // To suppress missing implicit constructor warnings.
5485 factory SvgSvgElement._() { throw new UnsupportedError("Not supported"); } 5501 factory SvgSvgElement._() { throw new UnsupportedError("Not supported"); }
5486 5502
5487 @DomName('SVGSVGElement.contentScriptType') 5503 @DomName('SVGSVGElement.contentScriptType')
5488 @DocsEditable() 5504 @DocsEditable()
5489 String get contentScriptType native "SVGSVGElement_contentScriptType_Getter"; 5505 String get contentScriptType native "SVGSVGElement_contentScriptType_Getter";
5490 5506
5491 @DomName('SVGSVGElement.contentScriptType') 5507 @DomName('SVGSVGElement.contentScriptType')
5492 @DocsEditable() 5508 @DocsEditable()
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
6876 @Unstable() 6892 @Unstable()
6877 abstract class _SVGVKernElement extends SvgElement { 6893 abstract class _SVGVKernElement extends SvgElement {
6878 // To suppress missing implicit constructor warnings. 6894 // To suppress missing implicit constructor warnings.
6879 factory _SVGVKernElement._() { throw new UnsupportedError("Not supported"); } 6895 factory _SVGVKernElement._() { throw new UnsupportedError("Not supported"); }
6880 6896
6881 @DomName('SVGVKernElement.SVGVKernElement') 6897 @DomName('SVGVKernElement.SVGVKernElement')
6882 @DocsEditable() 6898 @DocsEditable()
6883 factory _SVGVKernElement() => _SvgElementFactoryProvider.createSvgElement_tag( "vkern"); 6899 factory _SVGVKernElement() => _SvgElementFactoryProvider.createSvgElement_tag( "vkern");
6884 6900
6885 } 6901 }
OLDNEW
« no previous file with comments | « sdk/lib/svg/dart2js/svg_dart2js.dart ('k') | tests/html/cssstyledeclaration_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698