OLD | NEW |
---|---|
(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/gesture_prefs.h" | |
6 | |
7 #include "base/memory/singleton.h" | |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/prefs/pref_service.h" | |
10 #include "chrome/common/chrome_notification_types.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "ui/aura/gestures/gesture_configuration.h" | |
13 | |
14 namespace { | |
15 | |
16 #if defined(USE_AURA) | |
rjkroege
2012/02/24 15:21:34
From my experience, this pattern is atypical. I wo
| |
17 // This class manages gesture configuration preferences. | |
18 class GesturePrefs : public content::NotificationObserver { | |
19 public: | |
20 static GesturePrefs *GetInstance(); | |
21 void RegisterPrefs(PrefService* prefs); | |
22 | |
23 private: | |
24 GesturePrefs(); | |
25 friend struct DefaultSingletonTraits<GesturePrefs>; | |
26 virtual ~GesturePrefs(); | |
27 | |
28 // content::NotificationObserver implementation. | |
29 virtual void Observe(int type, | |
30 const content::NotificationSource& source, | |
31 const content::NotificationDetails& details) OVERRIDE; | |
32 | |
33 private: | |
34 void Update(); | |
35 | |
36 PrefChangeRegistrar registrar_; | |
37 | |
38 DISALLOW_COPY_AND_ASSIGN(GesturePrefs); | |
39 }; | |
40 | |
41 GesturePrefs::GesturePrefs() { | |
42 } | |
43 | |
44 GesturePrefs::~GesturePrefs() { | |
45 } | |
46 | |
47 GesturePrefs* GesturePrefs::GetInstance() { | |
48 return Singleton<GesturePrefs>::get(); | |
49 } | |
50 | |
51 // The list of prefs we want to observe. | |
rjkroege
2012/02/24 15:21:34
this would need to be updated for changes to the G
| |
52 const char* kPrefsToObserve[] = { | |
53 prefs::kMaximumTouchDownDurationInSecondsForClick, | |
54 prefs::kMinimumTouchDownDurationInSecondsForClick, | |
55 prefs::kMaximumSecondsBetweenDoubleClick, | |
56 prefs::kMaximumTouchMoveInPixelsForClick, | |
57 prefs::kMinFlickSpeedSquared, | |
58 }; | |
59 | |
60 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); | |
61 | |
62 void GesturePrefs::RegisterPrefs(PrefService* ) { | |
rjkroege
2012/02/24 15:21:34
how will the webui adjust the constants? Am I righ
| |
63 PrefService* local_state = g_browser_process->local_state(); | |
64 | |
65 local_state->RegisterDoublePref( | |
66 prefs::kMaximumTouchDownDurationInSecondsForClick, 0.8); | |
67 local_state->RegisterDoublePref( | |
68 prefs::kMinimumTouchDownDurationInSecondsForClick, 0.01); | |
69 local_state->RegisterDoublePref( | |
70 prefs::kMaximumSecondsBetweenDoubleClick, 0.7); | |
71 local_state->RegisterDoublePref( | |
72 prefs::kMaximumTouchMoveInPixelsForClick, 20); | |
73 local_state->RegisterDoublePref( | |
74 prefs::kMinFlickSpeedSquared, 550.f*550.f); | |
75 | |
76 registrar_.Init(local_state); | |
77 if (local_state) { | |
78 for (int i = 0; i < kPrefsToObserveLength; ++i) | |
79 registrar_.Add(kPrefsToObserve[i], this); | |
80 } | |
81 } | |
82 | |
83 void GesturePrefs::Update() { | |
84 PrefService* local_state = g_browser_process->local_state(); | |
85 | |
86 aura::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click( | |
87 local_state->GetDouble(prefs::kMaximumTouchDownDurationInSecondsForClick)); | |
88 aura::GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click( | |
89 local_state->GetDouble(prefs::kMinimumTouchDownDurationInSecondsForClick)); | |
90 aura::GestureConfiguration::set_max_seconds_between_double_click( | |
91 local_state->GetDouble(prefs::kMaximumSecondsBetweenDoubleClick)); | |
92 aura::GestureConfiguration::set_max_touch_move_in_pixels_for_click( | |
93 local_state->GetDouble(prefs::kMaximumTouchMoveInPixelsForClick)); | |
94 aura::GestureConfiguration::set_min_flick_speed_squared( | |
95 local_state->GetDouble(prefs::kMinFlickSpeedSquared)); | |
96 } | |
97 | |
98 void GesturePrefs::Observe(int type, | |
99 const content::NotificationSource& source, | |
100 const content::NotificationDetails& details) { | |
101 Update(); | |
102 } | |
103 #endif | |
104 | |
105 } // namespace | |
106 | |
107 | |
108 // static | |
109 void GesturePrefsHelper::RegisterPrefs(PrefService* prefs) { | |
110 #if defined(USE_AURA) | |
111 GesturePrefs::GetInstance()->RegisterPrefs(prefs); | |
112 #endif | |
113 } | |
OLD | NEW |