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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of html_common; 5 // TODO(jmesserly): everything in this file is copied straight from "dart:html".
6 library html5lib.dom.src;
7
8 import 'dart:collection';
9 import 'package:html5lib/dom.dart';
10
11 class ElementCssClassSet extends CssClassSetImpl {
12
13 final Element _element;
14
15 ElementCssClassSet(this._element);
16
17 Set<String> readClasses() {
18 var s = new LinkedHashSet<String>();
19 var classname = _element.className;
20
21 for (String name in classname.split(' ')) {
22 String trimmed = name.trim();
23 if (!trimmed.isEmpty) {
24 s.add(trimmed);
25 }
26 }
27 return s;
28 }
29
30 void writeClasses(Set<String> s) {
31 List list = new List.from(s);
32 _element.className = s.join(' ');
33 }
34 }
35
36
37 /** A Set that stores the CSS class names for an element. */
38 abstract class CssClassSet implements Set<String> {
39
40 /**
41 * Adds the class [value] to the element if it is not on it, removes it if it
42 * is.
43 *
44 * If [shouldAdd] is true, then we always add that [value] to the element. If
45 * [shouldAdd] is false then we always remove [value] from the element.
46 */
47 bool toggle(String value, [bool shouldAdd]);
48
49 /**
50 * Returns [:true:] if classes cannot be added or removed from this
51 * [:CssClassSet:].
52 */
53 bool get frozen;
54
55 /**
56 * Determine if this element contains the class [value].
57 *
58 * This is the Dart equivalent of jQuery's
59 * [hasClass](http://api.jquery.com/hasClass/).
60 */
61 bool contains(String value);
62
63 /**
64 * Add the class [value] to element.
65 *
66 * This is the Dart equivalent of jQuery's
67 * [addClass](http://api.jquery.com/addClass/).
68 *
69 * If this corresponds to one element. Returns true if [value] was added to
70 * the set, otherwise false.
71 *
72 * If this corresponds to many elements, null is always returned.
73 */
74 bool add(String value);
75
76 /**
77 * Remove the class [value] from element, and return true on successful
78 * removal.
79 *
80 * This is the Dart equivalent of jQuery's
81 * [removeClass](http://api.jquery.com/removeClass/).
82 */
83 bool remove(Object value);
84
85 /**
86 * Add all classes specified in [iterable] to element.
87 *
88 * This is the Dart equivalent of jQuery's
89 * [addClass](http://api.jquery.com/addClass/).
90 */
91 void addAll(Iterable<String> iterable);
92
93 /**
94 * Remove all classes specified in [iterable] from element.
95 *
96 * This is the Dart equivalent of jQuery's
97 * [removeClass](http://api.jquery.com/removeClass/).
98 */
99 void removeAll(Iterable<String> iterable);
100
101 /**
102 * Toggles all classes specified in [iterable] on element.
103 *
104 * Iterate through [iterable]'s items, and add it if it is not on it, or
105 * remove it if it is. This is the Dart equivalent of jQuery's
106 * [toggleClass](http://api.jquery.com/toggleClass/).
107 * If [shouldAdd] is true, then we always add all the classes in [iterable]
108 * element. If [shouldAdd] is false then we always remove all the classes in
109 * [iterable] from the element.
110 */
111 void toggleAll(Iterable<String> iterable, [bool shouldAdd]);
112 }
6 113
7 abstract class CssClassSetImpl implements CssClassSet { 114 abstract class CssClassSetImpl implements CssClassSet {
8 115
9 String toString() { 116 String toString() {
10 return readClasses().join(' '); 117 return readClasses().join(' ');
11 } 118 }
12 119
13 /** 120 /**
14 * Adds the class [value] to the element if it is not on it, removes it if it 121 * Adds the class [value] to the element if it is not on it, removes it if it
15 * is. 122 * is.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 */ 327 */
221 Set<String> readClasses(); 328 Set<String> readClasses();
222 329
223 /** 330 /**
224 * Join all the elements of a set into one string and write 331 * Join all the elements of a set into one string and write
225 * back to the element. 332 * back to the element.
226 * This is intended to be overridden by specific implementations. 333 * This is intended to be overridden by specific implementations.
227 */ 334 */
228 void writeClasses(Set<String> s); 335 void writeClasses(Set<String> s);
229 } 336 }
OLDNEW
« 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