| 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 "content/browser/renderer_host/input/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 SendWheelEvent(QueuedWheelEvent(wheel_event, false)); | 129 SendWheelEvent(QueuedWheelEvent(wheel_event, false)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void InputRouterImpl::SendWheelEvent(const QueuedWheelEvent& wheel_event) { | 132 void InputRouterImpl::SendWheelEvent(const QueuedWheelEvent& wheel_event) { |
| 133 if (mouse_wheel_pending_) { | 133 if (mouse_wheel_pending_) { |
| 134 // If there's already a mouse wheel event waiting to be sent to the | 134 // If there's already a mouse wheel event waiting to be sent to the |
| 135 // renderer, add the new deltas to that event. Not doing so (e.g., by | 135 // renderer, add the new deltas to that event. Not doing so (e.g., by |
| 136 // dropping the old event, as for mouse moves) results in very slow | 136 // dropping the old event, as for mouse moves) results in very slow |
| 137 // scrolling on the Mac (on which many, very small wheel events are sent). | 137 // scrolling on the Mac (on which many, very small wheel events are sent). |
| 138 // Note that we can't coalesce wheel events for pinches because the GEQ | 138 // Note that we can't coalesce wheel events for pinches because the GEQ |
| 139 // expects one ACK for each. But such events always have canScroll==false | 139 // expects one ACK for each (but it's fine to coalesce non-pinch wheels |
| 140 // and hasPreciseDeltas=true, which should never happen for a real wheel | 140 // into a pinch one). Note that the GestureEventQueue ensures we only |
| 141 // event and so coalescing shouldn't occur. Note that the | 141 // ever have a single pinch event queued here. |
| 142 // GestureEventQueue ensures we only ever have a single pinch event queued | |
| 143 // here. | |
| 144 if (coalesced_mouse_wheel_events_.empty() || | 142 if (coalesced_mouse_wheel_events_.empty() || |
| 145 wheel_event.synthesized_from_pinch != | 143 wheel_event.synthesized_from_pinch || |
| 146 coalesced_mouse_wheel_events_.back().synthesized_from_pinch || | |
| 147 !coalesced_mouse_wheel_events_.back().event.CanCoalesceWith( | 144 !coalesced_mouse_wheel_events_.back().event.CanCoalesceWith( |
| 148 wheel_event.event)) { | 145 wheel_event.event)) { |
| 149 coalesced_mouse_wheel_events_.push_back(wheel_event); | 146 coalesced_mouse_wheel_events_.push_back(wheel_event); |
| 150 } else { | 147 } else { |
| 151 coalesced_mouse_wheel_events_.back().event.CoalesceWith( | 148 coalesced_mouse_wheel_events_.back().event.CoalesceWith( |
| 152 wheel_event.event); | 149 wheel_event.event); |
| 153 } | 150 } |
| 154 return; | 151 return; |
| 155 } | 152 } |
| 156 | 153 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 // - magnitude roughly matches wheels: f(2) > 25 && f(2) < 100 | 451 // - magnitude roughly matches wheels: f(2) > 25 && f(2) < 100 |
| 455 // - a formula that's relatively easy to use from JavaScript | 452 // - a formula that's relatively easy to use from JavaScript |
| 456 // Note that 'wheel' event deltaY values have their sign inverted. So to | 453 // Note that 'wheel' event deltaY values have their sign inverted. So to |
| 457 // convert a wheel deltaY back to a scale use Math.exp(-deltaY/100). | 454 // convert a wheel deltaY back to a scale use Math.exp(-deltaY/100). |
| 458 DCHECK_GT(pinch_event.event.data.pinchUpdate.scale, 0); | 455 DCHECK_GT(pinch_event.event.data.pinchUpdate.scale, 0); |
| 459 wheelEvent.deltaY = 100.0f * log(pinch_event.event.data.pinchUpdate.scale); | 456 wheelEvent.deltaY = 100.0f * log(pinch_event.event.data.pinchUpdate.scale); |
| 460 wheelEvent.hasPreciseScrollingDeltas = true; | 457 wheelEvent.hasPreciseScrollingDeltas = true; |
| 461 wheelEvent.wheelTicksX = 0; | 458 wheelEvent.wheelTicksX = 0; |
| 462 wheelEvent.wheelTicksY = | 459 wheelEvent.wheelTicksY = |
| 463 pinch_event.event.data.pinchUpdate.scale > 1 ? 1 : -1; | 460 pinch_event.event.data.pinchUpdate.scale > 1 ? 1 : -1; |
| 464 wheelEvent.canScroll = false; | 461 |
| 465 SendWheelEvent(QueuedWheelEvent( | 462 SendWheelEvent(QueuedWheelEvent( |
| 466 MouseWheelEventWithLatencyInfo(wheelEvent, pinch_event.latency), true)); | 463 MouseWheelEventWithLatencyInfo(wheelEvent, pinch_event.latency), true)); |
| 467 } | 464 } |
| 468 | 465 |
| 469 void InputRouterImpl::OnInputEventAck( | 466 void InputRouterImpl::OnInputEventAck( |
| 470 const InputHostMsg_HandleInputEvent_ACK_Params& ack) { | 467 const InputHostMsg_HandleInputEvent_ACK_Params& ack) { |
| 471 client_->DecrementInFlightEventCount(); | 468 client_->DecrementInFlightEventCount(); |
| 472 | 469 |
| 473 // Log the time delta for processing an input event. | 470 // Log the time delta for processing an input event. |
| 474 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; | 471 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 InputRouterImpl::QueuedWheelEvent::QueuedWheelEvent( | 712 InputRouterImpl::QueuedWheelEvent::QueuedWheelEvent( |
| 716 const MouseWheelEventWithLatencyInfo& event, | 713 const MouseWheelEventWithLatencyInfo& event, |
| 717 bool synthesized_from_pinch) | 714 bool synthesized_from_pinch) |
| 718 : event(event), synthesized_from_pinch(synthesized_from_pinch) { | 715 : event(event), synthesized_from_pinch(synthesized_from_pinch) { |
| 719 } | 716 } |
| 720 | 717 |
| 721 InputRouterImpl::QueuedWheelEvent::~QueuedWheelEvent() { | 718 InputRouterImpl::QueuedWheelEvent::~QueuedWheelEvent() { |
| 722 } | 719 } |
| 723 | 720 |
| 724 } // namespace content | 721 } // namespace content |
| OLD | NEW |