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

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

Issue 2341873002: Handle touchpad flings with passive event listeners on compositor thread. (Closed)
Patch Set: Add dcheck for blimp Created 4 years, 3 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
« no previous file with comments | « ui/events/blink/input_handler_proxy.h ('k') | ui/events/blink/input_handler_proxy_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/events/blink/input_handler_proxy.h" 5 #include "ui/events/blink/input_handler_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "cc/input/main_thread_scrolling_reason.h" 19 #include "cc/input/main_thread_scrolling_reason.h"
20 #include "third_party/WebKit/public/platform/WebInputEvent.h" 20 #include "third_party/WebKit/public/platform/WebInputEvent.h"
21 #include "ui/events/blink/did_overscroll_params.h" 21 #include "ui/events/blink/did_overscroll_params.h"
22 #include "ui/events/blink/input_handler_proxy_client.h" 22 #include "ui/events/blink/input_handler_proxy_client.h"
23 #include "ui/events/blink/input_scroll_elasticity_controller.h" 23 #include "ui/events/blink/input_scroll_elasticity_controller.h"
24 #include "ui/events/blink/web_input_event_traits.h"
24 #include "ui/events/latency_info.h" 25 #include "ui/events/latency_info.h"
25 #include "ui/gfx/geometry/point_conversions.h" 26 #include "ui/gfx/geometry/point_conversions.h"
26 27
27 using blink::WebFloatPoint; 28 using blink::WebFloatPoint;
28 using blink::WebFloatSize; 29 using blink::WebFloatSize;
29 using blink::WebGestureEvent; 30 using blink::WebGestureEvent;
30 using blink::WebInputEvent; 31 using blink::WebInputEvent;
31 using blink::WebMouseEvent; 32 using blink::WebMouseEvent;
32 using blink::WebMouseWheelEvent; 33 using blink::WebMouseWheelEvent;
33 using blink::WebPoint; 34 using blink::WebPoint;
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 return DID_NOT_HANDLE; 481 return DID_NOT_HANDLE;
481 case cc::EventListenerProperties::kNone: 482 case cc::EventListenerProperties::kNone:
482 return DROP_EVENT; 483 return DROP_EVENT;
483 default: 484 default:
484 NOTREACHED(); 485 NOTREACHED();
485 return DROP_EVENT; 486 return DROP_EVENT;
486 } 487 }
487 } 488 }
488 489
489 InputHandlerProxy::EventDisposition InputHandlerProxy::ScrollByMouseWheel( 490 InputHandlerProxy::EventDisposition InputHandlerProxy::ScrollByMouseWheel(
490 const WebMouseWheelEvent& wheel_event) { 491 const WebMouseWheelEvent& wheel_event,
491 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE; 492 cc::EventListenerProperties listener_properties) {
492 cc::InputHandlerScrollResult scroll_result; 493 DCHECK(listener_properties == cc::EventListenerProperties::kPassive ||
494 listener_properties == cc::EventListenerProperties::kNone);
493 495
494 // TODO(ccameron): The rail information should be pushed down into 496 // TODO(ccameron): The rail information should be pushed down into
495 // InputHandler. 497 // InputHandler.
496 gfx::Vector2dF scroll_delta( 498 gfx::Vector2dF scroll_delta(
497 wheel_event.railsMode != WebInputEvent::RailsModeVertical 499 wheel_event.railsMode != WebInputEvent::RailsModeVertical
498 ? -wheel_event.deltaX 500 ? -wheel_event.deltaX
499 : 0, 501 : 0,
500 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal 502 wheel_event.railsMode != WebInputEvent::RailsModeHorizontal
501 ? -wheel_event.deltaY 503 ? -wheel_event.deltaY
502 : 0); 504 : 0);
503 505
504 if (wheel_event.scrollByPage) { 506 if (wheel_event.scrollByPage) {
505 // TODO(jamesr): We don't properly handle scroll by page in the compositor 507 // TODO(jamesr): We don't properly handle scroll by page in the compositor
506 // thread, so punt it to the main thread. http://crbug.com/236639 508 // thread, so punt it to the main thread. http://crbug.com/236639
507 result = DID_NOT_HANDLE;
508 RecordMainThreadScrollingReasons( 509 RecordMainThreadScrollingReasons(
509 blink::WebGestureDeviceTouchpad, 510 blink::WebGestureDeviceTouchpad,
510 cc::MainThreadScrollingReason::kPageBasedScrolling); 511 cc::MainThreadScrollingReason::kPageBasedScrolling);
512 return DID_NOT_HANDLE;
511 } else { 513 } else {
512 DCHECK(!ShouldAnimate(wheel_event.hasPreciseScrollingDeltas)); 514 DCHECK(!ShouldAnimate(wheel_event.hasPreciseScrollingDeltas));
513 cc::ScrollStateData scroll_state_begin_data; 515 cc::ScrollStateData scroll_state_begin_data;
514 scroll_state_begin_data.position_x = wheel_event.x; 516 scroll_state_begin_data.position_x = wheel_event.x;
515 scroll_state_begin_data.position_y = wheel_event.y; 517 scroll_state_begin_data.position_y = wheel_event.y;
516 scroll_state_begin_data.is_beginning = true; 518 scroll_state_begin_data.is_beginning = true;
517 cc::ScrollState scroll_state_begin(scroll_state_begin_data); 519 cc::ScrollState scroll_state_begin(scroll_state_begin_data);
518 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin( 520 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin(
519 &scroll_state_begin, cc::InputHandler::WHEEL); 521 &scroll_state_begin, cc::InputHandler::WHEEL);
520 522
521 RecordMainThreadScrollingReasons( 523 RecordMainThreadScrollingReasons(
522 blink::WebGestureDeviceTouchpad, 524 blink::WebGestureDeviceTouchpad,
523 scroll_status.main_thread_scrolling_reasons); 525 scroll_status.main_thread_scrolling_reasons);
524 526
525 switch (scroll_status.thread) { 527 switch (scroll_status.thread) {
526 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: { 528 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: {
527 TRACE_EVENT_INSTANT2("input", 529 TRACE_EVENT_INSTANT2("input",
528 "InputHandlerProxy::handle_input wheel scroll", 530 "InputHandlerProxy::handle_input wheel scroll",
529 TRACE_EVENT_SCOPE_THREAD, "deltaX", 531 TRACE_EVENT_SCOPE_THREAD, "deltaX",
530 scroll_delta.x(), "deltaY", scroll_delta.y()); 532 scroll_delta.x(), "deltaY", scroll_delta.y());
531 533
532 cc::ScrollStateData scroll_state_update_data; 534 cc::ScrollStateData scroll_state_update_data;
533 scroll_state_update_data.delta_x = scroll_delta.x(); 535 scroll_state_update_data.delta_x = scroll_delta.x();
534 scroll_state_update_data.delta_y = scroll_delta.y(); 536 scroll_state_update_data.delta_y = scroll_delta.y();
535 scroll_state_update_data.position_x = wheel_event.x; 537 scroll_state_update_data.position_x = wheel_event.x;
536 scroll_state_update_data.position_y = wheel_event.y; 538 scroll_state_update_data.position_y = wheel_event.y;
537 cc::ScrollState scroll_state_update(scroll_state_update_data); 539 cc::ScrollState scroll_state_update(scroll_state_update_data);
538 540
539 scroll_result = input_handler_->ScrollBy(&scroll_state_update); 541 cc::InputHandlerScrollResult scroll_result =
542 input_handler_->ScrollBy(&scroll_state_update);
540 HandleOverscroll(gfx::Point(wheel_event.x, wheel_event.y), 543 HandleOverscroll(gfx::Point(wheel_event.x, wheel_event.y),
541 scroll_result, false); 544 scroll_result, false);
542 545
543 cc::ScrollStateData scroll_state_end_data; 546 cc::ScrollStateData scroll_state_end_data;
544 scroll_state_end_data.is_ending = true; 547 scroll_state_end_data.is_ending = true;
545 cc::ScrollState scroll_state_end(scroll_state_end_data); 548 cc::ScrollState scroll_state_end(scroll_state_end_data);
546 input_handler_->ScrollEnd(&scroll_state_end); 549 input_handler_->ScrollEnd(&scroll_state_end);
547 550
548 result = scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT; 551 if (scroll_result.did_scroll) {
549 break; 552 return listener_properties == cc::EventListenerProperties::kPassive
553 ? DID_HANDLE_NON_BLOCKING
554 : DID_HANDLE;
555 }
556 return DROP_EVENT;
550 } 557 }
551 case cc::InputHandler::SCROLL_IGNORED: 558 case cc::InputHandler::SCROLL_IGNORED:
552 // TODO(jamesr): This should be DROP_EVENT, but in cases where we fail 559 // TODO(jamesr): This should be DROP_EVENT, but in cases where we fail
553 // to properly sync scrollability it's safer to send the event to the 560 // to properly sync scrollability it's safer to send the event to the
554 // main thread. Change back to DROP_EVENT once we have synchronization 561 // main thread. Change back to DROP_EVENT once we have synchronization
555 // bugs sorted out. 562 // bugs sorted out.
556 result = DID_NOT_HANDLE; 563 return DID_NOT_HANDLE;
557 break;
558 case cc::InputHandler::SCROLL_UNKNOWN: 564 case cc::InputHandler::SCROLL_UNKNOWN:
559 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: 565 case cc::InputHandler::SCROLL_ON_MAIN_THREAD:
560 result = DID_NOT_HANDLE; 566 return DID_NOT_HANDLE;
561 break; 567 default:
568 NOTREACHED();
569 return DID_NOT_HANDLE;
562 } 570 }
563 } 571 }
564 return result;
565 } 572 }
566 573
567 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollBegin( 574 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollBegin(
568 const WebGestureEvent& gesture_event) { 575 const WebGestureEvent& gesture_event) {
569 if (gesture_scroll_on_impl_thread_) 576 if (gesture_scroll_on_impl_thread_)
570 CancelCurrentFling(); 577 CancelCurrentFling();
571 578
572 #ifndef NDEBUG 579 #ifndef NDEBUG
573 DCHECK(!expect_scroll_update_end_); 580 DCHECK(!expect_scroll_update_end_);
574 expect_scroll_update_end_ = true; 581 expect_scroll_update_end_ = true;
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 input_handler_->SetNeedsAnimateInput(); 1230 input_handler_->SetNeedsAnimateInput();
1224 } 1231 }
1225 1232
1226 bool InputHandlerProxy::TouchpadFlingScroll( 1233 bool InputHandlerProxy::TouchpadFlingScroll(
1227 const WebFloatSize& increment) { 1234 const WebFloatSize& increment) {
1228 InputHandlerProxy::EventDisposition disposition; 1235 InputHandlerProxy::EventDisposition disposition;
1229 cc::EventListenerProperties properties = 1236 cc::EventListenerProperties properties =
1230 input_handler_->GetEventListenerProperties( 1237 input_handler_->GetEventListenerProperties(
1231 cc::EventListenerClass::kMouseWheel); 1238 cc::EventListenerClass::kMouseWheel);
1232 switch (properties) { 1239 switch (properties) {
1233 case cc::EventListenerProperties::kPassive:
1234 disposition = DID_HANDLE_NON_BLOCKING;
1235 break;
1236 case cc::EventListenerProperties::kBlocking: 1240 case cc::EventListenerProperties::kBlocking:
1237 disposition = DID_NOT_HANDLE; 1241 disposition = DID_NOT_HANDLE;
1238 break; 1242 break;
1243 case cc::EventListenerProperties::kPassive:
1239 case cc::EventListenerProperties::kNone: { 1244 case cc::EventListenerProperties::kNone: {
1240 WebMouseWheelEvent synthetic_wheel; 1245 WebMouseWheelEvent synthetic_wheel;
1241 synthetic_wheel.type = WebInputEvent::MouseWheel; 1246 synthetic_wheel.type = WebInputEvent::MouseWheel;
1242 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now()); 1247 synthetic_wheel.timeStampSeconds = InSecondsF(base::TimeTicks::Now());
1243 synthetic_wheel.deltaX = increment.width; 1248 synthetic_wheel.deltaX = increment.width;
1244 synthetic_wheel.deltaY = increment.height; 1249 synthetic_wheel.deltaY = increment.height;
1245 synthetic_wheel.hasPreciseScrollingDeltas = true; 1250 synthetic_wheel.hasPreciseScrollingDeltas = true;
1246 synthetic_wheel.x = fling_parameters_.point.x; 1251 synthetic_wheel.x = fling_parameters_.point.x;
1247 synthetic_wheel.y = fling_parameters_.point.y; 1252 synthetic_wheel.y = fling_parameters_.point.y;
1248 synthetic_wheel.globalX = fling_parameters_.globalPoint.x; 1253 synthetic_wheel.globalX = fling_parameters_.globalPoint.x;
1249 synthetic_wheel.globalY = fling_parameters_.globalPoint.y; 1254 synthetic_wheel.globalY = fling_parameters_.globalPoint.y;
1250 synthetic_wheel.modifiers = fling_parameters_.modifiers; 1255 synthetic_wheel.modifiers = fling_parameters_.modifiers;
1251 1256
1252 disposition = ScrollByMouseWheel(synthetic_wheel); 1257 disposition = ScrollByMouseWheel(synthetic_wheel, properties);
1258
1259 // Send the event over to the main thread.
1260 if (disposition == DID_HANDLE_NON_BLOCKING) {
1261 client_->DispatchNonBlockingEventToMainThread(
1262 ui::WebInputEventTraits::Clone(synthetic_wheel), ui::LatencyInfo());
1263 }
1253 break; 1264 break;
1254 } 1265 }
1255 default: 1266 default:
1256 NOTREACHED(); 1267 NOTREACHED();
1257 return false; 1268 return false;
1258 } 1269 }
1259 1270
1260 switch (disposition) { 1271 switch (disposition) {
1261 case DID_HANDLE: 1272 case DID_HANDLE:
1273 case DID_HANDLE_NON_BLOCKING:
1262 return true; 1274 return true;
1263 case DROP_EVENT: 1275 case DROP_EVENT:
1264 break; 1276 break;
1265 case DID_HANDLE_NON_BLOCKING:
1266 // TODO(dtapuska): Process the fling on the compositor thread
1267 // but post the events to the main thread; for now just pass it to the
1268 // main thread.
1269 case DID_NOT_HANDLE: 1277 case DID_NOT_HANDLE:
1270 TRACE_EVENT_INSTANT0("input", 1278 TRACE_EVENT_INSTANT0("input",
1271 "InputHandlerProxy::scrollBy::AbortFling", 1279 "InputHandlerProxy::scrollBy::AbortFling",
1272 TRACE_EVENT_SCOPE_THREAD); 1280 TRACE_EVENT_SCOPE_THREAD);
1273 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the 1281 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the
1274 // main thread. In this case we need to schedule a commit and transfer the 1282 // main thread. In this case we need to schedule a commit and transfer the
1275 // fling curve over to the main thread and run the rest of the wheels from 1283 // fling curve over to the main thread and run the rest of the wheels from
1276 // there. This can happen when flinging a page that contains a scrollable 1284 // there. This can happen when flinging a page that contains a scrollable
1277 // subarea that we can't scroll on the thread if the fling starts outside 1285 // subarea that we can't scroll on the thread if the fling starts outside
1278 // the subarea but then is flung "under" the pointer. 1286 // the subarea but then is flung "under" the pointer.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 // is made asynchronously, to minimize divergence between main thread and 1370 // is made asynchronously, to minimize divergence between main thread and
1363 // impl thread event handling paths. 1371 // impl thread event handling paths.
1364 base::ThreadTaskRunnerHandle::Get()->PostTask( 1372 base::ThreadTaskRunnerHandle::Get()->PostTask(
1365 FROM_HERE, 1373 FROM_HERE,
1366 base::Bind(&InputScrollElasticityController::ObserveGestureEventAndResult, 1374 base::Bind(&InputScrollElasticityController::ObserveGestureEventAndResult,
1367 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, 1375 scroll_elasticity_controller_->GetWeakPtr(), gesture_event,
1368 scroll_result)); 1376 scroll_result));
1369 } 1377 }
1370 1378
1371 } // namespace ui 1379 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/input_handler_proxy.h ('k') | ui/events/blink/input_handler_proxy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698