| Index: client/html/src/shared_FactoryProviders.dart
|
| diff --git a/client/html/src/shared_FactoryProviders.dart b/client/html/src/shared_FactoryProviders.dart
|
| index 7e13bfb10440002713c535bf158bdba37492b57a..90807d8150711b0723b86c142d84c6a244f559e1 100644
|
| --- a/client/html/src/shared_FactoryProviders.dart
|
| +++ b/client/html/src/shared_FactoryProviders.dart
|
| @@ -120,15 +120,44 @@ class _DocumentFragmentFactoryProvider {
|
| // return fragment;
|
| // }
|
|
|
| - // TODO(nweiz): enable this when SVG is ported.
|
| - // factory DocumentFragment.svg(String svg) {
|
| - // final fragment = new DocumentFragment();
|
| - // final e = new SVGSVGElement();
|
| - // e.innerHTML = svg;
|
| - //
|
| - // // Copy list first since we don't want liveness during iteration.
|
| - // final List nodes = new List.from(e.nodes);
|
| - // fragment.nodes.addAll(nodes);
|
| - // return fragment;
|
| - // }
|
| + factory DocumentFragment.svg(String svg) {
|
| + final fragment = new DocumentFragment();
|
| + final e = new SVGSVGElement();
|
| + e.innerHTML = svg;
|
| +
|
| + // Copy list first since we don't want liveness during iteration.
|
| + final List nodes = new List.from(e.nodes);
|
| + fragment.nodes.addAll(nodes);
|
| + return fragment;
|
| + }
|
| +}
|
| +
|
| +class _SVGElementFactoryProvider {
|
| + factory SVGElement.tag(String tag) =>
|
| + _document._createElementNS("http://www.w3.org/2000/svg", tag);
|
| +
|
| + factory SVGElement.svg(String svg) {
|
| + Element parentTag;
|
| + final match = _START_TAG_REGEXP.firstMatch(svg);
|
| + if (match != null && match.group(1).toLowerCase() == 'svg') {
|
| + parentTag = new Element.tag('div');
|
| + } else {
|
| + parentTag = new SVGSVGElement();
|
| + }
|
| +
|
| + parentTag.innerHTML = svg;
|
| + if (parentTag.elements.length == 1) return parentTag.nodes.removeLast();
|
| +
|
| + throw new IllegalArgumentException('SVG had ${parentTag.elements.length} ' +
|
| + 'top-level elements but 1 expected');
|
| + }
|
| +}
|
| +
|
| +class _SVGSVGElementFactoryProvider {
|
| + factory SVGSVGElement() {
|
| + final el = new SVGElement.tag("svg");
|
| + // The SVG spec requires the version attribute to match the spec version
|
| + el.attributes['version'] = "1.1";
|
| + return el;
|
| + }
|
| }
|
|
|