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 "ui/events/ozone/evdev/input_controller_evdev.h" | 5 #include "ui/events/ozone/evdev/input_controller_evdev.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 | 9 |
| 10 #include "base/thread_task_runner_handle.h" |
10 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h" | 11 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h" |
11 #include "ui/events/ozone/evdev/keyboard_evdev.h" | 12 #include "ui/events/ozone/evdev/keyboard_evdev.h" |
12 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" | 13 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
13 | 14 |
14 namespace ui { | 15 namespace ui { |
15 | 16 |
16 InputControllerEvdev::InputControllerEvdev(KeyboardEvdev* keyboard, | 17 InputControllerEvdev::InputControllerEvdev(KeyboardEvdev* keyboard, |
17 MouseButtonMapEvdev* button_map) | 18 MouseButtonMapEvdev* button_map) |
18 : input_device_factory_(nullptr), | 19 : settings_update_pending_(false), |
| 20 input_device_factory_(nullptr), |
19 keyboard_(keyboard), | 21 keyboard_(keyboard), |
20 button_map_(button_map), | 22 button_map_(button_map), |
21 has_mouse_(false), | 23 has_mouse_(false), |
22 has_touchpad_(false) { | 24 has_touchpad_(false), |
| 25 weak_ptr_factory_(this) { |
23 } | 26 } |
24 | 27 |
25 InputControllerEvdev::~InputControllerEvdev() { | 28 InputControllerEvdev::~InputControllerEvdev() { |
26 } | 29 } |
27 | 30 |
28 void InputControllerEvdev::SetInputDeviceFactory( | 31 void InputControllerEvdev::SetInputDeviceFactory( |
29 InputDeviceFactoryEvdevProxy* input_device_factory) { | 32 InputDeviceFactoryEvdevProxy* input_device_factory) { |
30 input_device_factory_ = input_device_factory; | 33 input_device_factory_ = input_device_factory; |
| 34 |
| 35 UpdateDeviceSettings(); |
31 } | 36 } |
32 | 37 |
33 void InputControllerEvdev::set_has_mouse(bool has_mouse) { | 38 void InputControllerEvdev::set_has_mouse(bool has_mouse) { |
34 has_mouse_ = has_mouse; | 39 has_mouse_ = has_mouse; |
35 } | 40 } |
36 | 41 |
37 void InputControllerEvdev::set_has_touchpad(bool has_touchpad) { | 42 void InputControllerEvdev::set_has_touchpad(bool has_touchpad) { |
38 has_touchpad_ = has_touchpad; | 43 has_touchpad_ = has_touchpad; |
39 } | 44 } |
40 | 45 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 excepted_keys.Pass()); | 98 excepted_keys.Pass()); |
94 } | 99 } |
95 } | 100 } |
96 | 101 |
97 void InputControllerEvdev::EnableInternalKeyboard() { | 102 void InputControllerEvdev::EnableInternalKeyboard() { |
98 if (input_device_factory_) | 103 if (input_device_factory_) |
99 input_device_factory_->EnableInternalKeyboard(); | 104 input_device_factory_->EnableInternalKeyboard(); |
100 } | 105 } |
101 | 106 |
102 void InputControllerEvdev::SetTouchpadSensitivity(int value) { | 107 void InputControllerEvdev::SetTouchpadSensitivity(int value) { |
103 if (input_device_factory_) | 108 input_device_settings_.touchpad_sensitivity = value; |
104 input_device_factory_->SetTouchpadSensitivity(value); | 109 ScheduleUpdateDeviceSettings(); |
105 } | 110 } |
106 | 111 |
107 void InputControllerEvdev::SetTapToClick(bool enabled) { | 112 void InputControllerEvdev::SetTapToClick(bool enabled) { |
108 if (input_device_factory_) | 113 input_device_settings_.tap_to_click_enabled = enabled; |
109 input_device_factory_->SetTapToClick(enabled); | 114 ScheduleUpdateDeviceSettings(); |
110 } | 115 } |
111 | 116 |
112 void InputControllerEvdev::SetThreeFingerClick(bool enabled) { | 117 void InputControllerEvdev::SetThreeFingerClick(bool enabled) { |
113 if (input_device_factory_) | 118 input_device_settings_.three_finger_click_enabled = enabled; |
114 input_device_factory_->SetThreeFingerClick(enabled); | 119 ScheduleUpdateDeviceSettings(); |
115 } | 120 } |
116 | 121 |
117 void InputControllerEvdev::SetTapDragging(bool enabled) { | 122 void InputControllerEvdev::SetTapDragging(bool enabled) { |
118 if (input_device_factory_) | 123 input_device_settings_.tap_dragging_enabled = enabled; |
119 input_device_factory_->SetTapDragging(enabled); | 124 ScheduleUpdateDeviceSettings(); |
120 } | 125 } |
121 | 126 |
122 void InputControllerEvdev::SetNaturalScroll(bool enabled) { | 127 void InputControllerEvdev::SetNaturalScroll(bool enabled) { |
123 if (input_device_factory_) | 128 input_device_settings_.natural_scroll_enabled = enabled; |
124 input_device_factory_->SetNaturalScroll(enabled); | 129 ScheduleUpdateDeviceSettings(); |
125 } | 130 } |
126 | 131 |
127 void InputControllerEvdev::SetMouseSensitivity(int value) { | 132 void InputControllerEvdev::SetMouseSensitivity(int value) { |
128 if (input_device_factory_) | 133 input_device_settings_.mouse_sensitivity = value; |
129 input_device_factory_->SetMouseSensitivity(value); | 134 ScheduleUpdateDeviceSettings(); |
130 } | 135 } |
131 | 136 |
132 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { | 137 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { |
133 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); | 138 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); |
134 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); | 139 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); |
135 } | 140 } |
136 | 141 |
137 void InputControllerEvdev::SetTapToClickPaused(bool state) { | 142 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
138 if (input_device_factory_) | 143 input_device_settings_.tap_to_click_paused = state; |
139 input_device_factory_->SetTapToClickPaused(state); | 144 ScheduleUpdateDeviceSettings(); |
140 } | 145 } |
141 | 146 |
142 void InputControllerEvdev::GetTouchDeviceStatus( | 147 void InputControllerEvdev::GetTouchDeviceStatus( |
143 const GetTouchDeviceStatusReply& reply) { | 148 const GetTouchDeviceStatusReply& reply) { |
144 if (input_device_factory_) | 149 if (input_device_factory_) |
145 input_device_factory_->GetTouchDeviceStatus(reply); | 150 input_device_factory_->GetTouchDeviceStatus(reply); |
146 else | 151 else |
147 reply.Run(make_scoped_ptr(new std::string)); | 152 reply.Run(make_scoped_ptr(new std::string)); |
148 } | 153 } |
149 | 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 |
150 } // namespace ui | 169 } // namespace ui |
OLD | NEW |