| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class FilteredElementList implements ElementList { | 5 class FilteredElementList implements ElementList { |
| 6 final Node _node; | 6 final Node _node; |
| 7 final NodeList _childNodes; | 7 final NodeList _childNodes; |
| 8 | 8 |
| 9 FilteredElementList(Node node): _childNodes = node.nodes, _node = node; | 9 FilteredElementList(Node node): _childNodes = node.nodes, _node = node; |
| 10 | 10 |
| 11 // We can't memoize this, since it's possible that children will be messed | 11 // We can't memoize this, since it's possible that children will be messed |
| 12 // with externally to this class. | 12 // with externally to this class. |
| 13 // | 13 // |
| 14 // TODO(nweiz): Do we really need to copy the list to make the types work out? | 14 // TODO(nweiz): Do we really need to copy the list to make the types work out? |
| 15 List<Element> get _filtered => | 15 List<Element> get _filtered() => |
| 16 new List.from(_childNodes.filter((n) => n is Element)); | 16 new List.from(_childNodes.filter((n) => n is Element)); |
| 17 | 17 |
| 18 // Don't use _filtered.first so we can short-circuit once we find an element. | 18 // Don't use _filtered.first so we can short-circuit once we find an element. |
| 19 Element get first { | 19 Element get first() { |
| 20 for (final node in _childNodes) { | 20 for (final node in _childNodes) { |
| 21 if (node is Element) { | 21 if (node is Element) { |
| 22 return node; | 22 return node; |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 return null; | 25 return null; |
| 26 } | 26 } |
| 27 | 27 |
| 28 void forEach(void f(Element element)) { | 28 void forEach(void f(Element element)) { |
| 29 _filtered.forEach(f); | 29 _filtered.forEach(f); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 result.remove(); | 84 result.remove(); |
| 85 } | 85 } |
| 86 return result; | 86 return result; |
| 87 } | 87 } |
| 88 | 88 |
| 89 Collection map(f(Element element)) => _filtered.map(f); | 89 Collection map(f(Element element)) => _filtered.map(f); |
| 90 Collection<Element> filter(bool f(Element element)) => _filtered.filter(f); | 90 Collection<Element> filter(bool f(Element element)) => _filtered.filter(f); |
| 91 bool every(bool f(Element element)) => _filtered.every(f); | 91 bool every(bool f(Element element)) => _filtered.every(f); |
| 92 bool some(bool f(Element element)) => _filtered.some(f); | 92 bool some(bool f(Element element)) => _filtered.some(f); |
| 93 bool isEmpty() => _filtered.isEmpty(); | 93 bool isEmpty() => _filtered.isEmpty(); |
| 94 int get length => _filtered.length; | 94 int get length() => _filtered.length; |
| 95 Element operator [](int index) => _filtered[index]; | 95 Element operator [](int index) => _filtered[index]; |
| 96 Iterator<Element> iterator() => _filtered.iterator(); | 96 Iterator<Element> iterator() => _filtered.iterator(); |
| 97 List<Element> getRange(int start, int rangeLength) => | 97 List<Element> getRange(int start, int rangeLength) => |
| 98 _filtered.getRange(start, rangeLength); | 98 _filtered.getRange(start, rangeLength); |
| 99 int indexOf(Element element, [int start = 0]) => | 99 int indexOf(Element element, [int start = 0]) => |
| 100 _filtered.indexOf(element, start); | 100 _filtered.indexOf(element, start); |
| 101 | 101 |
| 102 int lastIndexOf(Element element, [int start = null]) { | 102 int lastIndexOf(Element element, [int start = null]) { |
| 103 if (start === null) start = length - 1; | 103 if (start === null) start = length - 1; |
| 104 return _filtered.lastIndexOf(element, start); | 104 return _filtered.lastIndexOf(element, start); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 124 | 124 |
| 125 class _FrozenCSSClassSet extends _CssClassSet { | 125 class _FrozenCSSClassSet extends _CssClassSet { |
| 126 _FrozenCSSClassSet() : super(null); | 126 _FrozenCSSClassSet() : super(null); |
| 127 | 127 |
| 128 void _write(Set s) { | 128 void _write(Set s) { |
| 129 throw const UnsupportedOperationException( | 129 throw const UnsupportedOperationException( |
| 130 'frozen class set cannot be modified'); | 130 'frozen class set cannot be modified'); |
| 131 } | 131 } |
| 132 Set<String> _read() => new Set<String>(); | 132 Set<String> _read() => new Set<String>(); |
| 133 | 133 |
| 134 bool get isFrozen => true; | 134 bool get isFrozen() => true; |
| 135 } | 135 } |
| 136 | 136 |
| 137 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 137 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 138 ElementList _elements; | 138 ElementList _elements; |
| 139 | 139 |
| 140 ElementList get elements { | 140 ElementList get elements() { |
| 141 if (_elements == null) { | 141 if (_elements == null) { |
| 142 _elements = new FilteredElementList(this); | 142 _elements = new FilteredElementList(this); |
| 143 } | 143 } |
| 144 return _elements; | 144 return _elements; |
| 145 } | 145 } |
| 146 | 146 |
| 147 // TODO: The type of value should be Collection<Element>. See http://b/5392897 | 147 // TODO: The type of value should be Collection<Element>. See http://b/5392897 |
| 148 void set elements(value) { | 148 void set elements(value) { |
| 149 // Copy list first since we don't want liveness during iteration. | 149 // Copy list first since we don't want liveness during iteration. |
| 150 List copy = new List.from(value); | 150 List copy = new List.from(value); |
| 151 final elements = this.elements; | 151 final elements = this.elements; |
| 152 elements.clear(); | 152 elements.clear(); |
| 153 elements.addAll(copy); | 153 elements.addAll(copy); |
| 154 } | 154 } |
| 155 | 155 |
| 156 _ElementImpl query(String selectors) => $dom_querySelector(selectors); | 156 _ElementImpl query(String selectors) => $dom_querySelector(selectors); |
| 157 | 157 |
| 158 List<Element> queryAll(String selectors) => | 158 List<Element> queryAll(String selectors) => |
| 159 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); | 159 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); |
| 160 | 160 |
| 161 String get innerHTML { | 161 String get innerHTML() { |
| 162 final e = new Element.tag("div"); | 162 final e = new Element.tag("div"); |
| 163 e.nodes.add(this.clone(true)); | 163 e.nodes.add(this.clone(true)); |
| 164 return e.innerHTML; | 164 return e.innerHTML; |
| 165 } | 165 } |
| 166 | 166 |
| 167 String get outerHTML => innerHTML; | 167 String get outerHTML() => innerHTML; |
| 168 | 168 |
| 169 // TODO(nweiz): Do we want to support some variant of innerHTML for XML and/or | 169 // TODO(nweiz): Do we want to support some variant of innerHTML for XML and/or |
| 170 // SVG strings? | 170 // SVG strings? |
| 171 void set innerHTML(String value) { | 171 void set innerHTML(String value) { |
| 172 this.nodes.clear(); | 172 this.nodes.clear(); |
| 173 | 173 |
| 174 final e = new Element.tag("div"); | 174 final e = new Element.tag("div"); |
| 175 e.innerHTML = value; | 175 e.innerHTML = value; |
| 176 | 176 |
| 177 // Copy list first since we don't want liveness during iteration. | 177 // Copy list first since we don't want liveness during iteration. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 void addText(String text) { | 208 void addText(String text) { |
| 209 this.insertAdjacentText('beforeend', text); | 209 this.insertAdjacentText('beforeend', text); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void addHTML(String text) { | 212 void addHTML(String text) { |
| 213 this.insertAdjacentHTML('beforeend', text); | 213 this.insertAdjacentHTML('beforeend', text); |
| 214 } | 214 } |
| 215 | 215 |
| 216 Future<ElementRect> get rect { | 216 Future<ElementRect> get rect() { |
| 217 return _createMeasurementFuture(() => const EmptyElementRect(), | 217 return _createMeasurementFuture(() => const EmptyElementRect(), |
| 218 new Completer<ElementRect>()); | 218 new Completer<ElementRect>()); |
| 219 } | 219 } |
| 220 | 220 |
| 221 // If we can come up with a semi-reasonable default value for an Element | 221 // If we can come up with a semi-reasonable default value for an Element |
| 222 // getter, we'll use it. In general, these return the same values as an | 222 // getter, we'll use it. In general, these return the same values as an |
| 223 // element that has no parent. | 223 // element that has no parent. |
| 224 String get contentEditable => "false"; | 224 String get contentEditable() => "false"; |
| 225 bool get isContentEditable => false; | 225 bool get isContentEditable() => false; |
| 226 bool get draggable => false; | 226 bool get draggable() => false; |
| 227 bool get hidden => false; | 227 bool get hidden() => false; |
| 228 bool get spellcheck => false; | 228 bool get spellcheck() => false; |
| 229 bool get translate => false; | 229 bool get translate() => false; |
| 230 int get tabIndex => -1; | 230 int get tabIndex() => -1; |
| 231 String get id => ""; | 231 String get id() => ""; |
| 232 String get title => ""; | 232 String get title() => ""; |
| 233 String get tagName => ""; | 233 String get tagName() => ""; |
| 234 String get webkitdropzone => ""; | 234 String get webkitdropzone() => ""; |
| 235 String get webkitRegionOverflow => ""; | 235 String get webkitRegionOverflow() => ""; |
| 236 Element get $dom_firstElementChild() => elements.first(); | 236 Element get $dom_firstElementChild() => elements.first(); |
| 237 Element get $dom_lastElementChild() => elements.last(); | 237 Element get $dom_lastElementChild() => elements.last(); |
| 238 Element get nextElementSibling => null; | 238 Element get nextElementSibling() => null; |
| 239 Element get previousElementSibling => null; | 239 Element get previousElementSibling() => null; |
| 240 Element get offsetParent => null; | 240 Element get offsetParent() => null; |
| 241 Element get parent => null; | 241 Element get parent() => null; |
| 242 Map<String, String> get attributes => const {}; | 242 Map<String, String> get attributes() => const {}; |
| 243 CSSClassSet get classes => new _FrozenCSSClassSet(); | 243 CSSClassSet get classes() => new _FrozenCSSClassSet(); |
| 244 Map<String, String> get dataAttributes => const {}; | 244 Map<String, String> get dataAttributes() => const {}; |
| 245 CSSStyleDeclaration get style => new Element.tag('div').style; | 245 CSSStyleDeclaration get style() => new Element.tag('div').style; |
| 246 Future<CSSStyleDeclaration> get computedStyle => | 246 Future<CSSStyleDeclaration> get computedStyle() => |
| 247 _emptyStyleFuture(); | 247 _emptyStyleFuture(); |
| 248 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) => | 248 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) => |
| 249 _emptyStyleFuture(); | 249 _emptyStyleFuture(); |
| 250 bool matchesSelector(String selectors) => false; | 250 bool matchesSelector(String selectors) => false; |
| 251 | 251 |
| 252 // Imperative Element methods are made into no-ops, as they are on parentless | 252 // Imperative Element methods are made into no-ops, as they are on parentless |
| 253 // elements. | 253 // elements. |
| 254 void blur() {} | 254 void blur() {} |
| 255 void focus() {} | 255 void focus() {} |
| 256 void click() {} | 256 void click() {} |
| (...skipping 18 matching lines...) Expand all Loading... |
| 275 void set dataAttributes(Map<String, String> value) { | 275 void set dataAttributes(Map<String, String> value) { |
| 276 throw new UnsupportedOperationException( | 276 throw new UnsupportedOperationException( |
| 277 "Data attributes can't be set for document fragments."); | 277 "Data attributes can't be set for document fragments."); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void set contentEditable(String value) { | 280 void set contentEditable(String value) { |
| 281 throw new UnsupportedOperationException( | 281 throw new UnsupportedOperationException( |
| 282 "Content editable can't be set for document fragments."); | 282 "Content editable can't be set for document fragments."); |
| 283 } | 283 } |
| 284 | 284 |
| 285 String get dir { | 285 String get dir() { |
| 286 throw new UnsupportedOperationException( | 286 throw new UnsupportedOperationException( |
| 287 "Document fragments don't support text direction."); | 287 "Document fragments don't support text direction."); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void set dir(String value) { | 290 void set dir(String value) { |
| 291 throw new UnsupportedOperationException( | 291 throw new UnsupportedOperationException( |
| 292 "Document fragments don't support text direction."); | 292 "Document fragments don't support text direction."); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void set draggable(bool value) { | 295 void set draggable(bool value) { |
| 296 throw new UnsupportedOperationException( | 296 throw new UnsupportedOperationException( |
| 297 "Draggable can't be set for document fragments."); | 297 "Draggable can't be set for document fragments."); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void set hidden(bool value) { | 300 void set hidden(bool value) { |
| 301 throw new UnsupportedOperationException( | 301 throw new UnsupportedOperationException( |
| 302 "Hidden can't be set for document fragments."); | 302 "Hidden can't be set for document fragments."); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void set id(String value) { | 305 void set id(String value) { |
| 306 throw new UnsupportedOperationException( | 306 throw new UnsupportedOperationException( |
| 307 "ID can't be set for document fragments."); | 307 "ID can't be set for document fragments."); |
| 308 } | 308 } |
| 309 | 309 |
| 310 String get lang { | 310 String get lang() { |
| 311 throw new UnsupportedOperationException( | 311 throw new UnsupportedOperationException( |
| 312 "Document fragments don't support language."); | 312 "Document fragments don't support language."); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void set lang(String value) { | 315 void set lang(String value) { |
| 316 throw new UnsupportedOperationException( | 316 throw new UnsupportedOperationException( |
| 317 "Document fragments don't support language."); | 317 "Document fragments don't support language."); |
| 318 } | 318 } |
| 319 | 319 |
| 320 void set scrollLeft(int value) { | 320 void set scrollLeft(int value) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 "WebKit drop zone can't be set for document fragments."); | 352 "WebKit drop zone can't be set for document fragments."); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void set webkitRegionOverflow(String value) { | 355 void set webkitRegionOverflow(String value) { |
| 356 throw new UnsupportedOperationException( | 356 throw new UnsupportedOperationException( |
| 357 "WebKit region overflow can't be set for document fragments."); | 357 "WebKit region overflow can't be set for document fragments."); |
| 358 } | 358 } |
| 359 | 359 |
| 360 $!MEMBERS | 360 $!MEMBERS |
| 361 } | 361 } |
| OLD | NEW |