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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/system/input_device_settings.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "ui/ozone/public/input_controller.h"
9 #include "ui/ozone/public/ozone_platform.h"
16 InputDeviceSettings
* g_instance
= nullptr;
17 InputDeviceSettings
* g_test_instance
= nullptr;
19 // InputDeviceSettings for Linux without X11 (a.k.a. Ozone).
20 class InputDeviceSettingsImplOzone
: public InputDeviceSettings
{
22 InputDeviceSettingsImplOzone();
25 ~InputDeviceSettingsImplOzone() override
{}
28 // Overridden from InputDeviceSettings.
29 void TouchpadExists(const DeviceExistsCallback
& callback
) override
;
30 void UpdateTouchpadSettings(const TouchpadSettings
& settings
) override
;
31 void SetTouchpadSensitivity(int value
) override
;
32 void SetTapToClick(bool enabled
) override
;
33 void SetThreeFingerClick(bool enabled
) override
;
34 void SetTapDragging(bool enabled
) override
;
35 void SetNaturalScroll(bool enabled
) override
;
36 void MouseExists(const DeviceExistsCallback
& callback
) override
;
37 void UpdateMouseSettings(const MouseSettings
& settings
) override
;
38 void SetMouseSensitivity(int value
) override
;
39 void SetPrimaryButtonRight(bool right
) override
;
40 void ReapplyTouchpadSettings() override
;
41 void ReapplyMouseSettings() override
;
43 // Cached InputController pointer. It should be fixed throughout the browser
45 ui::InputController
* input_controller_
;
47 // Respective device setting objects.
48 TouchpadSettings current_touchpad_settings_
;
49 MouseSettings current_mouse_settings_
;
51 DISALLOW_COPY_AND_ASSIGN(InputDeviceSettingsImplOzone
);
54 InputDeviceSettingsImplOzone::InputDeviceSettingsImplOzone()
56 ui::OzonePlatform::GetInstance()->GetInputController()) {
57 // Make sure the input controller does exist.
58 DCHECK(ui::OzonePlatform::GetInstance()->GetInputController());
61 void InputDeviceSettingsImplOzone::TouchpadExists(
62 const DeviceExistsCallback
& callback
) {
63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
64 callback
.Run(input_controller_
->HasTouchpad());
67 void InputDeviceSettingsImplOzone::UpdateTouchpadSettings(
68 const TouchpadSettings
& settings
) {
69 if (current_touchpad_settings_
.Update(settings
))
70 ReapplyTouchpadSettings();
73 void InputDeviceSettingsImplOzone::SetTouchpadSensitivity(int value
) {
74 DCHECK(value
>= kMinPointerSensitivity
&& value
<= kMaxPointerSensitivity
);
75 current_touchpad_settings_
.SetSensitivity(value
);
76 input_controller_
->SetTouchpadSensitivity(value
);
79 void InputDeviceSettingsImplOzone::SetNaturalScroll(bool enabled
) {
80 current_touchpad_settings_
.SetNaturalScroll(enabled
);
81 input_controller_
->SetNaturalScroll(enabled
);
84 void InputDeviceSettingsImplOzone::SetTapToClick(bool enabled
) {
85 current_touchpad_settings_
.SetTapToClick(enabled
);
86 input_controller_
->SetTapToClick(enabled
);
89 void InputDeviceSettingsImplOzone::SetThreeFingerClick(bool enabled
) {
91 current_touchpad_settings_
.SetThreeFingerClick(enabled
);
92 input_controller_
->SetThreeFingerClick(enabled
);
95 void InputDeviceSettingsImplOzone::SetTapDragging(bool enabled
) {
96 current_touchpad_settings_
.SetTapDragging(enabled
);
97 input_controller_
->SetTapDragging(enabled
);
100 void InputDeviceSettingsImplOzone::MouseExists(
101 const DeviceExistsCallback
& callback
) {
102 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
103 callback
.Run(input_controller_
->HasMouse());
106 void InputDeviceSettingsImplOzone::UpdateMouseSettings(
107 const MouseSettings
& update
) {
108 if (current_mouse_settings_
.Update(update
))
109 ReapplyMouseSettings();
112 void InputDeviceSettingsImplOzone::SetMouseSensitivity(int value
) {
113 DCHECK(value
>= kMinPointerSensitivity
&& value
<= kMaxPointerSensitivity
);
114 current_mouse_settings_
.SetSensitivity(value
);
115 input_controller_
->SetMouseSensitivity(value
);
118 void InputDeviceSettingsImplOzone::SetPrimaryButtonRight(bool right
) {
119 current_mouse_settings_
.SetPrimaryButtonRight(right
);
120 input_controller_
->SetPrimaryButtonRight(right
);
123 void InputDeviceSettingsImplOzone::ReapplyTouchpadSettings() {
124 TouchpadSettings::Apply(current_touchpad_settings_
, this);
127 void InputDeviceSettingsImplOzone::ReapplyMouseSettings() {
128 MouseSettings::Apply(current_mouse_settings_
, this);
134 InputDeviceSettings
* InputDeviceSettings::Get() {
136 return g_test_instance
;
138 g_instance
= new InputDeviceSettingsImplOzone
;
143 void InputDeviceSettings::SetSettingsForTesting(
144 InputDeviceSettings
* test_settings
) {
145 if (g_test_instance
== test_settings
)
147 delete g_test_instance
;
148 g_test_instance
= test_settings
;
151 } // namespace system
152 } // namespace chromeos