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

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

Issue 144423006: Rewrite release event only if press event was rewritten for a given device. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comment Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/events/test/events_test_utils_x11.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10 matching lines...) Expand all
21 return 21 return
22 ((flags & ui::EF_SHIFT_DOWN) ? ShiftMask : 0) | 22 ((flags & ui::EF_SHIFT_DOWN) ? ShiftMask : 0) |
23 ((flags & ui::EF_CONTROL_DOWN) ? ControlMask : 0) | 23 ((flags & ui::EF_CONTROL_DOWN) ? ControlMask : 0) |
24 ((flags & ui::EF_ALT_DOWN) ? Mod1Mask : 0) | 24 ((flags & ui::EF_ALT_DOWN) ? Mod1Mask : 0) |
25 ((flags & ui::EF_CAPS_LOCK_DOWN) ? LockMask : 0) | 25 ((flags & ui::EF_CAPS_LOCK_DOWN) ? LockMask : 0) |
26 ((flags & ui::EF_LEFT_MOUSE_BUTTON) ? Button1Mask: 0) | 26 ((flags & ui::EF_LEFT_MOUSE_BUTTON) ? Button1Mask: 0) |
27 ((flags & ui::EF_MIDDLE_MOUSE_BUTTON) ? Button2Mask: 0) | 27 ((flags & ui::EF_MIDDLE_MOUSE_BUTTON) ? Button2Mask: 0) |
28 ((flags & ui::EF_RIGHT_MOUSE_BUTTON) ? Button3Mask: 0); 28 ((flags & ui::EF_RIGHT_MOUSE_BUTTON) ? Button3Mask: 0);
29 } 29 }
30 30
31 /*
32 int XButtonNum(int flags) {
33 if (flags & ui::EF_LEFT_MOUSE_BUTTON)
34 return 1;
35 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
36 return 2;
37 if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
38 return 3;
39 NOTREACHED();
40 return 0;
41 }
42 */
sadrul 2014/01/30 02:14:21 Just remove this.
oshima 2014/01/30 02:16:41 oops sorry. done.
43
31 // Converts EventType to XKeyEvent type. 44 // Converts EventType to XKeyEvent type.
32 int XKeyEventType(ui::EventType type) { 45 int XKeyEventType(ui::EventType type) {
33 switch (type) { 46 switch (type) {
34 case ui::ET_KEY_PRESSED: 47 case ui::ET_KEY_PRESSED:
35 return KeyPress; 48 return KeyPress;
36 case ui::ET_KEY_RELEASED: 49 case ui::ET_KEY_RELEASED:
37 return KeyRelease; 50 return KeyRelease;
38 default: 51 default:
39 return 0; 52 return 0;
40 } 53 }
41 } 54 }
42 55
56 int XIButtonEventType(ui::EventType type) {
57 switch (type) {
58 case ui::ET_MOUSEWHEEL:
59 case ui::ET_MOUSE_PRESSED:
60 // The button release X events for mouse wheels are dropped by Aura.
61 return XI_ButtonPress;
62 case ui::ET_MOUSE_RELEASED:
63 return XI_ButtonRelease;
64 default:
65 NOTREACHED();
66 return 0;
67 }
68 }
69
43 // Converts EventType to XButtonEvent type. 70 // Converts EventType to XButtonEvent type.
44 int XButtonEventType(ui::EventType type) { 71 int XButtonEventType(ui::EventType type) {
45 switch (type) { 72 switch (type) {
46 case ui::ET_MOUSEWHEEL: 73 case ui::ET_MOUSEWHEEL:
47 case ui::ET_MOUSE_PRESSED: 74 case ui::ET_MOUSE_PRESSED:
48 // The button release X events for mouse wheels are dropped by Aura. 75 // The button release X events for mouse wheels are dropped by Aura.
49 return ButtonPress; 76 return ButtonPress;
50 case ui::ET_MOUSE_RELEASED: 77 case ui::ET_MOUSE_RELEASED:
51 return ButtonRelease; 78 return ButtonRelease;
52 default: 79 default:
(...skipping 14 matching lines...) Expand all
67 } 94 }
68 95
69 // Converts Aura event type and flag to X button event. 96 // Converts Aura event type and flag to X button event.
70 unsigned int XButtonEventButton(ui::EventType type, 97 unsigned int XButtonEventButton(ui::EventType type,
71 int flags) { 98 int flags) {
72 // Aura events don't keep track of mouse wheel button, so just return 99 // Aura events don't keep track of mouse wheel button, so just return
73 // the first mouse wheel button. 100 // the first mouse wheel button.
74 if (type == ui::ET_MOUSEWHEEL) 101 if (type == ui::ET_MOUSEWHEEL)
75 return Button4; 102 return Button4;
76 103
77 switch (flags) { 104 if (flags & ui::EF_LEFT_MOUSE_BUTTON)
78 case ui::EF_LEFT_MOUSE_BUTTON: 105 return Button1;
79 return Button1; 106 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
80 case ui::EF_MIDDLE_MOUSE_BUTTON: 107 return Button2;
81 return Button2; 108 if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
82 case ui::EF_RIGHT_MOUSE_BUTTON: 109 return Button3;
83 return Button3;
84 }
85 110
86 return 0; 111 return 0;
87 } 112 }
88 113
89 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) { 114 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) {
90 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY; 115 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY;
91 xiev->valuators.mask_len = (valuator_count / 8) + 1; 116 xiev->valuators.mask_len = (valuator_count / 8) + 1;
92 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len]; 117 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len];
93 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len); 118 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len);
94 xiev->valuators.values = new double[valuator_count]; 119 xiev->valuators.values = new double[valuator_count];
95 } 120 }
96 121
97 XEvent* CreateXInput2Event(int deviceid, 122 XEvent* CreateXInput2Event(int deviceid,
98 int evtype, 123 int evtype,
99 int tracking_id, 124 int tracking_id,
100 const gfx::Point& location) { 125 const gfx::Point& location) {
101 XEvent* event = new XEvent; 126 XEvent* event = new XEvent;
102 memset(event, 0, sizeof(*event)); 127 memset(event, 0, sizeof(*event));
103 event->type = GenericEvent; 128 event->type = GenericEvent;
104 event->xcookie.data = new XIDeviceEvent; 129 event->xcookie.data = new XIDeviceEvent;
105 XIDeviceEvent* xiev = 130 XIDeviceEvent* xiev =
106 static_cast<XIDeviceEvent*>(event->xcookie.data); 131 static_cast<XIDeviceEvent*>(event->xcookie.data);
107 memset(xiev, 0, sizeof(XIDeviceEvent)); 132 memset(xiev, 0, sizeof(XIDeviceEvent));
108 xiev->deviceid = deviceid; 133 xiev->deviceid = deviceid;
109 xiev->sourceid = deviceid; 134 xiev->sourceid = deviceid;
110 xiev->evtype = evtype; 135 xiev->evtype = evtype;
111 xiev->detail = tracking_id; 136 xiev->detail = tracking_id;
112 xiev->event_x = location.x(); 137 xiev->event_x = location.x();
113 xiev->event_y = location.y(); 138 xiev->event_y = location.y();
114 139 if (evtype == XI_ButtonPress || evtype == XI_ButtonRelease) {
140 xiev->buttons.mask_len = 8;
141 xiev->buttons.mask = new unsigned char[xiev->buttons.mask_len];
142 memset(xiev->buttons.mask, 0, xiev->buttons.mask_len);
143 }
115 return event; 144 return event;
116 } 145 }
117 146
118 } // namespace 147 } // namespace
119 148
120 namespace ui { 149 namespace ui {
121 150
122 ScopedXI2Event::ScopedXI2Event() {} 151 ScopedXI2Event::ScopedXI2Event() {}
123 ScopedXI2Event::~ScopedXI2Event() { 152 ScopedXI2Event::~ScopedXI2Event() {
124 Cleanup(); 153 Cleanup();
(...skipping 17 matching lines...) Expand all
142 event_->xkey.subwindow = 0; 171 event_->xkey.subwindow = 0;
143 event_->xkey.x = 0; 172 event_->xkey.x = 0;
144 event_->xkey.y = 0; 173 event_->xkey.y = 0;
145 event_->xkey.x_root = 0; 174 event_->xkey.x_root = 0;
146 event_->xkey.y_root = 0; 175 event_->xkey.y_root = 0;
147 event_->xkey.state = XEventState(flags); 176 event_->xkey.state = XEventState(flags);
148 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display); 177 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display);
149 event_->xkey.same_screen = 1; 178 event_->xkey.same_screen = 1;
150 } 179 }
151 180
181 void ScopedXI2Event::InitGenericButtonEvent(int deviceid,
182 EventType type,
183 int flags) {
184 Cleanup();
185 event_.reset(CreateXInput2Event(deviceid,
186 XIButtonEventType(type), 0, gfx::Point()));
187 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data);
188 xievent->mods.effective = XEventState(flags);
189 xievent->detail = XButtonEventButton(type, flags);
190 XISetMask(xievent->buttons.mask, xievent->detail);
191 }
192
152 void ScopedXI2Event::InitButtonEvent(EventType type, 193 void ScopedXI2Event::InitButtonEvent(EventType type,
153 int flags) { 194 int flags) {
154 Cleanup(); 195 Cleanup();
155 event_.reset(new XEvent); 196 event_.reset(new XEvent);
156 memset(event_.get(), 0, sizeof(XEvent)); 197 memset(event_.get(), 0, sizeof(XEvent));
157 event_->type = XButtonEventType(type); 198 event_->type = XButtonEventType(type);
158 CHECK_NE(0, event_->type); 199 CHECK_NE(0, event_->type);
159 event_->xbutton.serial = 0; 200 event_->xbutton.serial = 0;
160 event_->xbutton.send_event = 0; 201 event_->xbutton.send_event = 0;
161 event_->xbutton.display = gfx::GetXDisplay(); 202 event_->xbutton.display = gfx::GetXDisplay();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 SetUpValuators(valuators); 272 SetUpValuators(valuators);
232 } 273 }
233 274
234 void ScopedXI2Event::Cleanup() { 275 void ScopedXI2Event::Cleanup() {
235 if (event_.get() && event_->type == GenericEvent) { 276 if (event_.get() && event_->type == GenericEvent) {
236 XIDeviceEvent* xiev = 277 XIDeviceEvent* xiev =
237 static_cast<XIDeviceEvent*>(event_->xcookie.data); 278 static_cast<XIDeviceEvent*>(event_->xcookie.data);
238 if (xiev) { 279 if (xiev) {
239 delete[] xiev->valuators.mask; 280 delete[] xiev->valuators.mask;
240 delete[] xiev->valuators.values; 281 delete[] xiev->valuators.values;
282 delete[] xiev->buttons.mask;
241 delete xiev; 283 delete xiev;
242 } 284 }
243 } 285 }
244 event_.reset(); 286 event_.reset();
245 } 287 }
246 288
247 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { 289 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) {
248 CHECK(event_.get()); 290 CHECK(event_.get());
249 CHECK_EQ(GenericEvent, event_->type); 291 CHECK_EQ(GenericEvent, event_->type);
250 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); 292 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data);
(...skipping 14 matching lines...) Expand all
265 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); 307 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list);
266 } 308 }
267 309
268 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { 310 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) {
269 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); 311 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices);
270 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 312 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance();
271 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); 313 manager->SetDeviceListForTest(devices, std::vector<unsigned int>());
272 } 314 }
273 315
274 } // namespace ui 316 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/test/events_test_utils_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698