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

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, 6 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 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'; 5 import 'dart:_collection-dev';
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 StyledElement implements UriReference, Tests, Transformab le, ExternalResourcesRequired, LangSpace native "SVGAElement" { 39 class AElement extends StyledElement implements UriReference, Tests, Transformab le, ExternalResourcesRequired, LangSpace native "SVGAElement" {
(...skipping 5391 matching lines...) Expand 10 before | Expand all | Expand 10 after
5459 } 5431 }
5460 5432
5461 void writeClasses(Set s) { 5433 void writeClasses(Set s) {
5462 _element.attributes['class'] = s.join(' '); 5434 _element.attributes['class'] = s.join(' ');
5463 } 5435 }
5464 } 5436 }
5465 5437
5466 @DomName('SVGElement') 5438 @DomName('SVGElement')
5467 @Unstable 5439 @Unstable
5468 class SvgElement extends Element native "SVGElement" { 5440 class SvgElement extends Element native "SVGElement" {
5441 static final _START_TAG_REGEXP = new RegExp('<(\\w+)');
5442
5469 factory SvgElement.tag(String tag) => 5443 factory SvgElement.tag(String tag) =>
5470 _SvgElementFactoryProvider.createSvgElement_tag(tag); 5444 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
5471 factory SvgElement.svg(String svg) => 5445
5472 _SvgElementFactoryProvider.createSvgElement_svg(svg); 5446 factory SvgElement.svg(String svg,
5447 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
5448
5449 if (validator == null && treeSanitizer == null) {
5450 validator = new NodeValidatorBuilder.common()
5451 ..allowSvg();
5452 }
5453
5454 final match = _START_TAG_REGEXP.firstMatch(svg);
5455 var parentElement;
5456 if (match != null && match.group(1).toLowerCase() == 'svg') {
5457 parentElement = document.body;
5458 } else {
5459 parentElement = new SvgSvgElement();
5460 }
5461 var fragment = parentElement.createFragment(svg, validator: validator,
5462 treeSanitizer: treeSanitizer);
5463 return fragment.nodes.where((e) => e is SvgElement).single;
5464 }
5473 5465
5474 _AttributeClassSet _cssClassSet; 5466 _AttributeClassSet _cssClassSet;
5475 CssClassSet get classes { 5467 CssClassSet get classes {
5476 if (_cssClassSet == null) { 5468 if (_cssClassSet == null) {
5477 _cssClassSet = new _AttributeClassSet(this); 5469 _cssClassSet = new _AttributeClassSet(this);
5478 } 5470 }
5479 return _cssClassSet; 5471 return _cssClassSet;
5480 } 5472 }
5481 5473
5482 List<Element> get children => new FilteredElementList<Element>(this); 5474 List<Element> get children => new FilteredElementList<Element>(this);
(...skipping 11 matching lines...) Expand all
5494 return container.innerHtml; 5486 return container.innerHtml;
5495 } 5487 }
5496 5488
5497 String get innerHtml { 5489 String get innerHtml {
5498 final container = new Element.tag("div"); 5490 final container = new Element.tag("div");
5499 final SvgElement cloned = this.clone(true); 5491 final SvgElement cloned = this.clone(true);
5500 container.children.addAll(cloned.children); 5492 container.children.addAll(cloned.children);
5501 return container.innerHtml; 5493 return container.innerHtml;
5502 } 5494 }
5503 5495
5504 void set innerHtml(String svg) { 5496 DocumentFragment createFragment(String svg,
5505 final container = new Element.tag("div"); 5497 {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
5506 // Wrap the SVG string in <svg> so that SvgElements are created, rather than 5498
5507 // HTMLElements. 5499 if (treeSanitizer == null) {
5508 container.innerHtml = '<svg version="1.1">$svg</svg>'; 5500 if (validator == null) {
5509 this.children = container.children[0].children; 5501 validator = new NodeValidatorBuilder.common()
5502 ..allowSvg();
5503 }
5504 treeSanitizer = new NodeTreeSanitizer(validator);
5505 }
5506
5507 // We create a fragment which will parse in the HTML parser
5508 var html = '<svg version="1.1">$svg</svg>';
5509 var fragment = document.body.createFragment(html,
5510 treeSanitizer: treeSanitizer);
5511
5512 var svgFragment = new DocumentFragment();
5513 // The root is the <svg/> element, need to pull out the contents.
5514 var root = fragment.nodes.single;
5515 while (root.$dom_firstChild != null) {
5516 svgFragment.append(root.$dom_firstChild);
5517 }
5518 return svgFragment;
5510 } 5519 }
5511 5520
5512 // Unsupported methods inherited from Element. 5521 // Unsupported methods inherited from Element.
5513 5522
5514 @DomName('Element.insertAdjacentText') 5523 @DomName('Element.insertAdjacentText')
5515 void insertAdjacentText(String where, String text) { 5524 void insertAdjacentText(String where, String text) {
5516 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG."); 5525 throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG.");
5517 } 5526 }
5518 5527
5519 @DomName('Element.insertAdjacentHTML') 5528 @DomName('Element.insertAdjacentHTML')
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
5607 String toString() native; 5616 String toString() native;
5608 } 5617 }
5609 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 5618 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
5610 // for details. All rights reserved. Use of this source code is governed by a 5619 // for details. All rights reserved. Use of this source code is governed by a
5611 // BSD-style license that can be found in the LICENSE file. 5620 // BSD-style license that can be found in the LICENSE file.
5612 5621
5613 5622
5614 @DomName('SVGSVGElement') 5623 @DomName('SVGSVGElement')
5615 @Unstable 5624 @Unstable
5616 class SvgSvgElement extends StyledElement implements FitToViewBox, Transformable , Tests, ExternalResourcesRequired, ZoomAndPan, LangSpace native "SVGSVGElement" { 5625 class SvgSvgElement extends StyledElement implements FitToViewBox, Transformable , Tests, ExternalResourcesRequired, ZoomAndPan, LangSpace native "SVGSVGElement" {
5617 factory SvgSvgElement() => _SvgSvgElementFactoryProvider.createSvgSvgElement() ; 5626 factory SvgSvgElement() {
5618 5627 final el = new SvgElement.tag("svg");
5628 // The SVG spec requires the version attribute to match the spec version
5629 el.attributes['version'] = "1.1";
5630 return el;
5631 }
5619 5632
5620 @DomName('SVGSVGElement.contentScriptType') 5633 @DomName('SVGSVGElement.contentScriptType')
5621 @DocsEditable 5634 @DocsEditable
5622 String contentScriptType; 5635 String contentScriptType;
5623 5636
5624 @DomName('SVGSVGElement.contentStyleType') 5637 @DomName('SVGSVGElement.contentStyleType')
5625 @DocsEditable 5638 @DocsEditable
5626 String contentStyleType; 5639 String contentStyleType;
5627 5640
5628 @DomName('SVGSVGElement.currentScale') 5641 @DomName('SVGSVGElement.currentScale')
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after
7116 7129
7117 @DocsEditable 7130 @DocsEditable
7118 @DomName('SVGVKernElement') 7131 @DomName('SVGVKernElement')
7119 @Unstable 7132 @Unstable
7120 abstract class _SVGVKernElement extends SvgElement native "SVGVKernElement" { 7133 abstract class _SVGVKernElement extends SvgElement native "SVGVKernElement" {
7121 7134
7122 @DomName('SVGVKernElement.SVGVKernElement') 7135 @DomName('SVGVKernElement.SVGVKernElement')
7123 @DocsEditable 7136 @DocsEditable
7124 factory _SVGVKernElement() => _SvgElementFactoryProvider.createSvgElement_tag( "vkern"); 7137 factory _SVGVKernElement() => _SvgElementFactoryProvider.createSvgElement_tag( "vkern");
7125 } 7138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698