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" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 TouchEventWithLatencyInfo timeout_event_; | 169 TouchEventWithLatencyInfo timeout_event_; |
170 | 170 |
171 // Provides timeout-based callback behavior. | 171 // Provides timeout-based callback behavior. |
172 TimeoutMonitor timeout_monitor_; | 172 TimeoutMonitor timeout_monitor_; |
173 }; | 173 }; |
174 | 174 |
175 // Provides touchmove slop suppression for a single touch that remains within | 175 // Provides touchmove slop suppression for a single touch that remains within |
176 // a given slop region, unless the touchstart is preventDefault'ed. | 176 // a given slop region, unless the touchstart is preventDefault'ed. |
177 class TouchEventQueue::TouchMoveSlopSuppressor { | 177 class TouchEventQueue::TouchMoveSlopSuppressor { |
178 public: | 178 public: |
179 // TODO(jdduke): Remove int cast on suppression length, crbug.com/3336807. | |
tdresser
2014/02/21 21:44:50
No such bug?
jdduke (slow)
2014/02/21 22:29:05
Oops, good catch.
| |
179 TouchMoveSlopSuppressor(double slop_suppression_length_dips) | 180 TouchMoveSlopSuppressor(double slop_suppression_length_dips) |
180 : slop_suppression_length_dips_squared_(slop_suppression_length_dips * | 181 : slop_suppression_length_dips_squared_( |
181 slop_suppression_length_dips), | 182 static_cast<int>(slop_suppression_length_dips) * |
183 static_cast<int>(slop_suppression_length_dips)), | |
182 suppressing_touch_moves_(false) {} | 184 suppressing_touch_moves_(false) {} |
183 | 185 |
184 bool FilterEvent(const WebTouchEvent& event) { | 186 bool FilterEvent(const WebTouchEvent& event) { |
185 if (IsNewTouchSequence(event)) { | 187 if (IsNewTouchSequence(event)) { |
186 touch_sequence_start_position_ = | 188 touch_sequence_start_position_ = |
187 gfx::Point(event.touches[0].position); | 189 gfx::Point(event.touches[0].position); |
188 suppressing_touch_moves_ = slop_suppression_length_dips_squared_ != 0; | 190 suppressing_touch_moves_ = slop_suppression_length_dips_squared_ != 0; |
189 } | 191 } |
190 | 192 |
191 if (event.type != WebInputEvent::TouchMove) | 193 if (event.type != WebInputEvent::TouchMove) |
192 return false; | 194 return false; |
193 | 195 |
194 if (suppressing_touch_moves_) { | 196 if (suppressing_touch_moves_) { |
195 // Movement with a secondary pointer should terminate suppression. | 197 // Movement with a secondary pointer should terminate suppression. |
196 if (event.touchesLength > 1) { | 198 if (event.touchesLength > 1) { |
197 suppressing_touch_moves_ = false; | 199 suppressing_touch_moves_ = false; |
198 } else if (event.touchesLength == 1) { | 200 } else if (event.touchesLength == 1) { |
199 // Movement outside of the slop region should terminate suppression. | 201 // Movement outside of the slop region should terminate suppression. |
200 gfx::PointF position = gfx::Point(event.touches[0].position); | 202 // TODO(jdduke): Use strict inequality, crbug.com/3336807. |
201 if ((position - touch_sequence_start_position_).LengthSquared() > | 203 gfx::PointF position(event.touches[0].position.x, |
204 event.touches[0].position.y); | |
205 if ((position - touch_sequence_start_position_).LengthSquared() >= | |
Rick Byers
2014/02/21 20:22:49
In my Aura fix I was trying to keep the strict ine
tdresser
2014/02/21 21:44:50
Consuming any touch move will prevent scrolling. (
jdduke (slow)
2014/02/21 22:29:05
Yeah, with unified GR we can toggle the inequality
| |
202 slop_suppression_length_dips_squared_) | 206 slop_suppression_length_dips_squared_) |
203 suppressing_touch_moves_ = false; | 207 suppressing_touch_moves_ = false; |
204 } | 208 } |
205 } | 209 } |
206 return suppressing_touch_moves_; | 210 return suppressing_touch_moves_; |
207 } | 211 } |
208 | 212 |
209 void ConfirmTouchEvent(InputEventAckState ack_result) { | 213 void ConfirmTouchEvent(InputEventAckState ack_result) { |
210 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 214 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
211 suppressing_touch_moves_ = false; | 215 suppressing_touch_moves_ = false; |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 } else if (event.type == WebInputEvent::TouchStart) { | 621 } else if (event.type == WebInputEvent::TouchStart) { |
618 for (unsigned i = 0; i < event.touchesLength; ++i) { | 622 for (unsigned i = 0; i < event.touchesLength; ++i) { |
619 const WebTouchPoint& point = event.touches[i]; | 623 const WebTouchPoint& point = event.touches[i]; |
620 if (point.state == WebTouchPoint::StatePressed) | 624 if (point.state == WebTouchPoint::StatePressed) |
621 touch_ack_states_[point.id] = ack_result; | 625 touch_ack_states_[point.id] = ack_result; |
622 } | 626 } |
623 } | 627 } |
624 } | 628 } |
625 | 629 |
626 } // namespace content | 630 } // namespace content |
OLD | NEW |