| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tap_suppression_controller.h" | 5 #include "content/browser/renderer_host/touchpad_tap_suppression_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
| 13 #include "ui/base/gestures/gesture_configuration.h" | 13 #include "ui/base/gestures/gesture_configuration.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 TapSuppressionController::TapSuppressionController(RenderWidgetHostImpl* rwhv) | 17 TouchpadTapSuppressionController::TouchpadTapSuppressionController( |
| 18 : render_widget_host_(rwhv), | 18 RenderWidgetHostImpl* rwhv) |
| 19 state_(TapSuppressionController::NOTHING) { | 19 : render_widget_host_(rwhv), |
| 20 state_(TouchpadTapSuppressionController::NOTHING) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 TapSuppressionController::~TapSuppressionController() { } | 23 TouchpadTapSuppressionController::~TouchpadTapSuppressionController() { } |
| 23 | 24 |
| 24 bool TapSuppressionController::ShouldSuppressMouseUp() { | 25 bool TouchpadTapSuppressionController::ShouldSuppressMouseUp() { |
| 25 switch (state_) { | 26 switch (state_) { |
| 26 case NOTHING: | 27 case NOTHING: |
| 27 case GFC_IN_PROGRESS: | 28 case GFC_IN_PROGRESS: |
| 28 return false; | 29 return false; |
| 29 case MD_STASHED: | 30 case MD_STASHED: |
| 30 state_ = NOTHING; | 31 state_ = NOTHING; |
| 31 mouse_down_timer_.Stop(); | 32 mouse_down_timer_.Stop(); |
| 32 return true; | 33 return true; |
| 33 case LAST_CANCEL_STOPPED_FLING: | 34 case LAST_CANCEL_STOPPED_FLING: |
| 34 NOTREACHED() << "Invalid MouseUp on LAST_CANCEL_STOPPED_FLING state"; | 35 NOTREACHED() << "Invalid MouseUp on LAST_CANCEL_STOPPED_FLING state"; |
| 35 } | 36 } |
| 36 return false; | 37 return false; |
| 37 } | 38 } |
| 38 | 39 |
| 39 bool TapSuppressionController::ShouldDeferMouseDown( | 40 bool TouchpadTapSuppressionController::ShouldDeferMouseDown( |
| 40 const WebKit::WebMouseEvent& event) { | 41 const WebKit::WebMouseEvent& event) { |
| 41 switch (state_) { | 42 switch (state_) { |
| 42 case NOTHING: | 43 case NOTHING: |
| 43 return false; | 44 return false; |
| 44 case GFC_IN_PROGRESS: | 45 case GFC_IN_PROGRESS: |
| 45 mouse_down_timer_.Start( | 46 mouse_down_timer_.Start( |
| 46 FROM_HERE, | 47 FROM_HERE, |
| 47 base::TimeDelta::FromMilliseconds( | 48 base::TimeDelta::FromMilliseconds( |
| 48 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), | 49 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), |
| 49 this, | 50 this, |
| 50 &TapSuppressionController::MouseDownTimerExpired); | 51 &TouchpadTapSuppressionController::MouseDownTimerExpired); |
| 51 stashed_mouse_down_ = event; | 52 stashed_mouse_down_ = event; |
| 52 state_ = MD_STASHED; | 53 state_ = MD_STASHED; |
| 53 return true; | 54 return true; |
| 54 case MD_STASHED: | 55 case MD_STASHED: |
| 55 NOTREACHED() << "MouseDown on MD_STASHED state"; | 56 NOTREACHED() << "MouseDown on MD_STASHED state"; |
| 56 state_ = NOTHING; | 57 state_ = NOTHING; |
| 57 return false; | 58 return false; |
| 58 case LAST_CANCEL_STOPPED_FLING: | 59 case LAST_CANCEL_STOPPED_FLING: |
| 59 if ((base::TimeTicks::Now() - fling_cancel_time_).InMilliseconds() | 60 if ((base::TimeTicks::Now() - fling_cancel_time_).InMilliseconds() |
| 60 < ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms()) { | 61 < ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms()) { |
| 61 state_ = MD_STASHED; | 62 state_ = MD_STASHED; |
| 62 mouse_down_timer_.Start( | 63 mouse_down_timer_.Start( |
| 63 FROM_HERE, | 64 FROM_HERE, |
| 64 base::TimeDelta::FromMilliseconds( | 65 base::TimeDelta::FromMilliseconds( |
| 65 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), | 66 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), |
| 66 this, | 67 this, |
| 67 &TapSuppressionController::MouseDownTimerExpired); | 68 &TouchpadTapSuppressionController::MouseDownTimerExpired); |
| 68 stashed_mouse_down_ = event; | 69 stashed_mouse_down_ = event; |
| 69 return true; | 70 return true; |
| 70 } else { | 71 } else { |
| 71 state_ = NOTHING; | 72 state_ = NOTHING; |
| 72 return false; | 73 return false; |
| 73 } | 74 } |
| 74 } | 75 } |
| 75 return false; | 76 return false; |
| 76 } | 77 } |
| 77 | 78 |
| 78 void TapSuppressionController::GestureFlingCancelAck(bool processed) { | 79 void TouchpadTapSuppressionController::GestureFlingCancelAck(bool processed) { |
| 79 switch (state_) { | 80 switch (state_) { |
| 80 case NOTHING: | 81 case NOTHING: |
| 81 NOTREACHED() << "GFC_Ack without a GFC"; | 82 NOTREACHED() << "GFC_Ack without a GFC"; |
| 82 break; | 83 break; |
| 83 case GFC_IN_PROGRESS: | 84 case GFC_IN_PROGRESS: |
| 84 if (processed) | 85 if (processed) |
| 85 fling_cancel_time_ = base::TimeTicks::Now(); | 86 fling_cancel_time_ = base::TimeTicks::Now(); |
| 86 state_ = LAST_CANCEL_STOPPED_FLING; | 87 state_ = LAST_CANCEL_STOPPED_FLING; |
| 87 break; | 88 break; |
| 88 case MD_STASHED: | 89 case MD_STASHED: |
| 89 if (!processed) { | 90 if (!processed) { |
| 90 TRACE_EVENT0("browser", | 91 TRACE_EVENT0("browser", |
| 91 "TapSuppressionController::GestureFlingCancelAck"); | 92 "TapSuppressionController::GestureFlingCancelAck"); |
| 92 mouse_down_timer_.Stop(); | 93 mouse_down_timer_.Stop(); |
| 93 render_widget_host_->ForwardMouseEventImmediately(stashed_mouse_down_); | 94 render_widget_host_->ForwardMouseEventImmediately(stashed_mouse_down_); |
| 94 state_ = NOTHING; | 95 state_ = NOTHING; |
| 95 } // Else waiting for the timer to release the mouse event. | 96 } // Else waiting for the timer to release the mouse event. |
| 96 break; | 97 break; |
| 97 case LAST_CANCEL_STOPPED_FLING: | 98 case LAST_CANCEL_STOPPED_FLING: |
| 98 break; | 99 break; |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 | 102 |
| 102 void TapSuppressionController::GestureFlingCancel(double cancel_time) { | 103 void TouchpadTapSuppressionController::GestureFlingCancel(double cancel_time) { |
| 103 switch (state_) { | 104 switch (state_) { |
| 104 case NOTHING: | 105 case NOTHING: |
| 105 case GFC_IN_PROGRESS: | 106 case GFC_IN_PROGRESS: |
| 106 case LAST_CANCEL_STOPPED_FLING: | 107 case LAST_CANCEL_STOPPED_FLING: |
| 107 state_ = GFC_IN_PROGRESS; | 108 state_ = GFC_IN_PROGRESS; |
| 108 break; | 109 break; |
| 109 case MD_STASHED: | 110 case MD_STASHED: |
| 110 break; | 111 break; |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 void TapSuppressionController::MouseDownTimerExpired() { | 115 void TouchpadTapSuppressionController::MouseDownTimerExpired() { |
| 115 switch (state_) { | 116 switch (state_) { |
| 116 case NOTHING: | 117 case NOTHING: |
| 117 case GFC_IN_PROGRESS: | 118 case GFC_IN_PROGRESS: |
| 118 case LAST_CANCEL_STOPPED_FLING: | 119 case LAST_CANCEL_STOPPED_FLING: |
| 119 NOTREACHED() << "Timer fired on invalid state."; | 120 NOTREACHED() << "Timer fired on invalid state."; |
| 120 state_ = NOTHING; | 121 state_ = NOTHING; |
| 121 break; | 122 break; |
| 122 case MD_STASHED: | 123 case MD_STASHED: |
| 123 TRACE_EVENT0("browser", | 124 TRACE_EVENT0("browser", |
| 124 "TapSuppressionController::MouseDownTimerExpired"); | 125 "TouchpadTapSuppressionController::MouseDownTimerExpired"); |
| 125 render_widget_host_->ForwardMouseEventImmediately(stashed_mouse_down_); | 126 render_widget_host_->ForwardMouseEventImmediately(stashed_mouse_down_); |
| 126 state_ = NOTHING; | 127 state_ = NOTHING; |
| 127 break; | 128 break; |
| 128 } | 129 } |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace content | 132 } // namespace content |
| OLD | NEW |