| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 InputScrollElasticityController::~InputScrollElasticityController() { | 99 InputScrollElasticityController::~InputScrollElasticityController() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 base::WeakPtr<InputScrollElasticityController> | 102 base::WeakPtr<InputScrollElasticityController> |
| 103 InputScrollElasticityController::GetWeakPtr() { | 103 InputScrollElasticityController::GetWeakPtr() { |
| 104 if (helper_) | 104 if (helper_) |
| 105 return weak_factory_.GetWeakPtr(); | 105 return weak_factory_.GetWeakPtr(); |
| 106 return base::WeakPtr<InputScrollElasticityController>(); | 106 return base::WeakPtr<InputScrollElasticityController>(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void InputScrollElasticityController::ObserveWheelEventAndResult( | |
| 110 const blink::WebMouseWheelEvent& wheel_event, | |
| 111 const cc::InputHandlerScrollResult& scroll_result) { | |
| 112 // We should only get PhaseMayBegin or PhaseBegan events while in the | |
| 113 // Inactive or MomentumAnimated states, but in case we get bad input (e.g, | |
| 114 // abbreviated by tab-switch), always re-set the state to ActiveScrolling | |
| 115 // when those events are received. | |
| 116 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseMayBegin || | |
| 117 wheel_event.phase == blink::WebMouseWheelEvent::PhaseBegan) { | |
| 118 scroll_velocity = gfx::Vector2dF(); | |
| 119 last_scroll_event_timestamp_ = base::TimeTicks(); | |
| 120 state_ = kStateActiveScroll; | |
| 121 pending_overscroll_delta_ = gfx::Vector2dF(); | |
| 122 return; | |
| 123 } | |
| 124 | |
| 125 gfx::Vector2dF event_delta(-wheel_event.deltaX, -wheel_event.deltaY); | |
| 126 base::TimeTicks event_timestamp = | |
| 127 base::TimeTicks() + | |
| 128 base::TimeDelta::FromSecondsD(wheel_event.timeStampSeconds); | |
| 129 switch (state_) { | |
| 130 case kStateInactive: { | |
| 131 // The PhaseMayBegin and PhaseBegan cases are handled at the top of the | |
| 132 // function. | |
| 133 if (wheel_event.momentumPhase == blink::WebMouseWheelEvent::PhaseBegan) | |
| 134 state_ = kStateMomentumScroll; | |
| 135 break; | |
| 136 } | |
| 137 case kStateActiveScroll: | |
| 138 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseChanged) { | |
| 139 UpdateVelocity(event_delta, event_timestamp); | |
| 140 Overscroll(event_delta, scroll_result.unused_scroll_delta); | |
| 141 } else if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseEnded || | |
| 142 wheel_event.phase == | |
| 143 blink::WebMouseWheelEvent::PhaseCancelled) { | |
| 144 if (helper_->StretchAmount().IsZero()) { | |
| 145 EnterStateInactive(); | |
| 146 } else { | |
| 147 EnterStateMomentumAnimated(event_timestamp); | |
| 148 } | |
| 149 } | |
| 150 break; | |
| 151 case kStateMomentumScroll: | |
| 152 if (wheel_event.momentumPhase == | |
| 153 blink::WebMouseWheelEvent::PhaseChanged) { | |
| 154 UpdateVelocity(event_delta, event_timestamp); | |
| 155 Overscroll(event_delta, scroll_result.unused_scroll_delta); | |
| 156 if (!helper_->StretchAmount().IsZero()) { | |
| 157 EnterStateMomentumAnimated(event_timestamp); | |
| 158 } | |
| 159 } else if (wheel_event.momentumPhase == | |
| 160 blink::WebMouseWheelEvent::PhaseEnded) { | |
| 161 EnterStateInactive(); | |
| 162 } | |
| 163 case kStateMomentumAnimated: | |
| 164 // The PhaseMayBegin and PhaseBegan cases are handled at the top of the | |
| 165 // function. | |
| 166 break; | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 void InputScrollElasticityController::ObserveGestureEventAndResult( | 109 void InputScrollElasticityController::ObserveGestureEventAndResult( |
| 171 const blink::WebGestureEvent& gesture_event, | 110 const blink::WebGestureEvent& gesture_event, |
| 172 const cc::InputHandlerScrollResult& scroll_result) { | 111 const cc::InputHandlerScrollResult& scroll_result) { |
| 173 base::TimeTicks event_timestamp = | 112 base::TimeTicks event_timestamp = |
| 174 base::TimeTicks() + | 113 base::TimeTicks() + |
| 175 base::TimeDelta::FromSecondsD(gesture_event.timeStampSeconds); | 114 base::TimeDelta::FromSecondsD(gesture_event.timeStampSeconds); |
| 176 | 115 |
| 177 switch (gesture_event.type) { | 116 switch (gesture_event.type) { |
| 178 case blink::WebInputEvent::GestureScrollBegin: { | 117 case blink::WebInputEvent::GestureScrollBegin: { |
| 179 if (gesture_event.data.scrollBegin.synthetic) | 118 if (gesture_event.data.scrollBegin.synthetic) |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 break; | 417 break; |
| 479 default: | 418 default: |
| 480 // These cases should not be hit because the stretch must be zero in the | 419 // These cases should not be hit because the stretch must be zero in the |
| 481 // Inactive and MomentumScroll states. | 420 // Inactive and MomentumScroll states. |
| 482 NOTREACHED(); | 421 NOTREACHED(); |
| 483 break; | 422 break; |
| 484 } | 423 } |
| 485 } | 424 } |
| 486 | 425 |
| 487 } // namespace ui | 426 } // namespace ui |
| OLD | NEW |