| Index: client/touch/Scroller.dart
|
| diff --git a/client/touch/Scroller.dart b/client/touch/Scroller.dart
|
| index f125c747b1d7acf0202a9e3383ffb52542808310..a9da0ebd72d9cab8ab7d61816c5351d6f8c23dc1 100644
|
| --- a/client/touch/Scroller.dart
|
| +++ b/client/touch/Scroller.dart
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// Copyright (c) 2011, 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,6 +32,21 @@
|
| */
|
| 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. */
|
| @@ -216,8 +231,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) {
|
| - window.requestMeasurementFrame(() {
|
| - assert(_element.computedStyle.position != "static");
|
| + _element.computedStyle.then((CSSStyleDeclaration style) {
|
| + assert(style.position != "static");
|
| });
|
| }
|
|
|
| @@ -488,8 +503,6 @@ 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();
|
| @@ -528,18 +541,24 @@ class Scroller implements Draggable, MomentumDelegate {
|
| * and maxPoint allowed for scrolling.
|
| */
|
| void _resize(Callback callback) {
|
| - 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);
|
| - }
|
| + final frameRect = _frame.rect;
|
| + Future contentSizeFuture;
|
|
|
| - _scrollSize = new Size(offset.width, offset.height);
|
| + 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);
|
| + });
|
| + }
|
| +
|
| + joinFutures(<Future>[frameRect, contentSizeFuture], () {
|
| + _scrollSize = new Size(frameRect.value.offset.width,
|
| + frameRect.value.offset.height);
|
| Size adjusted = _getAdjustedContentSize();
|
| _maxPoint = new Coordinate(-_maxOffset.x, -_maxOffset.y);
|
| _minPoint = new Coordinate(
|
| @@ -547,7 +566,7 @@ class Scroller implements Draggable, MomentumDelegate {
|
| _scrollSize.width - adjusted.width + _minOffset.x, _maxPoint.x),
|
| Math.min(
|
| _scrollSize.height - adjusted.height + _minOffset.y, _maxPoint.y));
|
| - return callback;
|
| + callback();
|
| });
|
| }
|
|
|
|
|