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

Unified Diff: lib/html/templates/html/impl/impl_Element.darttemplate

Issue 11033007: Revert "Removing ElementList (splitting out removing NodeList into a separate CL)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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: lib/html/templates/html/impl/impl_Element.darttemplate
diff --git a/lib/html/templates/html/impl/impl_Element.darttemplate b/lib/html/templates/html/impl/impl_Element.darttemplate
index eeadc48fce44fd9780d45b744bb1cbbd80f25873..c70ab47f54ff03214a8c082d28d40d5badcf050a 100644
--- a/lib/html/templates/html/impl/impl_Element.darttemplate
+++ b/lib/html/templates/html/impl/impl_Element.darttemplate
@@ -4,7 +4,7 @@
// TODO(jacobr): use _Lists.dart to remove some of the duplicated
// functionality.
-class _ChildrenElementList implements List {
+class _ChildrenElementList implements ElementList {
// Raw Element.
final _ElementImpl _element;
final _HTMLCollectionImpl _childElements;
@@ -21,14 +21,18 @@ class _ChildrenElementList implements List {
return output;
}
+ _ElementImpl get first {
+ return _element.$dom_firstElementChild;
+ }
+
void forEach(void f(Element element)) {
for (_ElementImpl element in _childElements) {
f(element);
}
}
- List<Element> filter(bool f(Element element)) {
- final output = [];
+ ElementList filter(bool f(Element element)) {
+ final output = <Element>[];
forEach((Element element) {
if (f(element)) {
output.add(element);
@@ -150,7 +154,7 @@ class _ChildrenElementList implements List {
// a better option given that we cannot quite force NodeList to be an
// ElementList as there are valid cases where a NodeList JavaScript object
// contains Node objects that are not Elements.
-class _FrozenElementList implements List {
+class _FrozenElementList implements ElementList {
final List<Node> _nodeList;
_FrozenElementList._wrap(this._nodeList);
@@ -173,8 +177,8 @@ class _FrozenElementList implements List {
return out;
}
- List<Element> filter(bool f(Element element)) {
- final out = <Element>[];
+ ElementList filter(bool f(Element element)) {
+ final out = new _ElementList([]);
for (Element el in this) {
if (f(el)) out.add(el);
}
@@ -243,7 +247,7 @@ class _FrozenElementList implements List {
throw const UnsupportedOperationException('');
}
- List<Element> getRange(int start, int rangeLength) =>
+ ElementList getRange(int start, int rangeLength) =>
new _FrozenElementList._wrap(_nodeList.getRange(start, rangeLength));
int indexOf(Element element, [int start = 0]) =>
@@ -287,6 +291,16 @@ class _FrozenElementListIterator implements Iterator<Element> {
bool hasNext() => _index < _list.length;
}
+class _ElementList extends _ListWrapper<Element> implements ElementList {
+ _ElementList(List<Element> list) : super(list);
+
+ ElementList filter(bool f(Element element)) =>
+ new _ElementList(super.filter(f));
+
+ ElementList getRange(int start, int rangeLength) =>
+ new _ElementList(super.getRange(start, rangeLength));
+}
+
class _ElementAttributeMap implements AttributeMap {
final _ElementImpl _element;
@@ -674,7 +688,7 @@ class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
elements.addAll(value);
}
- List<Element> get elements => new _ChildrenElementList._wrap(this);
+ ElementList get elements => new _ChildrenElementList._wrap(this);
_ElementImpl query(String selectors) => $dom_querySelector(selectors);
@@ -784,8 +798,7 @@ $if DART2JS
this.parent.insertBefore(node, this);
break;
case 'afterbegin':
- var first = this.nodes.length > 0 ? this.nodes[0] : null;
- this.insertBefore(node, first);
+ this.insertBefore(node, this.nodes.first);
break;
case 'beforeend':
this.nodes.add(node);
@@ -844,7 +857,7 @@ class _ElementFactoryProvider {
Element element;
if (temp.elements.length == 1) {
- element = temp.elements[0];
+ element = temp.elements.first;
} else if (parentTag == 'html' && temp.elements.length == 2) {
// Work around for edge case in WebKit and possibly other browsers where
// both body and head elements are created even though the inner html

Powered by Google App Engine
This is Rietveld 408576698