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

Unified Diff: client/touch/Scroller.dart

Issue 9148015: Example showing alternate async measurement solution (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Final version 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 side-by-side diff with in-line comments
Download patch
Index: client/touch/Scroller.dart
diff --git a/client/touch/Scroller.dart b/client/touch/Scroller.dart
index a9da0ebd72d9cab8ab7d61816c5351d6f8c23dc1..f125c747b1d7acf0202a9e3383ffb52542808310 100644
--- a/client/touch/Scroller.dart
+++ b/client/touch/Scroller.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -32,21 +32,6 @@
*/
typedef void Callback();
-// Helper method to await the completion of 2 futures.
-void joinFutures(List<Future> futures, Callback callback) {
- int count = 0;
- int len = futures.length;
- void helper(value) {
- count++;
- if (count == len) {
- callback();
- }
- }
- for (Future p in futures) {
- p.then(helper);
- }
-}
-
class Scroller implements Draggable, MomentumDelegate {
/** Pixels to move each time an arrow key is pressed. */
@@ -231,8 +216,8 @@ class Scroller implements Draggable, MomentumDelegate {
// The scrollable element must be relatively positioned.
// TODO(jacobr): this assert fires asynchronously which could be confusing.
if (_scrollTechnique == ScrollerScrollTechnique.RELATIVE_POSITIONING) {
- _element.computedStyle.then((CSSStyleDeclaration style) {
- assert(style.position != "static");
+ window.requestMeasurementFrame(() {
+ assert(_element.computedStyle.position != "static");
});
}
@@ -503,6 +488,8 @@ class Scroller implements Draggable, MomentumDelegate {
reconfigure(() {
final touch = e.touches[0];
if (_momentum.decelerating) {
+ // TODO(jacobr): this won't do any good as it is called too late due
+ // to async measurement.
e.preventDefault();
e.stopPropagation();
stop();
@@ -541,24 +528,18 @@ class Scroller implements Draggable, MomentumDelegate {
* and maxPoint allowed for scrolling.
*/
void _resize(Callback callback) {
- final frameRect = _frame.rect;
- Future contentSizeFuture;
-
- if (_lookupContentSizeDelegate !== null) {
- contentSizeFuture = _lookupContentSizeDelegate();
- contentSizeFuture.then((Size size) {
- _contentSize = size;
- });
- } else {
- contentSizeFuture = _element.rect;
- contentSizeFuture.then((ElementRect rect) {
- _contentSize = new Size(rect.scroll.width, rect.scroll.height);
- });
- }
+ window.requestMeasurementFrame(() {
+ final offset = _frame.rect.offset;
+
+ if (_lookupContentSizeDelegate !== null) {
+ // Guaranteed to be called within a measurement frame
+ _contentSize = _lookupContentSizeDelegate();
+ } else {
+ final scroll = _element.rect.scroll;
+ _contentSize = new Size(scroll.width, scroll.height);
+ }
- joinFutures(<Future>[frameRect, contentSizeFuture], () {
- _scrollSize = new Size(frameRect.value.offset.width,
- frameRect.value.offset.height);
+ _scrollSize = new Size(offset.width, offset.height);
Size adjusted = _getAdjustedContentSize();
_maxPoint = new Coordinate(-_maxOffset.x, -_maxOffset.y);
_minPoint = new Coordinate(
@@ -566,7 +547,7 @@ class Scroller implements Draggable, MomentumDelegate {
_scrollSize.width - adjusted.width + _minOffset.x, _maxPoint.x),
Math.min(
_scrollSize.height - adjusted.height + _minOffset.y, _maxPoint.y));
- callback();
+ return callback;
});
}

Powered by Google App Engine
This is Rietveld 408576698