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

Side by Side Diff: ui/events/blink/input_scroll_elasticity_controller.cc

Issue 1749343004: Implement Wheel Gesture Scrolling on OSX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ensure only high precision scroll begins are used Created 4 years, 9 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
OLDNEW
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
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 if (gesture_event.data.scrollBegin.deltaHintUnits ==
185 blink::WebGestureEvent::PrecisePixels) {
186 scroll_velocity = gfx::Vector2dF();
187 last_scroll_event_timestamp_ = base::TimeTicks();
188 state_ = kStateActiveScroll;
189 pending_overscroll_delta_ = gfx::Vector2dF();
190 }
191 break;
192 }
193 case blink::WebInputEvent::GestureScrollUpdate: {
194 gfx::Vector2dF event_delta(-gesture_event.data.scrollUpdate.deltaX,
195 -gesture_event.data.scrollUpdate.deltaY);
196 switch (state_) {
197 case kStateMomentumAnimated:
198 case kStateInactive:
199 break;
200 case kStateActiveScroll:
201 case kStateMomentumScroll:
202 UpdateVelocity(event_delta, event_timestamp);
203 Overscroll(event_delta, scroll_result.unused_scroll_delta);
204 if (gesture_event.data.scrollUpdate.inertial &&
205 !helper_->StretchAmount().IsZero()) {
206 EnterStateMomentumAnimated(event_timestamp);
207 }
208 break;
209 }
210 break;
211 }
212 case blink::WebInputEvent::GestureScrollEnd: {
213 if (gesture_event.data.scrollEnd.synthetic)
214 return;
215 switch (state_) {
216 case kStateMomentumAnimated:
217 case kStateInactive:
218 break;
219 case kStateActiveScroll:
220 case kStateMomentumScroll:
221 if (helper_->StretchAmount().IsZero()) {
222 EnterStateInactive();
223 } else {
224 EnterStateMomentumAnimated(event_timestamp);
225 }
226 break;
227 }
228 break;
229 }
230 default:
231 break;
232 }
233 }
234
170 void InputScrollElasticityController::UpdateVelocity( 235 void InputScrollElasticityController::UpdateVelocity(
171 const gfx::Vector2dF& event_delta, 236 const gfx::Vector2dF& event_delta,
172 const base::TimeTicks& event_timestamp) { 237 const base::TimeTicks& event_timestamp) {
173 float time_delta = 238 float time_delta =
174 (event_timestamp - last_scroll_event_timestamp_).InSecondsF(); 239 (event_timestamp - last_scroll_event_timestamp_).InSecondsF();
175 if (time_delta < kScrollVelocityZeroingTimeout && time_delta > 0) { 240 if (time_delta < kScrollVelocityZeroingTimeout && time_delta > 0) {
176 scroll_velocity = gfx::Vector2dF(event_delta.x() / time_delta, 241 scroll_velocity = gfx::Vector2dF(event_delta.x() / time_delta,
177 event_delta.y() / time_delta); 242 event_delta.y() / time_delta);
178 } else { 243 } else {
179 scroll_velocity = gfx::Vector2dF(); 244 scroll_velocity = gfx::Vector2dF();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 break; 474 break;
410 default: 475 default:
411 // These cases should not be hit because the stretch must be zero in the 476 // These cases should not be hit because the stretch must be zero in the
412 // Inactive and MomentumScroll states. 477 // Inactive and MomentumScroll states.
413 NOTREACHED(); 478 NOTREACHED();
414 break; 479 break;
415 } 480 }
416 } 481 }
417 482
418 } // namespace ui 483 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/input_scroll_elasticity_controller.h ('k') | ui/events/blink/input_scroll_elasticity_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698