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

Unified Diff: chrome/browser/gesture_prefs.cc

Issue 9460001: Adding persistance for gesture recognition parms. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/gesture_prefs.cc
diff --git a/chrome/browser/gesture_prefs.cc b/chrome/browser/gesture_prefs.cc
new file mode 100644
index 0000000000000000000000000000000000000000..36ed347db1a777af7c70fe70c1847e963c34e783
--- /dev/null
+++ b/chrome/browser/gesture_prefs.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gesture_prefs.h"
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/pref_names.h"
+#include "ui/aura/gestures/gesture_configuration.h"
+
+namespace {
+
+#if defined(USE_AURA)
rjkroege 2012/02/24 15:21:34 From my experience, this pattern is atypical. I wo
+// This class manages gesture configuration preferences.
+class GesturePrefs : public content::NotificationObserver {
+ public:
+ static GesturePrefs *GetInstance();
+ void RegisterPrefs(PrefService* prefs);
+
+ private:
+ GesturePrefs();
+ friend struct DefaultSingletonTraits<GesturePrefs>;
+ virtual ~GesturePrefs();
+
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ private:
+ void Update();
+
+ PrefChangeRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(GesturePrefs);
+};
+
+GesturePrefs::GesturePrefs() {
+}
+
+GesturePrefs::~GesturePrefs() {
+}
+
+GesturePrefs* GesturePrefs::GetInstance() {
+ return Singleton<GesturePrefs>::get();
+}
+
+// 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
+const char* kPrefsToObserve[] = {
+ prefs::kMaximumTouchDownDurationInSecondsForClick,
+ prefs::kMinimumTouchDownDurationInSecondsForClick,
+ prefs::kMaximumSecondsBetweenDoubleClick,
+ prefs::kMaximumTouchMoveInPixelsForClick,
+ prefs::kMinFlickSpeedSquared,
+};
+
+const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
+
+void GesturePrefs::RegisterPrefs(PrefService* ) {
rjkroege 2012/02/24 15:21:34 how will the webui adjust the constants? Am I righ
+ PrefService* local_state = g_browser_process->local_state();
+
+ local_state->RegisterDoublePref(
+ prefs::kMaximumTouchDownDurationInSecondsForClick, 0.8);
+ local_state->RegisterDoublePref(
+ prefs::kMinimumTouchDownDurationInSecondsForClick, 0.01);
+ local_state->RegisterDoublePref(
+ prefs::kMaximumSecondsBetweenDoubleClick, 0.7);
+ local_state->RegisterDoublePref(
+ prefs::kMaximumTouchMoveInPixelsForClick, 20);
+ local_state->RegisterDoublePref(
+ prefs::kMinFlickSpeedSquared, 550.f*550.f);
+
+ registrar_.Init(local_state);
+ if (local_state) {
+ for (int i = 0; i < kPrefsToObserveLength; ++i)
+ registrar_.Add(kPrefsToObserve[i], this);
+ }
+}
+
+void GesturePrefs::Update() {
+ PrefService* local_state = g_browser_process->local_state();
+
+ aura::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click(
+ local_state->GetDouble(prefs::kMaximumTouchDownDurationInSecondsForClick));
+ aura::GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click(
+ local_state->GetDouble(prefs::kMinimumTouchDownDurationInSecondsForClick));
+ aura::GestureConfiguration::set_max_seconds_between_double_click(
+ local_state->GetDouble(prefs::kMaximumSecondsBetweenDoubleClick));
+ aura::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
+ local_state->GetDouble(prefs::kMaximumTouchMoveInPixelsForClick));
+ aura::GestureConfiguration::set_min_flick_speed_squared(
+ local_state->GetDouble(prefs::kMinFlickSpeedSquared));
+}
+
+void GesturePrefs::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ Update();
+}
+#endif
+
+} // namespace
+
+
+// static
+void GesturePrefsHelper::RegisterPrefs(PrefService* prefs) {
+#if defined(USE_AURA)
+ GesturePrefs::GetInstance()->RegisterPrefs(prefs);
+#endif
+}

Powered by Google App Engine
This is Rietveld 408576698