summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorchocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-21 20:01:35 +0000
committerchocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-21 20:01:35 +0000
commitc31b3c720e5a7ea430cfeb3361f4ff44f358f9e9 (patch)
treebd4012cbc0d8a9ec61791b29316b94554becd5db /chrome
parent6806d48ab1ce1f7dc3104033467581959368c28e (diff)
downloadchromium_src-c31b3c720e5a7ea430cfeb3361f4ff44f358f9e9.zip
chromium_src-c31b3c720e5a7ea430cfeb3361f4ff44f358f9e9.tar.gz
chromium_src-c31b3c720e5a7ea430cfeb3361f4ff44f358f9e9.tar.bz2
Switch to use libcros to make changes to touchpad settings.
BUG=none TEST=none Review URL: http://codereview.chromium.org/300011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29693 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/preferences.cc15
-rw-r--r--chrome/browser/chromeos/synaptics_library.cc47
-rw-r--r--chrome/browser/chromeos/synaptics_library.h47
-rw-r--r--chrome/browser/chromeos/touchpad.cc86
-rw-r--r--chrome/browser/chromeos/touchpad.h33
-rwxr-xr-xchrome/chrome.gyp4
6 files changed, 106 insertions, 126 deletions
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc
index a586ade..89abbdf 100644
--- a/chrome/browser/chromeos/preferences.cc
+++ b/chrome/browser/chromeos/preferences.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/chromeos/preferences.h"
#include "base/string_util.h"
-#include "chrome/browser/chromeos/touchpad.h"
+#include "chrome/browser/chromeos/synaptics_library.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_member.h"
#include "chrome/common/pref_names.h"
@@ -45,13 +45,18 @@ void Preferences::NotifyPrefChanged(const std::wstring* pref_name) {
if (!pref_name || *pref_name == prefs::kTimeZone)
SetTimeZone(timezone_.GetValue());
if (!pref_name || *pref_name == prefs::kTapToClickEnabled)
- Touchpad::SetTapToClick(tap_to_click_enabled_.GetValue());
+ SynapticsLibrary::Get()->SetBoolParameter(PARAM_BOOL_TAP_TO_CLICK,
+ tap_to_click_enabled_.GetValue());
if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled)
- Touchpad::SetVertEdgeScroll(vert_edge_scroll_enabled_.GetValue());
+ SynapticsLibrary::Get()->SetBoolParameter(
+ PARAM_BOOL_VERTICAL_EDGE_SCROLLING,
+ vert_edge_scroll_enabled_.GetValue());
if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor)
- Touchpad::SetSpeedFactor(speed_factor_.GetValue());
+ SynapticsLibrary::Get()->SetRangeParameter(PARAM_RANGE_SPEED_SENSITIVITY,
+ speed_factor_.GetValue());
if (!pref_name || *pref_name == prefs::kTouchpadSensitivity)
- Touchpad::SetSensitivity(sensitivity_.GetValue());
+ SynapticsLibrary::Get()->SetRangeParameter(PARAM_RANGE_TOUCH_SENSITIVITY,
+ sensitivity_.GetValue());
}
void Preferences::SetTimeZone(const std::wstring& id) {
diff --git a/chrome/browser/chromeos/synaptics_library.cc b/chrome/browser/chromeos/synaptics_library.cc
new file mode 100644
index 0000000..85cb2cb
--- /dev/null
+++ b/chrome/browser/chromeos/synaptics_library.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2009 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/chromeos/synaptics_library.h"
+
+#include "base/message_loop.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/chromeos/cros_library.h"
+
+namespace chromeos {
+
+// static
+SynapticsLibrary* SynapticsLibrary::Get() {
+ return Singleton<SynapticsLibrary>::get();
+}
+
+// static
+bool SynapticsLibrary::loaded() {
+ return CrosLibrary::loaded();
+}
+
+void SynapticsLibrary::SetBoolParameter(SynapticsParameter param, bool value) {
+ SetParameter(param, value ? 1 : 0);
+}
+
+void SynapticsLibrary::SetRangeParameter(SynapticsParameter param, int value) {
+ if (value < 1)
+ value = 1;
+ if (value > 10)
+ value = 10;
+ SetParameter(param, value);
+}
+
+void SynapticsLibrary::SetParameter(SynapticsParameter param, int value) {
+ if (CrosLibrary::loaded()) {
+ // This calls SetSynapticsParameter in the cros library which is
+ // potentially time consuming. So we run this on the FILE thread.
+ MessageLoop* loop = ChromeThread::GetMessageLoop(ChromeThread::FILE);
+ if (loop) {
+ loop->PostTask(FROM_HERE, NewRunnableFunction(
+ &SetSynapticsParameter, param, value));
+ }
+ }
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/synaptics_library.h b/chrome/browser/chromeos/synaptics_library.h
new file mode 100644
index 0000000..af15a49
--- /dev/null
+++ b/chrome/browser/chromeos/synaptics_library.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_SYNAPTICS_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_SYNAPTICS_LIBRARY_H_
+
+#include "base/singleton.h"
+#include "third_party/cros/chromeos_synaptics.h"
+
+namespace chromeos {
+
+// This class handles the interaction with the ChromeOS synaptics library APIs.
+// Users can get an instance of this library class like this:
+// SynapticsLibrary::Get()
+// For a list of SynapticsPrameters, see third_party/cros/chromeos_synaptics.h
+class SynapticsLibrary {
+ public:
+ // This gets the singleton SynapticsLibrary.
+ static SynapticsLibrary* Get();
+
+ // Returns true if the ChromeOS library was loaded.
+ static bool loaded();
+
+ // Sets a boolean parameter. The actual call will be run on the FILE thread.
+ void SetBoolParameter(SynapticsParameter param, bool value);
+
+ // Sets a range parameter. The actual call will be run on the FILE thread.
+ // Value should be between 1 and 10 inclusive.
+ void SetRangeParameter(SynapticsParameter param, int value);
+
+ private:
+ friend struct DefaultSingletonTraits<SynapticsLibrary>;
+
+ SynapticsLibrary() {}
+ ~SynapticsLibrary() {}
+
+ // This helper methods calls into the libcros library to set the parameter.
+ // This call is run on the FILE thread.
+ void SetParameter(SynapticsParameter param, int value);
+
+ DISALLOW_COPY_AND_ASSIGN(SynapticsLibrary);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_SYNAPTICS_LIBRARY_H_
diff --git a/chrome/browser/chromeos/touchpad.cc b/chrome/browser/chromeos/touchpad.cc
deleted file mode 100644
index ccb1eb9..0000000
--- a/chrome/browser/chromeos/touchpad.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2009 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/chromeos/touchpad.h"
-
-#include <stdlib.h>
-#include <string>
-#include <vector>
-
-#include "base/process_util.h"
-#include "base/string_util.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_thread.h"
-
-// static
-void Touchpad::SetSynclientParam(const std::string& param, double value) {
- // If not running on the file thread, then re-run on the file thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) {
- base::Thread* file_thread = g_browser_process->file_thread();
- if (file_thread)
- file_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(&Touchpad::SetSynclientParam, param, value));
- } else {
- // launch binary synclient to set the parameter
- std::vector<std::string> argv;
- argv.push_back("/usr/bin/synclient");
- argv.push_back(StringPrintf("%s=%f", param.c_str(), value));
- base::file_handle_mapping_vector no_files;
- base::ProcessHandle handle;
- if (!base::LaunchApp(argv, no_files, true, &handle))
- LOG(ERROR) << "Failed to call /usr/bin/synclient";
- }
-}
-
-// static
-void Touchpad::SetTapToClick(bool value) {
- // To disable tap-to-click (i.e. a tap on the touchpad is recognized as a left
- // mouse click event), we set MaxTapTime to 0. MaxTapTime is the maximum time
- // (in milliseconds) for detecting a tap. The default is 180.
- if (value)
- SetSynclientParam("MaxTapTime", 180);
- else
- SetSynclientParam("MaxTapTime", 0);
-}
-
-// static
-void Touchpad::SetVertEdgeScroll(bool value) {
- // To disable vertical edge scroll, we set VertEdgeScroll to 0. Vertical edge
- // scroll lets you use the right edge of the touchpad to control the movement
- // of the vertical scroll bar.
- if (value)
- SetSynclientParam("VertEdgeScroll", 1);
- else
- SetSynclientParam("VertEdgeScroll", 0);
-}
-
-// static
-void Touchpad::SetSpeedFactor(int value) {
- // To set speed factor, we use MaxSpeed. MinSpeed is set to 0.2.
- // MaxSpeed can go from 0.2 to 1.1. The preference is an integer between
- // 1 and 10, so we divide that by 10 and add 0.1 for the value of MaxSpeed.
- if (value < 1)
- value = 1;
- if (value > 10)
- value = 10;
- // Convert from 1-10 to 0.2-1.1
- double d = static_cast<double>(value) / 10.0 + 0.1;
- SetSynclientParam("MaxSpeed", d);
-}
-
-// static
-void Touchpad::SetSensitivity(int value) {
- // To set the touch sensitivity, we use FingerHigh, which represents the
- // the pressure needed for a tap to be registered. The range of FingerHigh
- // goes from 25 to 70. We store the sensitivity preference as an int from
- // 1 to 10. So we need to map the preference value of 1 to 10 to the
- // FingerHigh value of 25 to 70 inversely.
- if (value < 1)
- value = 1;
- if (value > 10)
- value = 10;
- // Convert from 1-10 to 70-25.
- double d = (15 - value) * 5;
- SetSynclientParam("FingerHigh", d);
-}
diff --git a/chrome/browser/chromeos/touchpad.h b/chrome/browser/chromeos/touchpad.h
deleted file mode 100644
index bf861e8..0000000
--- a/chrome/browser/chromeos/touchpad.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2006-2008 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.
-
-#ifndef CHROME_BROWSER_CHROMEOS_TOUCHPAD_H_
-#define CHROME_BROWSER_CHROMEOS_TOUCHPAD_H_
-
-#include <string>
-
-// For Synaptics touchpads, we use synclient to change settings on-the-fly.
-// See "man synaptics" for a list of settings that can be changed.
-// Since we are doing a system call to run the synclient binary, we make sure
-// that we are running on the File thread so that we don't block the UI thread.
-class Touchpad {
- public:
- // This methods makes a system call to synclient to change touchpad settings.
- // The system call will be invoked on the file thread.
- static void SetSynclientParam(const std::string& param, double value);
-
- // Set tap-to-click to value stored in preferences.
- static void SetTapToClick(bool value);
-
- // Set vertical edge scrolling to value stored in preferences.
- static void SetVertEdgeScroll(bool value);
-
- // Set touchpad speed factor to value stored in preferences.
- static void SetSpeedFactor(int value);
-
- // Set tap sensitivity to value stored in preferences.
- static void SetSensitivity(int value);
-};
-
-#endif // CHROME_BROWSER_CHROMEOS_TOUCHPAD_H_
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 579ec13..23e79ad 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -994,8 +994,8 @@
'browser/chromeos/status_area_button.h',
'browser/chromeos/status_area_view.cc',
'browser/chromeos/status_area_view.h',
- 'browser/chromeos/touchpad.cc',
- 'browser/chromeos/touchpad.h',
+ 'browser/chromeos/synaptics_library.cc',
+ 'browser/chromeos/synaptics_library.h',
'browser/cocoa/about_ipc_bridge.h',
'browser/cocoa/about_ipc_bridge.mm',
'browser/cocoa/about_ipc_controller.h',