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

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: 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 22 matching lines...) Expand all
33 switch (type) { 33 switch (type) {
34 case ui::ET_KEY_PRESSED: 34 case ui::ET_KEY_PRESSED:
35 return KeyPress; 35 return KeyPress;
36 case ui::ET_KEY_RELEASED: 36 case ui::ET_KEY_RELEASED:
37 return KeyRelease; 37 return KeyRelease;
38 default: 38 default:
39 return 0; 39 return 0;
40 } 40 }
41 } 41 }
42 42
43 int XIButtonEventType(ui::EventType type) {
44 switch (type) {
45 case ui::ET_MOUSEWHEEL:
46 case ui::ET_MOUSE_PRESSED:
47 // The button release X events for mouse wheels are dropped by Aura.
48 return XI_ButtonPress;
49 case ui::ET_MOUSE_RELEASED:
50 return XI_ButtonRelease;
51 default:
52 NOTREACHED();
53 return 0;
54 }
55 }
56
43 // Converts EventType to XButtonEvent type. 57 // Converts EventType to XButtonEvent type.
44 int XButtonEventType(ui::EventType type) { 58 int XButtonEventType(ui::EventType type) {
45 switch (type) { 59 switch (type) {
46 case ui::ET_MOUSEWHEEL: 60 case ui::ET_MOUSEWHEEL:
47 case ui::ET_MOUSE_PRESSED: 61 case ui::ET_MOUSE_PRESSED:
48 // The button release X events for mouse wheels are dropped by Aura. 62 // The button release X events for mouse wheels are dropped by Aura.
49 return ButtonPress; 63 return ButtonPress;
50 case ui::ET_MOUSE_RELEASED: 64 case ui::ET_MOUSE_RELEASED:
51 return ButtonRelease; 65 return ButtonRelease;
52 default: 66 default:
(...skipping 14 matching lines...) Expand all
67 } 81 }
68 82
69 // Converts Aura event type and flag to X button event. 83 // Converts Aura event type and flag to X button event.
70 unsigned int XButtonEventButton(ui::EventType type, 84 unsigned int XButtonEventButton(ui::EventType type,
71 int flags) { 85 int flags) {
72 // Aura events don't keep track of mouse wheel button, so just return 86 // Aura events don't keep track of mouse wheel button, so just return
73 // the first mouse wheel button. 87 // the first mouse wheel button.
74 if (type == ui::ET_MOUSEWHEEL) 88 if (type == ui::ET_MOUSEWHEEL)
75 return Button4; 89 return Button4;
76 90
77 switch (flags) { 91 if (flags & ui::EF_LEFT_MOUSE_BUTTON)
78 case ui::EF_LEFT_MOUSE_BUTTON: 92 return Button1;
79 return Button1; 93 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
80 case ui::EF_MIDDLE_MOUSE_BUTTON: 94 return Button2;
81 return Button2; 95 if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
82 case ui::EF_RIGHT_MOUSE_BUTTON: 96 return Button3;
83 return Button3;
84 }
85 97
86 return 0; 98 return 0;
87 } 99 }
88 100
89 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) { 101 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) {
90 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY; 102 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY;
91 xiev->valuators.mask_len = (valuator_count / 8) + 1; 103 xiev->valuators.mask_len = (valuator_count / 8) + 1;
92 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len]; 104 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len];
93 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len); 105 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len);
94 xiev->valuators.values = new double[valuator_count]; 106 xiev->valuators.values = new double[valuator_count];
95 } 107 }
96 108
97 XEvent* CreateXInput2Event(int deviceid, 109 XEvent* CreateXInput2Event(int deviceid,
98 int evtype, 110 int evtype,
99 int tracking_id, 111 int tracking_id,
100 const gfx::Point& location) { 112 const gfx::Point& location) {
101 XEvent* event = new XEvent; 113 XEvent* event = new XEvent;
102 memset(event, 0, sizeof(*event)); 114 memset(event, 0, sizeof(*event));
103 event->type = GenericEvent; 115 event->type = GenericEvent;
104 event->xcookie.data = new XIDeviceEvent; 116 event->xcookie.data = new XIDeviceEvent;
105 XIDeviceEvent* xiev = 117 XIDeviceEvent* xiev =
106 static_cast<XIDeviceEvent*>(event->xcookie.data); 118 static_cast<XIDeviceEvent*>(event->xcookie.data);
107 memset(xiev, 0, sizeof(XIDeviceEvent)); 119 memset(xiev, 0, sizeof(XIDeviceEvent));
108 xiev->deviceid = deviceid; 120 xiev->deviceid = deviceid;
109 xiev->sourceid = deviceid; 121 xiev->sourceid = deviceid;
110 xiev->evtype = evtype; 122 xiev->evtype = evtype;
111 xiev->detail = tracking_id; 123 xiev->detail = tracking_id;
112 xiev->event_x = location.x(); 124 xiev->event_x = location.x();
113 xiev->event_y = location.y(); 125 xiev->event_y = location.y();
114 126 if (evtype == XI_ButtonPress || evtype == XI_ButtonRelease) {
127 xiev->buttons.mask_len = 8;
128 xiev->buttons.mask = new unsigned char[xiev->buttons.mask_len];
129 memset(xiev->buttons.mask, 0, xiev->buttons.mask_len);
130 }
115 return event; 131 return event;
116 } 132 }
117 133
118 } // namespace 134 } // namespace
119 135
120 namespace ui { 136 namespace ui {
121 137
122 ScopedXI2Event::ScopedXI2Event() {} 138 ScopedXI2Event::ScopedXI2Event() {}
123 ScopedXI2Event::~ScopedXI2Event() { 139 ScopedXI2Event::~ScopedXI2Event() {
124 Cleanup(); 140 Cleanup();
(...skipping 17 matching lines...) Expand all
142 event_->xkey.subwindow = 0; 158 event_->xkey.subwindow = 0;
143 event_->xkey.x = 0; 159 event_->xkey.x = 0;
144 event_->xkey.y = 0; 160 event_->xkey.y = 0;
145 event_->xkey.x_root = 0; 161 event_->xkey.x_root = 0;
146 event_->xkey.y_root = 0; 162 event_->xkey.y_root = 0;
147 event_->xkey.state = XEventState(flags); 163 event_->xkey.state = XEventState(flags);
148 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display); 164 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display);
149 event_->xkey.same_screen = 1; 165 event_->xkey.same_screen = 1;
150 } 166 }
151 167
168 void ScopedXI2Event::InitGenericButtonEvent(int deviceid,
169 EventType type,
170 int flags) {
171 Cleanup();
172 event_.reset(CreateXInput2Event(deviceid,
173 XIButtonEventType(type), 0, gfx::Point()));
174 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data);
175 xievent->mods.effective = XEventState(flags);
176 xievent->detail = XButtonEventButton(type, flags);
177 XISetMask(xievent->buttons.mask, xievent->detail);
178 }
179
152 void ScopedXI2Event::InitButtonEvent(EventType type, 180 void ScopedXI2Event::InitButtonEvent(EventType type,
153 int flags) { 181 int flags) {
154 Cleanup(); 182 Cleanup();
155 event_.reset(new XEvent); 183 event_.reset(new XEvent);
156 memset(event_.get(), 0, sizeof(XEvent)); 184 memset(event_.get(), 0, sizeof(XEvent));
157 event_->type = XButtonEventType(type); 185 event_->type = XButtonEventType(type);
158 CHECK_NE(0, event_->type); 186 CHECK_NE(0, event_->type);
159 event_->xbutton.serial = 0; 187 event_->xbutton.serial = 0;
160 event_->xbutton.send_event = 0; 188 event_->xbutton.send_event = 0;
161 event_->xbutton.display = gfx::GetXDisplay(); 189 event_->xbutton.display = gfx::GetXDisplay();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 SetUpValuators(valuators); 259 SetUpValuators(valuators);
232 } 260 }
233 261
234 void ScopedXI2Event::Cleanup() { 262 void ScopedXI2Event::Cleanup() {
235 if (event_.get() && event_->type == GenericEvent) { 263 if (event_.get() && event_->type == GenericEvent) {
236 XIDeviceEvent* xiev = 264 XIDeviceEvent* xiev =
237 static_cast<XIDeviceEvent*>(event_->xcookie.data); 265 static_cast<XIDeviceEvent*>(event_->xcookie.data);
238 if (xiev) { 266 if (xiev) {
239 delete[] xiev->valuators.mask; 267 delete[] xiev->valuators.mask;
240 delete[] xiev->valuators.values; 268 delete[] xiev->valuators.values;
269 delete[] xiev->buttons.mask;
241 delete xiev; 270 delete xiev;
242 } 271 }
243 } 272 }
244 event_.reset(); 273 event_.reset();
245 } 274 }
246 275
247 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { 276 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) {
248 CHECK(event_.get()); 277 CHECK(event_.get());
249 CHECK_EQ(GenericEvent, event_->type); 278 CHECK_EQ(GenericEvent, event_->type);
250 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); 279 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data);
(...skipping 14 matching lines...) Expand all
265 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); 294 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list);
266 } 295 }
267 296
268 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { 297 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) {
269 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); 298 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices);
270 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 299 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance();
271 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); 300 manager->SetDeviceListForTest(devices, std::vector<unsigned int>());
272 } 301 }
273 302
274 } // namespace ui 303 } // 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