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

Side by Side Diff: sky/sdk/lib/animation/scroll_behavior.dart

Issue 1226113007: Add @override annotation to known overriden methods (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « sky/sdk/lib/animation/mechanics.dart ('k') | sky/sdk/lib/editing/editable_text.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 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 import 'mechanics.dart'; 7 import 'mechanics.dart';
8 import 'generators.dart'; 8 import 'generators.dart';
9 9
10 const double _kScrollFriction = 0.005; 10 const double _kScrollFriction = 0.005;
11 const double _kOverscrollFriction = 0.075; 11 const double _kOverscrollFriction = 0.075;
12 const double _kBounceSlopeAngle = math.PI / 512.0; // radians 12 const double _kBounceSlopeAngle = math.PI / 512.0; // radians
13 13
14 abstract class ScrollBehavior { 14 abstract class ScrollBehavior {
15 Simulation release(Particle particle) => null; 15 Simulation release(Particle particle) => null;
16 16
17 // Returns the new scroll offset. 17 // Returns the new scroll offset.
18 double applyCurve(double scrollOffset, double scrollDelta); 18 double applyCurve(double scrollOffset, double scrollDelta);
19 } 19 }
20 20
21 class BoundedScrollBehavior extends ScrollBehavior { 21 class BoundedScrollBehavior extends ScrollBehavior {
22 double minOffset; 22 double minOffset;
23 double maxOffset; 23 double maxOffset;
24 24
25 BoundedScrollBehavior({this.minOffset: 0.0, this.maxOffset}); 25 BoundedScrollBehavior({this.minOffset: 0.0, this.maxOffset});
26 26
27 @override
27 double applyCurve(double scrollOffset, double scrollDelta) { 28 double applyCurve(double scrollOffset, double scrollDelta) {
28 double newScrollOffset = scrollOffset + scrollDelta; 29 double newScrollOffset = scrollOffset + scrollDelta;
29 if (minOffset != null) 30 if (minOffset != null)
30 newScrollOffset = math.max(minOffset, newScrollOffset); 31 newScrollOffset = math.max(minOffset, newScrollOffset);
31 if (maxOffset != null) 32 if (maxOffset != null)
32 newScrollOffset = math.min(maxOffset, newScrollOffset); 33 newScrollOffset = math.min(maxOffset, newScrollOffset);
33 return newScrollOffset; 34 return newScrollOffset;
34 } 35 }
35 } 36 }
36 37
(...skipping 16 matching lines...) Expand all
53 // TODO(ianh) now what? what if we have a simulation ongoing? 54 // TODO(ianh) now what? what if we have a simulation ongoing?
54 } 55 }
55 } 56 }
56 57
57 OverscrollBehavior({double contentsHeight: 0.0, double containerHeight: 0.0}) 58 OverscrollBehavior({double contentsHeight: 0.0, double containerHeight: 0.0})
58 : _contentsHeight = contentsHeight, 59 : _contentsHeight = contentsHeight,
59 _containerHeight = containerHeight; 60 _containerHeight = containerHeight;
60 61
61 double get maxScroll => math.max(0.0, _contentsHeight - _containerHeight); 62 double get maxScroll => math.max(0.0, _contentsHeight - _containerHeight);
62 63
64 @override
63 Simulation release(Particle particle) { 65 Simulation release(Particle particle) {
64 System system; 66 System system;
65 if ((particle.position >= 0.0) && (particle.position < maxScroll)) { 67 if ((particle.position >= 0.0) && (particle.position < maxScroll)) {
66 if (particle.velocity == 0.0) 68 if (particle.velocity == 0.0)
67 return null; 69 return null;
68 System slowdownSystem = new ParticleInBoxWithFriction( 70 System slowdownSystem = new ParticleInBoxWithFriction(
69 particle: particle, 71 particle: particle,
70 friction: _kScrollFriction, 72 friction: _kScrollFriction,
71 box: new GeofenceBox(min: 0.0, max: maxScroll, onEscape: () { 73 box: new GeofenceBox(min: 0.0, max: maxScroll, onEscape: () {
72 (system as Multisystem).transitionToSystem(new ParticleInBoxWithFricti on( 74 (system as Multisystem).transitionToSystem(new ParticleInBoxWithFricti on(
(...skipping 17 matching lines...) Expand all
90 box: new ClosedBox(max: 0.0), 92 box: new ClosedBox(max: 0.0),
91 theta: _kBounceSlopeAngle, 93 theta: _kBounceSlopeAngle,
92 targetPosition: 0.0); 94 targetPosition: 0.0);
93 return new ParticleClimbingRamp( 95 return new ParticleClimbingRamp(
94 particle: particle, 96 particle: particle,
95 box: new ClosedBox(min: maxScroll), 97 box: new ClosedBox(min: maxScroll),
96 theta: _kBounceSlopeAngle, 98 theta: _kBounceSlopeAngle,
97 targetPosition: maxScroll); 99 targetPosition: maxScroll);
98 } 100 }
99 101
102 @override
100 double applyCurve(double scrollOffset, double scrollDelta) { 103 double applyCurve(double scrollOffset, double scrollDelta) {
101 double newScrollOffset = scrollOffset + scrollDelta; 104 double newScrollOffset = scrollOffset + scrollDelta;
102 // If we're overscrolling, we want move the scroll offset 2x 105 // If we're overscrolling, we want move the scroll offset 2x
103 // slower than we would otherwise. Therefore, we "rewind" the 106 // slower than we would otherwise. Therefore, we "rewind" the
104 // newScrollOffset by half the amount that we moved it above. 107 // newScrollOffset by half the amount that we moved it above.
105 // Notice that we clap the "old" value to 0.0 so that we only 108 // Notice that we clap the "old" value to 0.0 so that we only
106 // reduce the portion of scrollDelta that's applied beyond 0.0. We 109 // reduce the portion of scrollDelta that's applied beyond 0.0. We
107 // do similar things for overscroll in the other direction. 110 // do similar things for overscroll in the other direction.
108 if (newScrollOffset < 0.0) { 111 if (newScrollOffset < 0.0) {
109 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0; 112 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0;
110 } else if (newScrollOffset > maxScroll) { 113 } else if (newScrollOffset > maxScroll) {
111 newScrollOffset -= (newScrollOffset - math.max(maxScroll, scrollOffset)) / 2.0; 114 newScrollOffset -= (newScrollOffset - math.max(maxScroll, scrollOffset)) / 2.0;
112 } 115 }
113 return newScrollOffset; 116 return newScrollOffset;
114 } 117 }
115 } 118 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/animation/mechanics.dart ('k') | sky/sdk/lib/editing/editable_text.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698