| OLD | NEW |
| 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); |
| 11 | 11 |
| 12 void addAll(Map<String, String> other) { | 12 void addAll(Map<String, String> other) { |
| 13 other.forEach((k, v) { this[k] = v; }); | 13 other.forEach((k, v) { |
| 14 this[k] = v; |
| 15 }); |
| 14 } | 16 } |
| 15 | 17 |
| 16 bool containsValue(Object value) { | 18 bool containsValue(Object value) { |
| 17 for (var v in this.values) { | 19 for (var v in this.values) { |
| 18 if (value == v) { | 20 if (value == v) { |
| 19 return true; | 21 return true; |
| 20 } | 22 } |
| 21 } | 23 } |
| 22 return false; | 24 return false; |
| 23 } | 25 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 /** | 85 /** |
| 84 * Checks to see if the node should be included in this map. | 86 * Checks to see if the node should be included in this map. |
| 85 */ | 87 */ |
| 86 bool _matches(Node node); | 88 bool _matches(Node node); |
| 87 } | 89 } |
| 88 | 90 |
| 89 /** | 91 /** |
| 90 * Wrapper to expose [Element.attributes] as a typed map. | 92 * Wrapper to expose [Element.attributes] as a typed map. |
| 91 */ | 93 */ |
| 92 class _ElementAttributeMap extends _AttributeMap { | 94 class _ElementAttributeMap extends _AttributeMap { |
| 93 | 95 _ElementAttributeMap(Element element) : super(element); |
| 94 _ElementAttributeMap(Element element): super(element); | |
| 95 | 96 |
| 96 bool containsKey(Object key) { | 97 bool containsKey(Object key) { |
| 97 return _element._hasAttribute(key); | 98 return _element._hasAttribute(key); |
| 98 } | 99 } |
| 99 | 100 |
| 100 String operator [](Object key) { | 101 String operator [](Object key) { |
| 101 return _element.getAttribute(key); | 102 return _element.getAttribute(key); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void operator []=(String key, String value) { | 105 void operator []=(String key, String value) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 return keys.length; | 119 return keys.length; |
| 119 } | 120 } |
| 120 | 121 |
| 121 bool _matches(Node node) => node._namespaceUri == null; | 122 bool _matches(Node node) => node._namespaceUri == null; |
| 122 } | 123 } |
| 123 | 124 |
| 124 /** | 125 /** |
| 125 * Wrapper to expose namespaced attributes as a typed map. | 126 * Wrapper to expose namespaced attributes as a typed map. |
| 126 */ | 127 */ |
| 127 class _NamespacedAttributeMap extends _AttributeMap { | 128 class _NamespacedAttributeMap extends _AttributeMap { |
| 128 | |
| 129 final String _namespace; | 129 final String _namespace; |
| 130 | 130 |
| 131 _NamespacedAttributeMap(Element element, this._namespace): super(element); | 131 _NamespacedAttributeMap(Element element, this._namespace) : super(element); |
| 132 | 132 |
| 133 bool containsKey(Object key) { | 133 bool containsKey(Object key) { |
| 134 return _element._hasAttributeNS(_namespace, key); | 134 return _element._hasAttributeNS(_namespace, key); |
| 135 } | 135 } |
| 136 | 136 |
| 137 String operator [](Object key) { | 137 String operator [](Object key) { |
| 138 return _element.getAttributeNS(_namespace, key); | 138 return _element.getAttributeNS(_namespace, key); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void operator []=(String key, String value) { | 141 void operator []=(String key, String value) { |
| 142 _element.setAttributeNS(_namespace, key, value); | 142 _element.setAttributeNS(_namespace, key, value); |
| 143 } | 143 } |
| 144 | 144 |
| 145 String remove(Object key) { | 145 String remove(Object key) { |
| 146 String value = this[key]; | 146 String value = this[key]; |
| 147 _element._removeAttributeNS(_namespace, key); | 147 _element._removeAttributeNS(_namespace, key); |
| 148 return value; | 148 return value; |
| 149 } | 149 } |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * The number of {key, value} pairs in the map. | 152 * The number of {key, value} pairs in the map. |
| 153 */ | 153 */ |
| 154 int get length { | 154 int get length { |
| 155 return keys.length; | 155 return keys.length; |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool _matches(Node node) => node._namespaceUri == _namespace; | 158 bool _matches(Node node) => node._namespaceUri == _namespace; |
| 159 } | 159 } |
| 160 | 160 |
| 161 | |
| 162 /** | 161 /** |
| 163 * Provides a Map abstraction on top of data-* attributes, similar to the | 162 * Provides a Map abstraction on top of data-* attributes, similar to the |
| 164 * dataSet in the old DOM. | 163 * dataSet in the old DOM. |
| 165 */ | 164 */ |
| 166 class _DataAttributeMap implements Map<String, String> { | 165 class _DataAttributeMap implements Map<String, String> { |
| 167 | |
| 168 final Map<String, String> _attributes; | 166 final Map<String, String> _attributes; |
| 169 | 167 |
| 170 _DataAttributeMap(this._attributes); | 168 _DataAttributeMap(this._attributes); |
| 171 | 169 |
| 172 // interface Map | 170 // interface Map |
| 173 | 171 |
| 174 void addAll(Map<String, String> other) { | 172 void addAll(Map<String, String> other) { |
| 175 other.forEach((k, v) { this[k] = v; }); | 173 other.forEach((k, v) { |
| 174 this[k] = v; |
| 175 }); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // TODO: Use lazy iterator when it is available on Map. | 178 // TODO: Use lazy iterator when it is available on Map. |
| 179 bool containsValue(Object value) => values.any((v) => v == value); | 179 bool containsValue(Object value) => values.any((v) => v == value); |
| 180 | 180 |
| 181 bool containsKey(Object key) => _attributes.containsKey(_attr(key)); | 181 bool containsKey(Object key) => _attributes.containsKey(_attr(key)); |
| 182 | 182 |
| 183 String operator [](Object key) => _attributes[_attr(key)]; | 183 String operator [](Object key) => _attributes[_attr(key)]; |
| 184 | 184 |
| 185 void operator []=(String key, String value) { | 185 void operator []=(String key, String value) { |
| 186 _attributes[_attr(key)] = value; | 186 _attributes[_attr(key)] = value; |
| 187 } | 187 } |
| 188 | 188 |
| 189 String putIfAbsent(String key, String ifAbsent()) => | 189 String putIfAbsent(String key, String ifAbsent()) => |
| 190 _attributes.putIfAbsent(_attr(key), ifAbsent); | 190 _attributes.putIfAbsent(_attr(key), ifAbsent); |
| 191 | 191 |
| 192 String remove(Object key) => _attributes.remove(_attr(key)); | 192 String remove(Object key) => _attributes.remove(_attr(key)); |
| 193 | 193 |
| 194 void clear() { | 194 void clear() { |
| 195 // Needs to operate on a snapshot since we are mutating the collection. | 195 // Needs to operate on a snapshot since we are mutating the collection. |
| 196 for (String key in keys) { | 196 for (String key in keys) { |
| 197 remove(key); | 197 remove(key); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 String _toHyphenedName(String word) { | 260 String _toHyphenedName(String word) { |
| 261 var sb = new StringBuffer(); | 261 var sb = new StringBuffer(); |
| 262 for (int i = 0; i < word.length; i++) { | 262 for (int i = 0; i < word.length; i++) { |
| 263 var lower = word[i].toLowerCase(); | 263 var lower = word[i].toLowerCase(); |
| 264 if (word[i] != lower && i > 0) sb.write('-'); | 264 if (word[i] != lower && i > 0) sb.write('-'); |
| 265 sb.write(lower); | 265 sb.write(lower); |
| 266 } | 266 } |
| 267 return sb.toString(); | 267 return sb.toString(); |
| 268 } | 268 } |
| 269 } | 269 } |
| OLD | NEW |