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 "base/memory/singleton.h" |
| 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/ui/gesture_prefs.h" |
| 8 #include "chrome/browser/prefs/pref_change_registrar.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 "content/public/browser/notification_observer.h" |
| 13 #include "ui/aura/gestures/gesture_configuration.h" |
| 14 |
| 15 using aura::GestureConfiguration; |
| 16 |
| 17 namespace { |
| 18 |
| 19 // This class manages gesture configuration preferences. |
| 20 class GesturePrefsObserverAura : public content::NotificationObserver { |
| 21 public: |
| 22 static GesturePrefsObserverAura *GetInstance(); |
| 23 void RegisterPrefs(PrefService* prefs); |
| 24 |
| 25 private: |
| 26 GesturePrefsObserverAura(); |
| 27 friend struct DefaultSingletonTraits<GesturePrefsObserverAura>; |
| 28 virtual ~GesturePrefsObserverAura(); |
| 29 |
| 30 // content::NotificationObserver implementation. |
| 31 virtual void Observe(int type, |
| 32 const content::NotificationSource& source, |
| 33 const content::NotificationDetails& details) OVERRIDE; |
| 34 |
| 35 private: |
| 36 void Update(); |
| 37 |
| 38 PrefChangeRegistrar registrar_; |
| 39 PrefService* local_state_; |
| 40 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserverAura); |
| 41 }; |
| 42 |
| 43 // The list of prefs we want to observe. |
| 44 // Note that this collection of settings should correspond to the settings used |
| 45 // in ui/aura/gestures/gesture_configuration.h |
| 46 const char* kPrefsToObserve[] = { |
| 47 prefs::kMaximumSecondsBetweenDoubleClick, |
| 48 prefs::kMaximumTouchDownDurationInSecondsForClick, |
| 49 prefs::kMaximumTouchMoveInPixelsForClick, |
| 50 prefs::kMinFlickSpeedSquared, |
| 51 prefs::kMinimumTouchDownDurationInSecondsForClick, |
| 52 }; |
| 53 |
| 54 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); |
| 55 |
| 56 GesturePrefsObserverAura::GesturePrefsObserverAura() |
| 57 : local_state_(0) { |
| 58 } |
| 59 |
| 60 GesturePrefsObserverAura::~GesturePrefsObserverAura() { |
| 61 } |
| 62 |
| 63 GesturePrefsObserverAura* GesturePrefsObserverAura::GetInstance() { |
| 64 return Singleton<GesturePrefsObserverAura, |
| 65 LeakySingletonTraits<GesturePrefsObserverAura> >::get(); |
| 66 } |
| 67 |
| 68 void GesturePrefsObserverAura::RegisterPrefs(PrefService* local_state) { |
| 69 if (local_state_ == 0) { |
| 70 local_state_ = local_state; |
| 71 |
| 72 if (local_state_) { |
| 73 local_state_->RegisterDoublePref( |
| 74 prefs::kMaximumSecondsBetweenDoubleClick, 0.7); |
| 75 local_state_->RegisterDoublePref( |
| 76 prefs::kMaximumTouchDownDurationInSecondsForClick, 0.8); |
| 77 local_state_->RegisterDoublePref( |
| 78 prefs::kMaximumTouchMoveInPixelsForClick, 20); |
| 79 local_state_->RegisterDoublePref( |
| 80 prefs::kMinFlickSpeedSquared, 550.f*550.f); |
| 81 local_state_->RegisterDoublePref( |
| 82 prefs::kMinimumTouchDownDurationInSecondsForClick, 0.01); |
| 83 |
| 84 registrar_.Init(local_state_); |
| 85 registrar_.RemoveAll(); |
| 86 for (int i = 0; i < kPrefsToObserveLength; ++i) |
| 87 registrar_.Add(kPrefsToObserve[i], this); |
| 88 } |
| 89 } |
| 90 } |
| 91 |
| 92 void GesturePrefsObserverAura::Update() { |
| 93 if (local_state_) { |
| 94 GestureConfiguration::set_max_seconds_between_double_click( |
| 95 local_state_->GetDouble(prefs::kMaximumSecondsBetweenDoubleClick)); |
| 96 GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click( |
| 97 local_state_->GetDouble( |
| 98 prefs::kMaximumTouchDownDurationInSecondsForClick)); |
| 99 GestureConfiguration::set_max_touch_move_in_pixels_for_click( |
| 100 local_state_->GetDouble(prefs::kMaximumTouchMoveInPixelsForClick)); |
| 101 GestureConfiguration::set_min_flick_speed_squared( |
| 102 local_state_->GetDouble(prefs::kMinFlickSpeedSquared)); |
| 103 GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click( |
| 104 local_state_->GetDouble( |
| 105 prefs::kMinimumTouchDownDurationInSecondsForClick)); |
| 106 } |
| 107 } |
| 108 |
| 109 void GesturePrefsObserverAura::Observe(int type, |
| 110 const content::NotificationSource& source, |
| 111 const content::NotificationDetails& details) { |
| 112 Update(); |
| 113 } |
| 114 |
| 115 } // namespace |
| 116 |
| 117 void GesturePrefsRegisterPrefs(PrefService* prefs) { |
| 118 GesturePrefsObserverAura::GetInstance()->RegisterPrefs(prefs); |
| 119 } |
OLD | NEW |