| 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/event_factory_evdev.h" | 5 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; | 103 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 } // namespace | 106 } // namespace |
| 107 | 107 |
| 108 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, | 108 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 109 DeviceManager* device_manager, | 109 DeviceManager* device_manager, |
| 110 KeyboardLayoutEngine* keyboard_layout) | 110 KeyboardLayoutEngine* keyboard_layout) |
| 111 : last_device_id_(0), | 111 : last_device_id_(0), |
| 112 device_manager_(device_manager), | 112 device_manager_(device_manager), |
| 113 dispatch_callback_( | 113 keyboard_(&modifiers_, |
| 114 base::Bind(&EventFactoryEvdev::PostUiEvent, base::Unretained(this))), | 114 keyboard_layout, |
| 115 keyboard_(&modifiers_, keyboard_layout, dispatch_callback_), | 115 base::Bind(&EventFactoryEvdev::DispatchUiEvent, |
| 116 base::Unretained(this))), |
| 116 cursor_(cursor), | 117 cursor_(cursor), |
| 117 input_controller_(&keyboard_, &button_map_), | 118 input_controller_(&keyboard_, &button_map_), |
| 118 initialized_(false), | 119 initialized_(false), |
| 119 weak_ptr_factory_(this) { | 120 weak_ptr_factory_(this) { |
| 120 DCHECK(device_manager_); | 121 DCHECK(device_manager_); |
| 121 } | 122 } |
| 122 | 123 |
| 123 EventFactoryEvdev::~EventFactoryEvdev() { | 124 EventFactoryEvdev::~EventFactoryEvdev() { |
| 124 } | 125 } |
| 125 | 126 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 152 weak_ptr_factory_.GetWeakPtr())); | 153 weak_ptr_factory_.GetWeakPtr())); |
| 153 return make_scoped_ptr(new InputInjectorEvdev(dispatcher.Pass(), cursor_)); | 154 return make_scoped_ptr(new InputInjectorEvdev(dispatcher.Pass(), cursor_)); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { | 157 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { |
| 157 keyboard_.OnKeyChange(params.code, params.down); | 158 keyboard_.OnKeyChange(params.code, params.down); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void EventFactoryEvdev::DispatchMouseMoveEvent( | 161 void EventFactoryEvdev::DispatchMouseMoveEvent( |
| 161 const MouseMoveEventParams& params) { | 162 const MouseMoveEventParams& params) { |
| 162 scoped_ptr<MouseEvent> event(new MouseEvent(ui::ET_MOUSE_MOVED, | 163 MouseEvent event(ui::ET_MOUSE_MOVED, params.location, params.location, |
| 163 params.location, params.location, | 164 modifiers_.GetModifierFlags(), |
| 164 modifiers_.GetModifierFlags(), | 165 /* changed_button_flags */ 0); |
| 165 /* changed_button_flags */ 0)); | 166 event.set_source_device_id(params.device_id); |
| 166 event->set_source_device_id(params.device_id); | 167 DispatchUiEvent(&event); |
| 167 PostUiEvent(event.Pass()); | |
| 168 } | 168 } |
| 169 | 169 |
| 170 void EventFactoryEvdev::DispatchMouseButtonEvent( | 170 void EventFactoryEvdev::DispatchMouseButtonEvent( |
| 171 const MouseButtonEventParams& params) { | 171 const MouseButtonEventParams& params) { |
| 172 // Mouse buttons can be remapped, touchpad taps & clicks cannot. | 172 // Mouse buttons can be remapped, touchpad taps & clicks cannot. |
| 173 unsigned int button = params.button; | 173 unsigned int button = params.button; |
| 174 if (params.allow_remap) | 174 if (params.allow_remap) |
| 175 button = button_map_.GetMappedButton(button); | 175 button = button_map_.GetMappedButton(button); |
| 176 | 176 |
| 177 int modifier = EVDEV_MODIFIER_NONE; | 177 int modifier = EVDEV_MODIFIER_NONE; |
| 178 switch (button) { | 178 switch (button) { |
| 179 case BTN_LEFT: | 179 case BTN_LEFT: |
| 180 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; | 180 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; |
| 181 break; | 181 break; |
| 182 case BTN_RIGHT: | 182 case BTN_RIGHT: |
| 183 modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | 183 modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; |
| 184 break; | 184 break; |
| 185 case BTN_MIDDLE: | 185 case BTN_MIDDLE: |
| 186 modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | 186 modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; |
| 187 break; | 187 break; |
| 188 default: | 188 default: |
| 189 return; | 189 return; |
| 190 } | 190 } |
| 191 | 191 |
| 192 int flag = modifiers_.GetEventFlagFromModifier(modifier); | 192 int flag = modifiers_.GetEventFlagFromModifier(modifier); |
| 193 modifiers_.UpdateModifier(modifier, params.down); | 193 modifiers_.UpdateModifier(modifier, params.down); |
| 194 | 194 |
| 195 scoped_ptr<MouseEvent> event(new MouseEvent( | 195 MouseEvent event(params.down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED, |
| 196 params.down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED, | 196 params.location, params.location, |
| 197 params.location, params.location, modifiers_.GetModifierFlags() | flag, | 197 modifiers_.GetModifierFlags() | flag, |
| 198 /* changed_button_flags */ flag)); | 198 /* changed_button_flags */ flag); |
| 199 event->set_source_device_id(params.device_id); | 199 event.set_source_device_id(params.device_id); |
| 200 PostUiEvent(event.Pass()); | 200 DispatchUiEvent(&event); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void EventFactoryEvdev::DispatchMouseWheelEvent( | 203 void EventFactoryEvdev::DispatchMouseWheelEvent( |
| 204 const MouseWheelEventParams& params) { | 204 const MouseWheelEventParams& params) { |
| 205 scoped_ptr<MouseWheelEvent> event(new MouseWheelEvent( | 205 MouseWheelEvent event(params.delta, params.location, params.location, |
| 206 params.delta, params.location, params.location, | 206 modifiers_.GetModifierFlags(), |
| 207 modifiers_.GetModifierFlags(), 0 /* changed_button_flags */)); | 207 0 /* changed_button_flags */); |
| 208 event->set_source_device_id(params.device_id); | 208 event.set_source_device_id(params.device_id); |
| 209 PostUiEvent(event.Pass()); | 209 DispatchUiEvent(&event); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void EventFactoryEvdev::DispatchScrollEvent(const ScrollEventParams& params) { | 212 void EventFactoryEvdev::DispatchScrollEvent(const ScrollEventParams& params) { |
| 213 scoped_ptr<ScrollEvent> event(new ScrollEvent( | 213 ScrollEvent event(params.type, params.location, params.timestamp, |
| 214 params.type, params.location, params.timestamp, | 214 modifiers_.GetModifierFlags(), params.delta.x(), |
| 215 modifiers_.GetModifierFlags(), params.delta.x(), params.delta.y(), | 215 params.delta.y(), params.ordinal_delta.x(), |
| 216 params.ordinal_delta.x(), params.ordinal_delta.y(), params.finger_count)); | 216 params.ordinal_delta.y(), params.finger_count); |
| 217 event->set_source_device_id(params.device_id); | 217 event.set_source_device_id(params.device_id); |
| 218 PostUiEvent(event.Pass()); | 218 DispatchUiEvent(&event); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) { | 221 void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) { |
| 222 float x = params.location.x(); | 222 float x = params.location.x(); |
| 223 float y = params.location.y(); | 223 float y = params.location.y(); |
| 224 double radius_x = params.radii.x(); | 224 double radius_x = params.radii.x(); |
| 225 double radius_y = params.radii.y(); | 225 double radius_y = params.radii.y(); |
| 226 | 226 |
| 227 // Transform the event to align touches to the image based on display mode. | 227 // Transform the event to align touches to the image based on display mode. |
| 228 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x, | 228 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x, |
| 229 &y); | 229 &y); |
| 230 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, | 230 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, |
| 231 &radius_x); | 231 &radius_x); |
| 232 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, | 232 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, |
| 233 &radius_y); | 233 &radius_y); |
| 234 | 234 |
| 235 scoped_ptr<TouchEvent> touch_event(new TouchEvent( | 235 TouchEvent touch_event(params.type, gfx::PointF(x, y), |
| 236 params.type, gfx::PointF(x, y), modifiers_.GetModifierFlags(), | 236 modifiers_.GetModifierFlags(), params.touch_id, |
| 237 params.touch_id, params.timestamp, radius_x, radius_y, | 237 params.timestamp, radius_x, radius_y, |
| 238 /* angle */ 0., params.pressure)); | 238 /* angle */ 0.f, params.pressure); |
| 239 touch_event->set_source_device_id(params.device_id); | 239 touch_event.set_source_device_id(params.device_id); |
| 240 PostUiEvent(touch_event.Pass()); | 240 DispatchUiEvent(&touch_event); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { | 243 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
| 244 base::ThreadTaskRunnerHandle::Get()->PostTask( | 244 // DispatchEvent takes PlatformEvent which is void*. This function |
| 245 FROM_HERE, | 245 // wraps it with the real type. |
| 246 base::Bind(&EventFactoryEvdev::DispatchUiEventTask, | 246 DispatchEvent(event); |
| 247 weak_ptr_factory_.GetWeakPtr(), | |
| 248 base::Passed(&event))); | |
| 249 } | 247 } |
| 250 | 248 |
| 251 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( | 249 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( |
| 252 const std::vector<KeyboardDevice>& devices) { | 250 const std::vector<KeyboardDevice>& devices) { |
| 253 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 251 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 254 observer->OnKeyboardDevicesUpdated(devices); | 252 observer->OnKeyboardDevicesUpdated(devices); |
| 255 } | 253 } |
| 256 | 254 |
| 257 void EventFactoryEvdev::DispatchTouchscreenDevicesUpdated( | 255 void EventFactoryEvdev::DispatchTouchscreenDevicesUpdated( |
| 258 const std::vector<TouchscreenDevice>& devices) { | 256 const std::vector<TouchscreenDevice>& devices) { |
| 259 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 257 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 260 observer->OnTouchscreenDevicesUpdated(devices); | 258 observer->OnTouchscreenDevicesUpdated(devices); |
| 261 } | 259 } |
| 262 | 260 |
| 263 void EventFactoryEvdev::DispatchMouseDevicesUpdated( | 261 void EventFactoryEvdev::DispatchMouseDevicesUpdated( |
| 264 const std::vector<InputDevice>& devices) { | 262 const std::vector<InputDevice>& devices) { |
| 265 // There's no list of mice in DeviceDataManager. | 263 // There's no list of mice in DeviceDataManager. |
| 266 input_controller_.set_has_mouse(devices.size() != 0); | 264 input_controller_.set_has_mouse(devices.size() != 0); |
| 267 } | 265 } |
| 268 | 266 |
| 269 void EventFactoryEvdev::DispatchTouchpadDevicesUpdated( | 267 void EventFactoryEvdev::DispatchTouchpadDevicesUpdated( |
| 270 const std::vector<InputDevice>& devices) { | 268 const std::vector<InputDevice>& devices) { |
| 271 // There's no list of touchpads in DeviceDataManager. | 269 // There's no list of touchpads in DeviceDataManager. |
| 272 input_controller_.set_has_touchpad(devices.size() != 0); | 270 input_controller_.set_has_touchpad(devices.size() != 0); |
| 273 } | 271 } |
| 274 | 272 |
| 275 void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) { | |
| 276 DispatchEvent(event.get()); | |
| 277 } | |
| 278 | 273 |
| 279 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { | 274 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { |
| 280 if (event.device_type() != DeviceEvent::INPUT) | 275 if (event.device_type() != DeviceEvent::INPUT) |
| 281 return; | 276 return; |
| 282 | 277 |
| 283 switch (event.action_type()) { | 278 switch (event.action_type()) { |
| 284 case DeviceEvent::ADD: | 279 case DeviceEvent::ADD: |
| 285 case DeviceEvent::CHANGE: { | 280 case DeviceEvent::CHANGE: { |
| 286 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); | 281 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
| 287 input_device_factory_->AddInputDevice(NextDeviceId(), event.path()); | 282 input_device_factory_->AddInputDevice(NextDeviceId(), event.path()); |
| 288 break; | 283 break; |
| 289 } | 284 } |
| 290 case DeviceEvent::REMOVE: { | 285 case DeviceEvent::REMOVE: { |
| 291 TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value()); | 286 TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value()); |
| 292 input_device_factory_->RemoveInputDevice(event.path()); | 287 input_device_factory_->RemoveInputDevice(event.path()); |
| 293 break; | 288 break; |
| 294 } | 289 } |
| 295 } | 290 } |
| 296 } | 291 } |
| 297 | 292 |
| 298 void EventFactoryEvdev::OnDispatcherListChanged() { | 293 void EventFactoryEvdev::OnDispatcherListChanged() { |
| 299 if (!initialized_) | 294 if (!initialized_) |
| 300 Init(); | 295 Init(); |
| 301 } | 296 } |
| 302 | 297 |
| 303 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, | 298 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, |
| 304 const gfx::PointF& location) { | 299 const gfx::PointF& location) { |
| 305 if (cursor_) { | 300 if (!cursor_) |
| 306 cursor_->MoveCursorTo(widget, location); | 301 return; |
| 307 PostUiEvent(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED, | 302 |
| 308 cursor_->GetLocation(), | 303 cursor_->MoveCursorTo(widget, location); |
| 309 cursor_->GetLocation(), | 304 |
| 310 modifiers_.GetModifierFlags(), | 305 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 311 /* changed_button_flags */ 0))); | 306 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent, |
| 312 } | 307 weak_ptr_factory_.GetWeakPtr(), |
| 308 MouseMoveEventParams(-1 /* device_id */, |
| 309 cursor_->GetLocation()))); |
| 313 } | 310 } |
| 314 | 311 |
| 315 int EventFactoryEvdev::NextDeviceId() { | 312 int EventFactoryEvdev::NextDeviceId() { |
| 316 return ++last_device_id_; | 313 return ++last_device_id_; |
| 317 } | 314 } |
| 318 | 315 |
| 319 } // namespace ui | 316 } // namespace ui |
| OLD | NEW |