OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/chromeos/touchpad.h" | 5 #include "chrome/browser/chromeos/touchpad.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 void RunnableMethodTraits<Touchpad>::RetainCallee( | 23 void RunnableMethodTraits<Touchpad>::RetainCallee( |
24 Touchpad* remover) { | 24 Touchpad* remover) { |
25 } | 25 } |
26 template<> | 26 template<> |
27 void RunnableMethodTraits<Touchpad>::ReleaseCallee( | 27 void RunnableMethodTraits<Touchpad>::ReleaseCallee( |
28 Touchpad* remover) { | 28 Touchpad* remover) { |
29 } | 29 } |
30 | 30 |
31 // static | 31 // static |
32 void Touchpad::RegisterUserPrefs(PrefService* prefs) { | 32 void Touchpad::RegisterUserPrefs(PrefService* prefs) { |
33 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled, true); | 33 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled, false); |
34 prefs->RegisterBooleanPref(prefs::kVertEdgeScrollEnabled, true); | 34 prefs->RegisterBooleanPref(prefs::kVertEdgeScrollEnabled, true); |
| 35 prefs->RegisterRealPref(prefs::kTouchpadSpeedFactor, 0.5); |
35 } | 36 } |
36 | 37 |
37 void Touchpad::Init(PrefService* prefs) { | 38 void Touchpad::Init(PrefService* prefs) { |
38 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this); | 39 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this); |
39 vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this); | 40 vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this); |
| 41 speed_factor_.Init(prefs::kTouchpadSpeedFactor, prefs, this); |
40 | 42 |
41 // Initialize touchpad settings to what's saved in user preferences. | 43 // Initialize touchpad settings to what's saved in user preferences. |
42 SetTapToClick(); | 44 SetTapToClick(); |
43 SetVertEdgeScroll(); | 45 SetVertEdgeScroll(); |
| 46 SetSpeedFactor(); |
44 } | 47 } |
45 | 48 |
46 void Touchpad::Observe(NotificationType type, | 49 void Touchpad::Observe(NotificationType type, |
47 const NotificationSource& source, | 50 const NotificationSource& source, |
48 const NotificationDetails& details) { | 51 const NotificationDetails& details) { |
49 if (type == NotificationType::PREF_CHANGED) | 52 if (type == NotificationType::PREF_CHANGED) |
50 NotifyPrefChanged(Details<std::wstring>(details).ptr()); | 53 NotifyPrefChanged(Details<std::wstring>(details).ptr()); |
51 } | 54 } |
52 | 55 |
53 void Touchpad::NotifyPrefChanged(const std::wstring* pref_name) { | 56 void Touchpad::NotifyPrefChanged(const std::wstring* pref_name) { |
54 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) | 57 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) |
55 SetTapToClick(); | 58 SetTapToClick(); |
56 if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled) | 59 if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled) |
57 SetVertEdgeScroll(); | 60 SetVertEdgeScroll(); |
| 61 if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor) |
| 62 SetSpeedFactor(); |
58 } | 63 } |
59 | 64 |
60 void Touchpad::SetSynclientParam(const std::string& param, | 65 void Touchpad::SetSynclientParam(const std::string& param, |
61 const std::string& value) { | 66 const std::string& value) { |
62 // If not running on the file thread, then re-run on the file thread. | 67 // If not running on the file thread, then re-run on the file thread. |
63 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { | 68 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { |
64 base::Thread* file_thread = g_browser_process->file_thread(); | 69 base::Thread* file_thread = g_browser_process->file_thread(); |
65 if (file_thread) | 70 if (file_thread) |
66 file_thread->message_loop()->PostTask(FROM_HERE, | 71 file_thread->message_loop()->PostTask(FROM_HERE, |
67 NewRunnableMethod(this, &Touchpad::SetSynclientParam, param, value)); | 72 NewRunnableMethod(this, &Touchpad::SetSynclientParam, param, value)); |
(...skipping 21 matching lines...) Expand all Loading... |
89 | 94 |
90 void Touchpad::SetVertEdgeScroll() { | 95 void Touchpad::SetVertEdgeScroll() { |
91 // To disable vertical edge scroll, we set VertEdgeScroll to 0. Vertical edge | 96 // To disable vertical edge scroll, we set VertEdgeScroll to 0. Vertical edge |
92 // scroll lets you use the right edge of the touchpad to control the movement | 97 // scroll lets you use the right edge of the touchpad to control the movement |
93 // of the vertical scroll bar. | 98 // of the vertical scroll bar. |
94 if (vert_edge_scroll_enabled_.GetValue()) | 99 if (vert_edge_scroll_enabled_.GetValue()) |
95 SetSynclientParam("VertEdgeScroll", "1"); | 100 SetSynclientParam("VertEdgeScroll", "1"); |
96 else | 101 else |
97 SetSynclientParam("VertEdgeScroll", "0"); | 102 SetSynclientParam("VertEdgeScroll", "0"); |
98 } | 103 } |
| 104 |
| 105 void Touchpad::SetSpeedFactor() { |
| 106 // To set speed factor, we use MinSpeed. Both MaxSpeed and AccelFactor are 0. |
| 107 // So MinSpeed will control the speed of the cursor with respect to the |
| 108 // touchpad movement and there will not be any acceleration. |
| 109 // We enforce that MinSpeed is between 0.01 and 1.00. |
| 110 double value = speed_factor_.GetValue(); |
| 111 if (value < 0.01) |
| 112 value = 0.01; |
| 113 if (value > 1.0) |
| 114 value = 1.0; |
| 115 SetSynclientParam("MinSpeed", StringPrintf("%f", value)); |
| 116 } |
OLD | NEW |