| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.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() |
| 14 : enabled(false), |
| 15 max_cancel_to_down_time(base::TimeDelta::FromMilliseconds(180)), |
| 16 max_tap_gap_time(base::TimeDelta::FromMilliseconds(500)) { |
| 17 } |
| 18 |
| 13 TapSuppressionController::TapSuppressionController( | 19 TapSuppressionController::TapSuppressionController( |
| 14 TapSuppressionControllerClient* client) | 20 TapSuppressionControllerClient* client, |
| 21 const Config& config) |
| 15 : client_(client), | 22 : client_(client), |
| 16 state_(TapSuppressionController::NOTHING) { | 23 state_(config.enabled ? NOTHING : DISABLED), |
| 24 max_cancel_to_down_time_(config.max_cancel_to_down_time), |
| 25 max_tap_gap_time_(config.max_tap_gap_time) { |
| 17 } | 26 } |
| 18 | 27 |
| 19 TapSuppressionController::~TapSuppressionController() {} | 28 TapSuppressionController::~TapSuppressionController() {} |
| 20 | 29 |
| 21 void TapSuppressionController::GestureFlingCancel() { | 30 void TapSuppressionController::GestureFlingCancel() { |
| 22 switch (state_) { | 31 switch (state_) { |
| 32 case DISABLED: |
| 33 break; |
| 23 case NOTHING: | 34 case NOTHING: |
| 24 case GFC_IN_PROGRESS: | 35 case GFC_IN_PROGRESS: |
| 25 case LAST_CANCEL_STOPPED_FLING: | 36 case LAST_CANCEL_STOPPED_FLING: |
| 26 state_ = GFC_IN_PROGRESS; | 37 state_ = GFC_IN_PROGRESS; |
| 27 break; | 38 break; |
| 28 case TAP_DOWN_STASHED: | 39 case TAP_DOWN_STASHED: |
| 29 break; | 40 break; |
| 30 } | 41 } |
| 31 } | 42 } |
| 32 | 43 |
| 33 void TapSuppressionController::GestureFlingCancelAck(bool processed) { | 44 void TapSuppressionController::GestureFlingCancelAck(bool processed) { |
| 34 base::TimeTicks event_time = Now(); | 45 base::TimeTicks event_time = Now(); |
| 35 switch (state_) { | 46 switch (state_) { |
| 47 case DISABLED: |
| 36 case NOTHING: | 48 case NOTHING: |
| 37 break; | 49 break; |
| 38 case GFC_IN_PROGRESS: | 50 case GFC_IN_PROGRESS: |
| 39 if (processed) | 51 if (processed) |
| 40 fling_cancel_time_ = event_time; | 52 fling_cancel_time_ = event_time; |
| 41 state_ = LAST_CANCEL_STOPPED_FLING; | 53 state_ = LAST_CANCEL_STOPPED_FLING; |
| 42 break; | 54 break; |
| 43 case TAP_DOWN_STASHED: | 55 case TAP_DOWN_STASHED: |
| 44 if (!processed) { | 56 if (!processed) { |
| 45 TRACE_EVENT0("browser", | 57 TRACE_EVENT0("browser", |
| 46 "TapSuppressionController::GestureFlingCancelAck"); | 58 "TapSuppressionController::GestureFlingCancelAck"); |
| 47 StopTapDownTimer(); | 59 StopTapDownTimer(); |
| 48 client_->ForwardStashedTapDown(); | 60 client_->ForwardStashedTapDown(); |
| 49 state_ = NOTHING; | 61 state_ = NOTHING; |
| 50 } // Else waiting for the timer to release the stashed tap down. | 62 } // Else waiting for the timer to release the stashed tap down. |
| 51 break; | 63 break; |
| 52 case LAST_CANCEL_STOPPED_FLING: | 64 case LAST_CANCEL_STOPPED_FLING: |
| 53 break; | 65 break; |
| 54 } | 66 } |
| 55 } | 67 } |
| 56 | 68 |
| 57 bool TapSuppressionController::ShouldDeferTapDown() { | 69 bool TapSuppressionController::ShouldDeferTapDown() { |
| 58 base::TimeTicks event_time = Now(); | 70 base::TimeTicks event_time = Now(); |
| 59 switch (state_) { | 71 switch (state_) { |
| 72 case DISABLED: |
| 60 case NOTHING: | 73 case NOTHING: |
| 61 return false; | 74 return false; |
| 62 case GFC_IN_PROGRESS: | 75 case GFC_IN_PROGRESS: |
| 63 state_ = TAP_DOWN_STASHED; | 76 state_ = TAP_DOWN_STASHED; |
| 64 StartTapDownTimer( | 77 StartTapDownTimer(max_tap_gap_time_); |
| 65 base::TimeDelta::FromMilliseconds(client_->MaxTapGapTimeInMs())); | |
| 66 return true; | 78 return true; |
| 67 case TAP_DOWN_STASHED: | 79 case TAP_DOWN_STASHED: |
| 68 NOTREACHED() << "TapDown on TAP_DOWN_STASHED state"; | 80 NOTREACHED() << "TapDown on TAP_DOWN_STASHED state"; |
| 69 state_ = NOTHING; | 81 state_ = NOTHING; |
| 70 return false; | 82 return false; |
| 71 case LAST_CANCEL_STOPPED_FLING: | 83 case LAST_CANCEL_STOPPED_FLING: |
| 72 if ((event_time - fling_cancel_time_).InMilliseconds() | 84 if ((event_time - fling_cancel_time_) < max_cancel_to_down_time_) { |
| 73 < client_->MaxCancelToDownTimeInMs()) { | |
| 74 state_ = TAP_DOWN_STASHED; | 85 state_ = TAP_DOWN_STASHED; |
| 75 StartTapDownTimer( | 86 StartTapDownTimer(max_tap_gap_time_); |
| 76 base::TimeDelta::FromMilliseconds(client_->MaxTapGapTimeInMs())); | |
| 77 return true; | 87 return true; |
| 78 } else { | 88 } else { |
| 79 state_ = NOTHING; | 89 state_ = NOTHING; |
| 80 return false; | 90 return false; |
| 81 } | 91 } |
| 82 } | 92 } |
| 83 NOTREACHED() << "Invalid state"; | 93 NOTREACHED() << "Invalid state"; |
| 84 return false; | 94 return false; |
| 85 } | 95 } |
| 86 | 96 |
| 87 bool TapSuppressionController::ShouldSuppressTapEnd() { | 97 bool TapSuppressionController::ShouldSuppressTapEnd() { |
| 88 switch (state_) { | 98 switch (state_) { |
| 99 case DISABLED: |
| 89 case NOTHING: | 100 case NOTHING: |
| 90 case GFC_IN_PROGRESS: | 101 case GFC_IN_PROGRESS: |
| 91 return false; | 102 return false; |
| 92 case TAP_DOWN_STASHED: | 103 case TAP_DOWN_STASHED: |
| 93 state_ = NOTHING; | 104 state_ = NOTHING; |
| 94 StopTapDownTimer(); | 105 StopTapDownTimer(); |
| 95 client_->DropStashedTapDown(); | 106 client_->DropStashedTapDown(); |
| 96 return true; | 107 return true; |
| 97 case LAST_CANCEL_STOPPED_FLING: | 108 case LAST_CANCEL_STOPPED_FLING: |
| 98 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state"; | 109 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state"; |
| 99 } | 110 } |
| 100 return false; | 111 return false; |
| 101 } | 112 } |
| 102 | 113 |
| 103 base::TimeTicks TapSuppressionController::Now() { | 114 base::TimeTicks TapSuppressionController::Now() { |
| 104 return base::TimeTicks::Now(); | 115 return base::TimeTicks::Now(); |
| 105 } | 116 } |
| 106 | 117 |
| 107 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) { | 118 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) { |
| 108 tap_down_timer_.Start(FROM_HERE, delay, this, | 119 tap_down_timer_.Start(FROM_HERE, delay, this, |
| 109 &TapSuppressionController::TapDownTimerExpired); | 120 &TapSuppressionController::TapDownTimerExpired); |
| 110 } | 121 } |
| 111 | 122 |
| 112 void TapSuppressionController::StopTapDownTimer() { | 123 void TapSuppressionController::StopTapDownTimer() { |
| 113 tap_down_timer_.Stop(); | 124 tap_down_timer_.Stop(); |
| 114 } | 125 } |
| 115 | 126 |
| 116 void TapSuppressionController::TapDownTimerExpired() { | 127 void TapSuppressionController::TapDownTimerExpired() { |
| 117 switch (state_) { | 128 switch (state_) { |
| 129 case DISABLED: |
| 118 case NOTHING: | 130 case NOTHING: |
| 131 NOTREACHED() << "Timer fired on invalid state."; |
| 132 break; |
| 119 case GFC_IN_PROGRESS: | 133 case GFC_IN_PROGRESS: |
| 120 case LAST_CANCEL_STOPPED_FLING: | 134 case LAST_CANCEL_STOPPED_FLING: |
| 121 NOTREACHED() << "Timer fired on invalid state."; | 135 NOTREACHED() << "Timer fired on invalid state."; |
| 122 state_ = NOTHING; | 136 state_ = NOTHING; |
| 123 break; | 137 break; |
| 124 case TAP_DOWN_STASHED: | 138 case TAP_DOWN_STASHED: |
| 125 TRACE_EVENT0("browser", | 139 TRACE_EVENT0("browser", |
| 126 "TapSuppressionController::TapDownTimerExpired"); | 140 "TapSuppressionController::TapDownTimerExpired"); |
| 127 client_->ForwardStashedTapDown(); | 141 client_->ForwardStashedTapDown(); |
| 128 state_ = NOTHING; | 142 state_ = NOTHING; |
| 129 break; | 143 break; |
| 130 } | 144 } |
| 131 } | 145 } |
| 132 | 146 |
| 133 } // namespace content | 147 } // namespace content |
| OLD | NEW |