| OLD | NEW |
| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 double InSecondsF(const base::TimeTicks& time) { | 77 double InSecondsF(const base::TimeTicks& time) { |
| 78 return (time - base::TimeTicks()).InSecondsF(); | 78 return (time - base::TimeTicks()).InSecondsF(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool ShouldSuppressScrollForFlingBoosting( | 81 bool ShouldSuppressScrollForFlingBoosting( |
| 82 const gfx::Vector2dF& current_fling_velocity, | 82 const gfx::Vector2dF& current_fling_velocity, |
| 83 const WebGestureEvent& scroll_update_event, | 83 const WebGestureEvent& scroll_update_event, |
| 84 double time_since_last_boost_event, | 84 double time_since_last_boost_event, |
| 85 double time_since_last_fling_animate) { | 85 double time_since_last_fling_animate) { |
| 86 DCHECK_EQ(WebInputEvent::GestureScrollUpdate, scroll_update_event.type); | 86 DCHECK_EQ(WebInputEvent::GestureScrollUpdate, scroll_update_event.type()); |
| 87 | 87 |
| 88 gfx::Vector2dF dx(scroll_update_event.data.scrollUpdate.deltaX, | 88 gfx::Vector2dF dx(scroll_update_event.data.scrollUpdate.deltaX, |
| 89 scroll_update_event.data.scrollUpdate.deltaY); | 89 scroll_update_event.data.scrollUpdate.deltaY); |
| 90 if (gfx::DotProduct(current_fling_velocity, dx) <= 0) | 90 if (gfx::DotProduct(current_fling_velocity, dx) <= 0) |
| 91 return false; | 91 return false; |
| 92 | 92 |
| 93 if (time_since_last_fling_animate > kFlingBoostTimeoutDelaySeconds) | 93 if (time_since_last_fling_animate > kFlingBoostTimeoutDelaySeconds) |
| 94 return false; | 94 return false; |
| 95 | 95 |
| 96 if (time_since_last_boost_event < 0.001) | 96 if (time_since_last_boost_event < 0.001) |
| 97 return true; | 97 return true; |
| 98 | 98 |
| 99 // TODO(jdduke): Use |scroll_update_event.data.scrollUpdate.velocity{X,Y}|. | 99 // TODO(jdduke): Use |scroll_update_event.data.scrollUpdate.velocity{X,Y}|. |
| 100 // The scroll must be of sufficient velocity to maintain the active fling. | 100 // The scroll must be of sufficient velocity to maintain the active fling. |
| 101 const gfx::Vector2dF scroll_velocity = | 101 const gfx::Vector2dF scroll_velocity = |
| 102 gfx::ScaleVector2d(dx, 1. / time_since_last_boost_event); | 102 gfx::ScaleVector2d(dx, 1. / time_since_last_boost_event); |
| 103 if (scroll_velocity.LengthSquared() < kMinBoostTouchScrollSpeedSquare) | 103 if (scroll_velocity.LengthSquared() < kMinBoostTouchScrollSpeedSquare) |
| 104 return false; | 104 return false; |
| 105 | 105 |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool ShouldBoostFling(const gfx::Vector2dF& current_fling_velocity, | 109 bool ShouldBoostFling(const gfx::Vector2dF& current_fling_velocity, |
| 110 const WebGestureEvent& fling_start_event) { | 110 const WebGestureEvent& fling_start_event) { |
| 111 DCHECK_EQ(WebInputEvent::GestureFlingStart, fling_start_event.type); | 111 DCHECK_EQ(WebInputEvent::GestureFlingStart, fling_start_event.type()); |
| 112 | 112 |
| 113 gfx::Vector2dF new_fling_velocity( | 113 gfx::Vector2dF new_fling_velocity( |
| 114 fling_start_event.data.flingStart.velocityX, | 114 fling_start_event.data.flingStart.velocityX, |
| 115 fling_start_event.data.flingStart.velocityY); | 115 fling_start_event.data.flingStart.velocityY); |
| 116 | 116 |
| 117 if (gfx::DotProduct(current_fling_velocity, new_fling_velocity) <= 0) | 117 if (gfx::DotProduct(current_fling_velocity, new_fling_velocity) <= 0) |
| 118 return false; | 118 return false; |
| 119 | 119 |
| 120 if (current_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) | 120 if (current_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) |
| 121 return false; | 121 return false; |
| 122 | 122 |
| 123 if (new_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) | 123 if (new_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) |
| 124 return false; | 124 return false; |
| 125 | 125 |
| 126 return true; | 126 return true; |
| 127 } | 127 } |
| 128 | 128 |
| 129 WebGestureEvent ObtainGestureScrollBegin(const WebGestureEvent& event) { | 129 WebGestureEvent ObtainGestureScrollBegin(const WebGestureEvent& event) { |
| 130 WebGestureEvent scroll_begin_event = event; | 130 WebGestureEvent scroll_begin_event = event; |
| 131 scroll_begin_event.setType(WebInputEvent::GestureScrollBegin); | 131 scroll_begin_event.setType(WebInputEvent::GestureScrollBegin); |
| 132 scroll_begin_event.data.scrollBegin.deltaXHint = 0; | 132 scroll_begin_event.data.scrollBegin.deltaXHint = 0; |
| 133 scroll_begin_event.data.scrollBegin.deltaYHint = 0; | 133 scroll_begin_event.data.scrollBegin.deltaYHint = 0; |
| 134 return scroll_begin_event; | 134 return scroll_begin_event; |
| 135 } | 135 } |
| 136 | 136 |
| 137 cc::ScrollState CreateScrollStateForGesture(const WebGestureEvent& event) { | 137 cc::ScrollState CreateScrollStateForGesture(const WebGestureEvent& event) { |
| 138 cc::ScrollStateData scroll_state_data; | 138 cc::ScrollStateData scroll_state_data; |
| 139 switch (event.type) { | 139 switch (event.type()) { |
| 140 case WebInputEvent::GestureScrollBegin: | 140 case WebInputEvent::GestureScrollBegin: |
| 141 scroll_state_data.position_x = event.x; | 141 scroll_state_data.position_x = event.x; |
| 142 scroll_state_data.position_y = event.y; | 142 scroll_state_data.position_y = event.y; |
| 143 scroll_state_data.is_beginning = true; | 143 scroll_state_data.is_beginning = true; |
| 144 // On Mac, a GestureScrollBegin in the inertial phase indicates a fling | 144 // On Mac, a GestureScrollBegin in the inertial phase indicates a fling |
| 145 // start. | 145 // start. |
| 146 scroll_state_data.is_in_inertial_phase = | 146 scroll_state_data.is_in_inertial_phase = |
| 147 (event.data.scrollBegin.inertialPhase == | 147 (event.data.scrollBegin.inertialPhase == |
| 148 WebGestureEvent::MomentumPhase); | 148 WebGestureEvent::MomentumPhase); |
| 149 break; | 149 break; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 167 break; | 167 break; |
| 168 default: | 168 default: |
| 169 NOTREACHED(); | 169 NOTREACHED(); |
| 170 break; | 170 break; |
| 171 } | 171 } |
| 172 return cc::ScrollState(scroll_state_data); | 172 return cc::ScrollState(scroll_state_data); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void ReportInputEventLatencyUma(const WebInputEvent& event, | 175 void ReportInputEventLatencyUma(const WebInputEvent& event, |
| 176 const ui::LatencyInfo& latency_info) { | 176 const ui::LatencyInfo& latency_info) { |
| 177 if (!(event.type == WebInputEvent::GestureScrollBegin || | 177 if (!(event.type() == WebInputEvent::GestureScrollBegin || |
| 178 event.type == WebInputEvent::GestureScrollUpdate || | 178 event.type() == WebInputEvent::GestureScrollUpdate || |
| 179 event.type == WebInputEvent::GesturePinchBegin || | 179 event.type() == WebInputEvent::GesturePinchBegin || |
| 180 event.type == WebInputEvent::GesturePinchUpdate || | 180 event.type() == WebInputEvent::GesturePinchUpdate || |
| 181 event.type == WebInputEvent::GestureFlingStart)) { | 181 event.type() == WebInputEvent::GestureFlingStart)) { |
| 182 return; | 182 return; |
| 183 } | 183 } |
| 184 | 184 |
| 185 ui::LatencyInfo::LatencyMap::const_iterator it = | 185 ui::LatencyInfo::LatencyMap::const_iterator it = |
| 186 latency_info.latency_components().find(std::make_pair( | 186 latency_info.latency_components().find(std::make_pair( |
| 187 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0)); | 187 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0)); |
| 188 | 188 |
| 189 if (it == latency_info.latency_components().end()) | 189 if (it == latency_info.latency_components().end()) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 base::TimeDelta delta = base::TimeTicks::Now() - it->second.event_time; | 192 base::TimeDelta delta = base::TimeTicks::Now() - it->second.event_time; |
| 193 for (size_t i = 0; i < it->second.event_count; ++i) { | 193 for (size_t i = 0; i < it->second.event_count; ++i) { |
| 194 switch (event.type) { | 194 switch (event.type()) { |
| 195 case blink::WebInputEvent::GestureScrollBegin: | 195 case blink::WebInputEvent::GestureScrollBegin: |
| 196 UMA_HISTOGRAM_CUSTOM_COUNTS( | 196 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 197 "Event.Latency.RendererImpl.GestureScrollBegin", | 197 "Event.Latency.RendererImpl.GestureScrollBegin", |
| 198 delta.InMicroseconds(), 1, 1000000, 100); | 198 delta.InMicroseconds(), 1, 1000000, 100); |
| 199 break; | 199 break; |
| 200 case blink::WebInputEvent::GestureScrollUpdate: | 200 case blink::WebInputEvent::GestureScrollUpdate: |
| 201 UMA_HISTOGRAM_CUSTOM_COUNTS( | 201 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 202 // So named for historical reasons. | 202 // So named for historical reasons. |
| 203 "Event.Latency.RendererImpl.GestureScroll2", | 203 "Event.Latency.RendererImpl.GestureScroll2", |
| 204 delta.InMicroseconds(), 1, 1000000, 100); | 204 delta.InMicroseconds(), 1, 1000000, 100); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | 295 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
| 296 "step", "HandleInputEventImpl"); | 296 "step", "HandleInputEventImpl"); |
| 297 | 297 |
| 298 std::unique_ptr<EventWithCallback> event_with_callback = | 298 std::unique_ptr<EventWithCallback> event_with_callback = |
| 299 base::MakeUnique<EventWithCallback>(std::move(event), latency_info, | 299 base::MakeUnique<EventWithCallback>(std::move(event), latency_info, |
| 300 tick_clock_->NowTicks(), callback); | 300 tick_clock_->NowTicks(), callback); |
| 301 | 301 |
| 302 // Note: Other input can race ahead of gesture input as they don't have to go | 302 // Note: Other input can race ahead of gesture input as they don't have to go |
| 303 // through the queue, but we believe it's OK to do so. | 303 // through the queue, but we believe it's OK to do so. |
| 304 if (!compositor_event_queue_ || | 304 if (!compositor_event_queue_ || |
| 305 !IsGestureScollOrPinch(event_with_callback->event().type)) { | 305 !IsGestureScollOrPinch(event_with_callback->event().type())) { |
| 306 DispatchSingleInputEvent(std::move(event_with_callback), | 306 DispatchSingleInputEvent(std::move(event_with_callback), |
| 307 tick_clock_->NowTicks()); | 307 tick_clock_->NowTicks()); |
| 308 return; | 308 return; |
| 309 } | 309 } |
| 310 | 310 |
| 311 if (has_ongoing_compositor_scroll_pinch_) { | 311 if (has_ongoing_compositor_scroll_pinch_) { |
| 312 bool needs_animate_input = compositor_event_queue_->empty(); | 312 bool needs_animate_input = compositor_event_queue_->empty(); |
| 313 compositor_event_queue_->Queue(std::move(event_with_callback), | 313 compositor_event_queue_->Queue(std::move(event_with_callback), |
| 314 tick_clock_->NowTicks()); | 314 tick_clock_->NowTicks()); |
| 315 if (needs_animate_input) | 315 if (needs_animate_input) |
| 316 input_handler_->SetNeedsAnimateInput(); | 316 input_handler_->SetNeedsAnimateInput(); |
| 317 return; | 317 return; |
| 318 } | 318 } |
| 319 | 319 |
| 320 // We have to dispatch the event to know whether the gesture sequence will be | 320 // We have to dispatch the event to know whether the gesture sequence will be |
| 321 // handled by the compositor or not. | 321 // handled by the compositor or not. |
| 322 DispatchSingleInputEvent(std::move(event_with_callback), | 322 DispatchSingleInputEvent(std::move(event_with_callback), |
| 323 tick_clock_->NowTicks()); | 323 tick_clock_->NowTicks()); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void InputHandlerProxy::DispatchSingleInputEvent( | 326 void InputHandlerProxy::DispatchSingleInputEvent( |
| 327 std::unique_ptr<EventWithCallback> event_with_callback, | 327 std::unique_ptr<EventWithCallback> event_with_callback, |
| 328 const base::TimeTicks now) { | 328 const base::TimeTicks now) { |
| 329 if (compositor_event_queue_ && | 329 if (compositor_event_queue_ && |
| 330 IsGestureScollOrPinch(event_with_callback->event().type)) { | 330 IsGestureScollOrPinch(event_with_callback->event().type())) { |
| 331 // Report the coalesced count only for continuous events to avoid the noise | 331 // Report the coalesced count only for continuous events to avoid the noise |
| 332 // from non-continuous events. | 332 // from non-continuous events. |
| 333 if (IsContinuousGestureEvent(event_with_callback->event().type)) { | 333 if (IsContinuousGestureEvent(event_with_callback->event().type())) { |
| 334 UMA_HISTOGRAM_CUSTOM_COUNTS( | 334 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 335 "Event.CompositorThreadEventQueue.Continuous.HeadQueueingTime", | 335 "Event.CompositorThreadEventQueue.Continuous.HeadQueueingTime", |
| 336 (now - event_with_callback->creation_timestamp()).InMicroseconds(), 1, | 336 (now - event_with_callback->creation_timestamp()).InMicroseconds(), 1, |
| 337 kTenSeconds, 50); | 337 kTenSeconds, 50); |
| 338 | 338 |
| 339 UMA_HISTOGRAM_CUSTOM_COUNTS( | 339 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 340 "Event.CompositorThreadEventQueue.Continuous.TailQueueingTime", | 340 "Event.CompositorThreadEventQueue.Continuous.TailQueueingTime", |
| 341 (now - event_with_callback->last_coalesced_timestamp()) | 341 (now - event_with_callback->last_coalesced_timestamp()) |
| 342 .InMicroseconds(), | 342 .InMicroseconds(), |
| 343 1, kTenSeconds, 50); | 343 1, kTenSeconds, 50); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 355 | 355 |
| 356 ui::LatencyInfo monitored_latency_info = event_with_callback->latency_info(); | 356 ui::LatencyInfo monitored_latency_info = event_with_callback->latency_info(); |
| 357 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor = | 357 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor = |
| 358 input_handler_->CreateLatencyInfoSwapPromiseMonitor( | 358 input_handler_->CreateLatencyInfoSwapPromiseMonitor( |
| 359 &monitored_latency_info); | 359 &monitored_latency_info); |
| 360 | 360 |
| 361 current_overscroll_params_.reset(); | 361 current_overscroll_params_.reset(); |
| 362 InputHandlerProxy::EventDisposition disposition = | 362 InputHandlerProxy::EventDisposition disposition = |
| 363 HandleInputEvent(event_with_callback->event()); | 363 HandleInputEvent(event_with_callback->event()); |
| 364 | 364 |
| 365 switch (event_with_callback->event().type) { | 365 switch (event_with_callback->event().type()) { |
| 366 case blink::WebGestureEvent::GestureScrollBegin: | 366 case blink::WebGestureEvent::GestureScrollBegin: |
| 367 case blink::WebGestureEvent::GesturePinchBegin: | 367 case blink::WebGestureEvent::GesturePinchBegin: |
| 368 case blink::WebGestureEvent::GestureScrollUpdate: | 368 case blink::WebGestureEvent::GestureScrollUpdate: |
| 369 case blink::WebGestureEvent::GesturePinchUpdate: | 369 case blink::WebGestureEvent::GesturePinchUpdate: |
| 370 has_ongoing_compositor_scroll_pinch_ = disposition == DID_HANDLE; | 370 has_ongoing_compositor_scroll_pinch_ = disposition == DID_HANDLE; |
| 371 break; | 371 break; |
| 372 | 372 |
| 373 case blink::WebGestureEvent::GestureScrollEnd: | 373 case blink::WebGestureEvent::GestureScrollEnd: |
| 374 case blink::WebGestureEvent::GesturePinchEnd: | 374 case blink::WebGestureEvent::GesturePinchEnd: |
| 375 has_ongoing_compositor_scroll_pinch_ = false; | 375 has_ongoing_compositor_scroll_pinch_ = false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 393 DispatchSingleInputEvent(compositor_event_queue_->Pop(), now); | 393 DispatchSingleInputEvent(compositor_event_queue_->Pop(), now); |
| 394 } | 394 } |
| 395 | 395 |
| 396 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleInputEvent( | 396 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleInputEvent( |
| 397 const WebInputEvent& event) { | 397 const WebInputEvent& event) { |
| 398 DCHECK(input_handler_); | 398 DCHECK(input_handler_); |
| 399 | 399 |
| 400 if (FilterInputEventForFlingBoosting(event)) | 400 if (FilterInputEventForFlingBoosting(event)) |
| 401 return DID_HANDLE; | 401 return DID_HANDLE; |
| 402 | 402 |
| 403 switch (event.type) { | 403 switch (event.type()) { |
| 404 case WebInputEvent::MouseWheel: | 404 case WebInputEvent::MouseWheel: |
| 405 return HandleMouseWheel(static_cast<const WebMouseWheelEvent&>(event)); | 405 return HandleMouseWheel(static_cast<const WebMouseWheelEvent&>(event)); |
| 406 | 406 |
| 407 case WebInputEvent::GestureScrollBegin: | 407 case WebInputEvent::GestureScrollBegin: |
| 408 return HandleGestureScrollBegin( | 408 return HandleGestureScrollBegin( |
| 409 static_cast<const WebGestureEvent&>(event)); | 409 static_cast<const WebGestureEvent&>(event)); |
| 410 | 410 |
| 411 case WebInputEvent::GestureScrollUpdate: | 411 case WebInputEvent::GestureScrollUpdate: |
| 412 return HandleGestureScrollUpdate( | 412 return HandleGestureScrollUpdate( |
| 413 static_cast<const WebGestureEvent&>(event)); | 413 static_cast<const WebGestureEvent&>(event)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y)); | 506 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y)); |
| 507 return DID_NOT_HANDLE; | 507 return DID_NOT_HANDLE; |
| 508 } | 508 } |
| 509 case WebInputEvent::MouseLeave: { | 509 case WebInputEvent::MouseLeave: { |
| 510 CHECK(input_handler_); | 510 CHECK(input_handler_); |
| 511 input_handler_->MouseLeave(); | 511 input_handler_->MouseLeave(); |
| 512 return DID_NOT_HANDLE; | 512 return DID_NOT_HANDLE; |
| 513 } | 513 } |
| 514 | 514 |
| 515 default: | 515 default: |
| 516 if (WebInputEvent::isKeyboardEventType(event.type)) { | 516 if (WebInputEvent::isKeyboardEventType(event.type())) { |
| 517 // Only call |CancelCurrentFling()| if a fling was active, as it will | 517 // Only call |CancelCurrentFling()| if a fling was active, as it will |
| 518 // otherwise disrupt an in-progress touch scroll. | 518 // otherwise disrupt an in-progress touch scroll. |
| 519 if (fling_curve_) | 519 if (fling_curve_) |
| 520 CancelCurrentFling(); | 520 CancelCurrentFling(); |
| 521 } | 521 } |
| 522 break; | 522 break; |
| 523 } | 523 } |
| 524 | 524 |
| 525 return DID_NOT_HANDLE; | 525 return DID_NOT_HANDLE; |
| 526 } | 526 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 cc::ScrollState scroll_state = CreateScrollStateForGesture(gesture_event); | 788 cc::ScrollState scroll_state = CreateScrollStateForGesture(gesture_event); |
| 789 gfx::Point scroll_point(gesture_event.x, gesture_event.y); | 789 gfx::Point scroll_point(gesture_event.x, gesture_event.y); |
| 790 gfx::Vector2dF scroll_delta(-gesture_event.data.scrollUpdate.deltaX, | 790 gfx::Vector2dF scroll_delta(-gesture_event.data.scrollUpdate.deltaX, |
| 791 -gesture_event.data.scrollUpdate.deltaY); | 791 -gesture_event.data.scrollUpdate.deltaY); |
| 792 | 792 |
| 793 if (ShouldAnimate(gesture_event.data.scrollUpdate.deltaUnits != | 793 if (ShouldAnimate(gesture_event.data.scrollUpdate.deltaUnits != |
| 794 blink::WebGestureEvent::ScrollUnits::Pixels)) { | 794 blink::WebGestureEvent::ScrollUnits::Pixels)) { |
| 795 DCHECK(!scroll_state.is_in_inertial_phase()); | 795 DCHECK(!scroll_state.is_in_inertial_phase()); |
| 796 base::TimeTicks event_time = | 796 base::TimeTicks event_time = |
| 797 base::TimeTicks() + | 797 base::TimeTicks() + |
| 798 base::TimeDelta::FromSecondsD(gesture_event.timeStampSeconds); | 798 base::TimeDelta::FromSecondsD(gesture_event.timeStampSeconds()); |
| 799 base::TimeDelta delay = base::TimeTicks::Now() - event_time; | 799 base::TimeDelta delay = base::TimeTicks::Now() - event_time; |
| 800 switch (input_handler_->ScrollAnimated(scroll_point, scroll_delta, delay) | 800 switch (input_handler_->ScrollAnimated(scroll_point, scroll_delta, delay) |
| 801 .thread) { | 801 .thread) { |
| 802 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: | 802 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: |
| 803 return DID_HANDLE; | 803 return DID_HANDLE; |
| 804 case cc::InputHandler::SCROLL_IGNORED: | 804 case cc::InputHandler::SCROLL_IGNORED: |
| 805 return DROP_EVENT; | 805 return DROP_EVENT; |
| 806 default: | 806 default: |
| 807 return DID_NOT_HANDLE; | 807 return DID_NOT_HANDLE; |
| 808 } | 808 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 WebFloatPoint(vx, vy), | 893 WebFloatPoint(vx, vy), |
| 894 blink::WebSize())); | 894 blink::WebSize())); |
| 895 disallow_horizontal_fling_scroll_ = !vx; | 895 disallow_horizontal_fling_scroll_ = !vx; |
| 896 disallow_vertical_fling_scroll_ = !vy; | 896 disallow_vertical_fling_scroll_ = !vy; |
| 897 TRACE_EVENT_ASYNC_BEGIN2("input,benchmark,rail", | 897 TRACE_EVENT_ASYNC_BEGIN2("input,benchmark,rail", |
| 898 "InputHandlerProxy::HandleGestureFling::started", | 898 "InputHandlerProxy::HandleGestureFling::started", |
| 899 this, "vx", vx, "vy", vy); | 899 this, "vx", vx, "vy", vy); |
| 900 // Note that the timestamp will only be used to kickstart the animation if | 900 // Note that the timestamp will only be used to kickstart the animation if |
| 901 // its sufficiently close to the timestamp of the first call |Animate()|. | 901 // its sufficiently close to the timestamp of the first call |Animate()|. |
| 902 has_fling_animation_started_ = false; | 902 has_fling_animation_started_ = false; |
| 903 fling_parameters_.startTime = gesture_event.timeStampSeconds; | 903 fling_parameters_.startTime = gesture_event.timeStampSeconds(); |
| 904 fling_parameters_.delta = WebFloatPoint(vx, vy); | 904 fling_parameters_.delta = WebFloatPoint(vx, vy); |
| 905 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 905 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
| 906 fling_parameters_.globalPoint = | 906 fling_parameters_.globalPoint = |
| 907 WebPoint(gesture_event.globalX, gesture_event.globalY); | 907 WebPoint(gesture_event.globalX, gesture_event.globalY); |
| 908 fling_parameters_.modifiers = gesture_event.modifiers; | 908 fling_parameters_.modifiers = gesture_event.modifiers(); |
| 909 fling_parameters_.sourceDevice = gesture_event.sourceDevice; | 909 fling_parameters_.sourceDevice = gesture_event.sourceDevice; |
| 910 RequestAnimation(); | 910 RequestAnimation(); |
| 911 return DID_HANDLE; | 911 return DID_HANDLE; |
| 912 } | 912 } |
| 913 case cc::InputHandler::SCROLL_UNKNOWN: | 913 case cc::InputHandler::SCROLL_UNKNOWN: |
| 914 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: { | 914 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: { |
| 915 TRACE_EVENT_INSTANT0("input,rail", | 915 TRACE_EVENT_INSTANT0("input,rail", |
| 916 "InputHandlerProxy::HandleGestureFling::" | 916 "InputHandlerProxy::HandleGestureFling::" |
| 917 "scroll_on_main_thread", | 917 "scroll_on_main_thread", |
| 918 TRACE_EVENT_SCOPE_THREAD); | 918 TRACE_EVENT_SCOPE_THREAD); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1021 |
| 1022 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchEnd( | 1022 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchEnd( |
| 1023 const blink::WebTouchEvent& touch_event) { | 1023 const blink::WebTouchEvent& touch_event) { |
| 1024 if (touch_event.touchesLength == 1) | 1024 if (touch_event.touchesLength == 1) |
| 1025 touch_start_result_ = kEventDispositionUndefined; | 1025 touch_start_result_ = kEventDispositionUndefined; |
| 1026 return DID_NOT_HANDLE; | 1026 return DID_NOT_HANDLE; |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 bool InputHandlerProxy::FilterInputEventForFlingBoosting( | 1029 bool InputHandlerProxy::FilterInputEventForFlingBoosting( |
| 1030 const WebInputEvent& event) { | 1030 const WebInputEvent& event) { |
| 1031 if (!WebInputEvent::isGestureEventType(event.type)) | 1031 if (!WebInputEvent::isGestureEventType(event.type())) |
| 1032 return false; | 1032 return false; |
| 1033 | 1033 |
| 1034 if (!fling_curve_) { | 1034 if (!fling_curve_) { |
| 1035 DCHECK(!deferred_fling_cancel_time_seconds_); | 1035 DCHECK(!deferred_fling_cancel_time_seconds_); |
| 1036 return false; | 1036 return false; |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 const WebGestureEvent& gesture_event = | 1039 const WebGestureEvent& gesture_event = |
| 1040 static_cast<const WebGestureEvent&>(event); | 1040 static_cast<const WebGestureEvent&>(event); |
| 1041 if (gesture_event.type == WebInputEvent::GestureFlingCancel) { | 1041 if (gesture_event.type() == WebInputEvent::GestureFlingCancel) { |
| 1042 if (gesture_event.data.flingCancel.preventBoosting) | 1042 if (gesture_event.data.flingCancel.preventBoosting) |
| 1043 return false; | 1043 return false; |
| 1044 | 1044 |
| 1045 if (current_fling_velocity_.LengthSquared() < kMinBoostFlingSpeedSquare) | 1045 if (current_fling_velocity_.LengthSquared() < kMinBoostFlingSpeedSquare) |
| 1046 return false; | 1046 return false; |
| 1047 | 1047 |
| 1048 TRACE_EVENT_INSTANT0("input", | 1048 TRACE_EVENT_INSTANT0("input", |
| 1049 "InputHandlerProxy::FlingBoostStart", | 1049 "InputHandlerProxy::FlingBoostStart", |
| 1050 TRACE_EVENT_SCOPE_THREAD); | 1050 TRACE_EVENT_SCOPE_THREAD); |
| 1051 deferred_fling_cancel_time_seconds_ = | 1051 deferred_fling_cancel_time_seconds_ = |
| 1052 event.timeStampSeconds + kFlingBoostTimeoutDelaySeconds; | 1052 event.timeStampSeconds() + kFlingBoostTimeoutDelaySeconds; |
| 1053 return true; | 1053 return true; |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 // A fling is either inactive or is "free spinning", i.e., has yet to be | 1056 // A fling is either inactive or is "free spinning", i.e., has yet to be |
| 1057 // interrupted by a touch gesture, in which case there is nothing to filter. | 1057 // interrupted by a touch gesture, in which case there is nothing to filter. |
| 1058 if (!deferred_fling_cancel_time_seconds_) | 1058 if (!deferred_fling_cancel_time_seconds_) |
| 1059 return false; | 1059 return false; |
| 1060 | 1060 |
| 1061 // Gestures from a different source should immediately interrupt the fling. | 1061 // Gestures from a different source should immediately interrupt the fling. |
| 1062 if (gesture_event.sourceDevice != fling_parameters_.sourceDevice) { | 1062 if (gesture_event.sourceDevice != fling_parameters_.sourceDevice) { |
| 1063 CancelCurrentFling(); | 1063 CancelCurrentFling(); |
| 1064 return false; | 1064 return false; |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 switch (gesture_event.type) { | 1067 switch (gesture_event.type()) { |
| 1068 case WebInputEvent::GestureTapCancel: | 1068 case WebInputEvent::GestureTapCancel: |
| 1069 case WebInputEvent::GestureTapDown: | 1069 case WebInputEvent::GestureTapDown: |
| 1070 return false; | 1070 return false; |
| 1071 | 1071 |
| 1072 case WebInputEvent::GestureScrollBegin: | 1072 case WebInputEvent::GestureScrollBegin: |
| 1073 if (!input_handler_->IsCurrentlyScrollingLayerAt( | 1073 if (!input_handler_->IsCurrentlyScrollingLayerAt( |
| 1074 gfx::Point(gesture_event.x, gesture_event.y), | 1074 gfx::Point(gesture_event.x, gesture_event.y), |
| 1075 fling_parameters_.sourceDevice == blink::WebGestureDeviceTouchpad | 1075 fling_parameters_.sourceDevice == blink::WebGestureDeviceTouchpad |
| 1076 ? cc::InputHandler::NON_BUBBLING_GESTURE | 1076 ? cc::InputHandler::NON_BUBBLING_GESTURE |
| 1077 : cc::InputHandler::TOUCHSCREEN)) { | 1077 : cc::InputHandler::TOUCHSCREEN)) { |
| 1078 CancelCurrentFling(); | 1078 CancelCurrentFling(); |
| 1079 return false; | 1079 return false; |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 // TODO(jdduke): Use |gesture_event.data.scrollBegin.delta{X,Y}Hint| to | 1082 // TODO(jdduke): Use |gesture_event.data.scrollBegin.delta{X,Y}Hint| to |
| 1083 // determine if the ScrollBegin should immediately cancel the fling. | 1083 // determine if the ScrollBegin should immediately cancel the fling. |
| 1084 ExtendBoostedFlingTimeout(gesture_event); | 1084 ExtendBoostedFlingTimeout(gesture_event); |
| 1085 return true; | 1085 return true; |
| 1086 | 1086 |
| 1087 case WebInputEvent::GestureScrollUpdate: { | 1087 case WebInputEvent::GestureScrollUpdate: { |
| 1088 const double time_since_last_boost_event = | 1088 const double time_since_last_boost_event = |
| 1089 event.timeStampSeconds - last_fling_boost_event_.timeStampSeconds; | 1089 event.timeStampSeconds() - last_fling_boost_event_.timeStampSeconds(); |
| 1090 const double time_since_last_fling_animate = std::max( | 1090 const double time_since_last_fling_animate = std::max( |
| 1091 0.0, event.timeStampSeconds - InSecondsF(last_fling_animate_time_)); | 1091 0.0, event.timeStampSeconds() - InSecondsF(last_fling_animate_time_)); |
| 1092 if (ShouldSuppressScrollForFlingBoosting(current_fling_velocity_, | 1092 if (ShouldSuppressScrollForFlingBoosting(current_fling_velocity_, |
| 1093 gesture_event, | 1093 gesture_event, |
| 1094 time_since_last_boost_event, | 1094 time_since_last_boost_event, |
| 1095 time_since_last_fling_animate)) { | 1095 time_since_last_fling_animate)) { |
| 1096 ExtendBoostedFlingTimeout(gesture_event); | 1096 ExtendBoostedFlingTimeout(gesture_event); |
| 1097 return true; | 1097 return true; |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 CancelCurrentFling(); | 1100 CancelCurrentFling(); |
| 1101 return false; | 1101 return false; |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 case WebInputEvent::GestureScrollEnd: | 1104 case WebInputEvent::GestureScrollEnd: |
| 1105 // Clear the last fling boost event *prior* to fling cancellation, | 1105 // Clear the last fling boost event *prior* to fling cancellation, |
| 1106 // preventing insertion of a synthetic GestureScrollBegin. | 1106 // preventing insertion of a synthetic GestureScrollBegin. |
| 1107 last_fling_boost_event_ = WebGestureEvent(); | 1107 last_fling_boost_event_ = WebGestureEvent(); |
| 1108 CancelCurrentFling(); | 1108 CancelCurrentFling(); |
| 1109 return true; | 1109 return true; |
| 1110 | 1110 |
| 1111 case WebInputEvent::GestureFlingStart: { | 1111 case WebInputEvent::GestureFlingStart: { |
| 1112 DCHECK_EQ(fling_parameters_.sourceDevice, gesture_event.sourceDevice); | 1112 DCHECK_EQ(fling_parameters_.sourceDevice, gesture_event.sourceDevice); |
| 1113 | 1113 |
| 1114 bool fling_boosted = | 1114 bool fling_boosted = |
| 1115 fling_parameters_.modifiers == gesture_event.modifiers && | 1115 fling_parameters_.modifiers == gesture_event.modifiers() && |
| 1116 ShouldBoostFling(current_fling_velocity_, gesture_event); | 1116 ShouldBoostFling(current_fling_velocity_, gesture_event); |
| 1117 | 1117 |
| 1118 gfx::Vector2dF new_fling_velocity( | 1118 gfx::Vector2dF new_fling_velocity( |
| 1119 gesture_event.data.flingStart.velocityX, | 1119 gesture_event.data.flingStart.velocityX, |
| 1120 gesture_event.data.flingStart.velocityY); | 1120 gesture_event.data.flingStart.velocityY); |
| 1121 DCHECK(!new_fling_velocity.IsZero()); | 1121 DCHECK(!new_fling_velocity.IsZero()); |
| 1122 | 1122 |
| 1123 if (fling_boosted) | 1123 if (fling_boosted) |
| 1124 current_fling_velocity_ += new_fling_velocity; | 1124 current_fling_velocity_ += new_fling_velocity; |
| 1125 else | 1125 else |
| 1126 current_fling_velocity_ = new_fling_velocity; | 1126 current_fling_velocity_ = new_fling_velocity; |
| 1127 | 1127 |
| 1128 WebFloatPoint velocity(current_fling_velocity_.x(), | 1128 WebFloatPoint velocity(current_fling_velocity_.x(), |
| 1129 current_fling_velocity_.y()); | 1129 current_fling_velocity_.y()); |
| 1130 deferred_fling_cancel_time_seconds_ = 0; | 1130 deferred_fling_cancel_time_seconds_ = 0; |
| 1131 disallow_horizontal_fling_scroll_ = !velocity.x; | 1131 disallow_horizontal_fling_scroll_ = !velocity.x; |
| 1132 disallow_vertical_fling_scroll_ = !velocity.y; | 1132 disallow_vertical_fling_scroll_ = !velocity.y; |
| 1133 last_fling_boost_event_ = WebGestureEvent(); | 1133 last_fling_boost_event_ = WebGestureEvent(); |
| 1134 fling_curve_.reset(client_->CreateFlingAnimationCurve( | 1134 fling_curve_.reset(client_->CreateFlingAnimationCurve( |
| 1135 gesture_event.sourceDevice, | 1135 gesture_event.sourceDevice, |
| 1136 velocity, | 1136 velocity, |
| 1137 blink::WebSize())); | 1137 blink::WebSize())); |
| 1138 fling_parameters_.startTime = gesture_event.timeStampSeconds; | 1138 fling_parameters_.startTime = gesture_event.timeStampSeconds(); |
| 1139 fling_parameters_.delta = velocity; | 1139 fling_parameters_.delta = velocity; |
| 1140 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 1140 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
| 1141 fling_parameters_.globalPoint = | 1141 fling_parameters_.globalPoint = |
| 1142 WebPoint(gesture_event.globalX, gesture_event.globalY); | 1142 WebPoint(gesture_event.globalX, gesture_event.globalY); |
| 1143 | 1143 |
| 1144 TRACE_EVENT_INSTANT2("input", | 1144 TRACE_EVENT_INSTANT2("input", |
| 1145 fling_boosted ? "InputHandlerProxy::FlingBoosted" | 1145 fling_boosted ? "InputHandlerProxy::FlingBoosted" |
| 1146 : "InputHandlerProxy::FlingReplaced", | 1146 : "InputHandlerProxy::FlingReplaced", |
| 1147 TRACE_EVENT_SCOPE_THREAD, | 1147 TRACE_EVENT_SCOPE_THREAD, |
| 1148 "vx", | 1148 "vx", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1163 return false; | 1163 return false; |
| 1164 } | 1164 } |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 void InputHandlerProxy::ExtendBoostedFlingTimeout( | 1167 void InputHandlerProxy::ExtendBoostedFlingTimeout( |
| 1168 const blink::WebGestureEvent& event) { | 1168 const blink::WebGestureEvent& event) { |
| 1169 TRACE_EVENT_INSTANT0("input", | 1169 TRACE_EVENT_INSTANT0("input", |
| 1170 "InputHandlerProxy::ExtendBoostedFlingTimeout", | 1170 "InputHandlerProxy::ExtendBoostedFlingTimeout", |
| 1171 TRACE_EVENT_SCOPE_THREAD); | 1171 TRACE_EVENT_SCOPE_THREAD); |
| 1172 deferred_fling_cancel_time_seconds_ = | 1172 deferred_fling_cancel_time_seconds_ = |
| 1173 event.timeStampSeconds + kFlingBoostTimeoutDelaySeconds; | 1173 event.timeStampSeconds() + kFlingBoostTimeoutDelaySeconds; |
| 1174 last_fling_boost_event_ = event; | 1174 last_fling_boost_event_ = event; |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 void InputHandlerProxy::Animate(base::TimeTicks time) { | 1177 void InputHandlerProxy::Animate(base::TimeTicks time) { |
| 1178 // If using synchronous animate, then only expect Animate attempts started by | 1178 // If using synchronous animate, then only expect Animate attempts started by |
| 1179 // the synchronous system. Don't let the InputHandler try to Animate also. | 1179 // the synchronous system. Don't let the InputHandler try to Animate also. |
| 1180 DCHECK(!input_handler_->IsCurrentlyScrollingViewport() || | 1180 DCHECK(!input_handler_->IsCurrentlyScrollingViewport() || |
| 1181 allow_root_animate_); | 1181 allow_root_animate_); |
| 1182 | 1182 |
| 1183 if (scroll_elasticity_controller_) | 1183 if (scroll_elasticity_controller_) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 has_fling_animation_started_ = false; | 1366 has_fling_animation_started_ = false; |
| 1367 gesture_scroll_on_impl_thread_ = false; | 1367 gesture_scroll_on_impl_thread_ = false; |
| 1368 current_fling_velocity_ = gfx::Vector2dF(); | 1368 current_fling_velocity_ = gfx::Vector2dF(); |
| 1369 fling_parameters_ = blink::WebActiveWheelFlingParameters(); | 1369 fling_parameters_ = blink::WebActiveWheelFlingParameters(); |
| 1370 | 1370 |
| 1371 if (deferred_fling_cancel_time_seconds_) { | 1371 if (deferred_fling_cancel_time_seconds_) { |
| 1372 deferred_fling_cancel_time_seconds_ = 0; | 1372 deferred_fling_cancel_time_seconds_ = 0; |
| 1373 | 1373 |
| 1374 WebGestureEvent last_fling_boost_event = last_fling_boost_event_; | 1374 WebGestureEvent last_fling_boost_event = last_fling_boost_event_; |
| 1375 last_fling_boost_event_ = WebGestureEvent(); | 1375 last_fling_boost_event_ = WebGestureEvent(); |
| 1376 if (last_fling_boost_event.type == WebInputEvent::GestureScrollBegin || | 1376 if (last_fling_boost_event.type() == WebInputEvent::GestureScrollBegin || |
| 1377 last_fling_boost_event.type == WebInputEvent::GestureScrollUpdate) { | 1377 last_fling_boost_event.type() == WebInputEvent::GestureScrollUpdate) { |
| 1378 // Synthesize a GestureScrollBegin, as the original was suppressed. | 1378 // Synthesize a GestureScrollBegin, as the original was suppressed. |
| 1379 HandleInputEvent(ObtainGestureScrollBegin(last_fling_boost_event)); | 1379 HandleInputEvent(ObtainGestureScrollBegin(last_fling_boost_event)); |
| 1380 } | 1380 } |
| 1381 } | 1381 } |
| 1382 | 1382 |
| 1383 return had_fling_animation; | 1383 return had_fling_animation; |
| 1384 } | 1384 } |
| 1385 | 1385 |
| 1386 void InputHandlerProxy::RequestAnimation() { | 1386 void InputHandlerProxy::RequestAnimation() { |
| 1387 // When a SynchronousInputHandler is present, root flings should go through | 1387 // When a SynchronousInputHandler is present, root flings should go through |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, | 1540 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, |
| 1541 scroll_result)); | 1541 scroll_result)); |
| 1542 } | 1542 } |
| 1543 | 1543 |
| 1544 void InputHandlerProxy::SetTickClockForTesting( | 1544 void InputHandlerProxy::SetTickClockForTesting( |
| 1545 std::unique_ptr<base::TickClock> tick_clock) { | 1545 std::unique_ptr<base::TickClock> tick_clock) { |
| 1546 tick_clock_ = std::move(tick_clock); | 1546 tick_clock_ = std::move(tick_clock); |
| 1547 } | 1547 } |
| 1548 | 1548 |
| 1549 } // namespace ui | 1549 } // namespace ui |
| OLD | NEW |