Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: ui/events/ozone/evdev/input_injector_evdev.cc

Issue 882503002: [PATCH 9.2/11] ozone: evdev: Use DeviceEventDispatcherEvdev from InputInjectorEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/event.h" 5 #include "ui/events/event.h"
6 #include "ui/events/keycodes/dom3/dom_code.h" 6 #include "ui/events/keycodes/dom3/dom_code.h"
7 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" 7 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
8 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
8 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" 9 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
9 #include "ui/events/ozone/evdev/input_injector_evdev.h" 10 #include "ui/events/ozone/evdev/input_injector_evdev.h"
10 #include "ui/events/ozone/evdev/keyboard_evdev.h" 11 #include "ui/events/ozone/evdev/keyboard_evdev.h"
11 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" 12 #include "ui/events/ozone/evdev/keyboard_util_evdev.h"
12 13
13 namespace ui { 14 namespace ui {
14 15
15 InputInjectorEvdev::InputInjectorEvdev(EventModifiersEvdev* modifiers, 16 namespace {
16 CursorDelegateEvdev* cursor, 17
17 KeyboardEvdev* keyboard, 18 const int kDeviceIdForInjection = -1;
18 const EventDispatchCallback& callback) 19
19 : modifiers_(modifiers), 20 } // namespace
20 cursor_(cursor), 21
21 keyboard_(keyboard), 22 InputInjectorEvdev::InputInjectorEvdev(
22 callback_(callback) { 23 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher,
23 DCHECK(modifiers_); 24 CursorDelegateEvdev* cursor)
24 DCHECK(cursor_); 25 : cursor_(cursor), dispatcher_(dispatcher.Pass()) {
25 DCHECK(keyboard_);
26 } 26 }
27 27
28 InputInjectorEvdev::~InputInjectorEvdev() { 28 InputInjectorEvdev::~InputInjectorEvdev() {
29 } 29 }
30 30
31 void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) { 31 void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) {
32 int changed_button = 0; 32 unsigned int code;
33 33 switch (button) {
34 switch(button) {
35 case EF_LEFT_MOUSE_BUTTON: 34 case EF_LEFT_MOUSE_BUTTON:
36 changed_button = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; 35 code = BTN_LEFT;
37 break; 36 break;
38 case EF_RIGHT_MOUSE_BUTTON: 37 case EF_RIGHT_MOUSE_BUTTON:
39 changed_button = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; 38 code = BTN_RIGHT;
40 break; 39 break;
41 case EF_MIDDLE_MOUSE_BUTTON: 40 case EF_MIDDLE_MOUSE_BUTTON:
42 changed_button = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; 41 code = BTN_MIDDLE;
43 default: 42 default:
44 LOG(WARNING) << "Invalid flag: " << button << " for the button parameter"; 43 LOG(WARNING) << "Invalid flag: " << button << " for the button parameter";
45 return; 44 return;
46 } 45 }
47 46
48 modifiers_->UpdateModifier(changed_button, down); 47 dispatcher_->DispatchMouseButtonEvent(
49 int changed_button_flag = 48 MouseButtonEventParams(kDeviceIdForInjection, cursor_->GetLocation(),
50 EventModifiersEvdev::GetEventFlagFromModifier(changed_button); 49 code, down, false /* allow_remap */));
51 callback_.Run(make_scoped_ptr(new MouseEvent(
52 (down) ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED,
53 cursor_->GetLocation(),
54 cursor_->GetLocation(),
55 modifiers_->GetModifierFlags() | changed_button_flag,
56 changed_button_flag)));
57 } 50 }
58 51
59 void InputInjectorEvdev::InjectMouseWheel(int delta_x, int delta_y) { 52 void InputInjectorEvdev::InjectMouseWheel(int delta_x, int delta_y) {
60 callback_.Run(make_scoped_ptr(new MouseWheelEvent( 53 dispatcher_->DispatchMouseWheelEvent(
61 gfx::Vector2d(delta_x, delta_y), 54 MouseWheelEventParams(kDeviceIdForInjection, cursor_->GetLocation(),
62 cursor_->GetLocation(), 55 gfx::Vector2d(delta_x, delta_y)));
63 cursor_->GetLocation(),
64 modifiers_->GetModifierFlags(),
65 0 /* changed_button_flags */)));
66 } 56 }
67 57
68 void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) { 58 void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) {
69 if (cursor_) { 59 if (!cursor_)
70 cursor_->MoveCursorTo(location); 60 return;
71 callback_.Run(make_scoped_ptr(new MouseEvent( 61
72 ET_MOUSE_MOVED, 62 cursor_->MoveCursorTo(location);
73 cursor_->GetLocation(), 63
74 cursor_->GetLocation(), 64 dispatcher_->DispatchMouseMoveEvent(
75 modifiers_->GetModifierFlags(), 65 MouseMoveEventParams(kDeviceIdForInjection, cursor_->GetLocation()));
76 0 /* changed_button_flags */)));
77 }
78 } 66 }
79 67
80 void InputInjectorEvdev::InjectKeyPress(DomCode physical_key, bool down) { 68 void InputInjectorEvdev::InjectKeyPress(DomCode physical_key, bool down) {
81 if (physical_key == DomCode::NONE) { 69 if (physical_key == DomCode::NONE) {
82 return; 70 return;
83 } 71 }
84 72
85 int native_keycode = KeycodeConverter::DomCodeToNativeKeycode(physical_key); 73 int native_keycode = KeycodeConverter::DomCodeToNativeKeycode(physical_key);
86 int evdev_code = NativeCodeToEvdevCode(native_keycode); 74 int evdev_code = NativeCodeToEvdevCode(native_keycode);
87 keyboard_->OnKeyChange(evdev_code, down); 75
76 dispatcher_->DispatchKeyEvent(
77 KeyEventParams(kDeviceIdForInjection, evdev_code, down));
88 } 78 }
89 79
90 } // namespace ui 80 } // namespace ui
91 81
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/input_injector_evdev.h ('k') | ui/events/ozone/evdev/input_injector_evdev_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698