OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "ui/events/blink/input_scroll_elasticity_controller.h" | 5 #include "ui/events/blink/input_scroll_elasticity_controller.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 blink::WebMouseWheelEvent::PhaseEnded) { | 160 blink::WebMouseWheelEvent::PhaseEnded) { |
161 EnterStateInactive(); | 161 EnterStateInactive(); |
162 } | 162 } |
163 case kStateMomentumAnimated: | 163 case kStateMomentumAnimated: |
164 // The PhaseMayBegin and PhaseBegan cases are handled at the top of the | 164 // The PhaseMayBegin and PhaseBegan cases are handled at the top of the |
165 // function. | 165 // function. |
166 break; | 166 break; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
| 170 void InputScrollElasticityController::ObserveGestureEventAndResult( |
| 171 const blink::WebGestureEvent& gesture_event, |
| 172 const cc::InputHandlerScrollResult& scroll_result) { |
| 173 base::TimeTicks event_timestamp = |
| 174 base::TimeTicks() + |
| 175 base::TimeDelta::FromSecondsD(gesture_event.timeStampSeconds); |
| 176 |
| 177 switch (gesture_event.type) { |
| 178 case blink::WebInputEvent::GestureScrollBegin: { |
| 179 if (gesture_event.data.scrollBegin.synthetic) |
| 180 return; |
| 181 if (gesture_event.data.scrollBegin.inertial) { |
| 182 if (state_ == kStateInactive) |
| 183 state_ = kStateMomentumScroll; |
| 184 } else { |
| 185 scroll_velocity = gfx::Vector2dF(); |
| 186 last_scroll_event_timestamp_ = base::TimeTicks(); |
| 187 state_ = kStateActiveScroll; |
| 188 pending_overscroll_delta_ = gfx::Vector2dF(); |
| 189 } |
| 190 break; |
| 191 } |
| 192 case blink::WebInputEvent::GestureScrollUpdate: { |
| 193 gfx::Vector2dF event_delta(-gesture_event.data.scrollUpdate.deltaX, |
| 194 -gesture_event.data.scrollUpdate.deltaY); |
| 195 switch (state_) { |
| 196 case kStateMomentumAnimated: |
| 197 case kStateInactive: |
| 198 break; |
| 199 case kStateActiveScroll: |
| 200 case kStateMomentumScroll: |
| 201 UpdateVelocity(event_delta, event_timestamp); |
| 202 Overscroll(event_delta, scroll_result.unused_scroll_delta); |
| 203 if (gesture_event.data.scrollUpdate.inertial && |
| 204 !helper_->StretchAmount().IsZero()) { |
| 205 EnterStateMomentumAnimated(event_timestamp); |
| 206 } |
| 207 break; |
| 208 } |
| 209 break; |
| 210 } |
| 211 case blink::WebInputEvent::GestureScrollEnd: { |
| 212 if (gesture_event.data.scrollEnd.synthetic) |
| 213 return; |
| 214 switch (state_) { |
| 215 case kStateMomentumAnimated: |
| 216 case kStateInactive: |
| 217 break; |
| 218 case kStateActiveScroll: |
| 219 case kStateMomentumScroll: |
| 220 if (helper_->StretchAmount().IsZero()) { |
| 221 EnterStateInactive(); |
| 222 } else { |
| 223 EnterStateMomentumAnimated(event_timestamp); |
| 224 } |
| 225 break; |
| 226 } |
| 227 break; |
| 228 } |
| 229 default: |
| 230 break; |
| 231 } |
| 232 } |
| 233 |
170 void InputScrollElasticityController::UpdateVelocity( | 234 void InputScrollElasticityController::UpdateVelocity( |
171 const gfx::Vector2dF& event_delta, | 235 const gfx::Vector2dF& event_delta, |
172 const base::TimeTicks& event_timestamp) { | 236 const base::TimeTicks& event_timestamp) { |
173 float time_delta = | 237 float time_delta = |
174 (event_timestamp - last_scroll_event_timestamp_).InSecondsF(); | 238 (event_timestamp - last_scroll_event_timestamp_).InSecondsF(); |
175 if (time_delta < kScrollVelocityZeroingTimeout && time_delta > 0) { | 239 if (time_delta < kScrollVelocityZeroingTimeout && time_delta > 0) { |
176 scroll_velocity = gfx::Vector2dF(event_delta.x() / time_delta, | 240 scroll_velocity = gfx::Vector2dF(event_delta.x() / time_delta, |
177 event_delta.y() / time_delta); | 241 event_delta.y() / time_delta); |
178 } else { | 242 } else { |
179 scroll_velocity = gfx::Vector2dF(); | 243 scroll_velocity = gfx::Vector2dF(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 break; | 473 break; |
410 default: | 474 default: |
411 // These cases should not be hit because the stretch must be zero in the | 475 // These cases should not be hit because the stretch must be zero in the |
412 // Inactive and MomentumScroll states. | 476 // Inactive and MomentumScroll states. |
413 NOTREACHED(); | 477 NOTREACHED(); |
414 break; | 478 break; |
415 } | 479 } |
416 } | 480 } |
417 | 481 |
418 } // namespace ui | 482 } // namespace ui |
OLD | NEW |