| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:math' as math; | 5 import 'dart:math' as math; |
| 6 | 6 |
| 7 abstract class ScrollCurve { | 7 abstract class ScrollCurve { |
| 8 // Returns the new scroll offset. | 8 // Returns the new scroll offset. |
| 9 double apply(double scrollOffset, double scrollDelta); | 9 double apply(double scrollOffset, double scrollDelta); |
| 10 } | 10 } |
| 11 | 11 |
| 12 class BoundedScrollCurve extends ScrollCurve { | 12 class BoundedScrollCurve extends ScrollCurve { |
| 13 double minOffset; | 13 double minOffset; |
| 14 double maxOffset; | 14 double maxOffset; |
| 15 | 15 |
| 16 BoundedScrollCurve({this.minOffset: 0.0, this.maxOffset}); | 16 BoundedScrollCurve({this.minOffset: 0.0, this.maxOffset}); |
| 17 | 17 |
| 18 double apply(double scrollOffset, double scrollDelta) { | 18 double apply(double scrollOffset, double scrollDelta) { |
| 19 double newScrollOffset = scrollOffset + scrollDelta; | 19 double newScrollOffset = scrollOffset + scrollDelta; |
| 20 if (minOffset != null) | 20 if (minOffset != null) |
| 21 newScrollOffset = math.max(minOffset, newScrollOffset); | 21 newScrollOffset = math.max(minOffset, newScrollOffset); |
| 22 if (maxOffset != null) | 22 if (maxOffset != null) |
| 23 newScrollOffset = math.min(maxOffset, newScrollOffset); | 23 newScrollOffset = math.min(maxOffset, newScrollOffset); |
| 24 return newScrollOffset; | 24 return newScrollOffset; |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 |
| 28 class OverscrollCurve extends ScrollCurve { |
| 29 double apply(double scrollOffset, double scrollDelta) { |
| 30 double newScrollOffset = scrollOffset + scrollDelta; |
| 31 if (newScrollOffset < 0.0) { |
| 32 // If we're overscrolling, we want move the scroll offset 2x slower than |
| 33 // we would otherwise. Therefore, we "rewind" the newScrollOffset by half |
| 34 // the amount that we moved it above. Notice that we clap the "old" value |
| 35 // to 0.0 so that we only reduce the portion of scrollDelta that's applied |
| 36 // beyond 0.0. |
| 37 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0; |
| 38 } |
| 39 return newScrollOffset; |
| 40 } |
| 41 } |
| OLD | NEW |