Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / events / ozone / evdev / input_controller_evdev.cc
blobc5b44ad8a72c685f7db57368571dca65c7159f0f
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 "ui/events/ozone/evdev/input_controller_evdev.h"
7 #include <algorithm>
8 #include <linux/input.h>
10 #include "base/thread_task_runner_handle.h"
11 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h"
12 #include "ui/events/ozone/evdev/keyboard_evdev.h"
13 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
15 namespace ui {
17 InputControllerEvdev::InputControllerEvdev(KeyboardEvdev* keyboard,
18 MouseButtonMapEvdev* button_map)
19 : settings_update_pending_(false),
20 input_device_factory_(nullptr),
21 keyboard_(keyboard),
22 button_map_(button_map),
23 has_mouse_(false),
24 has_touchpad_(false),
25 caps_lock_led_state_(false),
26 weak_ptr_factory_(this) {
29 InputControllerEvdev::~InputControllerEvdev() {
32 void InputControllerEvdev::SetInputDeviceFactory(
33 InputDeviceFactoryEvdevProxy* input_device_factory) {
34 input_device_factory_ = input_device_factory;
36 UpdateDeviceSettings();
37 UpdateCapsLockLed();
40 void InputControllerEvdev::set_has_mouse(bool has_mouse) {
41 has_mouse_ = has_mouse;
44 void InputControllerEvdev::set_has_touchpad(bool has_touchpad) {
45 has_touchpad_ = has_touchpad;
48 bool InputControllerEvdev::HasMouse() {
49 return has_mouse_;
52 bool InputControllerEvdev::HasTouchpad() {
53 return has_touchpad_;
56 bool InputControllerEvdev::IsCapsLockEnabled() {
57 return keyboard_->IsCapsLockEnabled();
60 void InputControllerEvdev::SetCapsLockEnabled(bool enabled) {
61 keyboard_->SetCapsLockEnabled(enabled);
62 UpdateCapsLockLed();
65 void InputControllerEvdev::SetNumLockEnabled(bool enabled) {
66 NOTIMPLEMENTED();
69 bool InputControllerEvdev::IsAutoRepeatEnabled() {
70 return keyboard_->IsAutoRepeatEnabled();
73 void InputControllerEvdev::SetAutoRepeatEnabled(bool enabled) {
74 keyboard_->SetAutoRepeatEnabled(enabled);
77 void InputControllerEvdev::SetAutoRepeatRate(const base::TimeDelta& delay,
78 const base::TimeDelta& interval) {
79 keyboard_->SetAutoRepeatRate(delay, interval);
82 void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta* delay,
83 base::TimeDelta* interval) {
84 keyboard_->GetAutoRepeatRate(delay, interval);
87 void InputControllerEvdev::DisableInternalTouchpad() {
88 if (input_device_factory_)
89 input_device_factory_->DisableInternalTouchpad();
92 void InputControllerEvdev::EnableInternalTouchpad() {
93 if (input_device_factory_)
94 input_device_factory_->EnableInternalTouchpad();
97 void InputControllerEvdev::DisableInternalKeyboardExceptKeys(
98 scoped_ptr<std::set<DomCode>> excepted_keys) {
99 if (input_device_factory_) {
100 input_device_factory_->DisableInternalKeyboardExceptKeys(
101 excepted_keys.Pass());
105 void InputControllerEvdev::EnableInternalKeyboard() {
106 if (input_device_factory_)
107 input_device_factory_->EnableInternalKeyboard();
110 void InputControllerEvdev::SetTouchpadSensitivity(int value) {
111 input_device_settings_.touchpad_sensitivity = value;
112 ScheduleUpdateDeviceSettings();
115 void InputControllerEvdev::SetTapToClick(bool enabled) {
116 input_device_settings_.tap_to_click_enabled = enabled;
117 ScheduleUpdateDeviceSettings();
120 void InputControllerEvdev::SetThreeFingerClick(bool enabled) {
121 input_device_settings_.three_finger_click_enabled = enabled;
122 ScheduleUpdateDeviceSettings();
125 void InputControllerEvdev::SetTapDragging(bool enabled) {
126 input_device_settings_.tap_dragging_enabled = enabled;
127 ScheduleUpdateDeviceSettings();
130 void InputControllerEvdev::SetNaturalScroll(bool enabled) {
131 input_device_settings_.natural_scroll_enabled = enabled;
132 ScheduleUpdateDeviceSettings();
135 void InputControllerEvdev::SetMouseSensitivity(int value) {
136 input_device_settings_.mouse_sensitivity = value;
137 ScheduleUpdateDeviceSettings();
140 void InputControllerEvdev::SetPrimaryButtonRight(bool right) {
141 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT);
142 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT);
145 void InputControllerEvdev::SetTapToClickPaused(bool state) {
146 input_device_settings_.tap_to_click_paused = state;
147 ScheduleUpdateDeviceSettings();
150 void InputControllerEvdev::GetTouchDeviceStatus(
151 const GetTouchDeviceStatusReply& reply) {
152 if (input_device_factory_)
153 input_device_factory_->GetTouchDeviceStatus(reply);
154 else
155 reply.Run(make_scoped_ptr(new std::string));
158 void InputControllerEvdev::GetTouchEventLog(
159 const base::FilePath& out_dir,
160 const GetTouchEventLogReply& reply) {
161 if (input_device_factory_)
162 input_device_factory_->GetTouchEventLog(out_dir, reply);
163 else
164 reply.Run(make_scoped_ptr(new std::vector<base::FilePath>));
167 void InputControllerEvdev::ScheduleUpdateDeviceSettings() {
168 if (!input_device_factory_ || settings_update_pending_)
169 return;
170 base::ThreadTaskRunnerHandle::Get()->PostTask(
171 FROM_HERE, base::Bind(&InputControllerEvdev::UpdateDeviceSettings,
172 weak_ptr_factory_.GetWeakPtr()));
173 settings_update_pending_ = true;
176 void InputControllerEvdev::UpdateDeviceSettings() {
177 input_device_factory_->UpdateInputDeviceSettings(input_device_settings_);
178 settings_update_pending_ = false;
181 void InputControllerEvdev::UpdateCapsLockLed() {
182 if (!input_device_factory_)
183 return;
184 bool caps_lock_state = IsCapsLockEnabled();
185 if (caps_lock_state != caps_lock_led_state_)
186 input_device_factory_->SetCapsLockLed(caps_lock_state);
187 caps_lock_led_state_ = caps_lock_state;
190 } // namespace ui