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

Side by Side Diff: client/html/src/NodeWrappingImplementation.dart

Issue 9199002: Support various range methods on NodeList. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge with HEAD Created 8 years, 11 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 | « client/html/release/htmlimpl.dart ('k') | client/tests/client/html/NodeTests.dart » ('j') | 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) 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 _ChildrenNodeList implements NodeList { 5 class _ChildrenNodeList implements NodeList {
6 // Raw node. 6 // Raw node.
7 final _node; 7 final _node;
8 final _childNodes; 8 final _childNodes;
9 9
10 _ChildrenNodeList._wrap(var node) 10 _ChildrenNodeList._wrap(var node)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 int get length() { 69 int get length() {
70 return _childNodes.length; 70 return _childNodes.length;
71 } 71 }
72 72
73 Node operator [](int index) { 73 Node operator [](int index) {
74 return LevelDom.wrapNode(_childNodes[index]); 74 return LevelDom.wrapNode(_childNodes[index]);
75 } 75 }
76 76
77 void operator []=(int index, Node value) { 77 void operator []=(int index, Node value) {
78 _childNodes[index] = LevelDom.unwrap(value); 78 _node.replaceChild(LevelDom.unwrap(value), _childNodes[index]);
79 } 79 }
80 80
81 void set length(int newLength) { 81 void set length(int newLength) {
82 throw new UnsupportedOperationException(''); 82 throw new UnsupportedOperationException('');
83 } 83 }
84 84
85 /** @domName Node.appendChild */ 85 /** @domName Node.appendChild */
86 Node add(Node value) { 86 Node add(Node value) {
87 _node.appendChild(LevelDom.unwrap(value)); 87 _node.appendChild(LevelDom.unwrap(value));
88 return value; 88 return value;
(...skipping 16 matching lines...) Expand all
105 105
106 void sort(int compare(Node a, Node b)) { 106 void sort(int compare(Node a, Node b)) {
107 throw const UnsupportedOperationException('TODO(jacobr): should we impl?'); 107 throw const UnsupportedOperationException('TODO(jacobr): should we impl?');
108 } 108 }
109 109
110 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { 110 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) {
111 throw 'Not impl yet. todo(jacobr)'; 111 throw 'Not impl yet. todo(jacobr)';
112 } 112 }
113 113
114 void setRange(int start, int length, List from, [int startFrom = 0]) { 114 void setRange(int start, int length, List from, [int startFrom = 0]) {
115 throw const NotImplementedException(); 115 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds
116 // checking for List indexing
117 if (start < 0) {
118 throw new IndexOutOfRangeException(start);
119 } else if (startFrom < 0) {
120 throw new IndexOutOfRangeException(startFrom);
121 } else if (length < 0) {
122 throw new IllegalArgumentException("negative length $length");
123 } else if (start + length > this.length) {
124 throw new IndexOutOfRangeException(Math.min(this.length, start));
125 } else if (startFrom + length > from.length) {
126 throw new IndexOutOfRangeException(Math.min(from.length, startFrom));
127 }
128
129 for (var i = 0; i < length; i++) {
130 this[start + i] = from[startFrom + i];
131 }
116 } 132 }
117 133
118 void removeRange(int start, int length) { 134 void removeRange(int start, int length) {
119 throw const NotImplementedException(); 135 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds
136 // checking for List indexing
137 if (start < 0) {
138 throw new IndexOutOfRangeException(start);
139 } else if (length < 0) {
140 throw new IllegalArgumentException("negative length $length");
141 } else if (start + length > this.length) {
142 throw new IndexOutOfRangeException(Math.min(this.length, start));
143 }
144
145 for (var i = 0; i < length; i++) {
146 this[start].remove();
147 }
120 } 148 }
121 149
122 void insertRange(int start, int length, [initialValue = null]) { 150 void insertRange(int start, int length, [initialValue = null]) {
123 throw const NotImplementedException(); 151 throw const NotImplementedException();
124 } 152 }
125 153
126 List getRange(int start, int length) { 154 List getRange(int start, int length) {
127 throw const NotImplementedException(); 155 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds
156 // checking for List indexing
157 if (start < 0) {
158 throw new IndexOutOfRangeException(start);
159 } else if (length < 0) {
160 throw new IllegalArgumentException("negative length $length");
161 } else if (start + length > this.length) {
162 throw new IndexOutOfRangeException(Math.min(this.length, start));
163 }
164
165 var nodes = <Node>[];
Jacob 2012/01/17 18:14:53 make this return a Nodelist rather than a List so
nweiz 2012/01/17 23:23:22 How will this work type-wise? The user only access
166 for (var i = 0; i < length; i++) {
167 nodes.add(this[start + i]);
168 }
169 return nodes;
128 } 170 }
129 171
130 int indexOf(Node element, [int start = 0]) { 172 int indexOf(Node element, [int start = 0]) {
131 return _Lists.indexOf(this, element, start, this.length); 173 return _Lists.indexOf(this, element, start, this.length);
132 } 174 }
133 175
134 int lastIndexOf(Node element, [int start = null]) { 176 int lastIndexOf(Node element, [int start = null]) {
135 if (start === null) start = length - 1; 177 if (start === null) start = length - 1;
136 return _Lists.lastIndexOf(this, element, start); 178 return _Lists.lastIndexOf(this, element, start);
137 } 179 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // array. 258 // array.
217 Node insertBefore(Node newChild, Node refChild) { 259 Node insertBefore(Node newChild, Node refChild) {
218 return LevelDom.wrapNode(_ptr.insertBefore( 260 return LevelDom.wrapNode(_ptr.insertBefore(
219 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); 261 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild)));
220 } 262 }
221 263
222 Node clone(bool deep) { 264 Node clone(bool deep) {
223 return LevelDom.wrapNode(_ptr.cloneNode(deep)); 265 return LevelDom.wrapNode(_ptr.cloneNode(deep));
224 } 266 }
225 } 267 }
OLDNEW
« no previous file with comments | « client/html/release/htmlimpl.dart ('k') | client/tests/client/html/NodeTests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698