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

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

Issue 9751011: Gesture recognition constants should all be stored in the GestureConfiguration object. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unified Units Created 8 years, 9 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
« no previous file with comments | « no previous file | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/singleton.h" 5 #include "base/memory/singleton.h"
6 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/ui/gesture_prefs.h" 7 #include "chrome/browser/ui/gesture_prefs.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/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
(...skipping 26 matching lines...) Expand all
37 37
38 PrefChangeRegistrar registrar_; 38 PrefChangeRegistrar registrar_;
39 PrefService* local_state_; 39 PrefService* local_state_;
40 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserverAura); 40 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserverAura);
41 }; 41 };
42 42
43 // The list of prefs we want to observe. 43 // The list of prefs we want to observe.
44 // Note that this collection of settings should correspond to the settings used 44 // Note that this collection of settings should correspond to the settings used
45 // in ui/aura/gestures/gesture_configuration.h 45 // in ui/aura/gestures/gesture_configuration.h
46 const char* kPrefsToObserve[] = { 46 const char* kPrefsToObserve[] = {
47 prefs::kMaximumSecondsBetweenDoubleClick, 47 prefs::kLongPressTimeInSeconds,
48 prefs::kMaximumTouchDownDurationInSecondsForClick, 48 prefs::kMaxSecondsBetweenDoubleClick,
49 prefs::kMaximumTouchMoveInPixelsForClick, 49 prefs::kMaxTouchDownDurationInSecondsForClick,
50 prefs::kMaxTouchMoveInPixelsForClick,
51 prefs::kMinDistanceForPinchScrollInPixels,
50 prefs::kMinFlickSpeedSquared, 52 prefs::kMinFlickSpeedSquared,
51 prefs::kMinimumTouchDownDurationInSecondsForClick, 53 prefs::kMinPinchUpdateDistanceInPixels,
54 prefs::kMinRailBreakVelocity,
55 prefs::kMinScrollDeltaSquared,
56 prefs::kMinTouchDownDurationInSecondsForClick,
57 prefs::kPointsBufferedForVelocity,
58 prefs::kRailBreakProportion,
59 prefs::kRailStartProportion,
52 }; 60 };
53 61
54 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); 62 const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
55 63
56 GesturePrefsObserverAura::GesturePrefsObserverAura() 64 GesturePrefsObserverAura::GesturePrefsObserverAura()
57 : local_state_(0) { 65 : local_state_(0) {
58 } 66 }
59 67
60 GesturePrefsObserverAura::~GesturePrefsObserverAura() { 68 GesturePrefsObserverAura::~GesturePrefsObserverAura() {
61 } 69 }
62 70
63 GesturePrefsObserverAura* GesturePrefsObserverAura::GetInstance() { 71 GesturePrefsObserverAura* GesturePrefsObserverAura::GetInstance() {
64 return Singleton<GesturePrefsObserverAura, 72 return Singleton<GesturePrefsObserverAura,
65 LeakySingletonTraits<GesturePrefsObserverAura> >::get(); 73 LeakySingletonTraits<GesturePrefsObserverAura> >::get();
66 } 74 }
67 75
68 void GesturePrefsObserverAura::RegisterPrefs(PrefService* local_state) { 76 void GesturePrefsObserverAura::RegisterPrefs(PrefService* local_state) {
69 if (local_state_ == 0) { 77 if (local_state_ == 0) {
70 local_state_ = local_state; 78 local_state_ = local_state;
71 79
72 if (local_state_) { 80 if (local_state_) {
81 local_state->RegisterDoublePref(
82 prefs::kLongPressTimeInSeconds,
83 GestureConfiguration::long_press_time_in_seconds());
73 local_state_->RegisterDoublePref( 84 local_state_->RegisterDoublePref(
74 prefs::kMaximumSecondsBetweenDoubleClick, 0.7); 85 prefs::kMaxSecondsBetweenDoubleClick,
86 GestureConfiguration::max_seconds_between_double_click());
75 local_state_->RegisterDoublePref( 87 local_state_->RegisterDoublePref(
76 prefs::kMaximumTouchDownDurationInSecondsForClick, 0.8); 88 prefs::kMaxTouchDownDurationInSecondsForClick,
89 GestureConfiguration::max_touch_down_duration_in_seconds_for_click());
77 local_state_->RegisterDoublePref( 90 local_state_->RegisterDoublePref(
78 prefs::kMaximumTouchMoveInPixelsForClick, 20); 91 prefs::kMaxTouchMoveInPixelsForClick,
92 GestureConfiguration::max_touch_move_in_pixels_for_click());
93 local_state->RegisterDoublePref(
94 prefs::kMinDistanceForPinchScrollInPixels,
95 GestureConfiguration::min_distance_for_pinch_scroll_in_pixels());
79 local_state_->RegisterDoublePref( 96 local_state_->RegisterDoublePref(
80 prefs::kMinFlickSpeedSquared, 550.f*550.f); 97 prefs::kMinFlickSpeedSquared,
98 GestureConfiguration::min_flick_speed_squared());
99 local_state->RegisterDoublePref(
100 prefs::kMinPinchUpdateDistanceInPixels,
101 GestureConfiguration::min_pinch_update_distance_in_pixels());
81 local_state_->RegisterDoublePref( 102 local_state_->RegisterDoublePref(
82 prefs::kMinimumTouchDownDurationInSecondsForClick, 0.01); 103 prefs::kMinRailBreakVelocity,
104 GestureConfiguration::min_rail_break_velocity());
105 local_state_->RegisterDoublePref(
106 prefs::kMinScrollDeltaSquared,
107 GestureConfiguration::min_scroll_delta_squared());
108 local_state_->RegisterDoublePref(
109 prefs::kMinTouchDownDurationInSecondsForClick,
110 GestureConfiguration::min_touch_down_duration_in_seconds_for_click());
111 local_state->RegisterIntegerPref(
112 prefs::kPointsBufferedForVelocity,
113 GestureConfiguration::points_buffered_for_velocity());
114 local_state->RegisterDoublePref(
115 prefs::kRailBreakProportion,
116 GestureConfiguration::rail_break_proportion());
117 local_state->RegisterDoublePref(
118 prefs::kRailStartProportion,
119 GestureConfiguration::rail_start_proportion());
83 120
84 registrar_.Init(local_state_); 121 registrar_.Init(local_state_);
85 registrar_.RemoveAll(); 122 registrar_.RemoveAll();
86 for (int i = 0; i < kPrefsToObserveLength; ++i) 123 for (int i = 0; i < kPrefsToObserveLength; ++i)
87 registrar_.Add(kPrefsToObserve[i], this); 124 registrar_.Add(kPrefsToObserve[i], this);
88 } 125 }
89 } 126 }
90 } 127 }
91 128
92 void GesturePrefsObserverAura::Update() { 129 void GesturePrefsObserverAura::Update() {
93 if (local_state_) { 130 if (local_state_) {
131 GestureConfiguration::set_long_press_time_in_seconds(
132 local_state_->GetDouble(
133 prefs::kLongPressTimeInSeconds));
94 GestureConfiguration::set_max_seconds_between_double_click( 134 GestureConfiguration::set_max_seconds_between_double_click(
95 local_state_->GetDouble(prefs::kMaximumSecondsBetweenDoubleClick)); 135 local_state_->GetDouble(
136 prefs::kMaxSecondsBetweenDoubleClick));
96 GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click( 137 GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click(
97 local_state_->GetDouble( 138 local_state_->GetDouble(
98 prefs::kMaximumTouchDownDurationInSecondsForClick)); 139 prefs::kMaxTouchDownDurationInSecondsForClick));
99 GestureConfiguration::set_max_touch_move_in_pixels_for_click( 140 GestureConfiguration::set_max_touch_move_in_pixels_for_click(
100 local_state_->GetDouble(prefs::kMaximumTouchMoveInPixelsForClick)); 141 local_state_->GetDouble(
142 prefs::kMaxTouchMoveInPixelsForClick));
143 GestureConfiguration::set_min_distance_for_pinch_scroll_in_pixels(
144 local_state_->GetDouble(
145 prefs::kMinDistanceForPinchScrollInPixels));
101 GestureConfiguration::set_min_flick_speed_squared( 146 GestureConfiguration::set_min_flick_speed_squared(
102 local_state_->GetDouble(prefs::kMinFlickSpeedSquared)); 147 local_state_->GetDouble(
148 prefs::kMinFlickSpeedSquared));
149 GestureConfiguration::set_min_pinch_update_distance_in_pixels(
150 local_state_->GetDouble(
151 prefs::kMinPinchUpdateDistanceInPixels));
152 GestureConfiguration::set_min_rail_break_velocity(
153 local_state_->GetDouble(
154 prefs::kMinRailBreakVelocity));
155 GestureConfiguration::set_min_scroll_delta_squared(
156 local_state_->GetDouble(
157 prefs::kMinScrollDeltaSquared));
103 GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click( 158 GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click(
104 local_state_->GetDouble( 159 local_state_->GetDouble(
105 prefs::kMinimumTouchDownDurationInSecondsForClick)); 160 prefs::kMinTouchDownDurationInSecondsForClick));
161 GestureConfiguration::set_points_buffered_for_velocity(
162 local_state_->GetInteger(
163 prefs::kPointsBufferedForVelocity));
164 GestureConfiguration::set_rail_break_proportion(
165 local_state_->GetDouble(
166 prefs::kRailBreakProportion));
167 GestureConfiguration::set_rail_start_proportion(
168 local_state_->GetDouble(
169 prefs::kRailStartProportion));
sadrul 2012/03/26 19:56:59 General comment: this is fairly icky. Updating all
106 } 170 }
107 } 171 }
108 172
109 void GesturePrefsObserverAura::Observe(int type, 173 void GesturePrefsObserverAura::Observe(int type,
110 const content::NotificationSource& source, 174 const content::NotificationSource& source,
111 const content::NotificationDetails& details) { 175 const content::NotificationDetails& details) {
112 Update(); 176 Update();
113 } 177 }
114 178
115 } // namespace 179 } // namespace
116 180
117 void GesturePrefsRegisterPrefs(PrefService* prefs) { 181 void GesturePrefsRegisterPrefs(PrefService* prefs) {
118 GesturePrefsObserverAura::GetInstance()->RegisterPrefs(prefs); 182 GesturePrefsObserverAura::GetInstance()->RegisterPrefs(prefs);
119 } 183 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698