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

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

Issue 2265393002: Refactor compositor event handling path to be callback-based (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dtapuska's review 2, use WeakPtr, tweak comments 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
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
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // Minimum velocity for the active touch scroll to preserve (boost) an active 54 // Minimum velocity for the active touch scroll to preserve (boost) an active
55 // fling for which cancellation has been deferred. 55 // fling for which cancellation has been deferred.
56 const double kMinBoostTouchScrollSpeedSquare = 150 * 150.; 56 const double kMinBoostTouchScrollSpeedSquare = 150 * 150.;
57 57
58 // Timeout window after which the active fling will be cancelled if no animation 58 // Timeout window after which the active fling will be cancelled if no animation
59 // ticks, scrolls or flings of sufficient velocity relative to the current fling 59 // ticks, scrolls or flings of sufficient velocity relative to the current fling
60 // are received. The default value on Android native views is 40ms, but we use a 60 // are received. The default value on Android native views is 40ms, but we use a
61 // slightly increased value to accomodate small IPC message delays. 61 // slightly increased value to accomodate small IPC message delays.
62 const double kFlingBoostTimeoutDelaySeconds = 0.05; 62 const double kFlingBoostTimeoutDelaySeconds = 0.05;
63 63
64 const bool kBundleAckWithTriggeringEvent = true;
tdresser 2016/09/01 16:58:45 The point of this bool is just to make this easy t
chongz 2016/09/01 20:13:13 Removed. I was just trying to avoid passing raw '
tdresser 2016/09/01 21:08:10 Yup, that is general good practice. I'd tend to do
65
64 gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { 66 gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) {
65 return gfx::Vector2dF(-increment.width, -increment.height); 67 return gfx::Vector2dF(-increment.width, -increment.height);
66 } 68 }
67 69
68 double InSecondsF(const base::TimeTicks& time) { 70 double InSecondsF(const base::TimeTicks& time) {
69 return (time - base::TimeTicks()).InSecondsF(); 71 return (time - base::TimeTicks()).InSecondsF();
70 } 72 }
71 73
72 bool ShouldSuppressScrollForFlingBoosting( 74 bool ShouldSuppressScrollForFlingBoosting(
73 const gfx::Vector2dF& current_fling_velocity, 75 const gfx::Vector2dF& current_fling_velocity,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 expect_scroll_update_end_(false), 241 expect_scroll_update_end_(false),
240 #endif 242 #endif
241 gesture_scroll_on_impl_thread_(false), 243 gesture_scroll_on_impl_thread_(false),
242 gesture_pinch_on_impl_thread_(false), 244 gesture_pinch_on_impl_thread_(false),
243 fling_may_be_active_on_main_thread_(false), 245 fling_may_be_active_on_main_thread_(false),
244 disallow_horizontal_fling_scroll_(false), 246 disallow_horizontal_fling_scroll_(false),
245 disallow_vertical_fling_scroll_(false), 247 disallow_vertical_fling_scroll_(false),
246 has_fling_animation_started_(false), 248 has_fling_animation_started_(false),
247 smooth_scroll_enabled_(false), 249 smooth_scroll_enabled_(false),
248 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()), 250 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()),
249 touch_start_result_(kEventDispositionUndefined) { 251 touch_start_result_(kEventDispositionUndefined),
252 current_overscroll_params_(nullptr) {
250 DCHECK(client); 253 DCHECK(client);
251 input_handler_->BindToClient(this); 254 input_handler_->BindToClient(this);
252 cc::ScrollElasticityHelper* scroll_elasticity_helper = 255 cc::ScrollElasticityHelper* scroll_elasticity_helper =
253 input_handler_->CreateScrollElasticityHelper(); 256 input_handler_->CreateScrollElasticityHelper();
254 if (scroll_elasticity_helper) { 257 if (scroll_elasticity_helper) {
255 scroll_elasticity_controller_.reset( 258 scroll_elasticity_controller_.reset(
256 new InputScrollElasticityController(scroll_elasticity_helper)); 259 new InputScrollElasticityController(scroll_elasticity_helper));
257 } 260 }
258 } 261 }
259 262
260 InputHandlerProxy::~InputHandlerProxy() {} 263 InputHandlerProxy::~InputHandlerProxy() {}
261 264
262 void InputHandlerProxy::WillShutdown() { 265 void InputHandlerProxy::WillShutdown() {
263 scroll_elasticity_controller_.reset(); 266 scroll_elasticity_controller_.reset();
264 input_handler_ = NULL; 267 input_handler_ = NULL;
265 client_->WillShutdown(); 268 client_->WillShutdown();
266 } 269 }
267 270
268 InputHandlerProxy::EventDisposition 271 void InputHandlerProxy::HandleInputEventWithLatencyInfo(
269 InputHandlerProxy::HandleInputEventWithLatencyInfo( 272 ScopedWebInputEvent event,
270 const WebInputEvent& event, 273 const LatencyInfo& latency_info,
271 ui::LatencyInfo* latency_info) { 274 const EventDispositionCallback& callback) {
272 DCHECK(input_handler_); 275 DCHECK(input_handler_);
273 276
274 if (uma_latency_reporting_enabled_) 277 if (uma_latency_reporting_enabled_)
275 ReportInputEventLatencyUma(event, *latency_info); 278 ReportInputEventLatencyUma(*event, latency_info);
276 279
277 TRACE_EVENT_WITH_FLOW1("input,benchmark", 280 TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow",
278 "LatencyInfo.Flow", 281 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
279 TRACE_ID_DONT_MANGLE(latency_info->trace_id()),
280 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, 282 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
281 "step", "HandleInputEventImpl"); 283 "step", "HandleInputEventImpl");
282 284
285 ui::LatencyInfo monitored_latency_info = latency_info;
283 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor = 286 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
284 input_handler_->CreateLatencyInfoSwapPromiseMonitor(latency_info); 287 input_handler_->CreateLatencyInfoSwapPromiseMonitor(
285 InputHandlerProxy::EventDisposition disposition = HandleInputEvent(event); 288 &monitored_latency_info);
286 return disposition; 289
290 current_overscroll_params_.reset();
291 InputHandlerProxy::EventDisposition disposition = HandleInputEvent(*event);
292 callback.Run(disposition, std::move(event), monitored_latency_info,
293 std::move(current_overscroll_params_));
287 } 294 }
288 295
289 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleInputEvent( 296 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleInputEvent(
290 const WebInputEvent& event) { 297 const WebInputEvent& event) {
291 DCHECK(input_handler_); 298 DCHECK(input_handler_);
292 299
293 if (FilterInputEventForFlingBoosting(event)) 300 if (FilterInputEventForFlingBoosting(event))
294 return DID_HANDLE; 301 return DID_HANDLE;
295 302
296 switch (event.type) { 303 switch (event.type) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 526
520 cc::ScrollStateData scroll_state_update_data; 527 cc::ScrollStateData scroll_state_update_data;
521 scroll_state_update_data.delta_x = scroll_delta.x(); 528 scroll_state_update_data.delta_x = scroll_delta.x();
522 scroll_state_update_data.delta_y = scroll_delta.y(); 529 scroll_state_update_data.delta_y = scroll_delta.y();
523 scroll_state_update_data.position_x = wheel_event.x; 530 scroll_state_update_data.position_x = wheel_event.x;
524 scroll_state_update_data.position_y = wheel_event.y; 531 scroll_state_update_data.position_y = wheel_event.y;
525 cc::ScrollState scroll_state_update(scroll_state_update_data); 532 cc::ScrollState scroll_state_update(scroll_state_update_data);
526 533
527 scroll_result = input_handler_->ScrollBy(&scroll_state_update); 534 scroll_result = input_handler_->ScrollBy(&scroll_state_update);
528 HandleOverscroll(gfx::Point(wheel_event.x, wheel_event.y), 535 HandleOverscroll(gfx::Point(wheel_event.x, wheel_event.y),
529 scroll_result); 536 scroll_result, !kBundleAckWithTriggeringEvent);
530 537
531 cc::ScrollStateData scroll_state_end_data; 538 cc::ScrollStateData scroll_state_end_data;
532 scroll_state_end_data.is_ending = true; 539 scroll_state_end_data.is_ending = true;
533 cc::ScrollState scroll_state_end(scroll_state_end_data); 540 cc::ScrollState scroll_state_end(scroll_state_end_data);
534 input_handler_->ScrollEnd(&scroll_state_end); 541 input_handler_->ScrollEnd(&scroll_state_end);
535 542
536 result = scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT; 543 result = scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT;
537 break; 544 break;
538 } 545 }
539 case cc::InputHandler::SCROLL_IGNORED: 546 case cc::InputHandler::SCROLL_IGNORED:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: 638 case cc::InputHandler::SCROLL_ON_IMPL_THREAD:
632 return DID_HANDLE; 639 return DID_HANDLE;
633 case cc::InputHandler::SCROLL_IGNORED: 640 case cc::InputHandler::SCROLL_IGNORED:
634 return DROP_EVENT; 641 return DROP_EVENT;
635 default: 642 default:
636 return DID_NOT_HANDLE; 643 return DID_NOT_HANDLE;
637 } 644 }
638 } 645 }
639 cc::InputHandlerScrollResult scroll_result = 646 cc::InputHandlerScrollResult scroll_result =
640 input_handler_->ScrollBy(&scroll_state); 647 input_handler_->ScrollBy(&scroll_state);
641 HandleOverscroll(scroll_point, scroll_result); 648 HandleOverscroll(scroll_point, scroll_result, kBundleAckWithTriggeringEvent);
642 649
643 if (scroll_elasticity_controller_) 650 if (scroll_elasticity_controller_)
644 HandleScrollElasticityOverscroll(gesture_event, scroll_result); 651 HandleScrollElasticityOverscroll(gesture_event, scroll_result);
645 652
646 return scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT; 653 return scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT;
647 } 654 }
648 655
649 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollEnd( 656 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollEnd(
650 const WebGestureEvent& gesture_event) { 657 const WebGestureEvent& gesture_event) {
651 #ifndef NDEBUG 658 #ifndef NDEBUG
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 void InputHandlerProxy::SynchronouslyZoomBy(float magnify_delta, 1103 void InputHandlerProxy::SynchronouslyZoomBy(float magnify_delta,
1097 const gfx::Point& anchor) { 1104 const gfx::Point& anchor) {
1098 DCHECK(synchronous_input_handler_); 1105 DCHECK(synchronous_input_handler_);
1099 input_handler_->PinchGestureBegin(); 1106 input_handler_->PinchGestureBegin();
1100 input_handler_->PinchGestureUpdate(magnify_delta, anchor); 1107 input_handler_->PinchGestureUpdate(magnify_delta, anchor);
1101 input_handler_->PinchGestureEnd(); 1108 input_handler_->PinchGestureEnd();
1102 } 1109 }
1103 1110
1104 void InputHandlerProxy::HandleOverscroll( 1111 void InputHandlerProxy::HandleOverscroll(
1105 const gfx::Point& causal_event_viewport_point, 1112 const gfx::Point& causal_event_viewport_point,
1106 const cc::InputHandlerScrollResult& scroll_result) { 1113 const cc::InputHandlerScrollResult& scroll_result,
1114 bool bundle_ack_with_triggering_event) {
tdresser 2016/09/01 16:58:45 Can we tweak this naming? bundle_overscroll_params
chongz 2016/09/01 20:13:13 Done.
1107 DCHECK(client_); 1115 DCHECK(client_);
1108 if (!scroll_result.did_overscroll_root) 1116 if (!scroll_result.did_overscroll_root)
1109 return; 1117 return;
1110 1118
1111 TRACE_EVENT2("input", 1119 TRACE_EVENT2("input",
1112 "InputHandlerProxy::DidOverscroll", 1120 "InputHandlerProxy::DidOverscroll",
1113 "dx", 1121 "dx",
1114 scroll_result.unused_scroll_delta.x(), 1122 scroll_result.unused_scroll_delta.x(),
1115 "dy", 1123 "dy",
1116 scroll_result.unused_scroll_delta.y()); 1124 scroll_result.unused_scroll_delta.y());
1117 1125
1118 if (fling_curve_) { 1126 if (fling_curve_) {
1119 static const int kFlingOverscrollThreshold = 1; 1127 static const int kFlingOverscrollThreshold = 1;
1120 disallow_horizontal_fling_scroll_ |= 1128 disallow_horizontal_fling_scroll_ |=
1121 std::abs(scroll_result.accumulated_root_overscroll.x()) >= 1129 std::abs(scroll_result.accumulated_root_overscroll.x()) >=
1122 kFlingOverscrollThreshold; 1130 kFlingOverscrollThreshold;
1123 disallow_vertical_fling_scroll_ |= 1131 disallow_vertical_fling_scroll_ |=
1124 std::abs(scroll_result.accumulated_root_overscroll.y()) >= 1132 std::abs(scroll_result.accumulated_root_overscroll.y()) >=
1125 kFlingOverscrollThreshold; 1133 kFlingOverscrollThreshold;
1126 } 1134 }
1127 1135
1136 if (bundle_ack_with_triggering_event) {
1137 // Bundle overscroll message with triggering event response, saving an IPC.
1138 current_overscroll_params_.reset(new DidOverscrollParams());
1139 current_overscroll_params_->accumulated_overscroll =
1140 scroll_result.accumulated_root_overscroll;
1141 current_overscroll_params_->latest_overscroll_delta =
1142 scroll_result.unused_scroll_delta;
1143 current_overscroll_params_->current_fling_velocity =
1144 ToClientScrollIncrement(current_fling_velocity_);
1145 current_overscroll_params_->causal_event_viewport_point =
1146 gfx::PointF(causal_event_viewport_point);
1147 return;
1148 }
1149
1128 client_->DidOverscroll(scroll_result.accumulated_root_overscroll, 1150 client_->DidOverscroll(scroll_result.accumulated_root_overscroll,
1129 scroll_result.unused_scroll_delta, 1151 scroll_result.unused_scroll_delta,
1130 ToClientScrollIncrement(current_fling_velocity_), 1152 ToClientScrollIncrement(current_fling_velocity_),
1131 gfx::PointF(causal_event_viewport_point)); 1153 gfx::PointF(causal_event_viewport_point));
1132 } 1154 }
1133 1155
1134 bool InputHandlerProxy::CancelCurrentFling() { 1156 bool InputHandlerProxy::CancelCurrentFling() {
1135 if (CancelCurrentFlingWithoutNotifyingClient()) { 1157 if (CancelCurrentFlingWithoutNotifyingClient()) {
1136 client_->DidStopFlinging(); 1158 client_->DidStopFlinging();
1137 return true; 1159 return true;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 clipped_increment = ToClientScrollIncrement(clipped_increment); 1312 clipped_increment = ToClientScrollIncrement(clipped_increment);
1291 cc::ScrollStateData scroll_state_data; 1313 cc::ScrollStateData scroll_state_data;
1292 scroll_state_data.delta_x = clipped_increment.width; 1314 scroll_state_data.delta_x = clipped_increment.width;
1293 scroll_state_data.delta_y = clipped_increment.height; 1315 scroll_state_data.delta_y = clipped_increment.height;
1294 scroll_state_data.velocity_x = clipped_velocity.width; 1316 scroll_state_data.velocity_x = clipped_velocity.width;
1295 scroll_state_data.velocity_y = clipped_velocity.height; 1317 scroll_state_data.velocity_y = clipped_velocity.height;
1296 scroll_state_data.is_in_inertial_phase = true; 1318 scroll_state_data.is_in_inertial_phase = true;
1297 cc::ScrollState scroll_state(scroll_state_data); 1319 cc::ScrollState scroll_state(scroll_state_data);
1298 cc::InputHandlerScrollResult scroll_result = 1320 cc::InputHandlerScrollResult scroll_result =
1299 input_handler_->ScrollBy(&scroll_state); 1321 input_handler_->ScrollBy(&scroll_state);
1300 HandleOverscroll(fling_parameters_.point, scroll_result); 1322 HandleOverscroll(fling_parameters_.point, scroll_result,
1323 !kBundleAckWithTriggeringEvent);
1301 did_scroll = scroll_result.did_scroll; 1324 did_scroll = scroll_result.did_scroll;
1302 } break; 1325 } break;
1303 case blink::WebGestureDeviceUninitialized: 1326 case blink::WebGestureDeviceUninitialized:
1304 NOTREACHED(); 1327 NOTREACHED();
1305 return false; 1328 return false;
1306 } 1329 }
1307 1330
1308 if (did_scroll) { 1331 if (did_scroll) {
1309 fling_parameters_.cumulativeScroll.width += clipped_increment.width; 1332 fling_parameters_.cumulativeScroll.width += clipped_increment.width;
1310 fling_parameters_.cumulativeScroll.height += clipped_increment.height; 1333 fling_parameters_.cumulativeScroll.height += clipped_increment.height;
(...skipping 18 matching lines...) Expand all
1329 // is made asynchronously, to minimize divergence between main thread and 1352 // is made asynchronously, to minimize divergence between main thread and
1330 // impl thread event handling paths. 1353 // impl thread event handling paths.
1331 base::ThreadTaskRunnerHandle::Get()->PostTask( 1354 base::ThreadTaskRunnerHandle::Get()->PostTask(
1332 FROM_HERE, 1355 FROM_HERE,
1333 base::Bind(&InputScrollElasticityController::ObserveGestureEventAndResult, 1356 base::Bind(&InputScrollElasticityController::ObserveGestureEventAndResult,
1334 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, 1357 scroll_elasticity_controller_->GetWeakPtr(), gesture_event,
1335 scroll_result)); 1358 scroll_result));
1336 } 1359 }
1337 1360
1338 } // namespace ui 1361 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698