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

Unified Diff: pkg/third_party/html5lib/lib/src/css_class_set.dart

Issue 268623002: [html5lib] implement querySelector/querySelectorAll (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months 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
Index: pkg/third_party/html5lib/lib/src/css_class_set.dart
diff --git a/sdk/lib/html/html_common/css_class_set.dart b/pkg/third_party/html5lib/lib/src/css_class_set.dart
similarity index 69%
copy from sdk/lib/html/html_common/css_class_set.dart
copy to pkg/third_party/html5lib/lib/src/css_class_set.dart
index a81497e401f08207a316f332de3962bba0dc4049..03136a7877f139a3a6da0b88cef1f32905ab7447 100644
--- a/sdk/lib/html/html_common/css_class_set.dart
+++ b/pkg/third_party/html5lib/lib/src/css_class_set.dart
@@ -1,8 +1,115 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2014, 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 html_common;
+// TODO(jmesserly): everything in this file is copied straight from "dart:html".
+library html5lib.dom.src;
+
+import 'dart:collection';
+import 'package:html5lib/dom.dart';
+
+class ElementCssClassSet extends CssClassSetImpl {
+
+ final Element _element;
+
+ ElementCssClassSet(this._element);
+
+ Set<String> readClasses() {
+ var s = new LinkedHashSet<String>();
+ var classname = _element.className;
+
+ for (String name in classname.split(' ')) {
+ String trimmed = name.trim();
+ if (!trimmed.isEmpty) {
+ s.add(trimmed);
+ }
+ }
+ return s;
+ }
+
+ void writeClasses(Set<String> s) {
+ List list = new List.from(s);
+ _element.className = s.join(' ');
+ }
+}
+
+
+/** A Set that stores the CSS class names for an element. */
+abstract class CssClassSet implements Set<String> {
+
+ /**
+ * Adds the class [value] to the element if it is not on it, removes it if it
+ * is.
+ *
+ * If [shouldAdd] is true, then we always add that [value] to the element. If
+ * [shouldAdd] is false then we always remove [value] from the element.
+ */
+ bool toggle(String value, [bool shouldAdd]);
+
+ /**
+ * Returns [:true:] if classes cannot be added or removed from this
+ * [:CssClassSet:].
+ */
+ bool get frozen;
+
+ /**
+ * Determine if this element contains the class [value].
+ *
+ * This is the Dart equivalent of jQuery's
+ * [hasClass](http://api.jquery.com/hasClass/).
+ */
+ bool contains(String value);
+
+ /**
+ * Add the class [value] to element.
+ *
+ * This is the Dart equivalent of jQuery's
+ * [addClass](http://api.jquery.com/addClass/).
+ *
+ * If this corresponds to one element. Returns true if [value] was added to
+ * the set, otherwise false.
+ *
+ * If this corresponds to many elements, null is always returned.
+ */
+ bool add(String value);
+
+ /**
+ * Remove the class [value] from element, and return true on successful
+ * removal.
+ *
+ * This is the Dart equivalent of jQuery's
+ * [removeClass](http://api.jquery.com/removeClass/).
+ */
+ bool remove(Object value);
+
+ /**
+ * Add all classes specified in [iterable] to element.
+ *
+ * This is the Dart equivalent of jQuery's
+ * [addClass](http://api.jquery.com/addClass/).
+ */
+ void addAll(Iterable<String> iterable);
+
+ /**
+ * Remove all classes specified in [iterable] from element.
+ *
+ * This is the Dart equivalent of jQuery's
+ * [removeClass](http://api.jquery.com/removeClass/).
+ */
+ void removeAll(Iterable<String> iterable);
+
+ /**
+ * Toggles all classes specified in [iterable] on element.
+ *
+ * Iterate through [iterable]'s items, and add it if it is not on it, or
+ * remove it if it is. This is the Dart equivalent of jQuery's
+ * [toggleClass](http://api.jquery.com/toggleClass/).
+ * If [shouldAdd] is true, then we always add all the classes in [iterable]
+ * element. If [shouldAdd] is false then we always remove all the classes in
+ * [iterable] from the element.
+ */
+ void toggleAll(Iterable<String> iterable, [bool shouldAdd]);
+}
abstract class CssClassSetImpl implements CssClassSet {
« no previous file with comments | « pkg/third_party/html5lib/lib/src/constants.dart ('k') | pkg/third_party/html5lib/lib/src/query_selector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698