| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/ui/gesture_prefs_observer_factory_aura.h" | 5 #include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver); | 87 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // The list of prefs we want to observe. | 90 // The list of prefs we want to observe. |
| 91 // Note that this collection of settings should correspond to the settings used | 91 // Note that this collection of settings should correspond to the settings used |
| 92 // in ui/events/gestures/gesture_configuration.h | 92 // in ui/events/gestures/gesture_configuration.h |
| 93 const char* kPrefsToObserve[] = { | 93 const char* kPrefsToObserve[] = { |
| 94 prefs::kFlingMaxCancelToDownTimeInMs, | 94 prefs::kFlingMaxCancelToDownTimeInMs, |
| 95 prefs::kFlingMaxTapGapTimeInMs, | 95 prefs::kFlingMaxTapGapTimeInMs, |
| 96 prefs::kTabScrubActivationDelayInMS, | 96 prefs::kTabScrubActivationDelayInMs, |
| 97 prefs::kMaxSeparationForGestureTouchesInPixels, | 97 prefs::kMaxSeparationForGestureTouchesInPixels, |
| 98 prefs::kSemiLongPressTimeInSeconds, | 98 prefs::kSemiLongPressTimeInMs, |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 const char* kPrefsToRemove[] = { | 101 const char* kPrefsToRemove[] = { |
| 102 "gesture.fling_acceleration_curve_coefficient_0", | 102 "gesture.fling_acceleration_curve_coefficient_0", |
| 103 "gesture.fling_acceleration_curve_coefficient_1", | 103 "gesture.fling_acceleration_curve_coefficient_1", |
| 104 "gesture.fling_acceleration_curve_coefficient_2", | 104 "gesture.fling_acceleration_curve_coefficient_2", |
| 105 "gesture.fling_acceleration_curve_coefficient_3", | 105 "gesture.fling_acceleration_curve_coefficient_3", |
| 106 "gesture.semi_long_press_time_in_seconds", |
| 106 "flingcurve.touchpad_alpha", | 107 "flingcurve.touchpad_alpha", |
| 107 "flingcurve.touchpad_beta", | 108 "flingcurve.touchpad_beta", |
| 108 "flingcurve.touchpad_gamma", | 109 "flingcurve.touchpad_gamma", |
| 109 "flingcurve.touchscreen_alpha", | 110 "flingcurve.touchscreen_alpha", |
| 110 "flingcurve.touchscreen_beta", | 111 "flingcurve.touchscreen_beta", |
| 111 "flingcurve.touchscreen_gamma", | 112 "flingcurve.touchscreen_gamma", |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs) | 115 GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs) |
| 115 : prefs_(prefs) { | 116 : prefs_(prefs) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 141 void GesturePrefsObserver::Shutdown() { | 142 void GesturePrefsObserver::Shutdown() { |
| 142 registrar_.RemoveAll(); | 143 registrar_.RemoveAll(); |
| 143 } | 144 } |
| 144 | 145 |
| 145 void GesturePrefsObserver::Update() { | 146 void GesturePrefsObserver::Update() { |
| 146 GestureConfiguration::set_fling_max_cancel_to_down_time_in_ms( | 147 GestureConfiguration::set_fling_max_cancel_to_down_time_in_ms( |
| 147 prefs_->GetInteger(prefs::kFlingMaxCancelToDownTimeInMs)); | 148 prefs_->GetInteger(prefs::kFlingMaxCancelToDownTimeInMs)); |
| 148 GestureConfiguration::set_fling_max_tap_gap_time_in_ms( | 149 GestureConfiguration::set_fling_max_tap_gap_time_in_ms( |
| 149 prefs_->GetInteger(prefs::kFlingMaxTapGapTimeInMs)); | 150 prefs_->GetInteger(prefs::kFlingMaxTapGapTimeInMs)); |
| 150 GestureConfiguration::set_tab_scrub_activation_delay_in_ms( | 151 GestureConfiguration::set_tab_scrub_activation_delay_in_ms( |
| 151 prefs_->GetInteger(prefs::kTabScrubActivationDelayInMS)); | 152 prefs_->GetInteger(prefs::kTabScrubActivationDelayInMs)); |
| 152 GestureConfiguration::set_semi_long_press_time_in_seconds( | 153 GestureConfiguration::set_semi_long_press_time_in_ms( |
| 153 prefs_->GetDouble(prefs::kSemiLongPressTimeInSeconds)); | 154 prefs_->GetInteger(prefs::kSemiLongPressTimeInMs)); |
| 154 GestureConfiguration::set_max_separation_for_gesture_touches_in_pixels( | 155 GestureConfiguration::set_max_separation_for_gesture_touches_in_pixels( |
| 155 prefs_->GetDouble(prefs::kMaxSeparationForGestureTouchesInPixels)); | 156 static_cast<float>( |
| 157 prefs_->GetDouble(prefs::kMaxSeparationForGestureTouchesInPixels))); |
| 156 | 158 |
| 157 UpdateOverscrollPrefs(); | 159 UpdateOverscrollPrefs(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 void GesturePrefsObserver::UpdateOverscrollPrefs() { | 162 void GesturePrefsObserver::UpdateOverscrollPrefs() { |
| 161 const std::vector<OverscrollPref>& overscroll_prefs = GetOverscrollPrefs(); | 163 const std::vector<OverscrollPref>& overscroll_prefs = GetOverscrollPrefs(); |
| 162 for (size_t i = 0; i < overscroll_prefs.size(); ++i) { | 164 for (size_t i = 0; i < overscroll_prefs.size(); ++i) { |
| 163 content::SetOverscrollConfig(overscroll_prefs[i].config, | 165 content::SetOverscrollConfig(overscroll_prefs[i].config, |
| 164 static_cast<float>(prefs_->GetDouble(overscroll_prefs[i].pref_name))); | 166 static_cast<float>(prefs_->GetDouble(overscroll_prefs[i].pref_name))); |
| 165 } | 167 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 user_prefs::PrefRegistrySyncable* registry) { | 212 user_prefs::PrefRegistrySyncable* registry) { |
| 211 registry->RegisterIntegerPref( | 213 registry->RegisterIntegerPref( |
| 212 prefs::kFlingMaxCancelToDownTimeInMs, | 214 prefs::kFlingMaxCancelToDownTimeInMs, |
| 213 GestureConfiguration::fling_max_cancel_to_down_time_in_ms(), | 215 GestureConfiguration::fling_max_cancel_to_down_time_in_ms(), |
| 214 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 216 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 215 registry->RegisterIntegerPref( | 217 registry->RegisterIntegerPref( |
| 216 prefs::kFlingMaxTapGapTimeInMs, | 218 prefs::kFlingMaxTapGapTimeInMs, |
| 217 GestureConfiguration::fling_max_tap_gap_time_in_ms(), | 219 GestureConfiguration::fling_max_tap_gap_time_in_ms(), |
| 218 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 220 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 219 registry->RegisterIntegerPref( | 221 registry->RegisterIntegerPref( |
| 220 prefs::kTabScrubActivationDelayInMS, | 222 prefs::kTabScrubActivationDelayInMs, |
| 221 GestureConfiguration::tab_scrub_activation_delay_in_ms(), | 223 GestureConfiguration::tab_scrub_activation_delay_in_ms(), |
| 222 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 224 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 223 registry->RegisterDoublePref( | 225 registry->RegisterIntegerPref( |
| 224 prefs::kSemiLongPressTimeInSeconds, | 226 prefs::kSemiLongPressTimeInMs, |
| 225 GestureConfiguration::semi_long_press_time_in_seconds(), | 227 GestureConfiguration::semi_long_press_time_in_ms(), |
| 226 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 228 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 227 registry->RegisterDoublePref( | 229 registry->RegisterDoublePref( |
| 228 prefs::kMaxSeparationForGestureTouchesInPixels, | 230 prefs::kMaxSeparationForGestureTouchesInPixels, |
| 229 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(), | 231 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(), |
| 230 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 232 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 231 RegisterOverscrollPrefs(registry); | 233 RegisterOverscrollPrefs(registry); |
| 232 } | 234 } |
| 233 | 235 |
| 234 bool | 236 bool |
| 235 GesturePrefsObserverFactoryAura::ServiceIsCreatedWithBrowserContext() const { | 237 GesturePrefsObserverFactoryAura::ServiceIsCreatedWithBrowserContext() const { |
| 236 // Create the observer as soon as the profile is created. | 238 // Create the observer as soon as the profile is created. |
| 237 return true; | 239 return true; |
| 238 } | 240 } |
| 239 | 241 |
| 240 content::BrowserContext* | 242 content::BrowserContext* |
| 241 GesturePrefsObserverFactoryAura::GetBrowserContextToUse( | 243 GesturePrefsObserverFactoryAura::GetBrowserContextToUse( |
| 242 content::BrowserContext* context) const { | 244 content::BrowserContext* context) const { |
| 243 // Use same gesture preferences on incognito windows. | 245 // Use same gesture preferences on incognito windows. |
| 244 return chrome::GetBrowserContextRedirectedInIncognito(context); | 246 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 245 } | 247 } |
| 246 | 248 |
| 247 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const { | 249 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const { |
| 248 // Some tests replace the PrefService of the TestingProfile after the | 250 // Some tests replace the PrefService of the TestingProfile after the |
| 249 // GesturePrefsObserver has been created, which makes Shutdown() | 251 // GesturePrefsObserver has been created, which makes Shutdown() |
| 250 // remove the registrar from a non-existent PrefService. | 252 // remove the registrar from a non-existent PrefService. |
| 251 return true; | 253 return true; |
| 252 } | 254 } |
| OLD | NEW |