From 5e235f9394c890c0af2afb0932346e2543c3c66f Mon Sep 17 00:00:00 2001 From: "mohsen@chromium.org" Date: Wed, 9 Jan 2013 17:42:13 +0000 Subject: [PATCH] Added TapSuppressionController params to gesture configurations Added TapSuppressionController parameters to GestureConfiguration and used them in TSC. Removed command line options for configuring TSC, because now they can be configured through UI. Added the ability to configure integer parameters through UI, since TSC parameters are integers. BUG=162031 Review URL: https://chromiumcodereview.appspot.com/11745006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175823 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chromeos/login/login_utils.cc | 2 - chrome/browser/resources/gesture_config.js | 10 ++++ .../ui/gesture_prefs_observer_factory_aura.cc | 14 +++++ chrome/browser/ui/webui/gesture_config_ui.cc | 13 ++++- chrome/common/pref_names.cc | 4 ++ chrome/common/pref_names.h | 2 + .../tap_suppression_controller_aura.cc | 64 ++++------------------ content/public/common/content_switches.cc | 6 -- content/public/common/content_switches.h | 2 - ui/base/gestures/gesture_configuration.cc | 2 + ui/base/gestures/gesture_configuration.h | 20 +++++++ 11 files changed, 75 insertions(+), 64 deletions(-) diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index 9f51de2fc3f3..705e77373018 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -817,8 +817,6 @@ std::string LoginUtilsImpl::GetOffTheRecordCommandLine( ::switches::kPpapiFlashVersion, ::switches::kPpapiOutOfProcess, ::switches::kRendererStartupDialog, - ::switches::kFlingTapSuppressMaxDown, - ::switches::kFlingTapSuppressMaxGap, #if defined(USE_XI2_MT) ::switches::kTouchCalibration, #endif diff --git a/chrome/browser/resources/gesture_config.js b/chrome/browser/resources/gesture_config.js index 74607f9ec714..16c60b38d602 100644 --- a/chrome/browser/resources/gesture_config.js +++ b/chrome/browser/resources/gesture_config.js @@ -132,6 +132,16 @@ function GestureConfig() { /** List of fields used to dynamically build form. **/ var GESTURE_FIELDS = [ { + key: 'fling_max_cancel_to_down_time_in_ms', + label: 'Maximum Cancel to Down Time for Tap Suppression', + units: 'milliseconds', + }, + { + key: 'fling_max_tap_gap_time_in_ms', + label: 'Maximum Tap Gap Time for Tap Suppression', + units: 'milliseconds', + }, + { key: 'long_press_time_in_seconds', label: 'Long Press Time', units: 'seconds' diff --git a/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc b/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc index e27a14883b96..a8c96811359c 100644 --- a/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc +++ b/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc @@ -74,6 +74,8 @@ const char* kPrefsToObserve[] = { prefs::kFlingAccelerationCurveCoefficient1, prefs::kFlingAccelerationCurveCoefficient2, prefs::kFlingAccelerationCurveCoefficient3, + prefs::kFlingMaxCancelToDownTimeInMs, + prefs::kFlingMaxTapGapTimeInMs, prefs::kFlingVelocityCap, prefs::kLongPressTimeInSeconds, prefs::kMaxDistanceForTwoFingerTapInPixels, @@ -130,6 +132,10 @@ void GesturePrefsObserver::Update() { prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient2)); GestureConfiguration::set_fling_acceleration_curve_coefficients(3, prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient3)); + GestureConfiguration::set_fling_max_cancel_to_down_time_in_ms( + prefs_->GetInteger(prefs::kFlingMaxCancelToDownTimeInMs)); + GestureConfiguration::set_fling_max_tap_gap_time_in_ms( + prefs_->GetInteger(prefs::kFlingMaxTapGapTimeInMs)); GestureConfiguration::set_fling_velocity_cap( prefs_->GetDouble(prefs::kFlingVelocityCap)); GestureConfiguration::set_long_press_time_in_seconds( @@ -252,6 +258,14 @@ void GesturePrefsObserverFactoryAura::RegisterUserPrefs( prefs::kFlingAccelerationCurveCoefficient3, GestureConfiguration::fling_acceleration_curve_coefficients(3), PrefServiceSyncable::UNSYNCABLE_PREF); + prefs->RegisterIntegerPref( + prefs::kFlingMaxCancelToDownTimeInMs, + GestureConfiguration::fling_max_cancel_to_down_time_in_ms(), + PrefServiceSyncable::UNSYNCABLE_PREF); + prefs->RegisterIntegerPref( + prefs::kFlingMaxTapGapTimeInMs, + GestureConfiguration::fling_max_tap_gap_time_in_ms(), + PrefServiceSyncable::UNSYNCABLE_PREF); prefs->RegisterDoublePref( prefs::kFlingVelocityCap, GestureConfiguration::fling_velocity_cap(), diff --git a/chrome/browser/ui/webui/gesture_config_ui.cc b/chrome/browser/ui/webui/gesture_config_ui.cc index 8f90f0dc53c2..6797789ad415 100644 --- a/chrome/browser/ui/webui/gesture_config_ui.cc +++ b/chrome/browser/ui/webui/gesture_config_ui.cc @@ -108,6 +108,17 @@ void GestureConfigUI::SetPreferenceValue(const base::ListValue* args) { Profile* profile = Profile::FromWebUI(web_ui()); PrefService* prefs = profile->GetPrefs(); - prefs->SetDouble(pref_name.c_str(), value); + const PrefService::Preference* pref = + prefs->FindPreference(pref_name.c_str()); + switch (pref->GetType()) { + case base::Value::TYPE_INTEGER: + prefs->SetInteger(pref_name.c_str(), static_cast(value)); + break; + case base::Value::TYPE_DOUBLE: + prefs->SetDouble(pref_name.c_str(), value); + break; + default: + NOTREACHED(); + } } diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index e4474d832e73..174bb0804ec7 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -2142,6 +2142,10 @@ const char kShowLogoutButtonInTray[] = "show_logout_button_in_tray"; // kShelfAutoHideBehavior. const char kShelfPreferences[] = "shelf_preferences"; +const char kFlingMaxCancelToDownTimeInMs[] = + "gesture.fling_max_cancel_to_down_time_in_ms"; +const char kFlingMaxTapGapTimeInMs[] = + "gesture.fling_max_tap_gap_time_in_ms"; const char kFlingVelocityCap[] = "gesture.fling_velocity_cap"; const char kLongPressTimeInSeconds[] = "gesture.long_press_time_in_seconds"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index bb9f352c8d73..77fab577abe8 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -777,6 +777,8 @@ extern const char kPinnedLauncherApps[]; extern const char kShowLogoutButtonInTray[]; extern const char kShelfPreferences[]; +extern const char kFlingMaxCancelToDownTimeInMs[]; +extern const char kFlingMaxTapGapTimeInMs[]; extern const char kFlingVelocityCap[]; extern const char kLongPressTimeInSeconds[]; extern const char kMaxDistanceBetweenTapsForDoubleTap[]; diff --git a/content/browser/renderer_host/tap_suppression_controller_aura.cc b/content/browser/renderer_host/tap_suppression_controller_aura.cc index 0f99f5c28668..7d7c2649023d 100644 --- a/content/browser/renderer_host/tap_suppression_controller_aura.cc +++ b/content/browser/renderer_host/tap_suppression_controller_aura.cc @@ -10,51 +10,7 @@ #include "base/string_number_conversions.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/public/common/content_switches.h" - -namespace { - -// Default maxium time between a mousedown/mouseup pair that is considered to -// be a suppressable tap. -static const int kMaxiumTapGapTimeMs = 200; - -// Default maximum time between a GestureFlingCancel and a mousedown such that -// the mousedown is considered associated with the cancel event. -static const int kMaxiumCancelToDownTimeMs = 400; - -// Sets |*value| to |switchKey| if it exists or sets it to |defaultValue|. -static void GetFlingParamHelper(int* value, int defaultValue, - const char switchKey[]) { - if (*value < 0) { - *value = defaultValue; - CommandLine* command_line = CommandLine::ForCurrentProcess(); - std::string command_line_param = - command_line->GetSwitchValueASCII(switchKey); - if (!command_line_param.empty()) { - int v; - if (base::StringToInt(command_line_param, &v)) - *value = static_cast(v); - } - DCHECK_GT(*value, 0); - } -} - -static int GetMaxiumTapGapTimeMs() { - static int maximum_tap_gap_time_ms = -1; - GetFlingParamHelper(&maximum_tap_gap_time_ms, - kMaxiumTapGapTimeMs, - switches::kFlingTapSuppressMaxGap); - return maximum_tap_gap_time_ms; -} - -static int GetMaxiumCancelToDownTimeMs() { - static int maximum_cancel_to_down_time_ms = -1; - GetFlingParamHelper(&maximum_cancel_to_down_time_ms, - kMaxiumCancelToDownTimeMs, - switches::kFlingTapSuppressMaxDown); - return maximum_cancel_to_down_time_ms; -} - -} // namespace +#include "ui/base/gestures/gesture_configuration.h" namespace content { @@ -86,11 +42,12 @@ bool TapSuppressionController::ShouldDeferMouseDown( case NOTHING: return false; case GFC_IN_PROGRESS: - mouse_down_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds( - GetMaxiumTapGapTimeMs()), - this, - &TapSuppressionController::MouseDownTimerExpired); + mouse_down_timer_.Start( + FROM_HERE, + base::TimeDelta::FromMilliseconds( + ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), + this, + &TapSuppressionController::MouseDownTimerExpired); stashed_mouse_down_ = event; state_ = MD_STASHED; return true; @@ -100,11 +57,12 @@ bool TapSuppressionController::ShouldDeferMouseDown( return false; case LAST_CANCEL_STOPPED_FLING: if ((base::TimeTicks::Now() - fling_cancel_time_).InMilliseconds() - < GetMaxiumCancelToDownTimeMs()) { + < ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms()) { state_ = MD_STASHED; - mouse_down_timer_.Start(FROM_HERE, + mouse_down_timer_.Start( + FROM_HERE, base::TimeDelta::FromMilliseconds( - GetMaxiumTapGapTimeMs()), + ui::GestureConfiguration::fling_max_tap_gap_time_in_ms()), this, &TapSuppressionController::MouseDownTimerExpired); stashed_mouse_down_ = event; diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index cba5f0ab52a7..aaa236d920df 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -748,12 +748,6 @@ const char kDisableCarbonInterposing[] = "disable-carbon-interposing"; const char kDisableSoftwareRasterizer[] = "disable-software-rasterizer"; #if defined(USE_AURA) -// Configures the time after a GestureFlingCancel in which taps are cancelled. -extern const char kFlingTapSuppressMaxDown[] = "fling-tap-suppress-max-down"; - -// Maximum time between mousedown and mouseup to be considered a tap. -extern const char kFlingTapSuppressMaxGap[] = "fling-tap-suppress-max-gap"; - // Forces usage of the test compositor. Needed to run ui tests on bots. extern const char kTestCompositor[] = "test-compositor"; #endif diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index 6d3d7959f746..d679b0781764 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -240,8 +240,6 @@ extern const char kDisableCarbonInterposing[]; #endif #if defined(USE_AURA) -CONTENT_EXPORT extern const char kFlingTapSuppressMaxDown[]; -CONTENT_EXPORT extern const char kFlingTapSuppressMaxGap[]; CONTENT_EXPORT extern const char kTestCompositor[]; #endif diff --git a/ui/base/gestures/gesture_configuration.cc b/ui/base/gestures/gesture_configuration.cc index ccd795801621..0689921178ed 100644 --- a/ui/base/gestures/gesture_configuration.cc +++ b/ui/base/gestures/gesture_configuration.cc @@ -7,6 +7,8 @@ namespace ui { int GestureConfiguration::default_radius_ = 15; +int GestureConfiguration::fling_max_cancel_to_down_time_in_ms_ = 400; +int GestureConfiguration::fling_max_tap_gap_time_in_ms_ = 200; float GestureConfiguration::fling_velocity_cap_ = 17000.0f; double GestureConfiguration::long_press_time_in_seconds_ = 1.0; double GestureConfiguration::semi_long_press_time_in_seconds_ = 0.4; diff --git a/ui/base/gestures/gesture_configuration.h b/ui/base/gestures/gesture_configuration.h index db46d9557165..525ee3b12dc7 100644 --- a/ui/base/gestures/gesture_configuration.h +++ b/ui/base/gestures/gesture_configuration.h @@ -26,6 +26,18 @@ class UI_EXPORT GestureConfiguration { return default_radius_; } static void set_default_radius(int radius) { default_radius_ = radius; } + static int fling_max_cancel_to_down_time_in_ms() { + return fling_max_cancel_to_down_time_in_ms_; + } + static void set_fling_max_cancel_to_down_time_in_ms(int val) { + fling_max_cancel_to_down_time_in_ms_ = val; + } + static int fling_max_tap_gap_time_in_ms() { + return fling_max_tap_gap_time_in_ms_; + } + static void set_fling_max_tap_gap_time_in_ms(int val) { + fling_max_tap_gap_time_in_ms_ = val; + } static double long_press_time_in_seconds() { return long_press_time_in_seconds_; } @@ -186,6 +198,14 @@ class UI_EXPORT GestureConfiguration { // forming an ET_GESTURE_TAP event. static int max_radius_; + // Maximum time between a GestureFlingCancel and a mousedown such that the + // mousedown is considered associated with the cancel event. + static int fling_max_cancel_to_down_time_in_ms_; + + // Maxium time between a mousedown/mouseup pair that is considered to be a + // suppressable tap. + static int fling_max_tap_gap_time_in_ms_; + static double long_press_time_in_seconds_; static double semi_long_press_time_in_seconds_; static double max_seconds_between_double_click_; -- 2.11.4.GIT