| 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 14 matching lines...) Expand all Loading... |
| 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, false); | 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 prefs->RegisterIntegerPref(prefs::kTouchpadSpeedFactor, 5); |
| 36 prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity, 5); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void Touchpad::Init(PrefService* prefs) { | 39 void Touchpad::Init(PrefService* prefs) { |
| 39 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this); | 40 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this); |
| 40 vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this); | 41 vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this); |
| 41 speed_factor_.Init(prefs::kTouchpadSpeedFactor, prefs, this); | 42 speed_factor_.Init(prefs::kTouchpadSpeedFactor, prefs, this); |
| 43 sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this); |
| 42 | 44 |
| 43 // Initialize touchpad settings to what's saved in user preferences. | 45 // Initialize touchpad settings to what's saved in user preferences. |
| 44 SetTapToClick(); | 46 SetTapToClick(); |
| 45 SetVertEdgeScroll(); | 47 SetVertEdgeScroll(); |
| 46 SetSpeedFactor(); | 48 SetSpeedFactor(); |
| 49 SetSensitivity(); |
| 47 } | 50 } |
| 48 | 51 |
| 49 void Touchpad::Observe(NotificationType type, | 52 void Touchpad::Observe(NotificationType type, |
| 50 const NotificationSource& source, | 53 const NotificationSource& source, |
| 51 const NotificationDetails& details) { | 54 const NotificationDetails& details) { |
| 52 if (type == NotificationType::PREF_CHANGED) | 55 if (type == NotificationType::PREF_CHANGED) |
| 53 NotifyPrefChanged(Details<std::wstring>(details).ptr()); | 56 NotifyPrefChanged(Details<std::wstring>(details).ptr()); |
| 54 } | 57 } |
| 55 | 58 |
| 56 void Touchpad::NotifyPrefChanged(const std::wstring* pref_name) { | 59 void Touchpad::NotifyPrefChanged(const std::wstring* pref_name) { |
| 57 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) | 60 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) |
| 58 SetTapToClick(); | 61 SetTapToClick(); |
| 59 if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled) | 62 if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled) |
| 60 SetVertEdgeScroll(); | 63 SetVertEdgeScroll(); |
| 61 if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor) | 64 if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor) |
| 62 SetSpeedFactor(); | 65 SetSpeedFactor(); |
| 66 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) |
| 67 SetSensitivity(); |
| 63 } | 68 } |
| 64 | 69 |
| 65 void Touchpad::SetSynclientParam(const std::string& param, | 70 void Touchpad::SetSynclientParam(const std::string& param, double value) { |
| 66 const std::string& value) { | |
| 67 // If not running on the file thread, then re-run on the file thread. | 71 // If not running on the file thread, then re-run on the file thread. |
| 68 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { | 72 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { |
| 69 base::Thread* file_thread = g_browser_process->file_thread(); | 73 base::Thread* file_thread = g_browser_process->file_thread(); |
| 70 if (file_thread) | 74 if (file_thread) |
| 71 file_thread->message_loop()->PostTask(FROM_HERE, | 75 file_thread->message_loop()->PostTask(FROM_HERE, |
| 72 NewRunnableMethod(this, &Touchpad::SetSynclientParam, param, value)); | 76 NewRunnableMethod(this, &Touchpad::SetSynclientParam, param, value)); |
| 73 } else { | 77 } else { |
| 74 // launch binary synclient to set the parameter | 78 // launch binary synclient to set the parameter |
| 75 std::vector<std::string> argv; | 79 std::vector<std::string> argv; |
| 76 argv.push_back("/usr/bin/synclient"); | 80 argv.push_back("/usr/bin/synclient"); |
| 77 argv.push_back(param + "=" + value); | 81 argv.push_back(StringPrintf("%s=%f", param.c_str(), value)); |
| 78 base::file_handle_mapping_vector no_files; | 82 base::file_handle_mapping_vector no_files; |
| 79 base::ProcessHandle handle; | 83 base::ProcessHandle handle; |
| 80 if (!base::LaunchApp(argv, no_files, true, &handle)) | 84 if (!base::LaunchApp(argv, no_files, true, &handle)) |
| 81 LOG(ERROR) << "Failed to call /usr/bin/synclient"; | 85 LOG(ERROR) << "Failed to call /usr/bin/synclient"; |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 85 void Touchpad::SetTapToClick() { | 89 void Touchpad::SetTapToClick() { |
| 86 // To disable tap-to-click (i.e. a tap on the touchpad is recognized as a left | 90 // To disable tap-to-click (i.e. a tap on the touchpad is recognized as a left |
| 87 // mouse click event), we set MaxTapTime to 0. MaxTapTime is the maximum time | 91 // mouse click event), we set MaxTapTime to 0. MaxTapTime is the maximum time |
| 88 // (in milliseconds) for detecting a tap. The default is 180. | 92 // (in milliseconds) for detecting a tap. The default is 180. |
| 89 if (tap_to_click_enabled_.GetValue()) | 93 if (tap_to_click_enabled_.GetValue()) |
| 90 SetSynclientParam("MaxTapTime", "180"); | 94 SetSynclientParam("MaxTapTime", 180); |
| 91 else | 95 else |
| 92 SetSynclientParam("MaxTapTime", "0"); | 96 SetSynclientParam("MaxTapTime", 0); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void Touchpad::SetVertEdgeScroll() { | 99 void Touchpad::SetVertEdgeScroll() { |
| 96 // To disable vertical edge scroll, we set VertEdgeScroll to 0. Vertical edge | 100 // To disable vertical edge scroll, we set VertEdgeScroll to 0. Vertical edge |
| 97 // scroll lets you use the right edge of the touchpad to control the movement | 101 // scroll lets you use the right edge of the touchpad to control the movement |
| 98 // of the vertical scroll bar. | 102 // of the vertical scroll bar. |
| 99 if (vert_edge_scroll_enabled_.GetValue()) | 103 if (vert_edge_scroll_enabled_.GetValue()) |
| 100 SetSynclientParam("VertEdgeScroll", "1"); | 104 SetSynclientParam("VertEdgeScroll", 1); |
| 101 else | 105 else |
| 102 SetSynclientParam("VertEdgeScroll", "0"); | 106 SetSynclientParam("VertEdgeScroll", 0); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void Touchpad::SetSpeedFactor() { | 109 void Touchpad::SetSpeedFactor() { |
| 106 // To set speed factor, we use MinSpeed. Both MaxSpeed and AccelFactor are 0. | 110 // 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 | 111 // So MinSpeed will control the speed of the cursor with respect to the |
| 108 // touchpad movement and there will not be any acceleration. | 112 // touchpad movement and there will not be any acceleration. |
| 109 // We enforce that MinSpeed is between 0.01 and 1.00. | 113 // MinSpeed is between 0.01 and 1.00. The preference is an integer between |
| 110 double value = speed_factor_.GetValue(); | 114 // 1 and 10, so we divide that by 10 for the value of MinSpeed. |
| 111 if (value < 0.01) | 115 int value = speed_factor_.GetValue(); |
| 112 value = 0.01; | 116 if (value < 1) |
| 113 if (value > 1.0) | 117 value = 1; |
| 114 value = 1.0; | 118 if (value > 10) |
| 115 SetSynclientParam("MinSpeed", StringPrintf("%f", value)); | 119 value = 10; |
| 120 // Convert from 1-10 to 0.1-1.0 |
| 121 double d = static_cast<double>(value) / 10.0; |
| 122 SetSynclientParam("MinSpeed", d); |
| 116 } | 123 } |
| 124 |
| 125 void Touchpad::SetSensitivity() { |
| 126 // To set the touch sensitivity, we use FingerHigh, which represents the |
| 127 // the pressure needed for a tap to be registered. The range of FingerHigh |
| 128 // goes from 30 to 75. We store the sensitivity preference as an int from |
| 129 // 1 to 10. So we need to map the preference value of 1 to 10 to the |
| 130 // FingerHigh value of 30 to 75. |
| 131 int value = sensitivity_.GetValue(); |
| 132 if (value < 1) |
| 133 value = 1; |
| 134 if (value > 10) |
| 135 value = 10; |
| 136 // Convert from 1-10 to 30-75. |
| 137 double d = value * 5 + 25; |
| 138 SetSynclientParam("FingerHigh", d); |
| 139 } |
| OLD | NEW |