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

Side by Side Diff: tools/dom/src/AttributeMap.dart

Issue 12549025: Narrowing attribute maps to only accept strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
« no previous file with comments | « tests/html/instance_of_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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; 5 part of html;
6 6
7 abstract class _AttributeMap implements Map<String, String> { 7 abstract class _AttributeMap implements Map<String, String> {
8 final Element _element; 8 final Element _element;
9 9
10 _AttributeMap(this._element); 10 _AttributeMap(this._element);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 _ElementAttributeMap(Element element): super(element); 83 _ElementAttributeMap(Element element): super(element);
84 84
85 bool containsKey(String key) { 85 bool containsKey(String key) {
86 return _element.$dom_hasAttribute(key); 86 return _element.$dom_hasAttribute(key);
87 } 87 }
88 88
89 String operator [](String key) { 89 String operator [](String key) {
90 return _element.$dom_getAttribute(key); 90 return _element.$dom_getAttribute(key);
91 } 91 }
92 92
93 void operator []=(String key, value) { 93 void operator []=(String key, String value) {
94 _element.$dom_setAttribute(key, '$value'); 94 _element.$dom_setAttribute(key, value);
95 } 95 }
96 96
97 String remove(String key) { 97 String remove(String key) {
98 String value = _element.$dom_getAttribute(key); 98 String value = _element.$dom_getAttribute(key);
99 _element.$dom_removeAttribute(key); 99 _element.$dom_removeAttribute(key);
100 return value; 100 return value;
101 } 101 }
102 102
103 /** 103 /**
104 * The number of {key, value} pairs in the map. 104 * The number of {key, value} pairs in the map.
(...skipping 15 matching lines...) Expand all
120 _NamespacedAttributeMap(Element element, this._namespace): super(element); 120 _NamespacedAttributeMap(Element element, this._namespace): super(element);
121 121
122 bool containsKey(String key) { 122 bool containsKey(String key) {
123 return _element.$dom_hasAttributeNS(_namespace, key); 123 return _element.$dom_hasAttributeNS(_namespace, key);
124 } 124 }
125 125
126 String operator [](String key) { 126 String operator [](String key) {
127 return _element.$dom_getAttributeNS(_namespace, key); 127 return _element.$dom_getAttributeNS(_namespace, key);
128 } 128 }
129 129
130 void operator []=(String key, value) { 130 void operator []=(String key, String value) {
131 _element.$dom_setAttributeNS(_namespace, key, '$value'); 131 _element.$dom_setAttributeNS(_namespace, key, value);
132 } 132 }
133 133
134 String remove(String key) { 134 String remove(String key) {
135 String value = this[key]; 135 String value = this[key];
136 _element.$dom_removeAttributeNS(_namespace, key); 136 _element.$dom_removeAttributeNS(_namespace, key);
137 return value; 137 return value;
138 } 138 }
139 139
140 /** 140 /**
141 * The number of {key, value} pairs in the map. 141 * The number of {key, value} pairs in the map.
(...skipping 18 matching lines...) Expand all
160 160
161 // interface Map 161 // interface Map
162 162
163 // TODO: Use lazy iterator when it is available on Map. 163 // TODO: Use lazy iterator when it is available on Map.
164 bool containsValue(String value) => values.any((v) => v == value); 164 bool containsValue(String value) => values.any((v) => v == value);
165 165
166 bool containsKey(String key) => $dom_attributes.containsKey(_attr(key)); 166 bool containsKey(String key) => $dom_attributes.containsKey(_attr(key));
167 167
168 String operator [](String key) => $dom_attributes[_attr(key)]; 168 String operator [](String key) => $dom_attributes[_attr(key)];
169 169
170 void operator []=(String key, value) { 170 void operator []=(String key, String value) {
171 $dom_attributes[_attr(key)] = '$value'; 171 $dom_attributes[_attr(key)] = value;
172 } 172 }
173 173
174 String putIfAbsent(String key, String ifAbsent()) => 174 String putIfAbsent(String key, String ifAbsent()) =>
175 $dom_attributes.putIfAbsent(_attr(key), ifAbsent); 175 $dom_attributes.putIfAbsent(_attr(key), ifAbsent);
176 176
177 String remove(String key) => $dom_attributes.remove(_attr(key)); 177 String remove(String key) => $dom_attributes.remove(_attr(key));
178 178
179 void clear() { 179 void clear() {
180 // Needs to operate on a snapshot since we are mutating the collection. 180 // Needs to operate on a snapshot since we are mutating the collection.
181 for (String key in keys) { 181 for (String key in keys) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 int get length => keys.length; 214 int get length => keys.length;
215 215
216 // TODO: Use lazy iterator when it is available on Map. 216 // TODO: Use lazy iterator when it is available on Map.
217 bool get isEmpty => length == 0; 217 bool get isEmpty => length == 0;
218 218
219 // Helpers. 219 // Helpers.
220 String _attr(String key) => 'data-$key'; 220 String _attr(String key) => 'data-$key';
221 bool _matches(String key) => key.startsWith('data-'); 221 bool _matches(String key) => key.startsWith('data-');
222 String _strip(String key) => key.substring(5); 222 String _strip(String key) => key.substring(5);
223 } 223 }
OLDNEW
« no previous file with comments | « tests/html/instance_of_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698