OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/events/ozone/evdev/input_controller_evdev.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <linux/input.h> |
| 9 |
| 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" |
| 14 |
| 15 namespace ui { |
| 16 |
| 17 InputControllerEvdev::InputControllerEvdev(KeyboardEvdev* keyboard, |
| 18 MouseButtonMapEvdev* button_map) |
| 19 : keyboard_(keyboard), button_map_(button_map), weak_ptr_factory_(this) { |
| 20 } |
| 21 |
| 22 InputControllerEvdev::~InputControllerEvdev() { |
| 23 } |
| 24 |
| 25 void InputControllerEvdev::SetInputDeviceFactory( |
| 26 InputDeviceFactoryEvdevProxy* input_device_factory) { |
| 27 input_device_factory_ = input_device_factory; |
| 28 |
| 29 UpdateDeviceSettings(); |
| 30 UpdateCapsLockLed(); |
| 31 } |
| 32 |
| 33 void InputControllerEvdev::set_has_mouse(bool has_mouse) { |
| 34 has_mouse_ = has_mouse; |
| 35 } |
| 36 |
| 37 void InputControllerEvdev::set_has_touchpad(bool has_touchpad) { |
| 38 has_touchpad_ = has_touchpad; |
| 39 } |
| 40 |
| 41 void InputControllerEvdev::SetInputDevicesEnabled(bool enabled) { |
| 42 input_device_settings_.enable_devices = enabled; |
| 43 ScheduleUpdateDeviceSettings(); |
| 44 } |
| 45 |
| 46 bool InputControllerEvdev::HasMouse() { |
| 47 return has_mouse_; |
| 48 } |
| 49 |
| 50 bool InputControllerEvdev::HasTouchpad() { |
| 51 return has_touchpad_; |
| 52 } |
| 53 |
| 54 bool InputControllerEvdev::IsCapsLockEnabled() { |
| 55 return keyboard_->IsCapsLockEnabled(); |
| 56 } |
| 57 |
| 58 void InputControllerEvdev::SetCapsLockEnabled(bool enabled) { |
| 59 keyboard_->SetCapsLockEnabled(enabled); |
| 60 UpdateCapsLockLed(); |
| 61 } |
| 62 |
| 63 void InputControllerEvdev::SetNumLockEnabled(bool enabled) { |
| 64 // No num lock on Chrome OS. |
| 65 } |
| 66 |
| 67 bool InputControllerEvdev::IsAutoRepeatEnabled() { |
| 68 return keyboard_->IsAutoRepeatEnabled(); |
| 69 } |
| 70 |
| 71 void InputControllerEvdev::SetAutoRepeatEnabled(bool enabled) { |
| 72 keyboard_->SetAutoRepeatEnabled(enabled); |
| 73 } |
| 74 |
| 75 void InputControllerEvdev::SetAutoRepeatRate(const base::TimeDelta& delay, |
| 76 const base::TimeDelta& interval) { |
| 77 keyboard_->SetAutoRepeatRate(delay, interval); |
| 78 } |
| 79 |
| 80 void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta* delay, |
| 81 base::TimeDelta* interval) { |
| 82 keyboard_->GetAutoRepeatRate(delay, interval); |
| 83 } |
| 84 |
| 85 void InputControllerEvdev::SetInternalTouchpadEnabled(bool enabled) { |
| 86 input_device_settings_.enable_internal_touchpad = enabled; |
| 87 ScheduleUpdateDeviceSettings(); |
| 88 } |
| 89 |
| 90 void InputControllerEvdev::SetInternalKeyboardFilter( |
| 91 bool enable_filter, |
| 92 std::vector<DomCode> allowed_keys) { |
| 93 input_device_settings_.enable_internal_keyboard_filter = enable_filter; |
| 94 input_device_settings_.internal_keyboard_allowed_keys = allowed_keys; |
| 95 ScheduleUpdateDeviceSettings(); |
| 96 } |
| 97 |
| 98 void InputControllerEvdev::SetTouchpadSensitivity(int value) { |
| 99 input_device_settings_.touchpad_sensitivity = value; |
| 100 ScheduleUpdateDeviceSettings(); |
| 101 } |
| 102 |
| 103 void InputControllerEvdev::SetTapToClick(bool enabled) { |
| 104 input_device_settings_.tap_to_click_enabled = enabled; |
| 105 ScheduleUpdateDeviceSettings(); |
| 106 } |
| 107 |
| 108 void InputControllerEvdev::SetThreeFingerClick(bool enabled) { |
| 109 input_device_settings_.three_finger_click_enabled = enabled; |
| 110 ScheduleUpdateDeviceSettings(); |
| 111 } |
| 112 |
| 113 void InputControllerEvdev::SetTapDragging(bool enabled) { |
| 114 input_device_settings_.tap_dragging_enabled = enabled; |
| 115 ScheduleUpdateDeviceSettings(); |
| 116 } |
| 117 |
| 118 void InputControllerEvdev::SetNaturalScroll(bool enabled) { |
| 119 input_device_settings_.natural_scroll_enabled = enabled; |
| 120 ScheduleUpdateDeviceSettings(); |
| 121 } |
| 122 |
| 123 void InputControllerEvdev::SetMouseSensitivity(int value) { |
| 124 input_device_settings_.mouse_sensitivity = value; |
| 125 ScheduleUpdateDeviceSettings(); |
| 126 } |
| 127 |
| 128 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { |
| 129 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); |
| 130 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); |
| 131 } |
| 132 |
| 133 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
| 134 input_device_settings_.tap_to_click_paused = state; |
| 135 ScheduleUpdateDeviceSettings(); |
| 136 } |
| 137 |
| 138 void InputControllerEvdev::GetTouchDeviceStatus( |
| 139 const GetTouchDeviceStatusReply& reply) { |
| 140 if (input_device_factory_) |
| 141 input_device_factory_->GetTouchDeviceStatus(reply); |
| 142 else |
| 143 reply.Run(make_scoped_ptr(new std::string)); |
| 144 } |
| 145 |
| 146 void InputControllerEvdev::GetTouchEventLog( |
| 147 const base::FilePath& out_dir, |
| 148 const GetTouchEventLogReply& reply) { |
| 149 if (input_device_factory_) |
| 150 input_device_factory_->GetTouchEventLog(out_dir, reply); |
| 151 else |
| 152 reply.Run(make_scoped_ptr(new std::vector<base::FilePath>)); |
| 153 } |
| 154 |
| 155 void InputControllerEvdev::ScheduleUpdateDeviceSettings() { |
| 156 if (!input_device_factory_ || settings_update_pending_) |
| 157 return; |
| 158 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 159 FROM_HERE, base::Bind(&InputControllerEvdev::UpdateDeviceSettings, |
| 160 weak_ptr_factory_.GetWeakPtr())); |
| 161 settings_update_pending_ = true; |
| 162 } |
| 163 |
| 164 void InputControllerEvdev::UpdateDeviceSettings() { |
| 165 input_device_factory_->UpdateInputDeviceSettings(input_device_settings_); |
| 166 settings_update_pending_ = false; |
| 167 } |
| 168 |
| 169 void InputControllerEvdev::UpdateCapsLockLed() { |
| 170 if (!input_device_factory_) |
| 171 return; |
| 172 bool caps_lock_state = IsCapsLockEnabled(); |
| 173 if (caps_lock_state != caps_lock_led_state_) |
| 174 input_device_factory_->SetCapsLockLed(caps_lock_state); |
| 175 caps_lock_led_state_ = caps_lock_state; |
| 176 } |
| 177 |
| 178 } // namespace ui |
OLD | NEW |