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

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

Issue 8363040: Implement measurement using futures (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to all comments Created 9 years, 1 month 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
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 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
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 throw new UnsupportedOperationException( 120 throw new UnsupportedOperationException(
121 "Can't modify a frozen style declaration."); 121 "Can't modify a frozen style declaration.");
122 } 122 }
123 123
124 void setProperty(String propertyName, String value, [String priority]) { 124 void setProperty(String propertyName, String value, [String priority]) {
125 throw new UnsupportedOperationException( 125 throw new UnsupportedOperationException(
126 "Can't modify a frozen style declaration."); 126 "Can't modify a frozen style declaration.");
127 } 127 }
128 } 128 }
129 129
130 class EmptyClientRect implements ClientRect { 130 Future<CSSStyleDeclaration> _emptyStyleFuture() {
nweiz 2011/10/28 03:58:38 This pattern (initialize then complete immediately
Jacob 2011/10/31 22:09:50 I agree. Ideally the completer class should have
131 num get bottom() => 0; 131 final completer = new Completer<CSSStyleDeclaration>();
132 num get top() => 0; 132 completer.complete(new EmptyStyleDeclaration());
nweiz 2011/10/28 03:58:38 It seems potentially dangerous to complete this sy
Jacob 2011/10/31 22:09:50 Good point. Fixed these two cases.
133 num get left() => 0; 133 return completer.future;
134 num get right() => 0; 134 }
135 num get height() => 0; 135
136 num get width() => 0; 136 class EmptyElementRect implements ElementRect {
137 final ClientRect client = const SimpleClientRect(0, 0, 0, 0);
138 final ClientRect offset = const SimpleClientRect(0, 0, 0, 0);
139 final ClientRect scroll = const SimpleClientRect(0, 0, 0, 0);
140 final ClientRect bounding = const SimpleClientRect(0, 0, 0, 0);
141 final List<ClientRect> clientRects = const <SimpleClientRect>[];
nweiz 2011/10/28 03:58:38 What's the reasoning behind specifying SimpleClien
Jacob 2011/10/31 22:09:50 that way clientRects is List<ClientRect> will ret
nweiz 2011/11/01 00:49:22 But why not "const <ClientRect>[]"?
Jacob 2011/11/01 02:42:39 I agree. const <ClientRect>[] is better. Fixed.
142
143 const EmptyElementRect();
137 } 144 }
138 145
139 class DocumentFragmentWrappingImplementation extends NodeWrappingImplementation implements DocumentFragment { 146 class DocumentFragmentWrappingImplementation extends NodeWrappingImplementation implements DocumentFragment {
140 ElementList _elements; 147 ElementList _elements;
141 148
142 DocumentFragmentWrappingImplementation._wrap(ptr) : super._wrap(ptr) {} 149 DocumentFragmentWrappingImplementation._wrap(ptr) : super._wrap(ptr) {}
143 150
144 factory DocumentFragmentWrappingImplementation() { 151 factory DocumentFragmentWrappingImplementation() {
145 return new DocumentFragmentWrappingImplementation._wrap( 152 return new DocumentFragmentWrappingImplementation._wrap(
146 dom.document.createDocumentFragment()); 153 dom.document.createDocumentFragment());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 position_OR_where, new DocumentFragment.html(text)); 222 position_OR_where, new DocumentFragment.html(text));
216 } 223 }
217 224
218 ElementEvents get on() { 225 ElementEvents get on() {
219 if (_on === null) { 226 if (_on === null) {
220 _on = new ElementEventsImplementation._wrap(_ptr); 227 _on = new ElementEventsImplementation._wrap(_ptr);
221 } 228 }
222 return _on; 229 return _on;
223 } 230 }
224 231
232 Future<ElementRect> get rect() {
233 final completer = new Completer<ElementRect>();
234 completer.complete(const EmptyElementRect());
235 return completer.future;
236 }
237
225 Element query(String selectors) => 238 Element query(String selectors) =>
226 LevelDom.wrapElement(_ptr.querySelector(selectors)); 239 LevelDom.wrapElement(_ptr.querySelector(selectors));
227 240
228 ElementList queryAll(String selectors) => 241 ElementList queryAll(String selectors) =>
229 LevelDom.wrapElementList(_ptr.querySelectorAll(selectors)); 242 LevelDom.wrapElementList(_ptr.querySelectorAll(selectors));
230 243
231 // If we can come up with a semi-reasonable default value for an Element 244 // If we can come up with a semi-reasonable default value for an Element
232 // getter, we'll use it. In general, these return the same values as an 245 // getter, we'll use it. In general, these return the same values as an
233 // element that has no parent. 246 // element that has no parent.
234 int get clientHeight() => 0;
235 int get clientWidth() => 0;
236 int get offsetHeight() => 0;
237 int get offsetWidth() => 0;
238 int get scrollHeight() => 0;
239 int get scrollWidth() => 0;
240 int get clientLeft() => 0;
241 int get clientTop() => 0;
242 int get offsetLeft() => 0;
243 int get offsetTop() => 0;
244 int get scrollLeft() => 0;
245 int get scrollTop() => 0;
246 String get contentEditable() => "false"; 247 String get contentEditable() => "false";
247 bool get isContentEditable() => false; 248 bool get isContentEditable() => false;
248 bool get draggable() => false; 249 bool get draggable() => false;
249 bool get hidden() => false; 250 bool get hidden() => false;
250 bool get spellcheck() => false; 251 bool get spellcheck() => false;
251 int get tabIndex() => -1; 252 int get tabIndex() => -1;
252 String get id() => ""; 253 String get id() => "";
253 String get title() => ""; 254 String get title() => "";
254 String get tagName() => ""; 255 String get tagName() => "";
255 String get webkitdropzone() => ""; 256 String get webkitdropzone() => "";
256 Element get firstElementChild() => elements.first(); 257 Element get firstElementChild() => elements.first();
257 Element get lastElementChild() => elements.last(); 258 Element get lastElementChild() => elements.last();
258 Element get nextElementSibling() => null; 259 Element get nextElementSibling() => null;
259 Element get previousElementSibling() => null; 260 Element get previousElementSibling() => null;
260 Element get offsetParent() => null; 261 Element get offsetParent() => null;
261 Element get parent() => null; 262 Element get parent() => null;
262 Map<String, String> get attributes() => const {}; 263 Map<String, String> get attributes() => const {};
263 // Issue 174: this should be a const set. 264 // Issue 174: this should be a const set.
264 Set<String> get classes() => new Set<String>(); 265 Set<String> get classes() => new Set<String>();
265 Map<String, String> get dataAttributes() => const {}; 266 Map<String, String> get dataAttributes() => const {};
266 CSSStyleDeclaration get style() => new EmptyStyleDeclaration(); 267 CSSStyleDeclaration get style() => new EmptyStyleDeclaration();
267 ClientRect getBoundingClientRect() => new EmptyClientRect(); 268 Future<CSSStyleDeclaration> get computedStyle() =>
268 List<ClientRect> getClientRects() => const []; 269 _emptyStyleFuture();
270 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) =>
nweiz 2011/10/28 03:58:38 Is there any reason not to have this call computed
Jacob 2011/10/31 22:09:50 It matters very little. My code is more verbose t
271 _emptyStyleFuture();
269 bool matchesSelector([String selectors]) => false; 272 bool matchesSelector([String selectors]) => false;
270 273
271 // Imperative Element methods are made into no-ops, as they are on parentless 274 // Imperative Element methods are made into no-ops, as they are on parentless
272 // elements. 275 // elements.
273 void blur() {} 276 void blur() {}
274 void focus() {} 277 void focus() {}
275 void scrollByLines([int lines]) {} 278 void scrollByLines([int lines]) {}
276 void scrollByPages([int pages]) {} 279 void scrollByPages([int pages]) {}
277 void scrollIntoView([bool centerIfNeeded]) {} 280 void scrollIntoView([bool centerIfNeeded]) {}
278 281
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 358
356 void set title(String value) { 359 void set title(String value) {
357 throw new UnsupportedOperationException( 360 throw new UnsupportedOperationException(
358 "Title can't be set for document fragments."); 361 "Title can't be set for document fragments.");
359 } 362 }
360 363
361 void set webkitdropzone(String value) { 364 void set webkitdropzone(String value) {
362 throw new UnsupportedOperationException( 365 throw new UnsupportedOperationException(
363 "WebKit drop zone can't be set for document fragments."); 366 "WebKit drop zone can't be set for document fragments.");
364 } 367 }
365 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698