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 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 | 7 |
8 import '../animation/generators.dart'; | 8 import '../animation/generators.dart'; |
9 import '../animation/mechanics.dart'; | 9 import '../animation/mechanics.dart'; |
10 import '../animation/scroll_behavior.dart'; | 10 import '../animation/scroll_behavior.dart'; |
11 import '../theme/colors.dart' as colors; | 11 import '../theme/colors.dart' as colors; |
12 import '../theme/theme_data.dart'; | 12 import '../theme/theme_data.dart'; |
13 import '../theme/view_configuration.dart' as config; | 13 import '../theme/view_configuration.dart' as config; |
14 import 'basic.dart'; | 14 import 'basic.dart'; |
15 import 'material.dart'; | 15 import 'material.dart'; |
16 import 'theme.dart'; | 16 import 'theme.dart'; |
17 | 17 |
18 const double _kMillisecondsPerSecond = 1000.0; | 18 const double _kMillisecondsPerSecond = 1000.0; |
19 | 19 |
20 double _velocityForFlingGesture(sky.GestureEvent event) { | 20 double _velocityForFlingGesture(double eventVelocity) { |
21 return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity, | 21 return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity, |
22 -event.velocityY)) / _kMillisecondsPerSecond; | 22 eventVelocity)) / _kMillisecondsPerSecond; |
23 } | 23 } |
abarth-chromium
2015/07/02 15:27:21
eventVelocity.clamp(-config.kMaxFlingVelocity, con
hansmuller
2015/07/06 17:21:46
Done.
| |
24 | 24 |
25 abstract class ScrollClient { | 25 abstract class ScrollClient { |
26 bool ancestorScrolled(Scrollable ancestor); | 26 bool ancestorScrolled(Scrollable ancestor); |
27 } | 27 } |
28 | 28 |
29 enum ScrollDirection { vertical, horizontal } | |
30 | |
29 abstract class Scrollable extends Component { | 31 abstract class Scrollable extends Component { |
30 | 32 |
31 Scrollable({ String key, Color this.backgroundColor }) | 33 Scrollable({ |
32 : super(key: key, stateful: true); | 34 String key, |
35 this.backgroundColor, | |
36 this.direction: ScrollDirection.vertical | |
37 }) : super(key: key, stateful: true); | |
33 | 38 |
34 Color backgroundColor; | 39 Color backgroundColor; |
40 ScrollDirection direction; | |
35 | 41 |
36 void syncFields(Scrollable source) { | 42 void syncFields(Scrollable source) { |
37 backgroundColor = source.backgroundColor; | 43 backgroundColor = source.backgroundColor; |
44 direction == source.direction; | |
38 } | 45 } |
39 | 46 |
40 Color get _nonNullBackgroundColor { | 47 Color get _nonNullBackgroundColor { |
41 if (backgroundColor != null) | 48 if (backgroundColor != null) |
42 return backgroundColor; | 49 return backgroundColor; |
43 switch (Theme.of(this).brightness) { | 50 switch (Theme.of(this).brightness) { |
44 case ThemeBrightness.light: | 51 case ThemeBrightness.light: |
45 return colors.Grey[50]; | 52 return colors.Grey[50]; |
46 case ThemeBrightness.dark: | 53 case ThemeBrightness.dark: |
47 return colors.Grey[850]; | 54 return colors.Grey[850]; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 void _handlePointerDown(_) { | 159 void _handlePointerDown(_) { |
153 _stopSimulation(); | 160 _stopSimulation(); |
154 } | 161 } |
155 | 162 |
156 void _handlePointerUpOrCancel(_) { | 163 void _handlePointerUpOrCancel(_) { |
157 if (_simulation == null) | 164 if (_simulation == null) |
158 _startSimulation(_createParticle()); | 165 _startSimulation(_createParticle()); |
159 } | 166 } |
160 | 167 |
161 void _handleScrollUpdate(sky.GestureEvent event) { | 168 void _handleScrollUpdate(sky.GestureEvent event) { |
162 scrollBy(-event.dy); | 169 scrollBy(direction == ScrollDirection.horizontal ? event.dx : -event.dy); |
163 } | 170 } |
164 | 171 |
165 void _handleFlingStart(sky.GestureEvent event) { | 172 void _handleFlingStart(sky.GestureEvent event) { |
166 _startSimulation(_createParticle(_velocityForFlingGesture(event))); | 173 double eventVelocity = direction == ScrollDirection.horizontal |
174 ? -event.velocityX | |
175 : -event.velocityY; | |
176 _startSimulation(_createParticle(_velocityForFlingGesture(eventVelocity))); | |
167 } | 177 } |
168 | 178 |
169 void _handleFlingCancel(sky.GestureEvent event) { | 179 void _handleFlingCancel(sky.GestureEvent event) { |
170 _startSimulation(_createParticle()); | 180 _startSimulation(_createParticle()); |
171 } | 181 } |
172 | 182 |
173 void _handleWheel(sky.WheelEvent event) { | 183 void _handleWheel(sky.WheelEvent event) { |
174 scrollBy(-event.offsetY); | 184 scrollBy(-event.offsetY); |
175 } | 185 } |
176 | 186 |
177 } | 187 } |
OLD | NEW |