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

Side by Side Diff: ui/events/test/events_test_utils_x11.cc

Issue 336403005: Use XInput2 events for keyboard events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments (derat), the sequel. Created 6 years, 6 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 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 27 matching lines...) Expand all
38 switch (type) { 38 switch (type) {
39 case ui::ET_KEY_PRESSED: 39 case ui::ET_KEY_PRESSED:
40 return KeyPress; 40 return KeyPress;
41 case ui::ET_KEY_RELEASED: 41 case ui::ET_KEY_RELEASED:
42 return KeyRelease; 42 return KeyRelease;
43 default: 43 default:
44 return 0; 44 return 0;
45 } 45 }
46 } 46 }
47 47
48 // Converts EventType to XI2 event type.
49 int XIKeyEventType(ui::EventType type) {
50 switch (type) {
51 case ui::ET_KEY_PRESSED:
52 return XI_KeyPress;
53 case ui::ET_KEY_RELEASED:
54 return XI_KeyRelease;
55 default:
56 return 0;
57 }
58 }
59
48 int XIButtonEventType(ui::EventType type) { 60 int XIButtonEventType(ui::EventType type) {
49 switch (type) { 61 switch (type) {
50 case ui::ET_MOUSEWHEEL: 62 case ui::ET_MOUSEWHEEL:
51 case ui::ET_MOUSE_PRESSED: 63 case ui::ET_MOUSE_PRESSED:
52 // 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.
53 return XI_ButtonPress; 65 return XI_ButtonPress;
54 case ui::ET_MOUSE_RELEASED: 66 case ui::ET_MOUSE_RELEASED:
55 return XI_ButtonRelease; 67 return XI_ButtonRelease;
56 default: 68 default:
57 NOTREACHED(); 69 NOTREACHED();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 event_->xkey.subwindow = 0; 175 event_->xkey.subwindow = 0;
164 event_->xkey.x = 0; 176 event_->xkey.x = 0;
165 event_->xkey.y = 0; 177 event_->xkey.y = 0;
166 event_->xkey.x_root = 0; 178 event_->xkey.x_root = 0;
167 event_->xkey.y_root = 0; 179 event_->xkey.y_root = 0;
168 event_->xkey.state = XEventState(flags); 180 event_->xkey.state = XEventState(flags);
169 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display); 181 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display);
170 event_->xkey.same_screen = 1; 182 event_->xkey.same_screen = 1;
171 } 183 }
172 184
185 void ScopedXI2Event::InitGenericKeyEvent(int deviceid,
186 EventType type,
187 KeyboardCode key_code,
188 int flags) {
189 event_.reset(
190 CreateXInput2Event(deviceid, XIKeyEventType(type), 0, gfx::Point()));
191 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data);
192 CHECK_NE(0, xievent->evtype);
193 XDisplay* display = gfx::GetXDisplay();
194 event_->xgeneric.display = display;
195 xievent->display = display;
196 xievent->mods.effective = XEventState(flags);
197 xievent->detail = XKeyEventKeyCode(key_code, flags, display);
198 }
199
173 void ScopedXI2Event::InitGenericButtonEvent(int deviceid, 200 void ScopedXI2Event::InitGenericButtonEvent(int deviceid,
174 EventType type, 201 EventType type,
175 const gfx::Point& location, 202 const gfx::Point& location,
176 int flags) { 203 int flags) {
177 event_.reset(CreateXInput2Event(deviceid, 204 event_.reset(CreateXInput2Event(deviceid,
178 XIButtonEventType(type), 0, gfx::Point())); 205 XIButtonEventType(type), 0, gfx::Point()));
179 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); 206 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data);
180 xievent->mods.effective = XEventState(flags); 207 xievent->mods.effective = XEventState(flags);
181 xievent->detail = XButtonEventButton(type, flags); 208 xievent->detail = XButtonEventButton(type, flags);
182 xievent->event_x = location.x(); 209 xievent->event_x = location.x();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); 305 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list);
279 } 306 }
280 307
281 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { 308 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) {
282 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); 309 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices);
283 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); 310 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
284 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); 311 manager->SetDeviceListForTest(devices, std::vector<unsigned int>());
285 } 312 }
286 313
287 } // namespace ui 314 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698