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

Unified Diff: sdk/lib/html/src/CssClassSet.dart

Issue 11398002: Splitting SVG types out of dart:html. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minifying. Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/scripts/systemnative.py ('k') | sdk/lib/html/src/FilteredElementList.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/src/CssClassSet.dart
diff --git a/sdk/lib/html/src/CssClassSet.dart b/sdk/lib/html/src/CssClassSet.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0add4f733498d28c65a7a38d6720ef53052fe639
--- /dev/null
+++ b/sdk/lib/html/src/CssClassSet.dart
@@ -0,0 +1,123 @@
+// Copyright (c) 2012, 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.
+
+abstract class CssClassSet implements Set<String> {
+
+ String toString() {
+ return Strings.join(new List.from(readClasses()), ' ');
+ }
+
+ /**
+ * 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 = readClasses();
+ bool result = false;
+ if (s.contains(value)) {
+ s.remove(value);
+ } else {
+ s.add(value);
+ result = true;
+ }
+ writeClasses(s);
+ return result;
+ }
+
+ /**
+ * Returns [:true:] if classes cannot be added or removed from this
+ * [:CssClassSet:].
+ */
+ bool get frozen => false;
+
+ // interface Iterable - BEGIN
+ Iterator<String> iterator() => readClasses().iterator();
+ // interface Iterable - END
+
+ // interface Collection - BEGIN
+ void forEach(void f(String element)) {
+ readClasses().forEach(f);
+ }
+
+ Collection map(f(String element)) => readClasses().map(f);
+
+ Collection<String> filter(bool f(String element)) => readClasses().filter(f);
+
+ bool every(bool f(String element)) => readClasses().every(f);
+
+ bool some(bool f(String element)) => readClasses().some(f);
+
+ bool get isEmpty => readClasses().isEmpty;
+
+ int get length =>readClasses().length;
+ // interface Collection - END
+
+ // interface Set - BEGIN
+ bool contains(String value) => readClasses().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 = readClasses();
+ bool result = s.remove(value);
+ writeClasses(s);
+ return result;
+ }
+
+ void addAll(Collection<String> collection) {
+ // TODO - see comment above about validation
+ _modify((s) => s.addAll(collection));
+ }
+
+ void removeAll(Collection<String> collection) {
+ _modify((s) => s.removeAll(collection));
+ }
+
+ bool isSubsetOf(Collection<String> collection) =>
+ readClasses().isSubsetOf(collection);
+
+ bool containsAll(Collection<String> collection) =>
+ readClasses().containsAll(collection);
+
+ Set<String> intersection(Collection<String> other) =>
+ readClasses().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 = readClasses();
+ f(s);
+ writeClasses(s);
+ }
+
+ /**
+ * Read the class names from the Element class property,
+ * and put them into a set (duplicates are discarded).
+ * This is intended to be overridden by specific implementations.
+ */
+ Set<String> readClasses();
+
+ /**
+ * Join all the elements of a set into one string and write
+ * back to the element.
+ * This is intended to be overridden by specific implementations.
+ */
+ void writeClasses(Set<String> s);
+}
« no previous file with comments | « sdk/lib/html/scripts/systemnative.py ('k') | sdk/lib/html/src/FilteredElementList.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698