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