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_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" |
| 11 | 11 |
| 12 using blink::WebInputEvent; | 12 using blink::WebInputEvent; |
| 13 using blink::WebGestureEvent; | 13 using blink::WebGestureEvent; |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 TouchActionFilter::TouchActionFilter() : | 17 TouchActionFilter::TouchActionFilter() : |
| 18 drop_scroll_gesture_events_(false), | 18 drop_scroll_gesture_events_(false), |
| 19 drop_pinch_gesture_events_(false), | 19 drop_pinch_gesture_events_(false), |
| 20 drop_current_tap_ending_event_(false), | |
| 20 allowed_touch_action_(TOUCH_ACTION_AUTO) { | 21 allowed_touch_action_(TOUCH_ACTION_AUTO) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 bool TouchActionFilter::FilterGestureEvent(WebGestureEvent* gesture_event) { | 24 bool TouchActionFilter::FilterGestureEvent(WebGestureEvent* gesture_event) { |
| 24 // Filter for allowable touch actions first (eg. before the TouchEventQueue | 25 // Filter for allowable touch actions first (eg. before the TouchEventQueue |
| 25 // can decide to send a touch cancel event). | 26 // can decide to send a touch cancel event). |
| 26 switch(gesture_event->type) { | 27 switch(gesture_event->type) { |
| 27 case WebInputEvent::GestureScrollBegin: | 28 case WebInputEvent::GestureScrollBegin: |
| 28 DCHECK(!drop_scroll_gesture_events_); | 29 DCHECK(!drop_scroll_gesture_events_); |
| 29 drop_scroll_gesture_events_ = ShouldSuppressScroll(*gesture_event); | 30 drop_scroll_gesture_events_ = ShouldSuppressScroll(*gesture_event); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 return drop_pinch_gesture_events_; | 74 return drop_pinch_gesture_events_; |
| 74 | 75 |
| 75 case WebInputEvent::GesturePinchEnd: | 76 case WebInputEvent::GesturePinchEnd: |
| 76 if (drop_pinch_gesture_events_) { | 77 if (drop_pinch_gesture_events_) { |
| 77 drop_pinch_gesture_events_ = false; | 78 drop_pinch_gesture_events_ = false; |
| 78 return true; | 79 return true; |
| 79 } | 80 } |
| 80 DCHECK(!drop_scroll_gesture_events_); | 81 DCHECK(!drop_scroll_gesture_events_); |
| 81 break; | 82 break; |
| 82 | 83 |
| 84 // If double tap is disabled, there's no reason for the tap delay. | |
| 85 case WebInputEvent::GestureTapUnconfirmed: | |
| 86 if (allowed_touch_action_ != TOUCH_ACTION_AUTO) { | |
| 87 gesture_event->type = WebInputEvent::GestureTap; | |
| 88 drop_current_tap_ending_event_ = true; | |
| 89 } | |
| 90 break; | |
| 91 | |
| 92 case WebInputEvent::GestureTap: | |
| 93 if (drop_current_tap_ending_event_) { | |
| 94 drop_current_tap_ending_event_ = false; | |
| 95 return true; | |
| 96 } | |
| 97 break; | |
| 98 | |
| 99 case WebInputEvent::GestureTapCancel: | |
|
Rick Byers
2014/02/18 20:40:16
maybe combine this case with the above into a sing
tdresser
2014/02/18 21:27:15
Done.
| |
| 100 if (drop_current_tap_ending_event_) { | |
| 101 drop_current_tap_ending_event_ = false; | |
| 102 return true; | |
| 103 } | |
| 104 break; | |
| 105 | |
| 106 case WebInputEvent::GestureTapDown: | |
| 107 DCHECK(!drop_current_tap_ending_event_); | |
| 108 break; | |
| 109 | |
| 110 case WebInputEvent::GestureDoubleTap: | |
| 111 if (allowed_touch_action_ != TOUCH_ACTION_AUTO) | |
| 112 return true; | |
| 113 break; | |
| 114 | |
| 83 default: | 115 default: |
| 84 // Gesture events unrelated to touch actions (panning/zooming) are left | 116 // Gesture events unrelated to touch actions (panning/zooming) are left |
| 85 // alone. | 117 // alone. |
| 86 break; | 118 break; |
| 87 } | 119 } |
| 88 | 120 |
| 89 return false; | 121 return false; |
| 90 } | 122 } |
| 91 | 123 |
| 92 bool TouchActionFilter::FilterScrollEndingGesture() { | 124 bool TouchActionFilter::FilterScrollEndingGesture() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 if (ta2 == TOUCH_ACTION_AUTO) | 175 if (ta2 == TOUCH_ACTION_AUTO) |
| 144 return ta1; | 176 return ta1; |
| 145 | 177 |
| 146 // Only the true flags are left - take their intersection. | 178 // Only the true flags are left - take their intersection. |
| 147 if (!(ta1 & ta2)) | 179 if (!(ta1 & ta2)) |
| 148 return TOUCH_ACTION_NONE; | 180 return TOUCH_ACTION_NONE; |
| 149 return static_cast<TouchAction>(ta1 & ta2); | 181 return static_cast<TouchAction>(ta1 & ta2); |
| 150 } | 182 } |
| 151 | 183 |
| 152 } | 184 } |
| OLD | NEW |