blob: c3ee68084aac18dabedd851d73f9c942eaff2ecf [file] [log] [blame]
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
class _AttributeClassSet extends CssClassSet {
final Element _element;
_AttributeClassSet(this._element);
Set<String> readClasses() {
var classname = _element.attributes['class'];
Set<String> s = new Set<String>();
if (classname == null) {
return s;
}
for (String name in classname.split(' ')) {
String trimmed = name.trim();
if (!trimmed.isEmpty) {
s.add(trimmed);
}
}
return s;
}
void writeClasses(Set s) {
List list = new List.from(s);
_element.attributes['class'] = Strings.join(list, ' ');
}
}
$(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
factory $CLASSNAME.tag(String tag) =>
_$(CLASSNAME)FactoryProvider.create$(CLASSNAME)_tag(tag);
factory $CLASSNAME.svg(String svg) =>
_$(CLASSNAME)FactoryProvider.create$(CLASSNAME)_svg(svg);
_AttributeClassSet _cssClassSet;
CssClassSet get classes {
if (_cssClassSet == null) {
_cssClassSet = new _AttributeClassSet(this);
}
return _cssClassSet;
}
List<Element> get children => new FilteredElementList(this);
void set children(List<Element> value) {
final children = this.children;
children.clear();
children.addAll(value);
}
String get outerHtml {
final container = new Element.tag("div");
final SvgElement cloned = this.clone(true);
container.children.add(cloned);
return container.innerHtml;
}
String get innerHtml {
final container = new Element.tag("div");
final SvgElement cloned = this.clone(true);
container.children.addAll(cloned.children);
return container.innerHtml;
}
void set innerHtml(String svg) {
final container = new Element.tag("div");
// Wrap the SVG string in <svg> so that SvgElements are created, rather than
// HTMLElements.
container.innerHtml = '<svg version="1.1">$svg</svg>';
this.children = container.children[0].children;
}
// Unsupported methods inherited from Element.
@DomName('Element.insertAdjacentText')
void insertAdjacentText(String where, String text) {
throw new UnsupportedError("Cannot invoke insertAdjacentText on SVG.");
}
@DomName('Element.insertAdjacentHTML')
void insertAdjacentHtml(String where, String text) {
throw new UnsupportedError("Cannot invoke insertAdjacentHtml on SVG.");
}
@DomName('Element.insertAdjacentHTML')
Element insertAdjacentElement(String where, Element element) {
throw new UnsupportedError("Cannot invoke insertAdjacentElement on SVG.");
}
HtmlCollection get $dom_children {
throw new UnsupportedError("Cannot get dom_children on SVG.");
}
bool get isContentEditable => false;
void click() {
throw new UnsupportedError("Cannot invoke click SVG.");
}
/**
* Checks to see if the SVG element type is supported by the current platform.
*
* The tag should be a valid SVG element tag name.
*/
static bool isTagSupported(String tag) {
var e = new $CLASSNAME.tag(tag);
return e is $CLASSNAME && !(e is UnknownElement);
}
$!MEMBERS
}