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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/profiles/incognito_helpers.h" | 15 #include "chrome/browser/profiles/incognito_helpers.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
19 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/overscroll_configuration.h" | 22 #include "content/public/browser/overscroll_configuration.h" |
23 #include "content/public/common/renderer_preferences.h" | 23 #include "content/public/common/renderer_preferences.h" |
24 #include "ui/events/gestures/gesture_configuration.h" | 24 #include "ui/events/gesture_detection/gesture_configuration.h" |
25 | 25 |
26 using ui::GestureConfiguration; | 26 using ui::GestureConfiguration; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 struct OverscrollPref { | 30 struct OverscrollPref { |
31 const char* pref_name; | 31 const char* pref_name; |
32 content::OverscrollConfig config; | 32 content::OverscrollConfig config; |
33 }; | 33 }; |
34 | 34 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 Update(); | 136 Update(); |
137 } | 137 } |
138 | 138 |
139 GesturePrefsObserver::~GesturePrefsObserver() {} | 139 GesturePrefsObserver::~GesturePrefsObserver() {} |
140 | 140 |
141 void GesturePrefsObserver::Shutdown() { | 141 void GesturePrefsObserver::Shutdown() { |
142 registrar_.RemoveAll(); | 142 registrar_.RemoveAll(); |
143 } | 143 } |
144 | 144 |
145 void GesturePrefsObserver::Update() { | 145 void GesturePrefsObserver::Update() { |
146 GestureConfiguration::set_fling_max_cancel_to_down_time_in_ms( | 146 GestureConfiguration::GetInstance()->set_fling_max_cancel_to_down_time_in_ms( |
147 prefs_->GetInteger(prefs::kFlingMaxCancelToDownTimeInMs)); | 147 prefs_->GetInteger(prefs::kFlingMaxCancelToDownTimeInMs)); |
148 GestureConfiguration::set_fling_max_tap_gap_time_in_ms( | 148 GestureConfiguration::GetInstance()->set_fling_max_tap_gap_time_in_ms( |
149 prefs_->GetInteger(prefs::kFlingMaxTapGapTimeInMs)); | 149 prefs_->GetInteger(prefs::kFlingMaxTapGapTimeInMs)); |
150 GestureConfiguration::set_tab_scrub_activation_delay_in_ms( | 150 GestureConfiguration::GetInstance()->set_tab_scrub_activation_delay_in_ms( |
151 prefs_->GetInteger(prefs::kTabScrubActivationDelayInMS)); | 151 prefs_->GetInteger(prefs::kTabScrubActivationDelayInMS)); |
152 GestureConfiguration::set_semi_long_press_time_in_seconds( | 152 GestureConfiguration::GetInstance()->set_semi_long_press_time_in_seconds( |
153 prefs_->GetDouble(prefs::kSemiLongPressTimeInSeconds)); | 153 prefs_->GetDouble(prefs::kSemiLongPressTimeInSeconds)); |
154 GestureConfiguration::set_max_separation_for_gesture_touches_in_pixels( | 154 GestureConfiguration::GetInstance() |
155 prefs_->GetDouble(prefs::kMaxSeparationForGestureTouchesInPixels)); | 155 ->set_max_separation_for_gesture_touches_in_pixels( |
| 156 prefs_->GetDouble(prefs::kMaxSeparationForGestureTouchesInPixels)); |
156 | 157 |
157 UpdateOverscrollPrefs(); | 158 UpdateOverscrollPrefs(); |
158 } | 159 } |
159 | 160 |
160 void GesturePrefsObserver::UpdateOverscrollPrefs() { | 161 void GesturePrefsObserver::UpdateOverscrollPrefs() { |
161 const std::vector<OverscrollPref>& overscroll_prefs = GetOverscrollPrefs(); | 162 const std::vector<OverscrollPref>& overscroll_prefs = GetOverscrollPrefs(); |
162 for (size_t i = 0; i < overscroll_prefs.size(); ++i) { | 163 for (size_t i = 0; i < overscroll_prefs.size(); ++i) { |
163 content::SetOverscrollConfig(overscroll_prefs[i].config, | 164 content::SetOverscrollConfig(overscroll_prefs[i].config, |
164 static_cast<float>(prefs_->GetDouble(overscroll_prefs[i].pref_name))); | 165 static_cast<float>(prefs_->GetDouble(overscroll_prefs[i].pref_name))); |
165 } | 166 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 overscroll_prefs[i].pref_name, | 204 overscroll_prefs[i].pref_name, |
204 content::GetOverscrollConfig(overscroll_prefs[i].config), | 205 content::GetOverscrollConfig(overscroll_prefs[i].config), |
205 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 206 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 void GesturePrefsObserverFactoryAura::RegisterProfilePrefs( | 210 void GesturePrefsObserverFactoryAura::RegisterProfilePrefs( |
210 user_prefs::PrefRegistrySyncable* registry) { | 211 user_prefs::PrefRegistrySyncable* registry) { |
211 registry->RegisterIntegerPref( | 212 registry->RegisterIntegerPref( |
212 prefs::kFlingMaxCancelToDownTimeInMs, | 213 prefs::kFlingMaxCancelToDownTimeInMs, |
213 GestureConfiguration::fling_max_cancel_to_down_time_in_ms(), | 214 GestureConfiguration::GetInstance() |
| 215 ->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::GetInstance()->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::GetInstance()->tab_scrub_activation_delay_in_ms(), |
222 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 224 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
223 registry->RegisterDoublePref( | 225 registry->RegisterDoublePref( |
224 prefs::kSemiLongPressTimeInSeconds, | 226 prefs::kSemiLongPressTimeInSeconds, |
225 GestureConfiguration::semi_long_press_time_in_seconds(), | 227 GestureConfiguration::GetInstance()->semi_long_press_time_in_seconds(), |
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::GetInstance() |
| 232 ->max_separation_for_gesture_touches_in_pixels(), |
230 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 233 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
231 RegisterOverscrollPrefs(registry); | 234 RegisterOverscrollPrefs(registry); |
232 } | 235 } |
233 | 236 |
234 bool | 237 bool |
235 GesturePrefsObserverFactoryAura::ServiceIsCreatedWithBrowserContext() const { | 238 GesturePrefsObserverFactoryAura::ServiceIsCreatedWithBrowserContext() const { |
236 // Create the observer as soon as the profile is created. | 239 // Create the observer as soon as the profile is created. |
237 return true; | 240 return true; |
238 } | 241 } |
239 | 242 |
240 content::BrowserContext* | 243 content::BrowserContext* |
241 GesturePrefsObserverFactoryAura::GetBrowserContextToUse( | 244 GesturePrefsObserverFactoryAura::GetBrowserContextToUse( |
242 content::BrowserContext* context) const { | 245 content::BrowserContext* context) const { |
243 // Use same gesture preferences on incognito windows. | 246 // Use same gesture preferences on incognito windows. |
244 return chrome::GetBrowserContextRedirectedInIncognito(context); | 247 return chrome::GetBrowserContextRedirectedInIncognito(context); |
245 } | 248 } |
246 | 249 |
247 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const { | 250 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const { |
248 // Some tests replace the PrefService of the TestingProfile after the | 251 // Some tests replace the PrefService of the TestingProfile after the |
249 // GesturePrefsObserver has been created, which makes Shutdown() | 252 // GesturePrefsObserver has been created, which makes Shutdown() |
250 // remove the registrar from a non-existent PrefService. | 253 // remove the registrar from a non-existent PrefService. |
251 return true; | 254 return true; |
252 } | 255 } |
OLD | NEW |