| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/system/input_device_settings.h" | 5 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
| 18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
| 19 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/sys_info.h" | 22 #include "base/sys_info.h" |
| 23 #include "base/task_runner.h" | 23 #include "base/task_runner.h" |
| 24 #include "base/threading/sequenced_worker_pool.h" | 24 #include "base/threading/sequenced_worker_pool.h" |
| 25 #include "chrome/browser/chromeos/system/fake_input_device_settings.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "ui/events/base_event_utils.h" | 27 #include "ui/events/base_event_utils.h" |
| 27 #include "ui/events/devices/x11/device_data_manager_x11.h" | 28 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 28 #include "ui/events/devices/x11/device_list_cache_x11.h" | 29 #include "ui/events/devices/x11/device_list_cache_x11.h" |
| 29 #include "ui/events/devices/x11/touch_factory_x11.h" | 30 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 30 #include "ui/gfx/x/x11_types.h" | 31 #include "ui/gfx/x/x11_types.h" |
| 31 | 32 |
| 32 namespace chromeos { | 33 namespace chromeos { |
| 33 namespace system { | 34 namespace system { |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 InputDeviceSettings* g_instance = nullptr; | 38 InputDeviceSettings* g_instance = nullptr; |
| 38 InputDeviceSettings* g_test_instance = nullptr; | |
| 39 | 39 |
| 40 const char kDeviceTypeTouchpad[] = "touchpad"; | 40 const char kDeviceTypeTouchpad[] = "touchpad"; |
| 41 const char kDeviceTypeMouse[] = "mouse"; | 41 const char kDeviceTypeMouse[] = "mouse"; |
| 42 const char kInputControl[] = "/opt/google/input/inputcontrol"; | 42 const char kInputControl[] = "/opt/google/input/inputcontrol"; |
| 43 | 43 |
| 44 // The name of the xinput device corresponding to the internal touchpad. | 44 // The name of the xinput device corresponding to the internal touchpad. |
| 45 const char kInternalTouchpadName[] = "Elan Touchpad"; | 45 const char kInternalTouchpadName[] = "Elan Touchpad"; |
| 46 | 46 |
| 47 typedef base::RefCountedData<bool> RefCountedBool; | 47 typedef base::RefCountedData<bool> RefCountedBool; |
| 48 | 48 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 void SetTapToClick(bool enabled) override; | 162 void SetTapToClick(bool enabled) override; |
| 163 void SetThreeFingerClick(bool enabled) override; | 163 void SetThreeFingerClick(bool enabled) override; |
| 164 void SetTapDragging(bool enabled) override; | 164 void SetTapDragging(bool enabled) override; |
| 165 void SetNaturalScroll(bool enabled) override; | 165 void SetNaturalScroll(bool enabled) override; |
| 166 void MouseExists(const DeviceExistsCallback& callback) override; | 166 void MouseExists(const DeviceExistsCallback& callback) override; |
| 167 void UpdateMouseSettings(const MouseSettings& settings) override; | 167 void UpdateMouseSettings(const MouseSettings& settings) override; |
| 168 void SetMouseSensitivity(int value) override; | 168 void SetMouseSensitivity(int value) override; |
| 169 void SetPrimaryButtonRight(bool right) override; | 169 void SetPrimaryButtonRight(bool right) override; |
| 170 void ReapplyTouchpadSettings() override; | 170 void ReapplyTouchpadSettings() override; |
| 171 void ReapplyMouseSettings() override; | 171 void ReapplyMouseSettings() override; |
| 172 InputDeviceSettings::FakeInterface* GetFakeInterface() override; |
| 172 void SetInternalTouchpadEnabled(bool enabled) override; | 173 void SetInternalTouchpadEnabled(bool enabled) override; |
| 173 void SetTouchscreensEnabled(bool enabled) override; | 174 void SetTouchscreensEnabled(bool enabled) override; |
| 174 | 175 |
| 175 // Generate arguments for the inputcontrol script. | 176 // Generate arguments for the inputcontrol script. |
| 176 // | 177 // |
| 177 // |argv| is filled with arguments of script, that should be launched in order | 178 // |argv| is filled with arguments of script, that should be launched in order |
| 178 // to apply update. | 179 // to apply update. |
| 179 void GenerateTouchpadArguments(std::vector<std::string>* argv); | 180 void GenerateTouchpadArguments(std::vector<std::string>* argv); |
| 180 void GenerateMouseArguments(std::vector<std::string>* argv); | 181 void GenerateMouseArguments(std::vector<std::string>* argv); |
| 181 | 182 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (enabled) | 289 if (enabled) |
| 289 device_data_manager->EnableDevice(xi_dev_list[i].deviceid); | 290 device_data_manager->EnableDevice(xi_dev_list[i].deviceid); |
| 290 else | 291 else |
| 291 device_data_manager->DisableDevice(xi_dev_list[i].deviceid); | 292 device_data_manager->DisableDevice(xi_dev_list[i].deviceid); |
| 292 | 293 |
| 293 return; | 294 return; |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 } | 297 } |
| 297 | 298 |
| 299 InputDeviceSettings::FakeInterface* |
| 300 InputDeviceSettingsImplX11::GetFakeInterface() { |
| 301 return nullptr; |
| 302 } |
| 303 |
| 298 void InputDeviceSettingsImplX11::SetTouchscreensEnabled(bool enabled) { | 304 void InputDeviceSettingsImplX11::SetTouchscreensEnabled(bool enabled) { |
| 299 ui::TouchFactory::GetInstance()->SetTouchscreensEnabled(enabled); | 305 ui::TouchFactory::GetInstance()->SetTouchscreensEnabled(enabled); |
| 300 } | 306 } |
| 301 | 307 |
| 302 void InputDeviceSettingsImplX11::GenerateTouchpadArguments( | 308 void InputDeviceSettingsImplX11::GenerateTouchpadArguments( |
| 303 std::vector<std::string>* argv) { | 309 std::vector<std::string>* argv) { |
| 304 argv->push_back(kInputControl); | 310 argv->push_back(kInputControl); |
| 305 if (current_touchpad_settings_.IsSensitivitySet()) { | 311 if (current_touchpad_settings_.IsSensitivitySet()) { |
| 306 AddSensitivityArguments(kDeviceTypeTouchpad, | 312 AddSensitivityArguments(kDeviceTypeTouchpad, |
| 307 current_touchpad_settings_.GetSensitivity(), argv); | 313 current_touchpad_settings_.GetSensitivity(), argv); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 335 if (current_mouse_settings_.IsPrimaryButtonRightSet()) { | 341 if (current_mouse_settings_.IsPrimaryButtonRightSet()) { |
| 336 AddTPControlArguments( | 342 AddTPControlArguments( |
| 337 "mouse_swap_lr", current_mouse_settings_.GetPrimaryButtonRight(), argv); | 343 "mouse_swap_lr", current_mouse_settings_.GetPrimaryButtonRight(), argv); |
| 338 } | 344 } |
| 339 } | 345 } |
| 340 | 346 |
| 341 } // namespace | 347 } // namespace |
| 342 | 348 |
| 343 // static | 349 // static |
| 344 InputDeviceSettings* InputDeviceSettings::Get() { | 350 InputDeviceSettings* InputDeviceSettings::Get() { |
| 345 if (g_test_instance) | 351 if (!g_instance) { |
| 346 return g_test_instance; | 352 if (base::SysInfo::IsRunningOnChromeOS()) |
| 347 if (!g_instance) | 353 g_instance = new InputDeviceSettingsImplX11; |
| 348 g_instance = new InputDeviceSettingsImplX11; | 354 else |
| 355 g_instance = new FakeInputDeviceSettings; |
| 356 } |
| 349 return g_instance; | 357 return g_instance; |
| 350 } | 358 } |
| 351 | 359 |
| 352 // static | |
| 353 void InputDeviceSettings::SetSettingsForTesting( | |
| 354 InputDeviceSettings* test_settings) { | |
| 355 if (g_test_instance == test_settings) | |
| 356 return; | |
| 357 delete g_test_instance; | |
| 358 g_test_instance = test_settings; | |
| 359 } | |
| 360 | |
| 361 } // namespace system | 360 } // namespace system |
| 362 } // namespace chromeos | 361 } // namespace chromeos |
| OLD | NEW |