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

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

Issue 10009024: Remove WAYLAND port (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 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 | « skia/skia.gyp ('k') | ui/gfx/gl/gl.gyp » ('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.h"
6
7 #include <linux/input.h>
8 #include <X11/extensions/XInput2.h>
9
10 #include "base/event_types.h"
11 #include "base/logging.h"
12 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
13 #include "ui/gfx/point.h"
14
15 using namespace base::wayland;
16
17 namespace ui {
18
19 // These are the mouse events expected. The event type Wayland sends is an
20 // evdev event. The following is the correct mapping from evdev to expected
21 // events type.
22 enum WaylandEventButtonType {
23 LEFT_BUTTON = BTN_LEFT,
24 MIDDLE_BUTTON = BTN_RIGHT,
25 RIGHT_BUTTON = BTN_MIDDLE,
26 SCROLL_UP = BTN_SIDE,
27 SCROLL_DOWN = BTN_EXTRA,
28 };
29
30 } // namespace ui
31
32 namespace {
33
34 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
35 static int kWheelScrollAmount = 53;
36
37 int GetEventFlagsFromState(unsigned int state) {
38 int flags = 0;
39 if (state & ControlMask)
40 flags |= ui::EF_CONTROL_DOWN;
41 if (state & ShiftMask)
42 flags |= ui::EF_SHIFT_DOWN;
43 if (state & Mod1Mask)
44 flags |= ui::EF_ALT_DOWN;
45 if (state & LockMask)
46 flags |= ui::EF_CAPS_LOCK_DOWN;
47 if (state & Button1Mask)
48 flags |= ui::EF_LEFT_MOUSE_BUTTON;
49 if (state & Button2Mask)
50 flags |= ui::EF_MIDDLE_MOUSE_BUTTON;
51 if (state & Button3Mask)
52 flags |= ui::EF_RIGHT_MOUSE_BUTTON;
53
54 return flags;
55 }
56
57 int GetButtonEventFlagsFromNativeEvent(const base::NativeEvent& native_event) {
58 // TODO(dnicoara): Need to add double click.
59 int flags = 0;
60 switch (native_event->button.button) {
61 case ui::LEFT_BUTTON:
62 return flags | ui::EF_LEFT_MOUSE_BUTTON;
63 case ui::MIDDLE_BUTTON:
64 return flags | ui::EF_MIDDLE_MOUSE_BUTTON;
65 case ui::RIGHT_BUTTON:
66 return flags | ui::EF_RIGHT_MOUSE_BUTTON;
67 }
68 return flags;
69 }
70
71 } // namespace
72
73 namespace ui {
74
75 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
76 switch (native_event->type) {
77 case WAYLAND_BUTTON:
78 switch (native_event->button.button) {
79 case LEFT_BUTTON:
80 case RIGHT_BUTTON:
81 case MIDDLE_BUTTON:
82 return native_event->button.state ? ET_MOUSE_PRESSED
83 : ET_MOUSE_RELEASED;
84 case SCROLL_UP:
85 case SCROLL_DOWN:
86 return ET_MOUSEWHEEL;
87 default:
88 break;
89 }
90 break;
91 case WAYLAND_KEY:
92 return native_event->key.state ? ET_KEY_PRESSED : ET_KEY_RELEASED;
93 case WAYLAND_MOTION:
94 return ET_MOUSE_MOVED;
95 case WAYLAND_POINTER_FOCUS:
96 return native_event->pointer_focus.state ? ET_MOUSE_ENTERED
97 : ET_MOUSE_EXITED;
98 case WAYLAND_KEYBOARD_FOCUS:
99 return ET_UNKNOWN;
100 default:
101 break;
102 }
103 return ET_UNKNOWN;
104 }
105
106 int EventFlagsFromNative(const base::NativeEvent& native_event) {
107 switch (native_event->type) {
108 case WAYLAND_BUTTON:
109 return GetButtonEventFlagsFromNativeEvent(native_event) |
110 GetEventFlagsFromState(native_event->button.modifiers);
111 case WAYLAND_KEY:
112 return GetEventFlagsFromState(native_event->key.modifiers);
113 case WAYLAND_MOTION:
114 return GetEventFlagsFromState(native_event->motion.modifiers);
115 case WAYLAND_KEYBOARD_FOCUS:
116 return GetEventFlagsFromState(native_event->keyboard_focus.modifiers);
117 default:
118 return 0;
119 }
120 }
121
122 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
123 switch (native_event->type) {
124 case WAYLAND_BUTTON:
125 return gfx::Point(native_event->button.x, native_event->button.y);
126 case WAYLAND_MOTION:
127 return gfx::Point(native_event->motion.x, native_event->motion.y);
128 case WAYLAND_POINTER_FOCUS:
129 return gfx::Point(native_event->pointer_focus.x,
130 native_event->pointer_focus.y);
131 default:
132 return gfx::Point();
133 }
134 }
135
136 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
137 return KeyboardCodeFromXKeysym(native_event->key.sym);
138 }
139
140 bool IsMouseEvent(const base::NativeEvent& native_event) {
141 return native_event->type == WAYLAND_BUTTON ||
142 native_event->type == WAYLAND_MOTION ||
143 native_event->type == WAYLAND_POINTER_FOCUS;
144 }
145
146 int GetMouseWheelOffset(const base::NativeEvent& native_event) {
147 return native_event->button.button == SCROLL_UP ?
148 kWheelScrollAmount : -kWheelScrollAmount;
149 }
150
151 } // namespace ui
OLDNEW
« no previous file with comments | « skia/skia.gyp ('k') | ui/gfx/gl/gl.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698