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

Side by Side Diff: content/renderer/input/input_handler_proxy.cc

Issue 713413002: Hook ScrollElasticityController to InputHandlerProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverse dtor order Created 6 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/input/input_handler_proxy.h" 5 #include "content/renderer/input/input_handler_proxy.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "content/common/input/did_overscroll_params.h" 12 #include "content/common/input/did_overscroll_params.h"
13 #include "content/common/input/web_input_event_traits.h" 13 #include "content/common/input/web_input_event_traits.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/renderer/input/input_handler_proxy_client.h" 15 #include "content/renderer/input/input_handler_proxy_client.h"
16 #include "content/renderer/input/input_scroll_elasticity_controller.h"
16 #include "third_party/WebKit/public/platform/Platform.h" 17 #include "third_party/WebKit/public/platform/Platform.h"
17 #include "third_party/WebKit/public/web/WebInputEvent.h" 18 #include "third_party/WebKit/public/web/WebInputEvent.h"
18 #include "ui/events/latency_info.h" 19 #include "ui/events/latency_info.h"
19 #include "ui/gfx/frame_time.h" 20 #include "ui/gfx/frame_time.h"
20 #include "ui/gfx/geometry/point_conversions.h" 21 #include "ui/gfx/geometry/point_conversions.h"
21 22
22 using blink::WebFloatPoint; 23 using blink::WebFloatPoint;
23 using blink::WebFloatSize; 24 using blink::WebFloatSize;
24 using blink::WebGestureEvent; 25 using blink::WebGestureEvent;
25 using blink::WebInputEvent; 26 using blink::WebInputEvent;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 gesture_scroll_on_impl_thread_(false), 155 gesture_scroll_on_impl_thread_(false),
155 gesture_pinch_on_impl_thread_(false), 156 gesture_pinch_on_impl_thread_(false),
156 fling_may_be_active_on_main_thread_(false), 157 fling_may_be_active_on_main_thread_(false),
157 disallow_horizontal_fling_scroll_(false), 158 disallow_horizontal_fling_scroll_(false),
158 disallow_vertical_fling_scroll_(false), 159 disallow_vertical_fling_scroll_(false),
159 has_fling_animation_started_(false) { 160 has_fling_animation_started_(false) {
160 DCHECK(client); 161 DCHECK(client);
161 input_handler_->BindToClient(this); 162 input_handler_->BindToClient(this);
162 smooth_scroll_enabled_ = CommandLine::ForCurrentProcess()->HasSwitch( 163 smooth_scroll_enabled_ = CommandLine::ForCurrentProcess()->HasSwitch(
163 switches::kEnableSmoothScrolling); 164 switches::kEnableSmoothScrolling);
165
166 #if defined(OS_MACOSX)
167 if (CommandLine::ForCurrentProcess()->HasSwitch(
168 switches::kEnableThreadedEventHandlingMac)) {
169 scroll_elasticity_controller_.reset(new InputScrollElasticityController(
170 input_handler_->CreateScrollElasticityHelper()));
171 }
172 #endif
164 } 173 }
165 174
166 InputHandlerProxy::~InputHandlerProxy() {} 175 InputHandlerProxy::~InputHandlerProxy() {}
167 176
168 void InputHandlerProxy::WillShutdown() { 177 void InputHandlerProxy::WillShutdown() {
178 scroll_elasticity_controller_.reset();
169 input_handler_ = NULL; 179 input_handler_ = NULL;
170 client_->WillShutdown(); 180 client_->WillShutdown();
171 } 181 }
172 182
173 InputHandlerProxy::EventDisposition 183 InputHandlerProxy::EventDisposition
174 InputHandlerProxy::HandleInputEventWithLatencyInfo( 184 InputHandlerProxy::HandleInputEventWithLatencyInfo(
175 const WebInputEvent& event, 185 const WebInputEvent& event,
176 ui::LatencyInfo* latency_info) { 186 ui::LatencyInfo* latency_info) {
177 DCHECK(input_handler_); 187 DCHECK(input_handler_);
178 188
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 CancelCurrentFling(); 279 CancelCurrentFling();
270 } 280 }
271 break; 281 break;
272 } 282 }
273 283
274 return DID_NOT_HANDLE; 284 return DID_NOT_HANDLE;
275 } 285 }
276 286
277 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel( 287 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel(
278 const WebMouseWheelEvent& wheel_event) { 288 const WebMouseWheelEvent& wheel_event) {
289 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE;
290 cc::InputHandlerScrollResult scroll_result;
291
279 if (wheel_event.scrollByPage) { 292 if (wheel_event.scrollByPage) {
280 // TODO(jamesr): We don't properly handle scroll by page in the compositor 293 // TODO(jamesr): We don't properly handle scroll by page in the compositor
281 // thread, so punt it to the main thread. http://crbug.com/236639 294 // thread, so punt it to the main thread. http://crbug.com/236639
282 return DID_NOT_HANDLE; 295 result = DID_NOT_HANDLE;
283 } 296 } else if (wheel_event.modifiers & WebInputEvent::ControlKey) {
284 if (wheel_event.modifiers & WebInputEvent::ControlKey) {
285 // Wheel events involving the control key never trigger scrolling, only 297 // Wheel events involving the control key never trigger scrolling, only
286 // event handlers. Forward to the main thread. 298 // event handlers. Forward to the main thread.
287 return DID_NOT_HANDLE; 299 result = DID_NOT_HANDLE;
288 } 300 } else if (smooth_scroll_enabled_) {
289 if (smooth_scroll_enabled_) {
290 cc::InputHandler::ScrollStatus scroll_status = 301 cc::InputHandler::ScrollStatus scroll_status =
291 input_handler_->ScrollAnimated( 302 input_handler_->ScrollAnimated(
292 gfx::Point(wheel_event.x, wheel_event.y), 303 gfx::Point(wheel_event.x, wheel_event.y),
293 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY)); 304 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY));
294 switch (scroll_status) { 305 switch (scroll_status) {
295 case cc::InputHandler::ScrollStarted: 306 case cc::InputHandler::ScrollStarted:
296 return DID_HANDLE; 307 result = DID_HANDLE;
308 break;
297 case cc::InputHandler::ScrollIgnored: 309 case cc::InputHandler::ScrollIgnored:
298 return DROP_EVENT; 310 result = DROP_EVENT;
299 default: 311 default:
300 return DID_NOT_HANDLE; 312 result = DID_NOT_HANDLE;
313 break;
314 }
315 } else {
316 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin(
317 gfx::Point(wheel_event.x, wheel_event.y), cc::InputHandler::Wheel);
318 switch (scroll_status) {
319 case cc::InputHandler::ScrollStarted: {
320 TRACE_EVENT_INSTANT2(
321 "input", "InputHandlerProxy::handle_input wheel scroll",
322 TRACE_EVENT_SCOPE_THREAD, "deltaX", -wheel_event.deltaX, "deltaY",
323 -wheel_event.deltaY);
324 gfx::Point scroll_point(wheel_event.x, wheel_event.y);
325 gfx::Vector2dF scroll_delta(-wheel_event.deltaX, -wheel_event.deltaY);
326 scroll_result = input_handler_->ScrollBy(scroll_point, scroll_delta);
327 HandleOverscroll(scroll_point, scroll_result);
328 input_handler_->ScrollEnd();
329 result = scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT;
330 break;
331 }
332 case cc::InputHandler::ScrollIgnored:
333 // TODO(jamesr): This should be DROP_EVENT, but in cases where we fail
334 // to properly sync scrollability it's safer to send the event to the
335 // main thread. Change back to DROP_EVENT once we have synchronization
336 // bugs sorted out.
337 result = DID_NOT_HANDLE;
338 break;
339 case cc::InputHandler::ScrollUnknown:
340 case cc::InputHandler::ScrollOnMainThread:
341 result = DID_NOT_HANDLE;
342 break;
343 case cc::InputHandler::ScrollStatusCount:
344 NOTREACHED();
345 break;
301 } 346 }
302 } 347 }
303 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin( 348
304 gfx::Point(wheel_event.x, wheel_event.y), cc::InputHandler::Wheel); 349 // Send the event and its disposition to the elasticity controller to update
305 switch (scroll_status) { 350 // the over-scroll animation. If the event is to be handled on the main
306 case cc::InputHandler::ScrollStarted: { 351 // thread, the event and its disposition will be sent to the elasticity
307 TRACE_EVENT_INSTANT2( 352 // controller after being handled on the main thread.
308 "input", 353 if (scroll_elasticity_controller_ && result != DID_NOT_HANDLE) {
309 "InputHandlerProxy::handle_input wheel scroll", 354 // Note that the call to the elasticity controller is made asynchronously,
310 TRACE_EVENT_SCOPE_THREAD, 355 // to minimize divergence between main thread and impl thread event
311 "deltaX", 356 // handling paths.
312 -wheel_event.deltaX, 357 base::MessageLoop::current()->PostTask(
313 "deltaY", 358 FROM_HERE,
314 -wheel_event.deltaY); 359 base::Bind(&InputScrollElasticityController::ObserveWheelEventAndResult,
315 gfx::Point scroll_point(wheel_event.x, wheel_event.y); 360 scroll_elasticity_controller_->GetWeakPtr(), wheel_event,
316 gfx::Vector2dF scroll_delta(-wheel_event.deltaX, -wheel_event.deltaY); 361 scroll_result));
317 cc::InputHandlerScrollResult scroll_result = input_handler_->ScrollBy(
318 scroll_point, scroll_delta);
319 HandleOverscroll(scroll_point, scroll_result);
320 input_handler_->ScrollEnd();
321 return scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT;
322 }
323 case cc::InputHandler::ScrollIgnored:
324 // TODO(jamesr): This should be DROP_EVENT, but in cases where we fail
325 // to properly sync scrollability it's safer to send the event to the
326 // main thread. Change back to DROP_EVENT once we have synchronization
327 // bugs sorted out.
328 return DID_NOT_HANDLE;
329 case cc::InputHandler::ScrollUnknown:
330 case cc::InputHandler::ScrollOnMainThread:
331 return DID_NOT_HANDLE;
332 case cc::InputHandler::ScrollStatusCount:
333 NOTREACHED();
334 break;
335 } 362 }
336 return DID_NOT_HANDLE; 363 return result;
337 } 364 }
338 365
339 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollBegin( 366 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollBegin(
340 const WebGestureEvent& gesture_event) { 367 const WebGestureEvent& gesture_event) {
341 DCHECK(!gesture_scroll_on_impl_thread_); 368 DCHECK(!gesture_scroll_on_impl_thread_);
342 #ifndef NDEBUG 369 #ifndef NDEBUG
343 DCHECK(!expect_scroll_update_end_); 370 DCHECK(!expect_scroll_update_end_);
344 expect_scroll_update_end_ = true; 371 expect_scroll_update_end_ = true;
345 #endif 372 #endif
346 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin( 373 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin(
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 const blink::WebGestureEvent& event) { 659 const blink::WebGestureEvent& event) {
633 TRACE_EVENT_INSTANT0("input", 660 TRACE_EVENT_INSTANT0("input",
634 "InputHandlerProxy::ExtendBoostedFlingTimeout", 661 "InputHandlerProxy::ExtendBoostedFlingTimeout",
635 TRACE_EVENT_SCOPE_THREAD); 662 TRACE_EVENT_SCOPE_THREAD);
636 deferred_fling_cancel_time_seconds_ = 663 deferred_fling_cancel_time_seconds_ =
637 event.timeStampSeconds + kFlingBoostTimeoutDelaySeconds; 664 event.timeStampSeconds + kFlingBoostTimeoutDelaySeconds;
638 last_fling_boost_event_ = event; 665 last_fling_boost_event_ = event;
639 } 666 }
640 667
641 void InputHandlerProxy::Animate(base::TimeTicks time) { 668 void InputHandlerProxy::Animate(base::TimeTicks time) {
669 if (scroll_elasticity_controller_)
670 scroll_elasticity_controller_->Animate(time);
671
642 if (!fling_curve_) 672 if (!fling_curve_)
643 return; 673 return;
644 674
645 double monotonic_time_sec = InSecondsF(time); 675 double monotonic_time_sec = InSecondsF(time);
646 676
647 if (deferred_fling_cancel_time_seconds_ && 677 if (deferred_fling_cancel_time_seconds_ &&
648 monotonic_time_sec > deferred_fling_cancel_time_seconds_) { 678 monotonic_time_sec > deferred_fling_cancel_time_seconds_) {
649 CancelCurrentFling(); 679 CancelCurrentFling();
650 return; 680 return;
651 } 681 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 // trigger a scroll, e.g., with a trivial time delta between fling updates. 887 // trigger a scroll, e.g., with a trivial time delta between fling updates.
858 // Return true in this case to prevent early fling termination. 888 // Return true in this case to prevent early fling termination.
859 if (std::abs(clipped_increment.width) < kScrollEpsilon && 889 if (std::abs(clipped_increment.width) < kScrollEpsilon &&
860 std::abs(clipped_increment.height) < kScrollEpsilon) 890 std::abs(clipped_increment.height) < kScrollEpsilon)
861 return true; 891 return true;
862 892
863 return did_scroll; 893 return did_scroll;
864 } 894 }
865 895
866 } // namespace content 896 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/input/input_handler_proxy.h ('k') | content/renderer/input/input_handler_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698