Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 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 int XButtonNum(int flags) { | |
|
sadrul
2014/01/30 02:01:42
Could you use XButtonEventButton() instead?
oshima
2014/01/30 02:12:54
I had to change XButtonEventButton, but I think th
| |
| 32 if (flags & ui::EF_LEFT_MOUSE_BUTTON) | |
| 33 return 1; | |
| 34 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) | |
| 35 return 2; | |
| 36 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) | |
| 37 return 3; | |
| 38 return 0; | |
| 39 } | |
| 40 | |
| 31 // Converts EventType to XKeyEvent type. | 41 // Converts EventType to XKeyEvent type. |
| 32 int XKeyEventType(ui::EventType type) { | 42 int XKeyEventType(ui::EventType type) { |
| 33 switch (type) { | 43 switch (type) { |
| 34 case ui::ET_KEY_PRESSED: | 44 case ui::ET_KEY_PRESSED: |
| 35 return KeyPress; | 45 return KeyPress; |
| 36 case ui::ET_KEY_RELEASED: | 46 case ui::ET_KEY_RELEASED: |
| 37 return KeyRelease; | 47 return KeyRelease; |
| 38 default: | 48 default: |
| 39 return 0; | 49 return 0; |
| 40 } | 50 } |
| 41 } | 51 } |
| 42 | 52 |
| 53 int XIButtonEventType(ui::EventType type) { | |
| 54 switch (type) { | |
| 55 case ui::ET_MOUSEWHEEL: | |
| 56 case ui::ET_MOUSE_PRESSED: | |
| 57 // The button release X events for mouse wheels are dropped by Aura. | |
| 58 return XI_ButtonPress; | |
| 59 case ui::ET_MOUSE_RELEASED: | |
| 60 return XI_ButtonRelease; | |
| 61 default: | |
| 62 return 0; | |
|
sadrul
2014/01/30 02:01:42
Should this have a NOTREACHED()?
oshima
2014/01/30 02:12:54
Done.
| |
| 63 } | |
| 64 } | |
| 65 | |
| 43 // Converts EventType to XButtonEvent type. | 66 // Converts EventType to XButtonEvent type. |
| 44 int XButtonEventType(ui::EventType type) { | 67 int XButtonEventType(ui::EventType type) { |
| 45 switch (type) { | 68 switch (type) { |
| 46 case ui::ET_MOUSEWHEEL: | 69 case ui::ET_MOUSEWHEEL: |
| 47 case ui::ET_MOUSE_PRESSED: | 70 case ui::ET_MOUSE_PRESSED: |
| 48 // The button release X events for mouse wheels are dropped by Aura. | 71 // The button release X events for mouse wheels are dropped by Aura. |
| 49 return ButtonPress; | 72 return ButtonPress; |
| 50 case ui::ET_MOUSE_RELEASED: | 73 case ui::ET_MOUSE_RELEASED: |
| 51 return ButtonRelease; | 74 return ButtonRelease; |
| 52 default: | 75 default: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 event->xcookie.data = new XIDeviceEvent; | 127 event->xcookie.data = new XIDeviceEvent; |
| 105 XIDeviceEvent* xiev = | 128 XIDeviceEvent* xiev = |
| 106 static_cast<XIDeviceEvent*>(event->xcookie.data); | 129 static_cast<XIDeviceEvent*>(event->xcookie.data); |
| 107 memset(xiev, 0, sizeof(XIDeviceEvent)); | 130 memset(xiev, 0, sizeof(XIDeviceEvent)); |
| 108 xiev->deviceid = deviceid; | 131 xiev->deviceid = deviceid; |
| 109 xiev->sourceid = deviceid; | 132 xiev->sourceid = deviceid; |
| 110 xiev->evtype = evtype; | 133 xiev->evtype = evtype; |
| 111 xiev->detail = tracking_id; | 134 xiev->detail = tracking_id; |
| 112 xiev->event_x = location.x(); | 135 xiev->event_x = location.x(); |
| 113 xiev->event_y = location.y(); | 136 xiev->event_y = location.y(); |
| 114 | 137 if (evtype == XI_ButtonPress || evtype == XI_ButtonRelease) { |
| 138 xiev->buttons.mask_len = 8; | |
| 139 xiev->buttons.mask = new unsigned char[xiev->buttons.mask_len]; | |
| 140 memset(xiev->buttons.mask, 0, xiev->buttons.mask_len); | |
| 141 } | |
| 115 return event; | 142 return event; |
| 116 } | 143 } |
| 117 | 144 |
| 118 } // namespace | 145 } // namespace |
| 119 | 146 |
| 120 namespace ui { | 147 namespace ui { |
| 121 | 148 |
| 122 ScopedXI2Event::ScopedXI2Event() {} | 149 ScopedXI2Event::ScopedXI2Event() {} |
| 123 ScopedXI2Event::~ScopedXI2Event() { | 150 ScopedXI2Event::~ScopedXI2Event() { |
| 124 Cleanup(); | 151 Cleanup(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 142 event_->xkey.subwindow = 0; | 169 event_->xkey.subwindow = 0; |
| 143 event_->xkey.x = 0; | 170 event_->xkey.x = 0; |
| 144 event_->xkey.y = 0; | 171 event_->xkey.y = 0; |
| 145 event_->xkey.x_root = 0; | 172 event_->xkey.x_root = 0; |
| 146 event_->xkey.y_root = 0; | 173 event_->xkey.y_root = 0; |
| 147 event_->xkey.state = XEventState(flags); | 174 event_->xkey.state = XEventState(flags); |
| 148 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display); | 175 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display); |
| 149 event_->xkey.same_screen = 1; | 176 event_->xkey.same_screen = 1; |
| 150 } | 177 } |
| 151 | 178 |
| 179 void ScopedXI2Event::InitGenericButtonEvent(int deviceid, | |
| 180 EventType type, | |
| 181 int flags) { | |
| 182 Cleanup(); | |
| 183 event_.reset(CreateXInput2Event(deviceid, | |
| 184 XIButtonEventType(type), 0, gfx::Point())); | |
| 185 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); | |
| 186 xievent->mods.effective = XEventState(flags); | |
| 187 xievent->detail = XButtonNum(flags); | |
| 188 XISetMask(xievent->buttons.mask, xievent->detail); | |
| 189 } | |
| 190 | |
| 152 void ScopedXI2Event::InitButtonEvent(EventType type, | 191 void ScopedXI2Event::InitButtonEvent(EventType type, |
| 153 int flags) { | 192 int flags) { |
| 154 Cleanup(); | 193 Cleanup(); |
| 155 event_.reset(new XEvent); | 194 event_.reset(new XEvent); |
| 156 memset(event_.get(), 0, sizeof(XEvent)); | 195 memset(event_.get(), 0, sizeof(XEvent)); |
| 157 event_->type = XButtonEventType(type); | 196 event_->type = XButtonEventType(type); |
| 158 CHECK_NE(0, event_->type); | 197 CHECK_NE(0, event_->type); |
| 159 event_->xbutton.serial = 0; | 198 event_->xbutton.serial = 0; |
| 160 event_->xbutton.send_event = 0; | 199 event_->xbutton.send_event = 0; |
| 161 event_->xbutton.display = gfx::GetXDisplay(); | 200 event_->xbutton.display = gfx::GetXDisplay(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 SetUpValuators(valuators); | 270 SetUpValuators(valuators); |
| 232 } | 271 } |
| 233 | 272 |
| 234 void ScopedXI2Event::Cleanup() { | 273 void ScopedXI2Event::Cleanup() { |
| 235 if (event_.get() && event_->type == GenericEvent) { | 274 if (event_.get() && event_->type == GenericEvent) { |
| 236 XIDeviceEvent* xiev = | 275 XIDeviceEvent* xiev = |
| 237 static_cast<XIDeviceEvent*>(event_->xcookie.data); | 276 static_cast<XIDeviceEvent*>(event_->xcookie.data); |
| 238 if (xiev) { | 277 if (xiev) { |
| 239 delete[] xiev->valuators.mask; | 278 delete[] xiev->valuators.mask; |
| 240 delete[] xiev->valuators.values; | 279 delete[] xiev->valuators.values; |
| 280 delete[] xiev->buttons.mask; | |
| 241 delete xiev; | 281 delete xiev; |
| 242 } | 282 } |
| 243 } | 283 } |
| 244 event_.reset(); | 284 event_.reset(); |
| 245 } | 285 } |
| 246 | 286 |
| 247 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { | 287 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { |
| 248 CHECK(event_.get()); | 288 CHECK(event_.get()); |
| 249 CHECK_EQ(GenericEvent, event_->type); | 289 CHECK_EQ(GenericEvent, event_->type); |
| 250 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); | 290 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 265 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); | 305 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); |
| 266 } | 306 } |
| 267 | 307 |
| 268 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { | 308 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { |
| 269 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); | 309 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); |
| 270 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); | 310 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); |
| 271 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); | 311 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); |
| 272 } | 312 } |
| 273 | 313 |
| 274 } // namespace ui | 314 } // namespace ui |
| OLD | NEW |