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

Side by Side Diff: ui/base/x/events_x.cc

Issue 8113028: Consolidate ui::NativeEvent and base::NativeEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new patch Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/events.h" 5 #include "ui/base/events.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 10 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { 59 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) {
60 int buttonflags = 0; 60 int buttonflags = 0;
61 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { 61 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) {
62 if (XIMaskIsSet(xievent->buttons.mask, i)) { 62 if (XIMaskIsSet(xievent->buttons.mask, i)) {
63 buttonflags |= GetEventFlagsForButton(i); 63 buttonflags |= GetEventFlagsForButton(i);
64 } 64 }
65 } 65 }
66 return buttonflags; 66 return buttonflags;
67 } 67 }
68 68
69 ui::EventType GetTouchEventType(const ui::NativeEvent& native_event) { 69 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
70 XIDeviceEvent* event = 70 XIDeviceEvent* event =
71 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 71 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
72 #if defined(USE_XI2_MT) 72 #if defined(USE_XI2_MT)
73 switch(event->evtype) { 73 switch(event->evtype) {
74 case XI_TouchBegin: 74 case XI_TouchBegin:
75 return ui::ET_TOUCH_PRESSED; 75 return ui::ET_TOUCH_PRESSED;
76 case XI_TouchUpdate: 76 case XI_TouchUpdate:
77 return ui::ET_TOUCH_MOVED; 77 return ui::ET_TOUCH_MOVED;
78 case XI_TouchEnd: 78 case XI_TouchEnd:
79 return ui::ET_TOUCH_RELEASED; 79 return ui::ET_TOUCH_RELEASED;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 return ui::ET_TOUCH_MOVED; 126 return ui::ET_TOUCH_MOVED;
127 #endif // defined(USE_XI2_MT) 127 #endif // defined(USE_XI2_MT)
128 } 128 }
129 129
130 } // namespace 130 } // namespace
131 131
132 namespace ui { 132 namespace ui {
133 133
134 EventType EventTypeFromNative(const NativeEvent& native_event) { 134 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
135 switch (native_event->type) { 135 switch (native_event->type) {
136 case KeyPress: 136 case KeyPress:
137 return ET_KEY_PRESSED; 137 return ET_KEY_PRESSED;
138 case KeyRelease: 138 case KeyRelease:
139 return ET_KEY_RELEASED; 139 return ET_KEY_RELEASED;
140 case ButtonPress: 140 case ButtonPress:
141 if (native_event->xbutton.button == 4 || 141 if (native_event->xbutton.button == 4 ||
142 native_event->xbutton.button == 5) 142 native_event->xbutton.button == 5)
143 return ET_MOUSEWHEEL; 143 return ET_MOUSEWHEEL;
144 return ET_MOUSE_PRESSED; 144 return ET_MOUSE_PRESSED;
(...skipping 24 matching lines...) Expand all
169 ET_MOUSE_DRAGGED : ET_MOUSE_MOVED; 169 ET_MOUSE_DRAGGED : ET_MOUSE_MOVED;
170 } 170 }
171 } 171 }
172 default: 172 default:
173 NOTREACHED(); 173 NOTREACHED();
174 break; 174 break;
175 } 175 }
176 return ET_UNKNOWN; 176 return ET_UNKNOWN;
177 } 177 }
178 178
179 int EventFlagsFromNative(const NativeEvent& native_event) { 179 int EventFlagsFromNative(const base::NativeEvent& native_event) {
180 switch (native_event->type) { 180 switch (native_event->type) {
181 case KeyPress: 181 case KeyPress:
182 case KeyRelease: 182 case KeyRelease:
183 return GetEventFlagsFromXState(native_event->xbutton.state); 183 return GetEventFlagsFromXState(native_event->xbutton.state);
184 case ButtonPress: 184 case ButtonPress:
185 case ButtonRelease: 185 case ButtonRelease:
186 return GetEventFlagsFromXState(native_event->xbutton.state) | 186 return GetEventFlagsFromXState(native_event->xbutton.state) |
187 GetEventFlagsForButton(native_event->xbutton.button); 187 GetEventFlagsForButton(native_event->xbutton.button);
188 case MotionNotify: 188 case MotionNotify:
189 return GetEventFlagsFromXState(native_event->xmotion.state); 189 return GetEventFlagsFromXState(native_event->xmotion.state);
(...skipping 10 matching lines...) Expand all
200 (touch ? 0 : GetEventFlagsForButton(xievent->detail)); 200 (touch ? 0 : GetEventFlagsForButton(xievent->detail));
201 case XI_Motion: 201 case XI_Motion:
202 return GetButtonMaskForX2Event(xievent) | 202 return GetButtonMaskForX2Event(xievent) |
203 GetEventFlagsFromXState(xievent->mods.effective); 203 GetEventFlagsFromXState(xievent->mods.effective);
204 } 204 }
205 } 205 }
206 } 206 }
207 return 0; 207 return 0;
208 } 208 }
209 209
210 gfx::Point EventLocationFromNative(const NativeEvent& native_event) { 210 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
211 switch (native_event->type) { 211 switch (native_event->type) {
212 case ButtonPress: 212 case ButtonPress:
213 case ButtonRelease: 213 case ButtonRelease:
214 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); 214 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y);
215 case MotionNotify: 215 case MotionNotify:
216 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); 216 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y);
217 case GenericEvent: { 217 case GenericEvent: {
218 XIDeviceEvent* xievent = 218 XIDeviceEvent* xievent =
219 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 219 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
220 return gfx::Point(static_cast<int>(xievent->event_x), 220 return gfx::Point(static_cast<int>(xievent->event_x),
221 static_cast<int>(xievent->event_y)); 221 static_cast<int>(xievent->event_y));
222 } 222 }
223 } 223 }
224 return gfx::Point(); 224 return gfx::Point();
225 } 225 }
226 226
227 KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) { 227 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
228 return KeyboardCodeFromXKeyEvent(native_event); 228 return KeyboardCodeFromXKeyEvent(native_event);
229 } 229 }
230 230
231 bool IsMouseEvent(const NativeEvent& native_event) { 231 bool IsMouseEvent(const base::NativeEvent& native_event) {
232 if (native_event->type == ButtonPress || 232 if (native_event->type == ButtonPress ||
233 native_event->type == ButtonRelease || 233 native_event->type == ButtonRelease ||
234 native_event->type == MotionNotify) 234 native_event->type == MotionNotify)
235 return true; 235 return true;
236 if (native_event->type == GenericEvent) { 236 if (native_event->type == GenericEvent) {
237 XIDeviceEvent* xievent = 237 XIDeviceEvent* xievent =
238 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 238 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
239 return xievent->evtype == XI_ButtonPress || 239 return xievent->evtype == XI_ButtonPress ||
240 xievent->evtype == XI_ButtonRelease || 240 xievent->evtype == XI_ButtonRelease ||
241 xievent->evtype == XI_Motion; 241 xievent->evtype == XI_Motion;
242 } 242 }
243 return false; 243 return false;
244 } 244 }
245 245
246 int GetMouseWheelOffset(const NativeEvent& native_event) { 246 int GetMouseWheelOffset(const base::NativeEvent& native_event) {
247 if (native_event->type == GenericEvent) { 247 if (native_event->type == GenericEvent) {
248 XIDeviceEvent* xiev = 248 XIDeviceEvent* xiev =
249 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 249 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
250 return xiev->detail == 4 ? kWheelScrollAmount : -kWheelScrollAmount; 250 return xiev->detail == 4 ? kWheelScrollAmount : -kWheelScrollAmount;
251 } 251 }
252 return native_event->xbutton.button == 4 ? 252 return native_event->xbutton.button == 4 ?
253 kWheelScrollAmount : -kWheelScrollAmount; 253 kWheelScrollAmount : -kWheelScrollAmount;
254 } 254 }
255 255
256 } // namespace ui 256 } // namespace ui
OLDNEW
« ui/base/events.h ('K') | « ui/base/win/events_win.cc ('k') | views/events/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698