Chromium Code Reviews| 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/touch_event_queue.h" | 5 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "content/browser/renderer_host/input/timeout_monitor.h" | 11 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| 12 #include "content/browser/renderer_host/input/web_touch_event_traits.h" | 12 #include "content/browser/renderer_host/input/web_touch_event_traits.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "ui/gfx/geometry/point_f.h" | 14 #include "ui/gfx/geometry/point_f.h" |
| 15 | 15 |
| 16 using blink::WebInputEvent; | 16 using blink::WebInputEvent; |
| 17 using blink::WebTouchEvent; | 17 using blink::WebTouchEvent; |
| 18 using blink::WebTouchPoint; | 18 using blink::WebTouchPoint; |
| 19 using ui::LatencyInfo; | 19 using ui::LatencyInfo; |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Using a small epsilon when comparing slop distances allows pixel perfect | |
| 25 // slop determination when using fractional DPI coordinates (assuming the slop | |
|
tdresser
2014/04/09 14:00:01
fractional DPI -> fractional DIP
jdduke (slow)
2014/04/10 22:04:53
Done.
| |
| 26 // region and DPI scale are reasonably proportioned). | |
| 27 const float SLOP_EPSILON = .05f; | |
| 28 | |
| 24 typedef std::vector<TouchEventWithLatencyInfo> WebTouchEventWithLatencyList; | 29 typedef std::vector<TouchEventWithLatencyInfo> WebTouchEventWithLatencyList; |
| 25 | 30 |
| 26 TouchEventWithLatencyInfo ObtainCancelEventForTouchEvent( | 31 TouchEventWithLatencyInfo ObtainCancelEventForTouchEvent( |
| 27 const TouchEventWithLatencyInfo& event_to_cancel) { | 32 const TouchEventWithLatencyInfo& event_to_cancel) { |
| 28 TouchEventWithLatencyInfo event = event_to_cancel; | 33 TouchEventWithLatencyInfo event = event_to_cancel; |
| 29 event.event.type = WebInputEvent::TouchCancel; | 34 event.event.type = WebInputEvent::TouchCancel; |
| 30 for (size_t i = 0; i < event.event.touchesLength; i++) | 35 for (size_t i = 0; i < event.event.touchesLength; i++) |
| 31 event.event.touches[i].state = WebTouchPoint::StateCancelled; | 36 event.event.touches[i].state = WebTouchPoint::StateCancelled; |
| 32 return event; | 37 return event; |
| 33 } | 38 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 | 165 |
| 161 // The event for which the ack timeout is triggered. | 166 // The event for which the ack timeout is triggered. |
| 162 TouchEventWithLatencyInfo timeout_event_; | 167 TouchEventWithLatencyInfo timeout_event_; |
| 163 | 168 |
| 164 // Provides timeout-based callback behavior. | 169 // Provides timeout-based callback behavior. |
| 165 TimeoutMonitor timeout_monitor_; | 170 TimeoutMonitor timeout_monitor_; |
| 166 }; | 171 }; |
| 167 | 172 |
| 168 // Provides touchmove slop suppression for a single touch that remains within | 173 // Provides touchmove slop suppression for a single touch that remains within |
| 169 // a given slop region, unless the touchstart is preventDefault'ed. | 174 // a given slop region, unless the touchstart is preventDefault'ed. |
| 175 // TODO(jdduke): Use a flag bundled with each TouchEvent declaring whether it | |
| 176 // has exceeded the slop region, removing duplicated slop determination logic. | |
| 170 class TouchEventQueue::TouchMoveSlopSuppressor { | 177 class TouchEventQueue::TouchMoveSlopSuppressor { |
| 171 public: | 178 public: |
| 172 TouchMoveSlopSuppressor(double slop_suppression_length_dips) | 179 TouchMoveSlopSuppressor(double slop_suppression_length_dips) |
| 173 : slop_suppression_length_dips_squared_(slop_suppression_length_dips * | 180 : slop_suppression_length_dips_squared_(slop_suppression_length_dips * |
| 174 slop_suppression_length_dips), | 181 slop_suppression_length_dips), |
| 175 suppressing_touch_moves_(false) {} | 182 suppressing_touch_moves_(false) {} |
| 176 | 183 |
| 177 bool FilterEvent(const WebTouchEvent& event) { | 184 bool FilterEvent(const WebTouchEvent& event) { |
| 178 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { | 185 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { |
| 179 touch_sequence_start_position_ = | 186 touch_sequence_start_position_ = |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 }; | 288 }; |
| 282 | 289 |
| 283 TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client, | 290 TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client, |
| 284 TouchScrollingMode mode, | 291 TouchScrollingMode mode, |
| 285 double touchmove_suppression_length_dips) | 292 double touchmove_suppression_length_dips) |
| 286 : client_(client), | 293 : client_(client), |
| 287 dispatching_touch_ack_(NULL), | 294 dispatching_touch_ack_(NULL), |
| 288 dispatching_touch_(false), | 295 dispatching_touch_(false), |
| 289 touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT), | 296 touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT), |
| 290 ack_timeout_enabled_(false), | 297 ack_timeout_enabled_(false), |
| 291 touchmove_slop_suppressor_( | 298 touchmove_slop_suppressor_(new TouchMoveSlopSuppressor( |
| 292 new TouchMoveSlopSuppressor(touchmove_suppression_length_dips)), | 299 touchmove_suppression_length_dips + SLOP_EPSILON)), |
| 293 absorbing_touch_moves_(false), | 300 absorbing_touch_moves_(false), |
| 294 touch_scrolling_mode_(mode) { | 301 touch_scrolling_mode_(mode) { |
| 295 DCHECK(client); | 302 DCHECK(client); |
| 296 } | 303 } |
| 297 | 304 |
| 298 TouchEventQueue::~TouchEventQueue() { | 305 TouchEventQueue::~TouchEventQueue() { |
| 299 if (!touch_queue_.empty()) | 306 if (!touch_queue_.empty()) |
| 300 STLDeleteElements(&touch_queue_); | 307 STLDeleteElements(&touch_queue_); |
| 301 } | 308 } |
| 302 | 309 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 } else if (event.type == WebInputEvent::TouchStart) { | 635 } else if (event.type == WebInputEvent::TouchStart) { |
| 629 for (unsigned i = 0; i < event.touchesLength; ++i) { | 636 for (unsigned i = 0; i < event.touchesLength; ++i) { |
| 630 const WebTouchPoint& point = event.touches[i]; | 637 const WebTouchPoint& point = event.touches[i]; |
| 631 if (point.state == WebTouchPoint::StatePressed) | 638 if (point.state == WebTouchPoint::StatePressed) |
| 632 touch_ack_states_[point.id] = ack_result; | 639 touch_ack_states_[point.id] = ack_result; |
| 633 } | 640 } |
| 634 } | 641 } |
| 635 } | 642 } |
| 636 | 643 |
| 637 } // namespace content | 644 } // namespace content |
| OLD | NEW |