| 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 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 14 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
| 15 #include "ui/events/ozone/evdev/keyboard_evdev.h" |
| 15 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" | 16 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
| 16 | 17 |
| 17 #if defined(USE_EVDEV_GESTURES) | 18 #if defined(USE_EVDEV_GESTURES) |
| 18 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 19 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 namespace ui { | 22 namespace ui { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); | 78 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); |
| 78 break; | 79 break; |
| 79 default: | 80 default: |
| 80 NOTREACHED(); | 81 NOTREACHED(); |
| 81 break; | 82 break; |
| 82 } | 83 } |
| 83 return std::string(); | 84 return std::string(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 // Dump touch device property values to a string. | 87 // Dump touch device property values to a string. |
| 87 void DumpTouchDeviceStatus(EventFactoryEvdev* event_factory, | 88 void DumpTouchDeviceStatus(InputDeviceFactoryEvdev* event_factory, |
| 88 GesturePropertyProvider* provider, | 89 GesturePropertyProvider* provider, |
| 89 std::string* status) { | 90 std::string* status) { |
| 90 // We use DT_ALL since we want gesture property values for all devices that | 91 // We use DT_ALL since we want gesture property values for all devices that |
| 91 // run with the gesture library, not just mice or touchpads. | 92 // run with the gesture library, not just mice or touchpads. |
| 92 std::vector<int> ids; | 93 std::vector<int> ids; |
| 93 event_factory->GetDeviceIdsByType(DT_ALL, &ids); | 94 event_factory->GetDeviceIdsByType(DT_ALL, &ids); |
| 94 | 95 |
| 95 // Dump the property names and values for each device. | 96 // Dump the property names and values for each device. |
| 96 for (size_t i = 0; i < ids.size(); ++i) { | 97 for (size_t i = 0; i < ids.size(); ++i) { |
| 97 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]); | 98 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 110 status->append("\t" + DumpGesturePropertyValue(property) + '\n'); | 111 status->append("\t" + DumpGesturePropertyValue(property) + '\n'); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 } | 114 } |
| 114 | 115 |
| 115 #endif | 116 #endif |
| 116 | 117 |
| 117 } // namespace | 118 } // namespace |
| 118 | 119 |
| 119 InputControllerEvdev::InputControllerEvdev( | 120 InputControllerEvdev::InputControllerEvdev( |
| 120 EventFactoryEvdev* event_factory, | |
| 121 KeyboardEvdev* keyboard, | 121 KeyboardEvdev* keyboard, |
| 122 MouseButtonMapEvdev* button_map | 122 MouseButtonMapEvdev* button_map |
| 123 #if defined(USE_EVDEV_GESTURES) | 123 #if defined(USE_EVDEV_GESTURES) |
| 124 , | 124 , |
| 125 GesturePropertyProvider* gesture_property_provider | 125 GesturePropertyProvider* gesture_property_provider |
| 126 #endif | 126 #endif |
| 127 ) | 127 ) |
| 128 : event_factory_(event_factory), | 128 : input_device_factory_(nullptr), |
| 129 keyboard_(keyboard), | 129 keyboard_(keyboard), |
| 130 button_map_(button_map) | 130 button_map_(button_map) |
| 131 #if defined(USE_EVDEV_GESTURES) | 131 #if defined(USE_EVDEV_GESTURES) |
| 132 , | 132 , |
| 133 gesture_property_provider_(gesture_property_provider) | 133 gesture_property_provider_(gesture_property_provider) |
| 134 #endif | 134 #endif |
| 135 { | 135 { |
| 136 } | 136 } |
| 137 | 137 |
| 138 InputControllerEvdev::~InputControllerEvdev() { | 138 InputControllerEvdev::~InputControllerEvdev() { |
| 139 } | 139 } |
| 140 | 140 |
| 141 void InputControllerEvdev::SetInputDeviceFactory( |
| 142 InputDeviceFactoryEvdev* input_device_factory) { |
| 143 input_device_factory_ = input_device_factory; |
| 144 } |
| 145 |
| 141 bool InputControllerEvdev::HasMouse() { | 146 bool InputControllerEvdev::HasMouse() { |
| 142 return event_factory_->GetDeviceIdsByType(DT_MOUSE, NULL); | 147 if (!input_device_factory_) |
| 148 return false; |
| 149 return input_device_factory_->GetDeviceIdsByType(DT_MOUSE, NULL); |
| 143 } | 150 } |
| 144 | 151 |
| 145 bool InputControllerEvdev::HasTouchpad() { | 152 bool InputControllerEvdev::HasTouchpad() { |
| 146 return event_factory_->GetDeviceIdsByType(DT_TOUCHPAD, NULL); | 153 if (!input_device_factory_) |
| 154 return false; |
| 155 return input_device_factory_->GetDeviceIdsByType(DT_TOUCHPAD, NULL); |
| 147 } | 156 } |
| 148 | 157 |
| 149 bool InputControllerEvdev::IsCapsLockEnabled() { | 158 bool InputControllerEvdev::IsCapsLockEnabled() { |
| 150 return keyboard_->IsCapsLockEnabled(); | 159 return keyboard_->IsCapsLockEnabled(); |
| 151 } | 160 } |
| 152 | 161 |
| 153 void InputControllerEvdev::SetCapsLockEnabled(bool enabled) { | 162 void InputControllerEvdev::SetCapsLockEnabled(bool enabled) { |
| 154 keyboard_->SetCapsLockEnabled(enabled); | 163 keyboard_->SetCapsLockEnabled(enabled); |
| 155 } | 164 } |
| 156 | 165 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 170 const base::TimeDelta& interval) { | 179 const base::TimeDelta& interval) { |
| 171 keyboard_->SetAutoRepeatRate(delay, interval); | 180 keyboard_->SetAutoRepeatRate(delay, interval); |
| 172 } | 181 } |
| 173 | 182 |
| 174 void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta* delay, | 183 void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta* delay, |
| 175 base::TimeDelta* interval) { | 184 base::TimeDelta* interval) { |
| 176 keyboard_->GetAutoRepeatRate(delay, interval); | 185 keyboard_->GetAutoRepeatRate(delay, interval); |
| 177 } | 186 } |
| 178 | 187 |
| 179 void InputControllerEvdev::DisableInternalTouchpad() { | 188 void InputControllerEvdev::DisableInternalTouchpad() { |
| 180 event_factory_->DisableInternalTouchpad(); | 189 if (input_device_factory_) |
| 190 input_device_factory_->DisableInternalTouchpad(); |
| 181 } | 191 } |
| 182 | 192 |
| 183 void InputControllerEvdev::EnableInternalTouchpad() { | 193 void InputControllerEvdev::EnableInternalTouchpad() { |
| 184 event_factory_->EnableInternalTouchpad(); | 194 if (input_device_factory_) |
| 195 input_device_factory_->EnableInternalTouchpad(); |
| 185 } | 196 } |
| 186 | 197 |
| 187 void InputControllerEvdev::DisableInternalKeyboardExceptKeys( | 198 void InputControllerEvdev::DisableInternalKeyboardExceptKeys( |
| 188 scoped_ptr<std::set<DomCode>> excepted_keys) { | 199 scoped_ptr<std::set<DomCode>> excepted_keys) { |
| 189 event_factory_->DisableInternalKeyboardExceptKeys(excepted_keys.Pass()); | 200 if (input_device_factory_) { |
| 201 input_device_factory_->DisableInternalKeyboardExceptKeys( |
| 202 excepted_keys.Pass()); |
| 203 } |
| 190 } | 204 } |
| 191 | 205 |
| 192 void InputControllerEvdev::EnableInternalKeyboard() { | 206 void InputControllerEvdev::EnableInternalKeyboard() { |
| 193 event_factory_->EnableInternalKeyboard(); | 207 if (input_device_factory_) |
| 208 input_device_factory_->EnableInternalKeyboard(); |
| 194 } | 209 } |
| 195 | 210 |
| 196 void InputControllerEvdev::SetIntPropertyForOneType(const EventDeviceType type, | 211 void InputControllerEvdev::SetIntPropertyForOneType(const EventDeviceType type, |
| 197 const std::string& name, | 212 const std::string& name, |
| 198 int value) { | 213 int value) { |
| 214 if (!input_device_factory_) |
| 215 return; |
| 199 #if defined(USE_EVDEV_GESTURES) | 216 #if defined(USE_EVDEV_GESTURES) |
| 200 std::vector<int> ids; | 217 std::vector<int> ids; |
| 201 event_factory_->GetDeviceIdsByType(type, &ids); | 218 input_device_factory_->GetDeviceIdsByType(type, &ids); |
| 202 for (size_t i = 0; i < ids.size(); ++i) { | 219 for (size_t i = 0; i < ids.size(); ++i) { |
| 203 SetGestureIntProperty(gesture_property_provider_, ids[i], name, value); | 220 SetGestureIntProperty(gesture_property_provider_, ids[i], name, value); |
| 204 } | 221 } |
| 205 #endif | 222 #endif |
| 206 // In the future, we may add property setting codes for other non-gesture | 223 // In the future, we may add property setting codes for other non-gesture |
| 207 // devices. One example would be keyboard settings. | 224 // devices. One example would be keyboard settings. |
| 208 // TODO(sheckylin): See http://crbug.com/398518 for example. | 225 // TODO(sheckylin): See http://crbug.com/398518 for example. |
| 209 } | 226 } |
| 210 | 227 |
| 211 void InputControllerEvdev::SetBoolPropertyForOneType(const EventDeviceType type, | 228 void InputControllerEvdev::SetBoolPropertyForOneType(const EventDeviceType type, |
| 212 const std::string& name, | 229 const std::string& name, |
| 213 bool value) { | 230 bool value) { |
| 231 if (!input_device_factory_) |
| 232 return; |
| 214 #if defined(USE_EVDEV_GESTURES) | 233 #if defined(USE_EVDEV_GESTURES) |
| 215 std::vector<int> ids; | 234 std::vector<int> ids; |
| 216 event_factory_->GetDeviceIdsByType(type, &ids); | 235 input_device_factory_->GetDeviceIdsByType(type, &ids); |
| 217 for (size_t i = 0; i < ids.size(); ++i) { | 236 for (size_t i = 0; i < ids.size(); ++i) { |
| 218 SetGestureBoolProperty(gesture_property_provider_, ids[i], name, value); | 237 SetGestureBoolProperty(gesture_property_provider_, ids[i], name, value); |
| 219 } | 238 } |
| 220 #endif | 239 #endif |
| 221 } | 240 } |
| 222 | 241 |
| 223 void InputControllerEvdev::SetTouchpadSensitivity(int value) { | 242 void InputControllerEvdev::SetTouchpadSensitivity(int value) { |
| 224 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value); | 243 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value); |
| 225 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value); | 244 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value); |
| 226 } | 245 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 255 void InputControllerEvdev::SetTapToClickPaused(bool state) { | 274 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
| 256 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 275 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
| 257 } | 276 } |
| 258 | 277 |
| 259 void InputControllerEvdev::GetTouchDeviceStatus( | 278 void InputControllerEvdev::GetTouchDeviceStatus( |
| 260 const GetTouchDeviceStatusReply& reply) { | 279 const GetTouchDeviceStatusReply& reply) { |
| 261 scoped_ptr<std::string> status(new std::string); | 280 scoped_ptr<std::string> status(new std::string); |
| 262 #if defined(USE_EVDEV_GESTURES) | 281 #if defined(USE_EVDEV_GESTURES) |
| 263 std::string* status_ptr = status.get(); | 282 std::string* status_ptr = status.get(); |
| 264 base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply( | 283 base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply( |
| 265 FROM_HERE, base::Bind(&DumpTouchDeviceStatus, event_factory_, | 284 FROM_HERE, base::Bind(&DumpTouchDeviceStatus, input_device_factory_, |
| 266 gesture_property_provider_, status_ptr), | 285 gesture_property_provider_, status_ptr), |
| 267 base::Bind(reply, base::Passed(&status))); | 286 base::Bind(reply, base::Passed(&status))); |
| 268 #else | 287 #else |
| 269 reply.Run(status.Pass()); | 288 reply.Run(status.Pass()); |
| 270 #endif | 289 #endif |
| 271 } | 290 } |
| 272 | 291 |
| 273 } // namespace ui | 292 } // namespace ui |
| OLD | NEW |