1 // Copyright (c) 2012 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 "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
9 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
10 #include "chromeos/system/statistics_provider.h"
15 TouchpadSettings::TouchpadSettings() {
18 TouchpadSettings
& TouchpadSettings::operator=(const TouchpadSettings
& other
) {
20 sensitivity_
= other
.sensitivity_
;
21 tap_to_click_
= other
.tap_to_click_
;
22 three_finger_click_
= other
.three_finger_click_
;
23 tap_dragging_
= other
.tap_dragging_
;
24 natural_scroll_
= other
.natural_scroll_
;
29 void TouchpadSettings::SetSensitivity(int value
) {
30 sensitivity_
.Set(value
);
33 int TouchpadSettings::GetSensitivity() const {
34 return sensitivity_
.value();
37 bool TouchpadSettings::IsSensitivitySet() const {
38 return sensitivity_
.is_set();
41 void TouchpadSettings::SetTapToClick(bool enabled
) {
42 tap_to_click_
.Set(enabled
);
45 bool TouchpadSettings::GetTapToClick() const {
46 return tap_to_click_
.value();
49 bool TouchpadSettings::IsTapToClickSet() const {
50 return tap_to_click_
.is_set();
53 void TouchpadSettings::SetNaturalScroll(bool enabled
) {
54 natural_scroll_
.Set(enabled
);
57 bool TouchpadSettings::GetNaturalScroll() const {
58 return natural_scroll_
.value();
61 bool TouchpadSettings::IsNaturalScrollSet() const {
62 return natural_scroll_
.is_set();
65 void TouchpadSettings::SetThreeFingerClick(bool enabled
) {
66 three_finger_click_
.Set(enabled
);
69 bool TouchpadSettings::GetThreeFingerClick() const {
70 return three_finger_click_
.value();
73 bool TouchpadSettings::IsThreeFingerClickSet() const {
74 return three_finger_click_
.is_set();
77 void TouchpadSettings::SetTapDragging(bool enabled
) {
78 tap_dragging_
.Set(enabled
);
81 bool TouchpadSettings::GetTapDragging() const {
82 return tap_dragging_
.value();
85 bool TouchpadSettings::IsTapDraggingSet() const {
86 return tap_dragging_
.is_set();
89 bool TouchpadSettings::Update(const TouchpadSettings
& settings
) {
91 if (sensitivity_
.Update(settings
.sensitivity_
))
93 if (tap_to_click_
.Update(settings
.tap_to_click_
))
95 if (three_finger_click_
.Update(settings
.three_finger_click_
))
97 if (tap_dragging_
.Update(settings
.tap_dragging_
))
99 natural_scroll_
.Update(settings
.natural_scroll_
);
100 // Always send natural scrolling to the shell command, as a workaround.
101 // See crbug.com/406480
102 if (natural_scroll_
.is_set())
108 void TouchpadSettings::Apply(const TouchpadSettings
& touchpad_settings
,
109 InputDeviceSettings
* input_device_settings
) {
110 if (!input_device_settings
)
112 if (touchpad_settings
.sensitivity_
.is_set()) {
113 input_device_settings
->SetTouchpadSensitivity(
114 touchpad_settings
.sensitivity_
.value());
116 if (touchpad_settings
.tap_to_click_
.is_set()) {
117 input_device_settings
->SetTapToClick(
118 touchpad_settings
.tap_to_click_
.value());
120 if (touchpad_settings
.three_finger_click_
.is_set()) {
121 input_device_settings
->SetThreeFingerClick(
122 touchpad_settings
.three_finger_click_
.value());
124 if (touchpad_settings
.tap_dragging_
.is_set()) {
125 input_device_settings
->SetTapDragging(
126 touchpad_settings
.tap_dragging_
.value());
128 if (touchpad_settings
.natural_scroll_
.is_set()) {
129 input_device_settings
->SetNaturalScroll(
130 touchpad_settings
.natural_scroll_
.value());
134 MouseSettings::MouseSettings() {
137 MouseSettings
& MouseSettings::operator=(const MouseSettings
& other
) {
138 if (&other
!= this) {
139 sensitivity_
= other
.sensitivity_
;
140 primary_button_right_
= other
.primary_button_right_
;
145 void MouseSettings::SetSensitivity(int value
) {
146 sensitivity_
.Set(value
);
149 int MouseSettings::GetSensitivity() const {
150 return sensitivity_
.value();
153 bool MouseSettings::IsSensitivitySet() const {
154 return sensitivity_
.is_set();
157 void MouseSettings::SetPrimaryButtonRight(bool right
) {
158 primary_button_right_
.Set(right
);
161 bool MouseSettings::GetPrimaryButtonRight() const {
162 return primary_button_right_
.value();
165 bool MouseSettings::IsPrimaryButtonRightSet() const {
166 return primary_button_right_
.is_set();
169 bool MouseSettings::Update(const MouseSettings
& settings
) {
170 bool updated
= false;
171 if (sensitivity_
.Update(settings
.sensitivity_
))
173 if (primary_button_right_
.Update(settings
.primary_button_right_
))
179 void MouseSettings::Apply(const MouseSettings
& mouse_settings
,
180 InputDeviceSettings
* input_device_settings
) {
181 if (!input_device_settings
)
183 if (mouse_settings
.sensitivity_
.is_set()) {
184 input_device_settings
->SetMouseSensitivity(
185 mouse_settings
.sensitivity_
.value());
187 if (mouse_settings
.primary_button_right_
.is_set()) {
188 input_device_settings
->SetPrimaryButtonRight(
189 mouse_settings
.primary_button_right_
.value());
194 bool InputDeviceSettings::ForceKeyboardDrivenUINavigation() {
195 policy::BrowserPolicyConnectorChromeOS
* connector
=
196 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
200 policy::DeviceCloudPolicyManagerChromeOS
* policy_manager
=
201 connector
->GetDeviceCloudPolicyManager();
205 if (policy_manager
->IsRemoraRequisition() ||
206 policy_manager
->IsSharkRequisition()) {
210 bool keyboard_driven
= false;
211 if (chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
212 kOemKeyboardDrivenOobeKey
, &keyboard_driven
)) {
213 return keyboard_driven
;
219 } // namespace system
220 } // namespace chromeos