| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/renderer_host/input/gesture_event_filter.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "content/browser/renderer_host/input/input_router.h" | |
| 10 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle
r.h" | |
| 11 #include "content/browser/renderer_host/input/touchscreen_tap_suppression_contro
ller.h" | |
| 12 #include "content/public/common/content_switches.h" | |
| 13 | |
| 14 using WebKit::WebGestureEvent; | |
| 15 using WebKit::WebInputEvent; | |
| 16 | |
| 17 namespace content { | |
| 18 GestureEventFilter::GestureEventFilter( | |
| 19 GestureEventFilterClient* client, | |
| 20 TouchpadTapSuppressionControllerClient* touchpad_client) | |
| 21 : BaseGestureEventFilter(client), | |
| 22 fling_in_progress_(false), | |
| 23 touchpad_tap_suppression_controller_( | |
| 24 new TouchpadTapSuppressionController(touchpad_client)), | |
| 25 touchscreen_tap_suppression_controller_( | |
| 26 new TouchscreenTapSuppressionController(this)) { | |
| 27 DCHECK(client); | |
| 28 DCHECK(touchpad_tap_suppression_controller_); | |
| 29 } | |
| 30 | |
| 31 GestureEventFilter::~GestureEventFilter() { } | |
| 32 | |
| 33 bool GestureEventFilter::ShouldDiscardFlingCancelEvent( | |
| 34 const GestureEventWithLatencyInfo& gesture_event) const { | |
| 35 if (coalesced_gesture_events_.empty() && fling_in_progress_) | |
| 36 return false; | |
| 37 GestureEventQueue::const_reverse_iterator it = | |
| 38 coalesced_gesture_events_.rbegin(); | |
| 39 while (it != coalesced_gesture_events_.rend()) { | |
| 40 if (it->event.type == WebInputEvent::GestureFlingStart) | |
| 41 return false; | |
| 42 if (it->event.type == WebInputEvent::GestureFlingCancel) | |
| 43 return true; | |
| 44 it++; | |
| 45 } | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 // NOTE: The filters are applied successively. This simplifies the change. | |
| 50 bool GestureEventFilter::ShouldForward( | |
| 51 const GestureEventWithLatencyInfo& gesture_event) { | |
| 52 return ShouldForwardForZeroVelocityFlingStart(gesture_event) && | |
| 53 ShouldForwardForBounceReduction(gesture_event) && | |
| 54 ShouldForwardForGFCFiltering(gesture_event) && | |
| 55 ShouldForwardForTapSuppression(gesture_event) && | |
| 56 ShouldForwardForCoalescing(gesture_event); | |
| 57 } | |
| 58 | |
| 59 bool GestureEventFilter::ShouldForwardForZeroVelocityFlingStart( | |
| 60 const GestureEventWithLatencyInfo& gesture_event) const { | |
| 61 return gesture_event.event.type != WebInputEvent::GestureFlingStart || | |
| 62 gesture_event.event.sourceDevice != WebGestureEvent::Touchpad || | |
| 63 gesture_event.event.data.flingStart.velocityX != 0 || | |
| 64 gesture_event.event.data.flingStart.velocityY != 0; | |
| 65 } | |
| 66 | |
| 67 bool GestureEventFilter::ShouldForwardForGFCFiltering( | |
| 68 const GestureEventWithLatencyInfo& gesture_event) const { | |
| 69 return gesture_event.event.type != WebInputEvent::GestureFlingCancel || | |
| 70 !ShouldDiscardFlingCancelEvent(gesture_event); | |
| 71 } | |
| 72 | |
| 73 bool GestureEventFilter::ShouldForwardForTapSuppression( | |
| 74 const GestureEventWithLatencyInfo& gesture_event) { | |
| 75 switch (gesture_event.event.type) { | |
| 76 case WebInputEvent::GestureFlingCancel: | |
| 77 if (gesture_event.event.sourceDevice == WebGestureEvent::Touchscreen) | |
| 78 touchscreen_tap_suppression_controller_->GestureFlingCancel(); | |
| 79 else | |
| 80 touchpad_tap_suppression_controller_->GestureFlingCancel(); | |
| 81 return true; | |
| 82 case WebInputEvent::GestureTapDown: | |
| 83 return !touchscreen_tap_suppression_controller_-> | |
| 84 ShouldDeferGestureTapDown(gesture_event); | |
| 85 case WebInputEvent::GestureTapCancel: | |
| 86 return !touchscreen_tap_suppression_controller_-> | |
| 87 ShouldSuppressGestureTapCancel(); | |
| 88 case WebInputEvent::GestureTap: | |
| 89 case WebInputEvent::GestureTapUnconfirmed: | |
| 90 return !touchscreen_tap_suppression_controller_-> | |
| 91 ShouldSuppressGestureTap(); | |
| 92 default: | |
| 93 return true; | |
| 94 } | |
| 95 NOTREACHED(); | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 bool GestureEventFilter::ShouldForwardScrollEndingEvent( | |
| 100 const GestureEventWithLatencyInfo& event) { | |
| 101 return ShouldForwardForGFCFiltering(event) && | |
| 102 ShouldForwardForTapSuppression(event) && | |
| 103 ShouldForwardForCoalescing(event); | |
| 104 } | |
| 105 | |
| 106 bool GestureEventFilter::ShouldForwardForCoalescing( | |
| 107 const GestureEventWithLatencyInfo& gesture_event) { | |
| 108 switch (gesture_event.event.type) { | |
| 109 case WebInputEvent::GestureFlingCancel: | |
| 110 fling_in_progress_ = false; | |
| 111 break; | |
| 112 case WebInputEvent::GestureFlingStart: | |
| 113 fling_in_progress_ = true; | |
| 114 break; | |
| 115 default: | |
| 116 break; | |
| 117 } | |
| 118 return BaseGestureEventFilter::ShouldForwardForCoalescing(gesture_event); | |
| 119 } | |
| 120 | |
| 121 void GestureEventFilter::ProcessGestureAck(InputEventAckState ack_result, | |
| 122 WebInputEvent::Type type, | |
| 123 const ui::LatencyInfo& latency) { | |
| 124 if (coalesced_gesture_events_.empty()) { | |
| 125 DLOG(ERROR) << "Received unexpected ACK for event type " << type; | |
| 126 return; | |
| 127 } | |
| 128 DCHECK_EQ(coalesced_gesture_events_.front().event.type, type); | |
| 129 | |
| 130 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); | |
| 131 if (type == WebInputEvent::GestureFlingCancel) { | |
| 132 if (coalesced_gesture_events_.front().event.sourceDevice == | |
| 133 WebGestureEvent::Touchscreen) | |
| 134 touchscreen_tap_suppression_controller_->GestureFlingCancelAck(processed); | |
| 135 else | |
| 136 touchpad_tap_suppression_controller_->GestureFlingCancelAck(processed); | |
| 137 } | |
| 138 | |
| 139 BaseGestureEventFilter::ProcessGestureAck(ack_result, type, latency); | |
| 140 } | |
| 141 | |
| 142 TouchpadTapSuppressionController* | |
| 143 GestureEventFilter::GetTouchpadTapSuppressionController() { | |
| 144 return touchpad_tap_suppression_controller_.get(); | |
| 145 } | |
| 146 | |
| 147 void GestureEventFilter::FlingHasBeenHalted() { | |
| 148 fling_in_progress_ = false; | |
| 149 } | |
| 150 | |
| 151 } // namespace content | |
| OLD | NEW |