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

Side by Side Diff: ui/base/wayland/events_wayland.cc

Issue 17265006: wayland patch for inspection Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/touch/touch_device_wayland.cc ('k') | ui/gfx/native_widget_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/base/events/event.h"
6 #include "ui/base/events/event_constants.h"
7
8 #include <linux/input.h>
9 #include <X11/extensions/XInput2.h>
10
11 #include "base/event_types.h"
12 #include "base/logging.h"
13 #include "base/time.h"
14 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
15 #include "ui/gfx/point.h"
16 #include "base/wayland/wayland_event.h"
17
18 using namespace base::wayland;
19
20 namespace ui {
21
22 // These are the mouse events expected. The event type Wayland sends is an
23 // evdev event. The following is the correct mapping from evdev to expected
24 // events type.
25 enum WaylandEventButtonType {
26 LEFT_BUTTON = BTN_LEFT,
27 MIDDLE_BUTTON = BTN_RIGHT,
28 RIGHT_BUTTON = BTN_MIDDLE,
29 SCROLL_UP = BTN_SIDE,
30 SCROLL_DOWN = BTN_EXTRA,
31 };
32
33 } // namespace ui
34
35 namespace {
36
37 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
38 static int kWheelScrollAmount = 53;
39
40 int GetEventFlagsFromState(unsigned int state) {
41 int flags = 0;
42 if (state & ControlMask)
43 flags |= ui::EF_CONTROL_DOWN;
44 if (state & ShiftMask)
45 flags |= ui::EF_SHIFT_DOWN;
46 if (state & Mod1Mask)
47 flags |= ui::EF_ALT_DOWN;
48 if (state & LockMask)
49 flags |= ui::EF_CAPS_LOCK_DOWN;
50 if (state & Button1Mask)
51 flags |= ui::EF_LEFT_MOUSE_BUTTON;
52 if (state & Button2Mask)
53 flags |= ui::EF_MIDDLE_MOUSE_BUTTON;
54 if (state & Button3Mask)
55 flags |= ui::EF_RIGHT_MOUSE_BUTTON;
56
57 return flags;
58 }
59
60 int GetButtonEventFlagsFromNativeEvent(const base::NativeEvent& native_event) {
61 // TODO(dnicoara): Need to add double click.
62 int flags = 0;
63 switch (native_event->button.button) {
64 case ui::LEFT_BUTTON:
65 return flags | ui::EF_LEFT_MOUSE_BUTTON;
66 case ui::MIDDLE_BUTTON:
67 return flags | ui::EF_MIDDLE_MOUSE_BUTTON;
68 case ui::RIGHT_BUTTON:
69 return flags | ui::EF_RIGHT_MOUSE_BUTTON;
70 }
71 return flags;
72 }
73
74 } // namespace
75
76 namespace ui {
77
78 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
79 switch (native_event->type) {
80 case WAYLAND_BUTTON:
81 switch (native_event->button.button) {
82 case LEFT_BUTTON:
83 case RIGHT_BUTTON:
84 case MIDDLE_BUTTON:
85 return native_event->button.state ? ET_MOUSE_PRESSED
86 : ET_MOUSE_RELEASED;
87 case SCROLL_UP:
88 case SCROLL_DOWN:
89 return ET_MOUSEWHEEL;
90 default:
91 break;
92 }
93 break;
94 case WAYLAND_KEY:
95 return native_event->key.state ? ET_KEY_PRESSED : ET_KEY_RELEASED;
96 case WAYLAND_MOTION:
97 return ET_MOUSE_MOVED;
98 case WAYLAND_POINTER_FOCUS:
99 return native_event->pointer_focus.state ? ET_MOUSE_ENTERED
100 : ET_MOUSE_EXITED;
101 case WAYLAND_KEYBOARD_FOCUS:
102 return ET_UNKNOWN;
103 default:
104 break;
105 }
106 return ET_UNKNOWN;
107 }
108
109 int EventFlagsFromNative(const base::NativeEvent& native_event) {
110 switch (native_event->type) {
111 case WAYLAND_BUTTON:
112 return GetButtonEventFlagsFromNativeEvent(native_event) |
113 GetEventFlagsFromState(native_event->button.modifiers);
114 case WAYLAND_KEY:
115 return GetEventFlagsFromState(native_event->key.modifiers);
116 case WAYLAND_MOTION:
117 return GetEventFlagsFromState(native_event->motion.modifiers);
118 case WAYLAND_KEYBOARD_FOCUS:
119 return GetEventFlagsFromState(native_event->keyboard_focus.modifiers);
120 default:
121 return 0;
122 }
123 }
124
125 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
126 switch (native_event->type) {
127 case WAYLAND_BUTTON:
128 return gfx::Point(native_event->button.x, native_event->button.y);
129 case WAYLAND_MOTION:
130 return gfx::Point(native_event->motion.x, native_event->motion.y);
131 case WAYLAND_POINTER_FOCUS:
132 return gfx::Point(native_event->pointer_focus.x,
133 native_event->pointer_focus.y);
134 default:
135 return gfx::Point();
136 }
137 }
138
139 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
140 return VKEY_UNKNOWN; // TODO: use KeyboardCodeFromXKeysym(native_event->key.sy m)
141 }
142
143 bool IsMouseEvent(const base::NativeEvent& native_event) {
144 return native_event->type == WAYLAND_BUTTON ||
145 native_event->type == WAYLAND_MOTION ||
146 native_event->type == WAYLAND_POINTER_FOCUS;
147 }
148
149 int GetChangedMouseButtonFlagsFromNative(
150 const base::NativeEvent& native_event) {
151 return 0;
152 }
153
154 int GetMouseWheelOffset(const base::NativeEvent& native_event) {
155 return native_event->button.button == SCROLL_UP ?
156 kWheelScrollAmount : -kWheelScrollAmount;
157 }
158
159 int GetTouchId(const base::NativeEvent& wev) {
160 return 0;
161 }
162
163 float GetTouchRadiusX(const base::NativeEvent& native_event) {
164 return 0.0;
165 }
166
167 float GetTouchRadiusY(const base::NativeEvent& native_event) {
168 return 0.0;
169 }
170
171 float GetTouchAngle(const base::NativeEvent& native_event) {
172 return 0.0;
173 }
174
175 float GetTouchForce(const base::NativeEvent& native_event) {
176 return 0.0;
177 }
178
179 bool GetScrollOffsets(const base::NativeEvent& native_event,
180 float* x_offset,
181 float* y_offset,
182 float* x_offset_ordinal,
183 float* y_offset_ordinal,
184 int* finger_count) {
185 return false;
186 }
187
188 bool GetFlingData(const base::NativeEvent& native_event,
189 float* vx,
190 float* vy,
191 float* vx_ordinal,
192 float* vy_ordinal,
193 bool* is_cancel) {
194 return false;
195 }
196
197 bool GetGestureTimes(const base::NativeEvent& native_event,
198 double* start_time,
199 double* end_time) {
200 return false;
201 }
202
203 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
204 return base::TimeDelta();
205 }
206
207 base::NativeEvent CreateNoopEvent() {
208 return NULL;
209 }
210
211 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/touch/touch_device_wayland.cc ('k') | ui/gfx/native_widget_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698