Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: chrome/browser/ui/views/ash/gesture_prefs_observer_factory_aura.cc

Issue 10020048: Work on USE_ASH/USE_AURA split. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/ash/gesture_prefs_observer_factory_aura.h"
6
7 #include "base/compiler_specific.h"
8 #include "chrome/browser/prefs/pref_change_registrar.h"
9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_dependency_manager.h"
12 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/common/pref_names.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "ui/base/gestures/gesture_configuration.h"
16
17 using ui::GestureConfiguration;
18
19 namespace {
20
21 // This class manages gesture configuration preferences.
22 class GesturePrefsObserver : public content::NotificationObserver,
23 public ProfileKeyedService {
24 public:
25 explicit GesturePrefsObserver(PrefService* prefs);
26 virtual ~GesturePrefsObserver();
27
28 // ProfileKeyedService implementation.
29 virtual void Shutdown() OVERRIDE;
30
31 // content::NotificationObserver implementation.
32 virtual void Observe(int type,
33 const content::NotificationSource& source,
34 const content::NotificationDetails& details) OVERRIDE;
35
36 private:
37 void Update();
38
39 PrefChangeRegistrar registrar_;
40 PrefService* prefs_;
41
42 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver);
43 };
44
45 // The list of prefs we want to observe.
46 // Note that this collection of settings should correspond to the settings used
47 // in ui/base/gestures/gesture_configuration.h
48 const char* kPrefsToObserve[] = {
49 prefs::kLongPressTimeInSeconds,
50 prefs::kMaxSecondsBetweenDoubleClick,
51 prefs::kMaxSeparationForGestureTouchesInPixels,
52 prefs::kMaxTouchDownDurationInSecondsForClick,
53 prefs::kMaxTouchMoveInPixelsForClick,
54 prefs::kMinDistanceForPinchScrollInPixels,
55 prefs::kMinFlickSpeedSquared,
56 prefs::kMinPinchUpdateDistanceInPixels,
57 prefs::kMinRailBreakVelocity,
58 prefs::kMinScrollDeltaSquared,
59 prefs::kMinTouchDownDurationInSecondsForClick,
60 prefs::kPointsBufferedForVelocity,
61 prefs::kRailBreakProportion,
62 prefs::kRailStartProportion,
63 };
64
65 GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs)
66 : prefs_(prefs) {
67 registrar_.Init(prefs);
68 registrar_.RemoveAll();
69 for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i)
70 registrar_.Add(kPrefsToObserve[i], this);
71 }
72
73 GesturePrefsObserver::~GesturePrefsObserver() {}
74
75 void GesturePrefsObserver::Shutdown() {
76 registrar_.RemoveAll();
77 }
78
79 void GesturePrefsObserver::Observe(
80 int type,
81 const content::NotificationSource& source,
82 const content::NotificationDetails& details) {
83 Update();
84 }
85
86 void GesturePrefsObserver::Update() {
87 GestureConfiguration::set_long_press_time_in_seconds(
88 prefs_->GetDouble(
89 prefs::kLongPressTimeInSeconds));
90 GestureConfiguration::set_max_seconds_between_double_click(
91 prefs_->GetDouble(
92 prefs::kMaxSecondsBetweenDoubleClick));
93 GestureConfiguration::set_max_separation_for_gesture_touches_in_pixels(
94 prefs_->GetDouble(
95 prefs::kMaxSeparationForGestureTouchesInPixels));
96 GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click(
97 prefs_->GetDouble(
98 prefs::kMaxTouchDownDurationInSecondsForClick));
99 GestureConfiguration::set_max_touch_move_in_pixels_for_click(
100 prefs_->GetDouble(
101 prefs::kMaxTouchMoveInPixelsForClick));
102 GestureConfiguration::set_min_distance_for_pinch_scroll_in_pixels(
103 prefs_->GetDouble(
104 prefs::kMinDistanceForPinchScrollInPixels));
105 GestureConfiguration::set_min_flick_speed_squared(
106 prefs_->GetDouble(
107 prefs::kMinFlickSpeedSquared));
108 GestureConfiguration::set_min_pinch_update_distance_in_pixels(
109 prefs_->GetDouble(
110 prefs::kMinPinchUpdateDistanceInPixels));
111 GestureConfiguration::set_min_rail_break_velocity(
112 prefs_->GetDouble(
113 prefs::kMinRailBreakVelocity));
114 GestureConfiguration::set_min_scroll_delta_squared(
115 prefs_->GetDouble(
116 prefs::kMinScrollDeltaSquared));
117 GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click(
118 prefs_->GetDouble(
119 prefs::kMinTouchDownDurationInSecondsForClick));
120 GestureConfiguration::set_points_buffered_for_velocity(
121 prefs_->GetInteger(
122 prefs::kPointsBufferedForVelocity));
123 GestureConfiguration::set_rail_break_proportion(
124 prefs_->GetDouble(
125 prefs::kRailBreakProportion));
126 GestureConfiguration::set_rail_start_proportion(
127 prefs_->GetDouble(
128 prefs::kRailStartProportion));
129 }
130
131 } // namespace
132
133 // static
134 GesturePrefsObserverFactoryAura*
135 GesturePrefsObserverFactoryAura::GetInstance() {
136 return Singleton<GesturePrefsObserverFactoryAura>::get();
137 }
138
139 GesturePrefsObserverFactoryAura::GesturePrefsObserverFactoryAura()
140 : ProfileKeyedServiceFactory("GesturePrefsObserverAura",
141 ProfileDependencyManager::GetInstance()) {}
142
143 GesturePrefsObserverFactoryAura::~GesturePrefsObserverFactoryAura() {}
144
145 ProfileKeyedService* GesturePrefsObserverFactoryAura::BuildServiceInstanceFor(
146 Profile* profile) const {
147 return new GesturePrefsObserver(profile->GetPrefs());
148 }
149
150 void GesturePrefsObserverFactoryAura::RegisterUserPrefs(PrefService* prefs) {
151 prefs->RegisterDoublePref(
152 prefs::kLongPressTimeInSeconds,
153 GestureConfiguration::long_press_time_in_seconds(),
154 PrefService::UNSYNCABLE_PREF);
155 prefs->RegisterDoublePref(
156 prefs::kMaxSecondsBetweenDoubleClick,
157 GestureConfiguration::max_seconds_between_double_click(),
158 PrefService::UNSYNCABLE_PREF);
159 prefs->RegisterDoublePref(
160 prefs::kMaxSeparationForGestureTouchesInPixels,
161 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(),
162 PrefService::UNSYNCABLE_PREF);
163 prefs->RegisterDoublePref(
164 prefs::kMaxTouchDownDurationInSecondsForClick,
165 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(),
166 PrefService::UNSYNCABLE_PREF);
167 prefs->RegisterDoublePref(
168 prefs::kMaxTouchMoveInPixelsForClick,
169 GestureConfiguration::max_touch_move_in_pixels_for_click(),
170 PrefService::UNSYNCABLE_PREF);
171 prefs->RegisterDoublePref(
172 prefs::kMinDistanceForPinchScrollInPixels,
173 GestureConfiguration::min_distance_for_pinch_scroll_in_pixels(),
174 PrefService::UNSYNCABLE_PREF);
175 prefs->RegisterDoublePref(
176 prefs::kMinFlickSpeedSquared,
177 GestureConfiguration::min_flick_speed_squared(),
178 PrefService::UNSYNCABLE_PREF);
179 prefs->RegisterDoublePref(
180 prefs::kMinPinchUpdateDistanceInPixels,
181 GestureConfiguration::min_pinch_update_distance_in_pixels(),
182 PrefService::UNSYNCABLE_PREF);
183 prefs->RegisterDoublePref(
184 prefs::kMinRailBreakVelocity,
185 GestureConfiguration::min_rail_break_velocity(),
186 PrefService::UNSYNCABLE_PREF);
187 prefs->RegisterDoublePref(
188 prefs::kMinScrollDeltaSquared,
189 GestureConfiguration::min_scroll_delta_squared(),
190 PrefService::UNSYNCABLE_PREF);
191 prefs->RegisterDoublePref(
192 prefs::kMinTouchDownDurationInSecondsForClick,
193 GestureConfiguration::min_touch_down_duration_in_seconds_for_click(),
194 PrefService::UNSYNCABLE_PREF);
195 prefs->RegisterIntegerPref(
196 prefs::kPointsBufferedForVelocity,
197 GestureConfiguration::points_buffered_for_velocity(),
198 PrefService::UNSYNCABLE_PREF);
199 prefs->RegisterDoublePref(
200 prefs::kRailBreakProportion,
201 GestureConfiguration::rail_break_proportion(),
202 PrefService::UNSYNCABLE_PREF);
203 prefs->RegisterDoublePref(
204 prefs::kRailStartProportion,
205 GestureConfiguration::rail_start_proportion(),
206 PrefService::UNSYNCABLE_PREF);
207 }
208
209 bool GesturePrefsObserverFactoryAura::ServiceIsCreatedWithProfile() {
210 // Create the observer as soon as the profile is created.
211 return true;
212 }
213
214 bool GesturePrefsObserverFactoryAura::ServiceRedirectedInIncognito() {
215 // Use same gesture preferences on incognito windows.
216 return true;
217 }
218
219 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() {
220 // Some tests replace the PrefService of the TestingProfile after the
221 // GesturePrefsObserver has been created, which makes Shutdown()
222 // remove the registrar from a non-existent PrefService.
223 return true;
224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698