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

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: 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;
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 expect_scroll_update_end_(false), 235 expect_scroll_update_end_(false),
234 #endif 236 #endif
235 gesture_scroll_on_impl_thread_(false), 237 gesture_scroll_on_impl_thread_(false),
236 gesture_pinch_on_impl_thread_(false), 238 gesture_pinch_on_impl_thread_(false),
237 fling_may_be_active_on_main_thread_(false), 239 fling_may_be_active_on_main_thread_(false),
238 disallow_horizontal_fling_scroll_(false), 240 disallow_horizontal_fling_scroll_(false),
239 disallow_vertical_fling_scroll_(false), 241 disallow_vertical_fling_scroll_(false),
240 has_fling_animation_started_(false), 242 has_fling_animation_started_(false),
241 smooth_scroll_enabled_(false), 243 smooth_scroll_enabled_(false),
242 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()), 244 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()),
243 touch_start_result_(kEventDispositionUndefined) { 245 touch_start_result_(kEventDispositionUndefined),
246 current_overscroll_params_(nullptr) {
244 DCHECK(client); 247 DCHECK(client);
245 input_handler_->BindToClient(this); 248 input_handler_->BindToClient(this);
246 cc::ScrollElasticityHelper* scroll_elasticity_helper = 249 cc::ScrollElasticityHelper* scroll_elasticity_helper =
247 input_handler_->CreateScrollElasticityHelper(); 250 input_handler_->CreateScrollElasticityHelper();
248 if (scroll_elasticity_helper) { 251 if (scroll_elasticity_helper) {
249 scroll_elasticity_controller_.reset( 252 scroll_elasticity_controller_.reset(
250 new InputScrollElasticityController(scroll_elasticity_helper)); 253 new InputScrollElasticityController(scroll_elasticity_helper));
251 } 254 }
252 } 255 }
253 256
254 InputHandlerProxy::~InputHandlerProxy() {} 257 InputHandlerProxy::~InputHandlerProxy() {}
255 258
256 void InputHandlerProxy::WillShutdown() { 259 void InputHandlerProxy::WillShutdown() {
257 scroll_elasticity_controller_.reset(); 260 scroll_elasticity_controller_.reset();
258 input_handler_ = NULL; 261 input_handler_ = NULL;
259 client_->WillShutdown(); 262 client_->WillShutdown();
260 } 263 }
261 264
262 InputHandlerProxy::EventDisposition 265 void InputHandlerProxy::HandleInputEventWithLatencyInfo(
263 InputHandlerProxy::HandleInputEventWithLatencyInfo( 266 ScopedWebInputEvent event,
264 const WebInputEvent& event, 267 const LatencyInfo& latency_info,
265 ui::LatencyInfo* latency_info) { 268 const EventDispositionCallback& callback) {
266 DCHECK(input_handler_); 269 DCHECK(input_handler_);
267 270
268 if (uma_latency_reporting_enabled_) 271 if (uma_latency_reporting_enabled_)
269 ReportInputEventLatencyUma(event, *latency_info); 272 ReportInputEventLatencyUma(*event, latency_info);
270 273
271 TRACE_EVENT_WITH_FLOW1("input,benchmark", 274 TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow",
272 "LatencyInfo.Flow", 275 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
273 TRACE_ID_DONT_MANGLE(latency_info->trace_id()),
274 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, 276 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
275 "step", "HandleInputEventImpl"); 277 "step", "HandleInputEventImpl");
276 278
279 ui::LatencyInfo monitored_latency_info = latency_info;
277 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor = 280 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
278 input_handler_->CreateLatencyInfoSwapPromiseMonitor(latency_info); 281 input_handler_->CreateLatencyInfoSwapPromiseMonitor(
279 InputHandlerProxy::EventDisposition disposition = HandleInputEvent(event); 282 &monitored_latency_info);
280 return disposition; 283
284 current_overscroll_params_.reset();
285 InputHandlerProxy::EventDisposition disposition = HandleInputEvent(*event);
286 callback.Run(disposition, std::move(event), monitored_latency_info,
287 std::move(current_overscroll_params_));
chongz 2016/08/23 04:35:24 Handles event immediately.
281 } 288 }
282 289
283 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleInputEvent( 290 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleInputEvent(
284 const WebInputEvent& event) { 291 const WebInputEvent& event) {
285 DCHECK(input_handler_); 292 DCHECK(input_handler_);
286 293
287 if (FilterInputEventForFlingBoosting(event)) 294 if (FilterInputEventForFlingBoosting(event))
288 return DID_HANDLE; 295 return DID_HANDLE;
289 296
290 switch (event.type) { 297 switch (event.type) {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 539
533 cc::ScrollStateData scroll_state_update_data; 540 cc::ScrollStateData scroll_state_update_data;
534 scroll_state_update_data.delta_x = scroll_delta.x(); 541 scroll_state_update_data.delta_x = scroll_delta.x();
535 scroll_state_update_data.delta_y = scroll_delta.y(); 542 scroll_state_update_data.delta_y = scroll_delta.y();
536 scroll_state_update_data.position_x = wheel_event.x; 543 scroll_state_update_data.position_x = wheel_event.x;
537 scroll_state_update_data.position_y = wheel_event.y; 544 scroll_state_update_data.position_y = wheel_event.y;
538 cc::ScrollState scroll_state_update(scroll_state_update_data); 545 cc::ScrollState scroll_state_update(scroll_state_update_data);
539 546
540 scroll_result = input_handler_->ScrollBy(&scroll_state_update); 547 scroll_result = input_handler_->ScrollBy(&scroll_state_update);
541 HandleOverscroll(gfx::Point(wheel_event.x, wheel_event.y), 548 HandleOverscroll(gfx::Point(wheel_event.x, wheel_event.y),
542 scroll_result); 549 scroll_result, !kBundleAckWithTriggeringEvent);
543 550
544 cc::ScrollStateData scroll_state_end_data; 551 cc::ScrollStateData scroll_state_end_data;
545 scroll_state_end_data.is_ending = true; 552 scroll_state_end_data.is_ending = true;
546 cc::ScrollState scroll_state_end(scroll_state_end_data); 553 cc::ScrollState scroll_state_end(scroll_state_end_data);
547 input_handler_->ScrollEnd(&scroll_state_end); 554 input_handler_->ScrollEnd(&scroll_state_end);
548 555
549 result = scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT; 556 result = scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT;
550 break; 557 break;
551 } 558 }
552 case cc::InputHandler::SCROLL_IGNORED: 559 case cc::InputHandler::SCROLL_IGNORED:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: 650 case cc::InputHandler::SCROLL_ON_IMPL_THREAD:
644 return DID_HANDLE; 651 return DID_HANDLE;
645 case cc::InputHandler::SCROLL_IGNORED: 652 case cc::InputHandler::SCROLL_IGNORED:
646 return DROP_EVENT; 653 return DROP_EVENT;
647 default: 654 default:
648 return DID_NOT_HANDLE; 655 return DID_NOT_HANDLE;
649 } 656 }
650 } 657 }
651 cc::InputHandlerScrollResult scroll_result = 658 cc::InputHandlerScrollResult scroll_result =
652 input_handler_->ScrollBy(&scroll_state); 659 input_handler_->ScrollBy(&scroll_state);
653 HandleOverscroll(scroll_point, scroll_result); 660 HandleOverscroll(scroll_point, scroll_result, kBundleAckWithTriggeringEvent);
654 661
655 if (scroll_elasticity_controller_) 662 if (scroll_elasticity_controller_)
656 HandleScrollElasticityOverscroll(gesture_event, scroll_result); 663 HandleScrollElasticityOverscroll(gesture_event, scroll_result);
657 664
658 return scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT; 665 return scroll_result.did_scroll ? DID_HANDLE : DROP_EVENT;
659 } 666 }
660 667
661 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollEnd( 668 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureScrollEnd(
662 const WebGestureEvent& gesture_event) { 669 const WebGestureEvent& gesture_event) {
663 #ifndef NDEBUG 670 #ifndef NDEBUG
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 void InputHandlerProxy::SynchronouslyZoomBy(float magnify_delta, 1115 void InputHandlerProxy::SynchronouslyZoomBy(float magnify_delta,
1109 const gfx::Point& anchor) { 1116 const gfx::Point& anchor) {
1110 DCHECK(synchronous_input_handler_); 1117 DCHECK(synchronous_input_handler_);
1111 input_handler_->PinchGestureBegin(); 1118 input_handler_->PinchGestureBegin();
1112 input_handler_->PinchGestureUpdate(magnify_delta, anchor); 1119 input_handler_->PinchGestureUpdate(magnify_delta, anchor);
1113 input_handler_->PinchGestureEnd(); 1120 input_handler_->PinchGestureEnd();
1114 } 1121 }
1115 1122
1116 void InputHandlerProxy::HandleOverscroll( 1123 void InputHandlerProxy::HandleOverscroll(
1117 const gfx::Point& causal_event_viewport_point, 1124 const gfx::Point& causal_event_viewport_point,
1118 const cc::InputHandlerScrollResult& scroll_result) { 1125 const cc::InputHandlerScrollResult& scroll_result,
1126 bool bundle_ack_with_triggering_event) {
1119 DCHECK(client_); 1127 DCHECK(client_);
1120 if (!scroll_result.did_overscroll_root) 1128 if (!scroll_result.did_overscroll_root)
1121 return; 1129 return;
1122 1130
1123 TRACE_EVENT2("input", 1131 TRACE_EVENT2("input",
1124 "InputHandlerProxy::DidOverscroll", 1132 "InputHandlerProxy::DidOverscroll",
1125 "dx", 1133 "dx",
1126 scroll_result.unused_scroll_delta.x(), 1134 scroll_result.unused_scroll_delta.x(),
1127 "dy", 1135 "dy",
1128 scroll_result.unused_scroll_delta.y()); 1136 scroll_result.unused_scroll_delta.y());
1129 1137
1130 if (fling_curve_) { 1138 if (fling_curve_) {
1131 static const int kFlingOverscrollThreshold = 1; 1139 static const int kFlingOverscrollThreshold = 1;
1132 disallow_horizontal_fling_scroll_ |= 1140 disallow_horizontal_fling_scroll_ |=
1133 std::abs(scroll_result.accumulated_root_overscroll.x()) >= 1141 std::abs(scroll_result.accumulated_root_overscroll.x()) >=
1134 kFlingOverscrollThreshold; 1142 kFlingOverscrollThreshold;
1135 disallow_vertical_fling_scroll_ |= 1143 disallow_vertical_fling_scroll_ |=
1136 std::abs(scroll_result.accumulated_root_overscroll.y()) >= 1144 std::abs(scroll_result.accumulated_root_overscroll.y()) >=
1137 kFlingOverscrollThreshold; 1145 kFlingOverscrollThreshold;
1138 } 1146 }
1139 1147
1148 if (bundle_ack_with_triggering_event) {
1149 // Bundle overscroll message with triggering event response, saving an IPC.
1150 current_overscroll_params_.reset(new DidOverscrollParams());
1151 current_overscroll_params_->accumulated_overscroll =
1152 scroll_result.accumulated_root_overscroll;
1153 current_overscroll_params_->latest_overscroll_delta =
1154 scroll_result.unused_scroll_delta;
1155 current_overscroll_params_->current_fling_velocity =
1156 ToClientScrollIncrement(current_fling_velocity_);
1157 current_overscroll_params_->causal_event_viewport_point =
1158 gfx::PointF(causal_event_viewport_point);
1159 }
1160
1140 client_->DidOverscroll(scroll_result.accumulated_root_overscroll, 1161 client_->DidOverscroll(scroll_result.accumulated_root_overscroll,
1141 scroll_result.unused_scroll_delta, 1162 scroll_result.unused_scroll_delta,
1142 ToClientScrollIncrement(current_fling_velocity_), 1163 ToClientScrollIncrement(current_fling_velocity_),
1143 gfx::PointF(causal_event_viewport_point)); 1164 gfx::PointF(causal_event_viewport_point),
1165 bundle_ack_with_triggering_event);
chongz 2016/08/23 04:35:24 Have to pass raw data instead of |DidOverscrollPar
1144 } 1166 }
1145 1167
1146 bool InputHandlerProxy::CancelCurrentFling() { 1168 bool InputHandlerProxy::CancelCurrentFling() {
1147 if (CancelCurrentFlingWithoutNotifyingClient()) { 1169 if (CancelCurrentFlingWithoutNotifyingClient()) {
1148 client_->DidStopFlinging(); 1170 client_->DidStopFlinging();
1149 return true; 1171 return true;
1150 } 1172 }
1151 return false; 1173 return false;
1152 } 1174 }
1153 1175
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 clipped_increment = ToClientScrollIncrement(clipped_increment); 1324 clipped_increment = ToClientScrollIncrement(clipped_increment);
1303 cc::ScrollStateData scroll_state_data; 1325 cc::ScrollStateData scroll_state_data;
1304 scroll_state_data.delta_x = clipped_increment.width; 1326 scroll_state_data.delta_x = clipped_increment.width;
1305 scroll_state_data.delta_y = clipped_increment.height; 1327 scroll_state_data.delta_y = clipped_increment.height;
1306 scroll_state_data.velocity_x = clipped_velocity.width; 1328 scroll_state_data.velocity_x = clipped_velocity.width;
1307 scroll_state_data.velocity_y = clipped_velocity.height; 1329 scroll_state_data.velocity_y = clipped_velocity.height;
1308 scroll_state_data.is_in_inertial_phase = true; 1330 scroll_state_data.is_in_inertial_phase = true;
1309 cc::ScrollState scroll_state(scroll_state_data); 1331 cc::ScrollState scroll_state(scroll_state_data);
1310 cc::InputHandlerScrollResult scroll_result = 1332 cc::InputHandlerScrollResult scroll_result =
1311 input_handler_->ScrollBy(&scroll_state); 1333 input_handler_->ScrollBy(&scroll_state);
1312 HandleOverscroll(fling_parameters_.point, scroll_result); 1334 HandleOverscroll(fling_parameters_.point, scroll_result,
1335 !kBundleAckWithTriggeringEvent);
1313 did_scroll = scroll_result.did_scroll; 1336 did_scroll = scroll_result.did_scroll;
1314 } break; 1337 } break;
1315 case blink::WebGestureDeviceUninitialized: 1338 case blink::WebGestureDeviceUninitialized:
1316 NOTREACHED(); 1339 NOTREACHED();
1317 return false; 1340 return false;
1318 } 1341 }
1319 1342
1320 if (did_scroll) { 1343 if (did_scroll) {
1321 fling_parameters_.cumulativeScroll.width += clipped_increment.width; 1344 fling_parameters_.cumulativeScroll.width += clipped_increment.width;
1322 fling_parameters_.cumulativeScroll.height += clipped_increment.height; 1345 fling_parameters_.cumulativeScroll.height += clipped_increment.height;
(...skipping 18 matching lines...) Expand all
1341 // is made asynchronously, to minimize divergence between main thread and 1364 // is made asynchronously, to minimize divergence between main thread and
1342 // impl thread event handling paths. 1365 // impl thread event handling paths.
1343 base::ThreadTaskRunnerHandle::Get()->PostTask( 1366 base::ThreadTaskRunnerHandle::Get()->PostTask(
1344 FROM_HERE, 1367 FROM_HERE,
1345 base::Bind(&InputScrollElasticityController::ObserveGestureEventAndResult, 1368 base::Bind(&InputScrollElasticityController::ObserveGestureEventAndResult,
1346 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, 1369 scroll_elasticity_controller_->GetWeakPtr(), gesture_event,
1347 scroll_result)); 1370 scroll_result));
1348 } 1371 }
1349 1372
1350 } // namespace ui 1373 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698