| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 svg; | 5 part of svg; |
| 6 | 6 |
| 7 final _START_TAG_REGEXP = new RegExp('<(\\w+)'); | 7 final _START_TAG_REGEXP = new RegExp('<(\\w+)'); |
| 8 | 8 |
| 9 class _SvgElementFactoryProvider { | 9 class _SvgElementFactoryProvider { |
| 10 static SvgElement createSvgElement_tag(String tag) { | 10 static SvgElement createSvgElement_tag(String tag) { |
| 11 final Element temp = | 11 final Element temp = |
| 12 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag); | 12 document.$dom_createElementNS("http://www.w3.org/2000/svg", tag); |
| 13 return temp; | 13 return temp; |
| 14 } | 14 } |
| 15 | 15 |
| 16 static SvgElement createSvgElement_svg(String svg) { | 16 static SvgElement createSvgElement_svg(String svg) { |
| 17 Element parentTag; | 17 Element parentTag; |
| 18 final match = _START_TAG_REGEXP.firstMatch(svg); | 18 final match = _START_TAG_REGEXP.firstMatch(svg); |
| 19 if (match != null && match.group(1).toLowerCase() == 'svg') { | 19 if (match != null && match.group(1).toLowerCase() == 'svg') { |
| 20 parentTag = new Element.tag('div'); | 20 parentTag = new Element.tag('div'); |
| 21 } else { | 21 } else { |
| 22 parentTag = new SvgSvgElement(); | 22 parentTag = new SvgSvgElement(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 parentTag.innerHtml = svg; | 25 parentTag.innerHtml = svg; |
| 26 if (parentTag.elements.length == 1) return parentTag.elements.removeLast(); | 26 if (parentTag.children.length == 1) return parentTag.children.removeLast(); |
| 27 | 27 |
| 28 throw new ArgumentError( | 28 throw new ArgumentError( |
| 29 'SVG had ${parentTag.elements.length} ' | 29 'SVG had ${parentTag.children.length} ' |
| 30 'top-level elements but 1 expected'); | 30 'top-level children but 1 expected'); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 class _SvgSvgElementFactoryProvider { | 34 class _SvgSvgElementFactoryProvider { |
| 35 static SvgSvgElement createSvgSvgElement() { | 35 static SvgSvgElement createSvgSvgElement() { |
| 36 final el = new SvgElement.tag("svg"); | 36 final el = new SvgElement.tag("svg"); |
| 37 // The SVG spec requires the version attribute to match the spec version | 37 // The SVG spec requires the version attribute to match the spec version |
| 38 el.attributes['version'] = "1.1"; | 38 el.attributes['version'] = "1.1"; |
| 39 return el; | 39 return el; |
| 40 } | 40 } |
| 41 } | 41 } |
| OLD | NEW |