| Index: sdk/lib/html/templates/html/impl/impl_Element.darttemplate
|
| diff --git a/sdk/lib/html/templates/html/impl/impl_Element.darttemplate b/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
|
| index a223a5dda4e2270169be859e13df60c0197cd096..b164569a532c96a1ffbd1074435efd0a22f2f97b 100644
|
| --- a/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
|
| +++ b/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
|
| @@ -472,136 +472,17 @@ class _DataAttributeMap extends AttributeMap {
|
| String _strip(String key) => key.substring(5);
|
| }
|
|
|
| -abstract class CssClassSet implements Set<String> {
|
| - /**
|
| - * Adds the class [token] to the element if it is not on it, removes it if it
|
| - * is.
|
| - */
|
| - bool toggle(String token);
|
| -
|
| - /**
|
| - * Returns [:true:] if classes cannot be added or removed from this
|
| - * [:CssClassSet:].
|
| - */
|
| - bool get frozen;
|
| -}
|
| -
|
| -class _CssClassSet extends CssClassSet {
|
| +class _ElementCssClassSet extends CssClassSet {
|
|
|
| final Element _element;
|
|
|
| - _CssClassSet(this._element);
|
| -
|
| - String toString() => _formatSet(_read());
|
| -
|
| - // interface Iterable - BEGIN
|
| - Iterator<String> iterator() => _read().iterator();
|
| - // interface Iterable - END
|
| -
|
| - // interface Collection - BEGIN
|
| - void forEach(void f(String element)) {
|
| - _read().forEach(f);
|
| - }
|
| -
|
| - Collection map(f(String element)) => _read().map(f);
|
| -
|
| - Collection<String> filter(bool f(String element)) => _read().filter(f);
|
| -
|
| - bool every(bool f(String element)) => _read().every(f);
|
| -
|
| - bool some(bool f(String element)) => _read().some(f);
|
| -
|
| - bool get isEmpty => _read().isEmpty;
|
| -
|
| - /**
|
| - * Returns [:true:] if classes cannot be added or removed from this
|
| - * [:CssClassSet:].
|
| - */
|
| - bool get frozen => false;
|
| -
|
| - int get length =>_read().length;
|
| -
|
| - // interface Collection - END
|
| -
|
| - // interface Set - BEGIN
|
| - bool contains(String value) => _read().contains(value);
|
| -
|
| - void add(String value) {
|
| - // TODO - figure out if we need to do any validation here
|
| - // or if the browser natively does enough
|
| - _modify((s) => s.add(value));
|
| - }
|
| -
|
| - bool remove(String value) {
|
| - Set<String> s = _read();
|
| - bool result = s.remove(value);
|
| - _write(s);
|
| - return result;
|
| - }
|
| -
|
| - /**
|
| - * Adds the class [token] to the element if it is not on it, removes it if it
|
| - * is.
|
| - */
|
| - bool toggle(String value) {
|
| - Set<String> s = _read();
|
| - bool result = false;
|
| - if (s.contains(value)) {
|
| - s.remove(value);
|
| - } else {
|
| - s.add(value);
|
| - result = true;
|
| - }
|
| - _write(s);
|
| - return result;
|
| - }
|
| -
|
| - void addAll(Collection<String> collection) {
|
| - // TODO - see comment above about validation
|
| - _modify((s) => s.addAll(collection));
|
| - }
|
| + _ElementCssClassSet(this._element);
|
|
|
| - void removeAll(Collection<String> collection) {
|
| - _modify((s) => s.removeAll(collection));
|
| - }
|
| + Set<String> readClasses() {
|
| + var s = new Set<String>();
|
| + var classname = _element.$dom_className;
|
|
|
| - bool isSubsetOf(Collection<String> collection) =>
|
| - _read().isSubsetOf(collection);
|
| -
|
| - bool containsAll(Collection<String> collection) =>
|
| - _read().containsAll(collection);
|
| -
|
| - Set<String> intersection(Collection<String> other) =>
|
| - _read().intersection(other);
|
| -
|
| - void clear() {
|
| - _modify((s) => s.clear());
|
| - }
|
| - // interface Set - END
|
| -
|
| - /**
|
| - * Helper method used to modify the set of css classes on this element.
|
| - *
|
| - * f - callback with:
|
| - * s - a Set of all the css class name currently on this element.
|
| - *
|
| - * After f returns, the modified set is written to the
|
| - * className property of this element.
|
| - */
|
| - void _modify( f(Set<String> s)) {
|
| - Set<String> s = _read();
|
| - f(s);
|
| - _write(s);
|
| - }
|
| -
|
| - /**
|
| - * Read the class names from the Element class property,
|
| - * and put them into a set (duplicates are discarded).
|
| - */
|
| - Set<String> _read() {
|
| - // TODO(mattsh) simplify this once split can take regex.
|
| - Set<String> s = new Set<String>();
|
| - for (String name in _classname().split(' ')) {
|
| + for (String name in classname.split(' ')) {
|
| String trimmed = name.trim();
|
| if (!trimmed.isEmpty) {
|
| s.add(trimmed);
|
| @@ -610,24 +491,9 @@ class _CssClassSet extends CssClassSet {
|
| return s;
|
| }
|
|
|
| - /**
|
| - * Read the class names as a space-separated string. This is meant to be
|
| - * overridden by subclasses.
|
| - */
|
| - String _classname() => _element.$dom_className;
|
| -
|
| - /**
|
| - * Join all the elements of a set into one string and write
|
| - * back to the element.
|
| - */
|
| - void _write(Set s) {
|
| - _element.$dom_className = _formatSet(s);
|
| - }
|
| -
|
| - String _formatSet(Set<String> s) {
|
| - // TODO(mattsh) should be able to pass Set to String.joins http:/b/5398605
|
| + void writeClasses(Set<String> s) {
|
| List list = new List.from(s);
|
| - return Strings.join(list, ' ');
|
| + _element.$dom_className = Strings.join(list, ' ');
|
| }
|
| }
|
|
|
| @@ -688,7 +554,7 @@ class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
|
| new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
|
|
|
| /** @domName className, classList */
|
| - CssClassSet get classes => new _CssClassSet(this);
|
| + CssClassSet get classes => new _ElementCssClassSet(this);
|
|
|
| void set classes(Collection<String> value) {
|
| CssClassSet classSet = classes;
|
|
|