| Index: tools/dom/templates/html/impl/impl_Element.darttemplate
|
| diff --git a/tools/dom/templates/html/impl/impl_Element.darttemplate b/tools/dom/templates/html/impl/impl_Element.darttemplate
|
| index 9f62f9a60289c8cf3999697cb1e9932bf07ef48e..9fd0d99f02cfe61d643dd011965e9336bfe2cbbe 100644
|
| --- a/tools/dom/templates/html/impl/impl_Element.darttemplate
|
| +++ b/tools/dom/templates/html/impl/impl_Element.darttemplate
|
| @@ -4,6 +4,8 @@
|
|
|
| part of $LIBRARYNAME;
|
|
|
| +// TODO(jacobr): use _Lists.dart to remove some of the duplicated
|
| +// functionality.
|
| class _ChildrenElementList extends ListBase<Element> {
|
| // Raw Element.
|
| final Element _element;
|
| @@ -13,13 +15,106 @@ class _ChildrenElementList extends ListBase<Element> {
|
| : _childElements = element.$dom_children,
|
| _element = element;
|
|
|
| + List<Element> toList({ bool growable: true }) {
|
| + List<Element> output;
|
| + if (growable) {
|
| + output = <Element>[];
|
| + output.length = _childElements.length;
|
| + } else {
|
| + output = new List<Element>(_childElements.length);
|
| + }
|
| + for (int i = 0, len = _childElements.length; i < len; i++) {
|
| + output[i] = _childElements[i];
|
| + }
|
| + return output;
|
| + }
|
| +
|
| + Set<Element> toSet() {
|
| + final output = new Set<Element>();
|
| + for (int i = 0, len = _childElements.length; i < len; i++) {
|
| + output.add(_childElements[i]);
|
| + }
|
| + return output;
|
| + }
|
| +
|
| bool contains(Element element) => _childElements.contains(element);
|
|
|
| + void forEach(void f(Element element)) {
|
| + for (Element element in _childElements) {
|
| + f(element);
|
| + }
|
| + }
|
| +
|
| + bool every(bool f(Element element)) {
|
| + for (Element element in this) {
|
| + if (!f(element)) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + bool any(bool f(Element element)) {
|
| + for (Element element in this) {
|
| + if (f(element)) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + String join([String separator = ""]) {
|
| + return _childElements.join(separator);
|
| + }
|
| +
|
| + Iterable map(f(Element element)) {
|
| + return _childElements.map(f);
|
| + }
|
| +
|
| + Iterable<Element> where(bool f(Element element)) {
|
| + return _childElements.where(f);
|
| + }
|
| +
|
| + Iterable expand(Iterable f(Element element)) {
|
| + return _childElements.expand(f);
|
| + }
|
|
|
| bool get isEmpty {
|
| return _element.$dom_firstElementChild == null;
|
| }
|
|
|
| + Iterable<Element> take(int n) {
|
| + return _childElements.take(n);
|
| + }
|
| +
|
| + Iterable<Element> takeWhile(bool test(Element value)) {
|
| + return _childElements.takeWhile(test);
|
| + }
|
| +
|
| + Iterable<Element> skip(int n) {
|
| + return _childElements.skip(n);
|
| + }
|
| +
|
| + Iterable<Element> skipWhile(bool test(Element value)) {
|
| + return _childElements.skipWhile(test);
|
| + }
|
| +
|
| + Element firstWhere(bool test(Element value), {Element orElse()}) {
|
| + return _childElements.firstWhere(test, orElse: orElse);
|
| + }
|
| +
|
| + Element lastWhere(bool test(Element value), {Element orElse()}) {
|
| + return _childElements.lastWhere(test, orElse: orElse);
|
| + }
|
| +
|
| + Element singleWhere(bool test(Element value)) {
|
| + return _childElements.singleWhere(test);
|
| + }
|
| +
|
| + Element elementAt(int index) {
|
| + return this[index];
|
| + }
|
| +
|
| int get length {
|
| return _childElements.length;
|
| }
|
| @@ -34,7 +129,7 @@ class _ChildrenElementList extends ListBase<Element> {
|
|
|
| void set length(int newLength) {
|
| // TODO(jacobr): remove children when length is reduced.
|
| - throw new UnsupportedError('Cannot resize element lists');
|
| + throw new UnsupportedError('');
|
| }
|
|
|
| Element add(Element value) {
|
| @@ -54,8 +149,21 @@ class _ChildrenElementList extends ListBase<Element> {
|
| }
|
| }
|
|
|
| + Iterable<Element> get reversed {
|
| + return _childElements.reversed;
|
| + }
|
| +
|
| void sort([int compare(Element a, Element b)]) {
|
| - throw new UnsupportedError('Cannot sort element lists');
|
| + throw new UnsupportedError('TODO(jacobr): should we impl?');
|
| + }
|
| +
|
| + Element reduce(Element combine(Element value, Element element)) {
|
| + return _childElements.reduce(combine);
|
| + }
|
| +
|
| + dynamic fold(dynamic initialValue,
|
| + dynamic combine(dynamic previousValue, Element element)) {
|
| + return _childElements.fold(initialValue, combine);
|
| }
|
|
|
| void setRange(int start, int end, Iterable<Element> iterable,
|
| @@ -80,6 +188,36 @@ class _ChildrenElementList extends ListBase<Element> {
|
| }
|
| }
|
|
|
| + void removeWhere(bool test(Element element)) {
|
| + _childElements.removeWhere(test);
|
| + }
|
| +
|
| + void retainWhere(bool test(Element element)) {
|
| + _childElements.retainWhere(test);
|
| + }
|
| +
|
| + void removeRange(int start, int end) {
|
| + throw new UnimplementedError();
|
| + }
|
| +
|
| + Iterable getRange(int start, int end) {
|
| + throw new UnimplementedError();
|
| + }
|
| +
|
| + List sublist(int start, [int end]) {
|
| + if (end == null) end = length;
|
| + return new _FrozenElementList._wrap(Lists.getRange(this, start, end, []));
|
| + }
|
| +
|
| + int indexOf(Element element, [int start = 0]) {
|
| + return Lists.indexOf(this, element, start, this.length);
|
| + }
|
| +
|
| + int lastIndexOf(Element element, [int start = null]) {
|
| + if (start == null) start = length - 1;
|
| + return Lists.lastIndexOf(this, element, start);
|
| + }
|
| +
|
| void insert(int index, Element element) {
|
| if (index < 0 || index > length) {
|
| throw new RangeError.range(index, 0, length);
|
| @@ -91,6 +229,10 @@ class _ChildrenElementList extends ListBase<Element> {
|
| }
|
| }
|
|
|
| + void insertAll(int index, Iterable<Element> iterable) {
|
| + throw new UnimplementedError();
|
| + }
|
| +
|
| void setAll(int index, Iterable<Element> iterable) {
|
| throw new UnimplementedError();
|
| }
|
| @@ -133,13 +275,24 @@ class _ChildrenElementList extends ListBase<Element> {
|
| if (length > 1) throw new StateError("More than one element");
|
| return first;
|
| }
|
| +
|
| + Map<int, Element> asMap() {
|
| + return _childElements.asMap();
|
| + }
|
| +
|
| + String toString() {
|
| + StringBuffer buffer = new StringBuffer('[');
|
| + buffer.writeAll(this, ', ');
|
| + buffer.write(']');
|
| + return buffer.toString();
|
| + }
|
| }
|
|
|
| // TODO(jacobr): this is an inefficient implementation but it is hard to see
|
| // 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 extends ListBase<Element> {
|
| +class _FrozenElementList extends ListBase {
|
| final List<Node> _nodeList;
|
|
|
| _FrozenElementList._wrap(this._nodeList);
|
| @@ -149,15 +302,60 @@ class _FrozenElementList extends ListBase<Element> {
|
| Element operator [](int index) => _nodeList[index];
|
|
|
| void operator []=(int index, Element value) {
|
| - throw new UnsupportedError('Cannot modify list');
|
| + throw new UnsupportedError('');
|
| }
|
|
|
| void set length(int newLength) {
|
| - throw new UnsupportedError('Cannot modify list');
|
| + _nodeList.length = newLength;
|
| }
|
|
|
| - void sort([Comparator<Element> compare]) {
|
| - throw new UnsupportedError('Cannot sort list');
|
| + void add(Element value) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + void addAll(Iterable<Element> iterable) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + void sort([int compare(Element a, Element b)]) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + void setRange(int start, int end, Iterable<Element> iterable,
|
| + [int skipCount = 0]) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + void removeRange(int start, int end) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + List<Element> sublist(int start, [int end]) {
|
| + return new _FrozenElementList._wrap(_nodeList.sublist(start, end));
|
| + }
|
| +
|
| + void clear() {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + Element removeAt(int index) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + Element removeLast() {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + void remove(Object element) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + void removeWhere(bool test(Element element)) {
|
| + throw new UnsupportedError('');
|
| + }
|
| +
|
| + void retainWhere(bool test(Element element)) {
|
| + throw new UnsupportedError('');
|
| }
|
|
|
| Element get first => _nodeList.first;
|
| @@ -165,6 +363,13 @@ class _FrozenElementList extends ListBase<Element> {
|
| Element get last => _nodeList.last;
|
|
|
| Element get single => _nodeList.single;
|
| +
|
| + String toString() {
|
| + StringBuffer buffer = new StringBuffer('[');
|
| + buffer.writeAll(this, ', ');
|
| + buffer.write(']');
|
| + return buffer.toString();
|
| + }
|
| }
|
|
|
| class _ElementCssClassSet extends CssClassSet {
|
|
|