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 "chrome/browser/ui/gesture_prefs_observer_factory_aura.h" | 5 #include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "chrome/browser/prefs/pref_change_registrar.h" | 8 #include "chrome/browser/prefs/pref_change_registrar.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 PrefService* prefs_; | 40 PrefService* prefs_; |
41 | 41 |
42 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver); | 42 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver); |
43 }; | 43 }; |
44 | 44 |
45 // The list of prefs we want to observe. | 45 // The list of prefs we want to observe. |
46 // Note that this collection of settings should correspond to the settings used | 46 // Note that this collection of settings should correspond to the settings used |
47 // in ui/base/gestures/gesture_configuration.h | 47 // in ui/base/gestures/gesture_configuration.h |
48 const char* kPrefsToObserve[] = { | 48 const char* kPrefsToObserve[] = { |
49 prefs::kLongPressTimeInSeconds, | 49 prefs::kLongPressTimeInSeconds, |
| 50 prefs::kMaxDistanceForTwoFingerTapInPixels, |
50 prefs::kMaxSecondsBetweenDoubleClick, | 51 prefs::kMaxSecondsBetweenDoubleClick, |
51 prefs::kMaxSeparationForGestureTouchesInPixels, | 52 prefs::kMaxSeparationForGestureTouchesInPixels, |
52 prefs::kMaxSwipeDeviationRatio, | 53 prefs::kMaxSwipeDeviationRatio, |
53 prefs::kMaxTouchDownDurationInSecondsForClick, | 54 prefs::kMaxTouchDownDurationInSecondsForClick, |
54 prefs::kMaxTouchMoveInPixelsForClick, | 55 prefs::kMaxTouchMoveInPixelsForClick, |
55 prefs::kMinDistanceForPinchScrollInPixels, | 56 prefs::kMinDistanceForPinchScrollInPixels, |
56 prefs::kMinFlickSpeedSquared, | 57 prefs::kMinFlickSpeedSquared, |
57 prefs::kMinPinchUpdateDistanceInPixels, | 58 prefs::kMinPinchUpdateDistanceInPixels, |
58 prefs::kMinRailBreakVelocity, | 59 prefs::kMinRailBreakVelocity, |
59 prefs::kMinScrollDeltaSquared, | 60 prefs::kMinScrollDeltaSquared, |
60 prefs::kMinSwipeSpeed, | 61 prefs::kMinSwipeSpeed, |
61 prefs::kMinTouchDownDurationInSecondsForClick, | 62 prefs::kMinTouchDownDurationInSecondsForClick, |
62 prefs::kPointsBufferedForVelocity, | 63 prefs::kPointsBufferedForVelocity, |
63 prefs::kRailBreakProportion, | 64 prefs::kRailBreakProportion, |
64 prefs::kRailStartProportion, | 65 prefs::kRailStartProportion, |
| 66 prefs::kSemiLongPressTimeInSeconds, |
65 }; | 67 }; |
66 | 68 |
67 GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs) | 69 GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs) |
68 : prefs_(prefs) { | 70 : prefs_(prefs) { |
69 registrar_.Init(prefs); | 71 registrar_.Init(prefs); |
70 registrar_.RemoveAll(); | 72 registrar_.RemoveAll(); |
71 for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i) | 73 for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i) |
72 registrar_.Add(kPrefsToObserve[i], this); | 74 registrar_.Add(kPrefsToObserve[i], this); |
73 } | 75 } |
74 | 76 |
75 GesturePrefsObserver::~GesturePrefsObserver() {} | 77 GesturePrefsObserver::~GesturePrefsObserver() {} |
76 | 78 |
77 void GesturePrefsObserver::Shutdown() { | 79 void GesturePrefsObserver::Shutdown() { |
78 registrar_.RemoveAll(); | 80 registrar_.RemoveAll(); |
79 } | 81 } |
80 | 82 |
81 void GesturePrefsObserver::Observe( | 83 void GesturePrefsObserver::Observe( |
82 int type, | 84 int type, |
83 const content::NotificationSource& source, | 85 const content::NotificationSource& source, |
84 const content::NotificationDetails& details) { | 86 const content::NotificationDetails& details) { |
85 Update(); | 87 Update(); |
86 } | 88 } |
87 | 89 |
88 void GesturePrefsObserver::Update() { | 90 void GesturePrefsObserver::Update() { |
89 GestureConfiguration::set_long_press_time_in_seconds( | 91 GestureConfiguration::set_long_press_time_in_seconds( |
90 prefs_->GetDouble( | 92 prefs_->GetDouble( |
91 prefs::kLongPressTimeInSeconds)); | 93 prefs::kLongPressTimeInSeconds)); |
| 94 GestureConfiguration::set_semi_long_press_time_in_seconds( |
| 95 prefs_->GetDouble( |
| 96 prefs::kSemiLongPressTimeInSeconds)); |
92 GestureConfiguration::set_max_distance_for_two_finger_tap_in_pixels( | 97 GestureConfiguration::set_max_distance_for_two_finger_tap_in_pixels( |
93 prefs_->GetDouble( | 98 prefs_->GetDouble( |
94 prefs::kMaxDistanceForTwoFingerTapInPixels)); | 99 prefs::kMaxDistanceForTwoFingerTapInPixels)); |
95 GestureConfiguration::set_max_seconds_between_double_click( | 100 GestureConfiguration::set_max_seconds_between_double_click( |
96 prefs_->GetDouble( | 101 prefs_->GetDouble( |
97 prefs::kMaxSecondsBetweenDoubleClick)); | 102 prefs::kMaxSecondsBetweenDoubleClick)); |
98 GestureConfiguration::set_max_separation_for_gesture_touches_in_pixels( | 103 GestureConfiguration::set_max_separation_for_gesture_touches_in_pixels( |
99 prefs_->GetDouble( | 104 prefs_->GetDouble( |
100 prefs::kMaxSeparationForGestureTouchesInPixels)); | 105 prefs::kMaxSeparationForGestureTouchesInPixels)); |
101 GestureConfiguration::set_max_swipe_deviation_ratio( | 106 GestureConfiguration::set_max_swipe_deviation_ratio( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 Profile* profile) const { | 162 Profile* profile) const { |
158 return new GesturePrefsObserver(profile->GetPrefs()); | 163 return new GesturePrefsObserver(profile->GetPrefs()); |
159 } | 164 } |
160 | 165 |
161 void GesturePrefsObserverFactoryAura::RegisterUserPrefs(PrefService* prefs) { | 166 void GesturePrefsObserverFactoryAura::RegisterUserPrefs(PrefService* prefs) { |
162 prefs->RegisterDoublePref( | 167 prefs->RegisterDoublePref( |
163 prefs::kLongPressTimeInSeconds, | 168 prefs::kLongPressTimeInSeconds, |
164 GestureConfiguration::long_press_time_in_seconds(), | 169 GestureConfiguration::long_press_time_in_seconds(), |
165 PrefService::UNSYNCABLE_PREF); | 170 PrefService::UNSYNCABLE_PREF); |
166 prefs->RegisterDoublePref( | 171 prefs->RegisterDoublePref( |
| 172 prefs::kSemiLongPressTimeInSeconds, |
| 173 GestureConfiguration::semi_long_press_time_in_seconds(), |
| 174 PrefService::UNSYNCABLE_PREF); |
| 175 prefs->RegisterDoublePref( |
167 prefs::kMaxDistanceForTwoFingerTapInPixels, | 176 prefs::kMaxDistanceForTwoFingerTapInPixels, |
168 GestureConfiguration::max_distance_for_two_finger_tap_in_pixels(), | 177 GestureConfiguration::max_distance_for_two_finger_tap_in_pixels(), |
169 PrefService::UNSYNCABLE_PREF); | 178 PrefService::UNSYNCABLE_PREF); |
170 prefs->RegisterDoublePref( | 179 prefs->RegisterDoublePref( |
171 prefs::kMaxSecondsBetweenDoubleClick, | 180 prefs::kMaxSecondsBetweenDoubleClick, |
172 GestureConfiguration::max_seconds_between_double_click(), | 181 GestureConfiguration::max_seconds_between_double_click(), |
173 PrefService::UNSYNCABLE_PREF); | 182 PrefService::UNSYNCABLE_PREF); |
174 prefs->RegisterDoublePref( | 183 prefs->RegisterDoublePref( |
175 prefs::kMaxSeparationForGestureTouchesInPixels, | 184 prefs::kMaxSeparationForGestureTouchesInPixels, |
176 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(), | 185 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(), |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // Use same gesture preferences on incognito windows. | 247 // Use same gesture preferences on incognito windows. |
239 return true; | 248 return true; |
240 } | 249 } |
241 | 250 |
242 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() { | 251 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() { |
243 // Some tests replace the PrefService of the TestingProfile after the | 252 // Some tests replace the PrefService of the TestingProfile after the |
244 // GesturePrefsObserver has been created, which makes Shutdown() | 253 // GesturePrefsObserver has been created, which makes Shutdown() |
245 // remove the registrar from a non-existent PrefService. | 254 // remove the registrar from a non-existent PrefService. |
246 return true; | 255 return true; |
247 } | 256 } |
OLD | NEW |