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_action_filter.h" | 5 #include "content/browser/renderer_host/input/touch_action_filter.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "third_party/WebKit/public/web/WebInputEvent.h" | 10 #include "third_party/WebKit/public/web/WebInputEvent.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 bool TouchActionFilter::FilterGestureEvent(WebGestureEvent* gesture_event) { | 38 bool TouchActionFilter::FilterGestureEvent(WebGestureEvent* gesture_event) { |
39 if (gesture_event->sourceDevice != blink::WebGestureDeviceTouchscreen) | 39 if (gesture_event->sourceDevice != blink::WebGestureDeviceTouchscreen) |
40 return false; | 40 return false; |
41 | 41 |
42 // Filter for allowable touch actions first (eg. before the TouchEventQueue | 42 // Filter for allowable touch actions first (eg. before the TouchEventQueue |
43 // can decide to send a touch cancel event). | 43 // can decide to send a touch cancel event). |
44 switch (gesture_event->type) { | 44 switch (gesture_event->type) { |
45 case WebInputEvent::GestureScrollBegin: | 45 case WebInputEvent::GestureScrollBegin: |
46 DCHECK(!drop_scroll_gesture_events_); | 46 DCHECK(!drop_scroll_gesture_events_); |
47 DCHECK(!drop_pinch_gesture_events_); | |
47 drop_scroll_gesture_events_ = ShouldSuppressScroll(*gesture_event); | 48 drop_scroll_gesture_events_ = ShouldSuppressScroll(*gesture_event); |
49 drop_pinch_gesture_events_ = | |
50 (allowed_touch_action_ & TOUCH_ACTION_PINCH_ZOOM) == 0; | |
51 | |
52 // if there are two or more pointers then ensure that we allow panning | |
Rick Byers
2016/09/14 15:47:51
nit: wouldn't this make more sense in ShouldSuppre
dtapuska
2016/09/21 19:29:37
Done.
| |
53 // if pinch-zoom is allowed. | |
Rick Byers
2016/09/14 15:47:51
You were going to file a bug to track the subtle b
dtapuska
2016/09/21 19:29:37
Done.
| |
54 if (!drop_pinch_gesture_events_ && drop_scroll_gesture_events_ && | |
55 gesture_event->data.scrollBegin.pointerCount >= 2) { | |
56 drop_scroll_gesture_events_ = false; | |
57 } | |
58 | |
48 return drop_scroll_gesture_events_; | 59 return drop_scroll_gesture_events_; |
49 | 60 |
50 case WebInputEvent::GestureScrollUpdate: | 61 case WebInputEvent::GestureScrollUpdate: |
51 if (drop_scroll_gesture_events_) { | 62 if (drop_scroll_gesture_events_) { |
52 return true; | 63 return true; |
53 } else { | 64 } else { |
54 // Scrolls restricted to a specific axis shouldn't permit movement | 65 // Scrolls restricted to a specific axis shouldn't permit movement |
55 // in the perpendicular axis. | 66 // in the perpendicular axis. |
56 if (IsYAxisActionDisallowed(allowed_touch_action_)) { | 67 if (IsYAxisActionDisallowed(allowed_touch_action_)) { |
57 gesture_event->data.scrollUpdate.deltaY = 0; | 68 gesture_event->data.scrollUpdate.deltaY = 0; |
(...skipping 22 matching lines...) Expand all Loading... | |
80 !gesture_event->data.flingStart.velocityY) { | 91 !gesture_event->data.flingStart.velocityY) { |
81 gesture_event->type = WebInputEvent::GestureScrollEnd; | 92 gesture_event->type = WebInputEvent::GestureScrollEnd; |
82 } | 93 } |
83 } | 94 } |
84 return FilterScrollEndingGesture(); | 95 return FilterScrollEndingGesture(); |
85 | 96 |
86 case WebInputEvent::GestureScrollEnd: | 97 case WebInputEvent::GestureScrollEnd: |
87 return FilterScrollEndingGesture(); | 98 return FilterScrollEndingGesture(); |
88 | 99 |
89 case WebInputEvent::GesturePinchBegin: | 100 case WebInputEvent::GesturePinchBegin: |
90 DCHECK(!drop_pinch_gesture_events_); | |
91 if (allowed_touch_action_ & TOUCH_ACTION_PINCH_ZOOM) { | |
92 // Pinch events are always bracketed by scroll events, and the W3C | |
93 // standard touch-action provides no way to disable scrolling without | |
94 // also disabling pinching (validated by the IPC ENUM traits). | |
95 DCHECK(allowed_touch_action_ == TOUCH_ACTION_AUTO || | |
96 allowed_touch_action_ == TOUCH_ACTION_MANIPULATION); | |
97 DCHECK(!drop_scroll_gesture_events_); | |
98 } else { | |
99 drop_pinch_gesture_events_ = true; | |
100 } | |
101 return drop_pinch_gesture_events_; | 101 return drop_pinch_gesture_events_; |
102 | 102 |
103 case WebInputEvent::GesturePinchUpdate: | 103 case WebInputEvent::GesturePinchUpdate: |
104 return drop_pinch_gesture_events_; | 104 return drop_pinch_gesture_events_; |
105 | 105 |
106 case WebInputEvent::GesturePinchEnd: | 106 case WebInputEvent::GesturePinchEnd: |
107 if (drop_pinch_gesture_events_) { | 107 if (drop_pinch_gesture_events_) { |
108 drop_pinch_gesture_events_ = false; | 108 drop_pinch_gesture_events_ = false; |
109 return true; | 109 return true; |
110 } | 110 } |
111 DCHECK(!drop_scroll_gesture_events_); | |
112 break; | 111 break; |
113 | 112 |
114 // The double tap gesture is a tap ending event. If a double tap gesture is | 113 // The double tap gesture is a tap ending event. If a double tap gesture is |
115 // filtered out, replace it with a tap event. | 114 // filtered out, replace it with a tap event. |
116 case WebInputEvent::GestureDoubleTap: | 115 case WebInputEvent::GestureDoubleTap: |
117 DCHECK_EQ(1, gesture_event->data.tap.tapCount); | 116 DCHECK_EQ(1, gesture_event->data.tap.tapCount); |
118 if (!allow_current_double_tap_event_) | 117 if (!allow_current_double_tap_event_) |
119 gesture_event->type = WebInputEvent::GestureTap; | 118 gesture_event->type = WebInputEvent::GestureTap; |
120 allow_current_double_tap_event_ = true; | 119 allow_current_double_tap_event_ = true; |
121 break; | 120 break; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 | 180 |
182 void TouchActionFilter::ResetTouchAction() { | 181 void TouchActionFilter::ResetTouchAction() { |
183 // Note that resetting the action mid-sequence is tolerated. Gestures that had | 182 // Note that resetting the action mid-sequence is tolerated. Gestures that had |
184 // their begin event(s) suppressed will be suppressed until the next sequence. | 183 // their begin event(s) suppressed will be suppressed until the next sequence. |
185 allowed_touch_action_ = TOUCH_ACTION_AUTO; | 184 allowed_touch_action_ = TOUCH_ACTION_AUTO; |
186 } | 185 } |
187 | 186 |
188 bool TouchActionFilter::ShouldSuppressScroll( | 187 bool TouchActionFilter::ShouldSuppressScroll( |
189 const blink::WebGestureEvent& gesture_event) { | 188 const blink::WebGestureEvent& gesture_event) { |
190 DCHECK_EQ(gesture_event.type, WebInputEvent::GestureScrollBegin); | 189 DCHECK_EQ(gesture_event.type, WebInputEvent::GestureScrollBegin); |
190 LOG(ERROR) << "Got scroll begin"; | |
Rick Byers
2016/09/14 15:47:50
remove
dtapuska
2016/09/21 19:29:37
Done.
| |
191 if ((allowed_touch_action_ & TOUCH_ACTION_PAN) == TOUCH_ACTION_PAN) | 191 if ((allowed_touch_action_ & TOUCH_ACTION_PAN) == TOUCH_ACTION_PAN) |
192 // All possible panning is enabled. | 192 // All possible panning is enabled. |
193 return false; | 193 return false; |
194 if (!(allowed_touch_action_ & TOUCH_ACTION_PAN)) | 194 if (!(allowed_touch_action_ & TOUCH_ACTION_PAN)) |
195 // No panning is enabled. | 195 // No panning is enabled. |
196 return true; | 196 return true; |
197 | 197 |
198 // If there's no hint or it's perfectly diagonal, then allow the scroll. | 198 // If there's no hint or it's perfectly diagonal, then allow the scroll. |
199 if (fabs(gesture_event.data.scrollBegin.deltaXHint) == | 199 if (fabs(gesture_event.data.scrollBegin.deltaXHint) == |
200 fabs(gesture_event.data.scrollBegin.deltaYHint)) | 200 fabs(gesture_event.data.scrollBegin.deltaYHint)) |
(...skipping 19 matching lines...) Expand all Loading... | |
220 } else if (gesture_event.data.scrollBegin.deltaYHint < 0 && | 220 } else if (gesture_event.data.scrollBegin.deltaYHint < 0 && |
221 allowed_touch_action_ & TOUCH_ACTION_PAN_DOWN) { | 221 allowed_touch_action_ & TOUCH_ACTION_PAN_DOWN) { |
222 return false; | 222 return false; |
223 } else { | 223 } else { |
224 return true; | 224 return true; |
225 } | 225 } |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 } // namespace content | 229 } // namespace content |
OLD | NEW |