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/tap_suppression_controller.h" | 5 #include "content/browser/renderer_host/input/tap_suppression_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "content/browser/renderer_host/input/tap_suppression_controller_client. h" | 9 #include "content/browser/renderer_host/input/tap_suppression_controller_client. h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 TapSuppressionController::Config::Config() | 13 TapSuppressionController::Config::Config() |
| 14 : enabled(false), | 14 : enabled(false), |
| 15 max_cancel_to_down_time(base::TimeDelta::FromMilliseconds(180)), | 15 max_cancel_to_down_time(base::TimeDelta::FromMilliseconds(180)), |
| 16 max_tap_gap_time(base::TimeDelta::FromMilliseconds(500)) { | 16 max_tap_gap_time(base::TimeDelta::FromMilliseconds(550)) { |
|
tdresser
2016/12/01 18:57:59
Why this change? This constant likely needs a comm
sahel
2016/12/06 15:18:13
This is set to 500ms, because that's the long pres
| |
| 17 } | 17 } |
| 18 | 18 |
| 19 TapSuppressionController::TapSuppressionController( | 19 TapSuppressionController::TapSuppressionController( |
| 20 TapSuppressionControllerClient* client, | 20 TapSuppressionControllerClient* client, |
| 21 const Config& config) | 21 const Config& config) |
| 22 : client_(client), | 22 : client_(client), |
| 23 state_(config.enabled ? NOTHING : DISABLED), | 23 state_(config.enabled ? NOTHING : DISABLED), |
| 24 max_cancel_to_down_time_(config.max_cancel_to_down_time), | 24 max_cancel_to_down_time_(config.max_cancel_to_down_time), |
| 25 max_tap_gap_time_(config.max_tap_gap_time) { | 25 max_tap_gap_time_(config.max_tap_gap_time) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 TapSuppressionController::~TapSuppressionController() {} | 28 TapSuppressionController::~TapSuppressionController() {} |
| 29 | 29 |
| 30 void TapSuppressionController::GestureFlingCancel() { | 30 void TapSuppressionController::GestureFlingCancel() { |
| 31 switch (state_) { | 31 switch (state_) { |
| 32 case DISABLED: | 32 case DISABLED: |
| 33 break; | 33 break; |
| 34 case NOTHING: | 34 case NOTHING: |
| 35 case GFC_IN_PROGRESS: | 35 case GFC_IN_PROGRESS: |
| 36 case LAST_CANCEL_STOPPED_FLING: | 36 case LAST_CANCEL_STOPPED_FLING: |
| 37 case MUST_SUPPRESS_TAP_ENDS: | |
| 37 state_ = GFC_IN_PROGRESS; | 38 state_ = GFC_IN_PROGRESS; |
| 38 break; | 39 break; |
| 39 case TAP_DOWN_STASHED: | 40 case TAP_DOWN_STASHED: |
| 40 break; | 41 break; |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 void TapSuppressionController::GestureFlingCancelAck(bool processed) { | 45 void TapSuppressionController::GestureFlingCancelAck(bool processed) { |
| 45 base::TimeTicks event_time = Now(); | 46 base::TimeTicks event_time = Now(); |
| 46 switch (state_) { | 47 switch (state_) { |
| 47 case DISABLED: | 48 case DISABLED: |
| 48 case NOTHING: | 49 case NOTHING: |
| 50 case MUST_SUPPRESS_TAP_ENDS: | |
| 49 break; | 51 break; |
| 50 case GFC_IN_PROGRESS: | 52 case GFC_IN_PROGRESS: |
| 51 if (processed) | 53 if (processed) |
| 52 fling_cancel_time_ = event_time; | 54 fling_cancel_time_ = event_time; |
| 53 state_ = LAST_CANCEL_STOPPED_FLING; | 55 state_ = LAST_CANCEL_STOPPED_FLING; |
| 54 break; | 56 break; |
| 55 case TAP_DOWN_STASHED: | 57 case TAP_DOWN_STASHED: |
| 56 if (!processed) { | 58 if (!processed) { |
| 57 TRACE_EVENT0("browser", | 59 TRACE_EVENT0("browser", |
| 58 "TapSuppressionController::GestureFlingCancelAck"); | 60 "TapSuppressionController::GestureFlingCancelAck"); |
| 59 StopTapDownTimer(); | 61 StopTapDownTimer(); |
| 60 client_->ForwardStashedTapDown(); | 62 // If the fling cancel is not processed, forward all stashed |
| 63 // gesture events. | |
| 64 client_->ForwardStashedGestureEvents(); | |
| 61 state_ = NOTHING; | 65 state_ = NOTHING; |
| 62 } // Else waiting for the timer to release the stashed tap down. | 66 } // Else waiting for the timer to release the stashed tap down. |
| 63 break; | 67 break; |
| 64 case LAST_CANCEL_STOPPED_FLING: | 68 case LAST_CANCEL_STOPPED_FLING: |
| 65 break; | 69 break; |
| 66 } | 70 } |
| 67 } | 71 } |
| 68 | 72 |
| 69 bool TapSuppressionController::ShouldDeferTapDown() { | 73 bool TapSuppressionController::ShouldDeferTapDown() { |
| 70 base::TimeTicks event_time = Now(); | 74 base::TimeTicks event_time = Now(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 82 return false; | 86 return false; |
| 83 case LAST_CANCEL_STOPPED_FLING: | 87 case LAST_CANCEL_STOPPED_FLING: |
| 84 if ((event_time - fling_cancel_time_) < max_cancel_to_down_time_) { | 88 if ((event_time - fling_cancel_time_) < max_cancel_to_down_time_) { |
| 85 state_ = TAP_DOWN_STASHED; | 89 state_ = TAP_DOWN_STASHED; |
| 86 StartTapDownTimer(max_tap_gap_time_); | 90 StartTapDownTimer(max_tap_gap_time_); |
| 87 return true; | 91 return true; |
| 88 } else { | 92 } else { |
| 89 state_ = NOTHING; | 93 state_ = NOTHING; |
| 90 return false; | 94 return false; |
| 91 } | 95 } |
| 96 // Stop suppressing tap end events. | |
| 97 case MUST_SUPPRESS_TAP_ENDS: | |
| 98 state_ = NOTHING; | |
| 99 return false; | |
| 92 } | 100 } |
| 93 NOTREACHED() << "Invalid state"; | 101 NOTREACHED() << "Invalid state"; |
| 94 return false; | 102 return false; |
| 95 } | 103 } |
| 96 | 104 |
| 97 bool TapSuppressionController::ShouldSuppressTapEnd() { | 105 bool TapSuppressionController::ShouldSuppressTapEnd() { |
| 98 switch (state_) { | 106 switch (state_) { |
| 99 case DISABLED: | 107 case DISABLED: |
| 100 case NOTHING: | 108 case NOTHING: |
| 101 case GFC_IN_PROGRESS: | 109 case GFC_IN_PROGRESS: |
| 102 return false; | 110 return false; |
| 103 case TAP_DOWN_STASHED: | 111 case TAP_DOWN_STASHED: |
| 104 state_ = NOTHING; | 112 // A tap cancel happens before long tap and two finger tap events. To |
| 113 // drop the latter events as well as the tap cancel, don't change the | |
| 114 // state to NOTHING when the stashed tap down is dropped. | |
|
tdresser
2016/12/01 18:57:59
This comment feels related to the history of the f
sahel
2016/12/06 15:18:13
Done.
| |
| 115 state_ = MUST_SUPPRESS_TAP_ENDS; | |
| 105 StopTapDownTimer(); | 116 StopTapDownTimer(); |
| 106 client_->DropStashedTapDown(); | 117 client_->DropStashedTapDown(); |
| 107 return true; | 118 return true; |
| 108 case LAST_CANCEL_STOPPED_FLING: | 119 case LAST_CANCEL_STOPPED_FLING: |
| 109 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state"; | 120 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state"; |
| 121 case MUST_SUPPRESS_TAP_ENDS: | |
| 122 return true; | |
| 110 } | 123 } |
| 111 return false; | 124 return false; |
| 112 } | 125 } |
| 113 | 126 |
| 114 base::TimeTicks TapSuppressionController::Now() { | 127 base::TimeTicks TapSuppressionController::Now() { |
| 115 return base::TimeTicks::Now(); | 128 return base::TimeTicks::Now(); |
| 116 } | 129 } |
| 117 | 130 |
| 118 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) { | 131 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) { |
| 119 tap_down_timer_.Start(FROM_HERE, delay, this, | 132 tap_down_timer_.Start(FROM_HERE, delay, this, |
| 120 &TapSuppressionController::TapDownTimerExpired); | 133 &TapSuppressionController::TapDownTimerExpired); |
| 121 } | 134 } |
| 122 | 135 |
| 123 void TapSuppressionController::StopTapDownTimer() { | 136 void TapSuppressionController::StopTapDownTimer() { |
| 124 tap_down_timer_.Stop(); | 137 tap_down_timer_.Stop(); |
| 125 } | 138 } |
| 126 | 139 |
| 127 void TapSuppressionController::TapDownTimerExpired() { | 140 void TapSuppressionController::TapDownTimerExpired() { |
| 128 switch (state_) { | 141 switch (state_) { |
| 129 case DISABLED: | 142 case DISABLED: |
| 130 case NOTHING: | 143 case NOTHING: |
| 144 case MUST_SUPPRESS_TAP_ENDS: | |
| 131 NOTREACHED() << "Timer fired on invalid state."; | 145 NOTREACHED() << "Timer fired on invalid state."; |
| 132 break; | 146 break; |
| 133 case GFC_IN_PROGRESS: | 147 case GFC_IN_PROGRESS: |
| 134 case LAST_CANCEL_STOPPED_FLING: | 148 case LAST_CANCEL_STOPPED_FLING: |
| 135 NOTREACHED() << "Timer fired on invalid state."; | 149 NOTREACHED() << "Timer fired on invalid state."; |
| 136 state_ = NOTHING; | 150 state_ = NOTHING; |
| 137 break; | 151 break; |
| 138 case TAP_DOWN_STASHED: | 152 case TAP_DOWN_STASHED: |
| 139 TRACE_EVENT0("browser", | 153 TRACE_EVENT0("browser", |
| 140 "TapSuppressionController::TapDownTimerExpired"); | 154 "TapSuppressionController::TapDownTimerExpired"); |
| 155 // When the timer expires, only forward the stashed tap down event, and | |
| 156 // drop other stashed gesture events (show press or long press). | |
| 141 client_->ForwardStashedTapDown(); | 157 client_->ForwardStashedTapDown(); |
| 142 state_ = NOTHING; | 158 state_ = MUST_SUPPRESS_TAP_ENDS; |
| 143 break; | 159 break; |
| 144 } | 160 } |
| 145 } | 161 } |
| 146 | 162 |
| 147 } // namespace content | 163 } // namespace content |
| OLD | NEW |