| 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/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 | 13 #include "ui/base/gestures/gesture_configuration.h" |
| 14 namespace { | |
| 15 | |
| 16 // Default maxium time between a mousedown/mouseup pair that is considered to | |
| 17 // be a suppressable tap. | |
| 18 static const int kMaxiumTapGapTimeMs = 200; | |
| 19 | |
| 20 // Default maximum time between a GestureFlingCancel and a mousedown such that | |
| 21 // the mousedown is considered associated with the cancel event. | |
| 22 static const int kMaxiumCancelToDownTimeMs = 400; | |
| 23 | |
| 24 // Sets |*value| to |switchKey| if it exists or sets it to |defaultValue|. | |
| 25 static void GetFlingParamHelper(int* value, int defaultValue, | |
| 26 const char switchKey[]) { | |
| 27 if (*value < 0) { | |
| 28 *value = defaultValue; | |
| 29 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 30 std::string command_line_param = | |
| 31 command_line->GetSwitchValueASCII(switchKey); | |
| 32 if (!command_line_param.empty()) { | |
| 33 int v; | |
| 34 if (base::StringToInt(command_line_param, &v)) | |
| 35 *value = static_cast<int>(v); | |
| 36 } | |
| 37 DCHECK_GT(*value, 0); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 static int GetMaxiumTapGapTimeMs() { | |
| 42 static int maximum_tap_gap_time_ms = -1; | |
| 43 GetFlingParamHelper(&maximum_tap_gap_time_ms, | |
| 44 kMaxiumTapGapTimeMs, | |
| 45 switches::kFlingTapSuppressMaxGap); | |
| 46 return maximum_tap_gap_time_ms; | |
| 47 } | |
| 48 | |
| 49 static int GetMaxiumCancelToDownTimeMs() { | |
| 50 static int maximum_cancel_to_down_time_ms = -1; | |
| 51 GetFlingParamHelper(&maximum_cancel_to_down_time_ms, | |
| 52 kMaxiumCancelToDownTimeMs, | |
| 53 switches::kFlingTapSuppressMaxDown); | |
| 54 return maximum_cancel_to_down_time_ms; | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | 14 |
| 59 namespace content { | 15 namespace content { |
| 60 | 16 |
| 61 TapSuppressionController::TapSuppressionController(RenderWidgetHostImpl* rwhv) | 17 TapSuppressionController::TapSuppressionController(RenderWidgetHostImpl* rwhv) |
| 62 : render_widget_host_(rwhv), | 18 : render_widget_host_(rwhv), |
| 63 state_(TapSuppressionController::NOTHING) { | 19 state_(TapSuppressionController::NOTHING) { |
| 64 } | 20 } |
| 65 | 21 |
| 66 TapSuppressionController::~TapSuppressionController() { } | 22 TapSuppressionController::~TapSuppressionController() { } |
| 67 | 23 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 79 } | 35 } |
| 80 return false; | 36 return false; |
| 81 } | 37 } |
| 82 | 38 |
| 83 bool TapSuppressionController::ShouldDeferMouseDown( | 39 bool TapSuppressionController::ShouldDeferMouseDown( |
| 84 const WebKit::WebMouseEvent& event) { | 40 const WebKit::WebMouseEvent& event) { |
| 85 switch (state_) { | 41 switch (state_) { |
| 86 case NOTHING: | 42 case NOTHING: |
| 87 return false; | 43 return false; |
| 88 case GFC_IN_PROGRESS: | 44 case GFC_IN_PROGRESS: |
| 89 mouse_down_timer_.Start(FROM_HERE, | 45 mouse_down_timer_.Start( |
| 90 base::TimeDelta::FromMilliseconds( | 46 FROM_HERE, |
| 91 GetMaxiumTapGapTimeMs()), | 47 base::TimeDelta::FromMilliseconds( |
| 92 this, | 48 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), |
| 93 &TapSuppressionController::MouseDownTimerExpired); | 49 this, |
| 50 &TapSuppressionController::MouseDownTimerExpired); |
| 94 stashed_mouse_down_ = event; | 51 stashed_mouse_down_ = event; |
| 95 state_ = MD_STASHED; | 52 state_ = MD_STASHED; |
| 96 return true; | 53 return true; |
| 97 case MD_STASHED: | 54 case MD_STASHED: |
| 98 NOTREACHED() << "MouseDown on MD_STASHED state"; | 55 NOTREACHED() << "MouseDown on MD_STASHED state"; |
| 99 state_ = NOTHING; | 56 state_ = NOTHING; |
| 100 return false; | 57 return false; |
| 101 case LAST_CANCEL_STOPPED_FLING: | 58 case LAST_CANCEL_STOPPED_FLING: |
| 102 if ((base::TimeTicks::Now() - fling_cancel_time_).InMilliseconds() | 59 if ((base::TimeTicks::Now() - fling_cancel_time_).InMilliseconds() |
| 103 < GetMaxiumCancelToDownTimeMs()) { | 60 < ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms()) { |
| 104 state_ = MD_STASHED; | 61 state_ = MD_STASHED; |
| 105 mouse_down_timer_.Start(FROM_HERE, | 62 mouse_down_timer_.Start( |
| 63 FROM_HERE, |
| 106 base::TimeDelta::FromMilliseconds( | 64 base::TimeDelta::FromMilliseconds( |
| 107 GetMaxiumTapGapTimeMs()), | 65 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), |
| 108 this, | 66 this, |
| 109 &TapSuppressionController::MouseDownTimerExpired); | 67 &TapSuppressionController::MouseDownTimerExpired); |
| 110 stashed_mouse_down_ = event; | 68 stashed_mouse_down_ = event; |
| 111 return true; | 69 return true; |
| 112 } else { | 70 } else { |
| 113 state_ = NOTHING; | 71 state_ = NOTHING; |
| 114 return false; | 72 return false; |
| 115 } | 73 } |
| 116 } | 74 } |
| 117 return false; | 75 return false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 case MD_STASHED: | 122 case MD_STASHED: |
| 165 TRACE_EVENT0("browser", | 123 TRACE_EVENT0("browser", |
| 166 "TapSuppressionController::MouseDownTimerExpired"); | 124 "TapSuppressionController::MouseDownTimerExpired"); |
| 167 render_widget_host_->ForwardMouseEventImmediately(stashed_mouse_down_); | 125 render_widget_host_->ForwardMouseEventImmediately(stashed_mouse_down_); |
| 168 state_ = NOTHING; | 126 state_ = NOTHING; |
| 169 break; | 127 break; |
| 170 } | 128 } |
| 171 } | 129 } |
| 172 | 130 |
| 173 } // namespace content | 131 } // namespace content |
| OLD | NEW |