| 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_); |
| 48 drop_pinch_gesture_events_ = |
| 49 (allowed_touch_action_ & TOUCH_ACTION_PINCH_ZOOM) == 0; |
| 47 drop_scroll_gesture_events_ = ShouldSuppressScroll(*gesture_event); | 50 drop_scroll_gesture_events_ = ShouldSuppressScroll(*gesture_event); |
| 48 return drop_scroll_gesture_events_; | 51 return drop_scroll_gesture_events_; |
| 49 | 52 |
| 50 case WebInputEvent::GestureScrollUpdate: | 53 case WebInputEvent::GestureScrollUpdate: |
| 51 if (drop_scroll_gesture_events_) { | 54 if (drop_scroll_gesture_events_) { |
| 52 return true; | 55 return true; |
| 53 } else { | 56 } else { |
| 54 // Scrolls restricted to a specific axis shouldn't permit movement | 57 // Scrolls restricted to a specific axis shouldn't permit movement |
| 55 // in the perpendicular axis. | 58 // in the perpendicular axis. |
| 56 if (IsYAxisActionDisallowed(allowed_touch_action_)) { | 59 if (IsYAxisActionDisallowed(allowed_touch_action_)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 80 !gesture_event->data.flingStart.velocityY) { | 83 !gesture_event->data.flingStart.velocityY) { |
| 81 gesture_event->type = WebInputEvent::GestureScrollEnd; | 84 gesture_event->type = WebInputEvent::GestureScrollEnd; |
| 82 } | 85 } |
| 83 } | 86 } |
| 84 return FilterScrollEndingGesture(); | 87 return FilterScrollEndingGesture(); |
| 85 | 88 |
| 86 case WebInputEvent::GestureScrollEnd: | 89 case WebInputEvent::GestureScrollEnd: |
| 87 return FilterScrollEndingGesture(); | 90 return FilterScrollEndingGesture(); |
| 88 | 91 |
| 89 case WebInputEvent::GesturePinchBegin: | 92 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_; | 93 return drop_pinch_gesture_events_; |
| 102 | 94 |
| 103 case WebInputEvent::GesturePinchUpdate: | 95 case WebInputEvent::GesturePinchUpdate: |
| 104 return drop_pinch_gesture_events_; | 96 return drop_pinch_gesture_events_; |
| 105 | 97 |
| 106 case WebInputEvent::GesturePinchEnd: | 98 case WebInputEvent::GesturePinchEnd: |
| 107 if (drop_pinch_gesture_events_) { | 99 if (drop_pinch_gesture_events_) { |
| 108 drop_pinch_gesture_events_ = false; | 100 drop_pinch_gesture_events_ = false; |
| 109 return true; | 101 return true; |
| 110 } | 102 } |
| 111 DCHECK(!drop_scroll_gesture_events_); | |
| 112 break; | 103 break; |
| 113 | 104 |
| 114 // The double tap gesture is a tap ending event. If a double tap gesture is | 105 // The double tap gesture is a tap ending event. If a double tap gesture is |
| 115 // filtered out, replace it with a tap event. | 106 // filtered out, replace it with a tap event. |
| 116 case WebInputEvent::GestureDoubleTap: | 107 case WebInputEvent::GestureDoubleTap: |
| 117 DCHECK_EQ(1, gesture_event->data.tap.tapCount); | 108 DCHECK_EQ(1, gesture_event->data.tap.tapCount); |
| 118 if (!allow_current_double_tap_event_) | 109 if (!allow_current_double_tap_event_) |
| 119 gesture_event->type = WebInputEvent::GestureTap; | 110 gesture_event->type = WebInputEvent::GestureTap; |
| 120 allow_current_double_tap_event_ = true; | 111 allow_current_double_tap_event_ = true; |
| 121 break; | 112 break; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 149 default: | 140 default: |
| 150 // Gesture events unrelated to touch actions (panning/zooming) are left | 141 // Gesture events unrelated to touch actions (panning/zooming) are left |
| 151 // alone. | 142 // alone. |
| 152 break; | 143 break; |
| 153 } | 144 } |
| 154 | 145 |
| 155 return false; | 146 return false; |
| 156 } | 147 } |
| 157 | 148 |
| 158 bool TouchActionFilter::FilterScrollEndingGesture() { | 149 bool TouchActionFilter::FilterScrollEndingGesture() { |
| 159 DCHECK(!drop_pinch_gesture_events_); | 150 drop_pinch_gesture_events_ = false; |
| 160 if (drop_scroll_gesture_events_) { | 151 if (drop_scroll_gesture_events_) { |
| 161 drop_scroll_gesture_events_ = false; | 152 drop_scroll_gesture_events_ = false; |
| 162 return true; | 153 return true; |
| 163 } | 154 } |
| 164 return false; | 155 return false; |
| 165 } | 156 } |
| 166 | 157 |
| 167 void TouchActionFilter::OnSetTouchAction(TouchAction touch_action) { | 158 void TouchActionFilter::OnSetTouchAction(TouchAction touch_action) { |
| 168 // For multiple fingers, we take the intersection of the touch actions for | 159 // For multiple fingers, we take the intersection of the touch actions for |
| 169 // all fingers that have gone down during this action. In the majority of | 160 // all fingers that have gone down during this action. In the majority of |
| (...skipping 11 matching lines...) Expand all Loading... |
| 181 | 172 |
| 182 void TouchActionFilter::ResetTouchAction() { | 173 void TouchActionFilter::ResetTouchAction() { |
| 183 // Note that resetting the action mid-sequence is tolerated. Gestures that had | 174 // 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. | 175 // their begin event(s) suppressed will be suppressed until the next sequence. |
| 185 allowed_touch_action_ = TOUCH_ACTION_AUTO; | 176 allowed_touch_action_ = TOUCH_ACTION_AUTO; |
| 186 } | 177 } |
| 187 | 178 |
| 188 bool TouchActionFilter::ShouldSuppressScroll( | 179 bool TouchActionFilter::ShouldSuppressScroll( |
| 189 const blink::WebGestureEvent& gesture_event) { | 180 const blink::WebGestureEvent& gesture_event) { |
| 190 DCHECK_EQ(gesture_event.type, WebInputEvent::GestureScrollBegin); | 181 DCHECK_EQ(gesture_event.type, WebInputEvent::GestureScrollBegin); |
| 182 // if there are two or more pointers then ensure that we allow panning |
| 183 // if pinch-zoom is allowed. Determine if this should really occur in the |
| 184 // GestureScrollBegin or not; see crbug.com/649034. |
| 185 if (!drop_pinch_gesture_events_ && |
| 186 gesture_event.data.scrollBegin.pointerCount >= 2) { |
| 187 return false; |
| 188 } |
| 189 |
| 191 if ((allowed_touch_action_ & TOUCH_ACTION_PAN) == TOUCH_ACTION_PAN) | 190 if ((allowed_touch_action_ & TOUCH_ACTION_PAN) == TOUCH_ACTION_PAN) |
| 192 // All possible panning is enabled. | 191 // All possible panning is enabled. |
| 193 return false; | 192 return false; |
| 193 |
| 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)) |
| 201 return false; | 201 return false; |
| 202 | 202 |
| 203 // Determine the primary initial axis of the scroll, and check whether | 203 // Determine the primary initial axis of the scroll, and check whether |
| (...skipping 16 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 |