OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/touchpad.h" |
| 6 |
| 7 #include <stdlib.h> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/string_util.h" |
| 12 #include "base/process_util.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_thread.h" |
| 15 #include "chrome/common/notification_service.h" |
| 16 #include "chrome/common/pref_member.h" |
| 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/pref_service.h" |
| 19 |
| 20 // Allows InvokeLater without adding refcounting. The object is only deleted |
| 21 // when its last InvokeLater is run anyway. |
| 22 template<> |
| 23 void RunnableMethodTraits<Touchpad>::RetainCallee( |
| 24 Touchpad* remover) { |
| 25 } |
| 26 template<> |
| 27 void RunnableMethodTraits<Touchpad>::ReleaseCallee( |
| 28 Touchpad* remover) { |
| 29 } |
| 30 |
| 31 // static |
| 32 void Touchpad::RegisterUserPrefs(PrefService* prefs) { |
| 33 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled, true); |
| 34 prefs->RegisterBooleanPref(prefs::kVertEdgeScrollEnabled, true); |
| 35 } |
| 36 |
| 37 void Touchpad::Init(PrefService* prefs) { |
| 38 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this); |
| 39 vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this); |
| 40 |
| 41 // Initialize touchpad settings to what's saved in user preferences. |
| 42 SetTapToClick(); |
| 43 SetVertEdgeScroll(); |
| 44 } |
| 45 |
| 46 void Touchpad::Observe(NotificationType type, |
| 47 const NotificationSource& source, |
| 48 const NotificationDetails& details) { |
| 49 if (type == NotificationType::PREF_CHANGED) |
| 50 NotifyPrefChanged(Details<std::wstring>(details).ptr()); |
| 51 } |
| 52 |
| 53 void Touchpad::NotifyPrefChanged(const std::wstring* pref_name) { |
| 54 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) |
| 55 SetTapToClick(); |
| 56 if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled) |
| 57 SetVertEdgeScroll(); |
| 58 } |
| 59 |
| 60 void Touchpad::SetSynclientParam(const std::string& param, |
| 61 const std::string& value) { |
| 62 // If not running on the file thread, then re-run on the file thread. |
| 63 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { |
| 64 base::Thread* file_thread = g_browser_process->file_thread(); |
| 65 if (file_thread) |
| 66 file_thread->message_loop()->PostTask(FROM_HERE, |
| 67 NewRunnableMethod(this, &Touchpad::SetSynclientParam, param, value)); |
| 68 } else { |
| 69 // launch binary synclient to set the parameter |
| 70 std::vector<std::string> argv; |
| 71 argv.push_back("/usr/bin/synclient"); |
| 72 argv.push_back(param + "=" + value); |
| 73 base::file_handle_mapping_vector no_files; |
| 74 base::ProcessHandle handle; |
| 75 if (!base::LaunchApp(argv, no_files, true, &handle)) |
| 76 LOG(ERROR) << "Failed to call /usr/bin/synclient"; |
| 77 } |
| 78 } |
| 79 |
| 80 void Touchpad::SetTapToClick() { |
| 81 // To disable tap-to-click (i.e. a tap on the touchpad is recognized as a left |
| 82 // mouse click event), we set MaxTapTime to 0. MaxTapTime is the maximum time |
| 83 // (in milliseconds) for detecting a tap. The default is 180. |
| 84 if (tap_to_click_enabled_.GetValue()) |
| 85 SetSynclientParam("MaxTapTime", "180"); |
| 86 else |
| 87 SetSynclientParam("MaxTapTime", "0"); |
| 88 } |
| 89 |
| 90 void Touchpad::SetVertEdgeScroll() { |
| 91 // 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 |
| 93 // of the vertical scroll bar. |
| 94 if (vert_edge_scroll_enabled_.GetValue()) |
| 95 SetSynclientParam("VertEdgeScroll", "1"); |
| 96 else |
| 97 SetSynclientParam("VertEdgeScroll", "0"); |
| 98 } |
OLD | NEW |