OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/events_test_utils_x11.h" | 5 #include "ui/events/test/events_test_utils_x11.h" |
6 | 6 |
7 #include <X11/extensions/XI2.h> | 7 #include <X11/extensions/XI2.h> |
8 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
9 #include <X11/X.h> | 9 #include <X11/X.h> |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // The button release X events for mouse wheels are dropped by Aura. | 64 // The button release X events for mouse wheels are dropped by Aura. |
65 return XI_ButtonPress; | 65 return XI_ButtonPress; |
66 case ui::ET_MOUSE_RELEASED: | 66 case ui::ET_MOUSE_RELEASED: |
67 return XI_ButtonRelease; | 67 return XI_ButtonRelease; |
68 default: | 68 default: |
69 NOTREACHED(); | 69 NOTREACHED(); |
70 return 0; | 70 return 0; |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 // Converts KeyboardCode to XKeyEvent keycode. | |
75 unsigned int XKeyEventKeyCode(ui::KeyboardCode key_code, | |
76 int flags, | |
77 XDisplay* display) { | |
78 // XKeyEvent keycode is hardware keycode which doesn't consider SHIFT state. | |
79 // There are bugs in XKeysymToKeycode that it returns wrong keycode for keysym | |
80 // with SHIFT state. e.g. XK_less should return 59 but returns 94; | |
81 // XK_parenright should return 19 but returns 188; etc. | |
82 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false)); | |
83 } | |
84 | |
85 // Converts Aura event type and flag to X button event. | 74 // Converts Aura event type and flag to X button event. |
86 unsigned int XButtonEventButton(ui::EventType type, | 75 unsigned int XButtonEventButton(ui::EventType type, |
87 int flags) { | 76 int flags) { |
88 // Aura events don't keep track of mouse wheel button, so just return | 77 // Aura events don't keep track of mouse wheel button, so just return |
89 // the first mouse wheel button. | 78 // the first mouse wheel button. |
90 if (type == ui::ET_MOUSEWHEEL) | 79 if (type == ui::ET_MOUSEWHEEL) |
91 return Button4; | 80 return Button4; |
92 | 81 |
93 if (flags & ui::EF_LEFT_MOUSE_BUTTON) | 82 if (flags & ui::EF_LEFT_MOUSE_BUTTON) |
94 return Button1; | 83 return Button1; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 event_->xkey.display = display; | 159 event_->xkey.display = display; |
171 event_->xkey.time = 0; | 160 event_->xkey.time = 0; |
172 event_->xkey.window = 0; | 161 event_->xkey.window = 0; |
173 event_->xkey.root = 0; | 162 event_->xkey.root = 0; |
174 event_->xkey.subwindow = 0; | 163 event_->xkey.subwindow = 0; |
175 event_->xkey.x = 0; | 164 event_->xkey.x = 0; |
176 event_->xkey.y = 0; | 165 event_->xkey.y = 0; |
177 event_->xkey.x_root = 0; | 166 event_->xkey.x_root = 0; |
178 event_->xkey.y_root = 0; | 167 event_->xkey.y_root = 0; |
179 event_->xkey.state = XEventState(flags); | 168 event_->xkey.state = XEventState(flags); |
180 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display); | 169 event_->xkey.keycode = XKeyCodeForWindowsKeyCode(key_code, flags, display); |
181 event_->xkey.same_screen = 1; | 170 event_->xkey.same_screen = 1; |
182 } | 171 } |
183 | 172 |
184 void ScopedXI2Event::InitGenericKeyEvent(int deviceid, | 173 void ScopedXI2Event::InitGenericKeyEvent(int deviceid, |
185 EventType type, | 174 EventType type, |
186 KeyboardCode key_code, | 175 KeyboardCode key_code, |
187 int flags) { | 176 int flags) { |
188 event_.reset( | 177 event_.reset( |
189 CreateXInput2Event(deviceid, XIKeyEventType(type), 0, gfx::Point())); | 178 CreateXInput2Event(deviceid, XIKeyEventType(type), 0, gfx::Point())); |
190 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); | 179 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); |
191 CHECK_NE(0, xievent->evtype); | 180 CHECK_NE(0, xievent->evtype); |
192 XDisplay* display = gfx::GetXDisplay(); | 181 XDisplay* display = gfx::GetXDisplay(); |
193 event_->xgeneric.display = display; | 182 event_->xgeneric.display = display; |
194 xievent->display = display; | 183 xievent->display = display; |
195 xievent->mods.effective = XEventState(flags); | 184 xievent->mods.effective = XEventState(flags); |
196 xievent->detail = XKeyEventKeyCode(key_code, flags, display); | 185 xievent->detail = XKeyCodeForWindowsKeyCode(key_code, flags, display); |
197 } | 186 } |
198 | 187 |
199 void ScopedXI2Event::InitGenericButtonEvent(int deviceid, | 188 void ScopedXI2Event::InitGenericButtonEvent(int deviceid, |
200 EventType type, | 189 EventType type, |
201 const gfx::Point& location, | 190 const gfx::Point& location, |
202 int flags) { | 191 int flags) { |
203 event_.reset(CreateXInput2Event(deviceid, | 192 event_.reset(CreateXInput2Event(deviceid, |
204 XIButtonEventType(type), 0, gfx::Point())); | 193 XIButtonEventType(type), 0, gfx::Point())); |
205 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); | 194 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); |
206 xievent->mods.effective = XEventState(flags); | 195 xievent->mods.effective = XEventState(flags); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); | 293 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); |
305 } | 294 } |
306 | 295 |
307 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { | 296 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { |
308 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); | 297 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); |
309 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 298 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
310 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); | 299 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); |
311 } | 300 } |
312 | 301 |
313 } // namespace ui | 302 } // namespace ui |
OLD | NEW |