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

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

Issue 7942004: Consolidate/cleanup event cracking code; single out GdkEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge removal of compact nav. 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
« no previous file with comments | « ui/base/touch/touch_factory.cc ('k') | ui/base/win/events_win.cc » ('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 <X11/extensions/XInput2.h>
8
9 #include "base/logging.h"
10 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
11 #include "ui/wayland/events/wayland_event.h"
12 #include "ui/gfx/point.h"
13
14 namespace {
15
16 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
17 static int kWheelScrollAmount = 53;
18
19 int GetEventFlagsFromState(unsigned int state) {
20 int flags = 0;
21 if (state & ControlMask)
22 flags |= ui::EF_CONTROL_DOWN;
23 if (state & ShiftMask)
24 flags |= ui::EF_SHIFT_DOWN;
25 if (state & Mod1Mask)
26 flags |= ui::EF_ALT_DOWN;
27 if (state & LockMask)
28 flags |= ui::EF_CAPS_LOCK_DOWN;
29 if (state & Button1Mask)
30 flags |= ui::EF_LEFT_BUTTON_DOWN;
31 if (state & Button2Mask)
32 flags |= ui::EF_MIDDLE_BUTTON_DOWN;
33 if (state & Button3Mask)
34 flags |= ui::EF_RIGHT_BUTTON_DOWN;
35
36 return flags;
37 }
38
39 int GetButtonEventFlagsFromNativeEvent(const ui::NativeEvent& native_event) {
40 // TODO(dnicoara): Need to add double click.
41 int flags = 0;
42 switch (native_event->button.button) {
43 case ui::LEFT_BUTTON:
44 return flags | ui::EF_LEFT_BUTTON_DOWN;
45 case ui::MIDDLE_BUTTON:
46 return flags | ui::EF_MIDDLE_BUTTON_DOWN;
47 case ui::RIGHT_BUTTON:
48 return flags | ui::EF_RIGHT_BUTTON_DOWN;
49 }
50 return flags;
51 }
52
53 } // namespace
54
55 namespace ui {
56
57 EventType EventTypeFromNative(const NativeEvent& native_event) {
58 switch (native_event->type) {
59 case WAYLAND_BUTTON:
60 switch (native_event->button.button) {
61 case LEFT_BUTTON:
62 case RIGHT_BUTTON:
63 case MIDDLE_BUTTON:
64 return native_event->button.state ? ET_MOUSE_PRESSED
65 : ET_MOUSE_RELEASED;
66 case SCROLL_UP:
67 case SCROLL_DOWN:
68 return ET_MOUSEWHEEL;
69 default:
70 break;
71 }
72 break;
73 case WAYLAND_KEY:
74 return native_event->key.state ? ET_KEY_PRESSED : ET_KEY_RELEASED;
75 case WAYLAND_MOTION:
76 return ET_MOUSE_MOVED;
77 case WAYLAND_POINTER_FOCUS:
78 return native_event->pointer_focus.state ? ET_MOUSE_ENTERED
79 : ET_MOUSE_EXITED;
80 case WAYLAND_KEYBOARD_FOCUS:
81 return ET_UNKNOWN;
82 default:
83 break;
84 }
85 return ET_UNKNOWN;
86 }
87
88 int EventFlagsFromNative(const NativeEvent& native_event) {
89 switch (native_event->type) {
90 case WAYLAND_BUTTON:
91 return GetButtonEventFlagsFromNativeEvent(native_event) |
92 GetEventFlagsFromState(native_event->button.modifiers);
93 case WAYLAND_KEY:
94 return GetEventFlagsFromState(native_event->key.modifiers);
95 case WAYLAND_MOTION:
96 return GetEventFlagsFromState(native_event->motion.modifiers);
97 case WAYLAND_KEYBOARD_FOCUS:
98 return GetEventFlagsFromState(native_event->keyboard_focus.modifiers);
99 default:
100 return 0;
101 }
102 }
103
104 gfx::Point EventLocationFromNative(const NativeEvent& native_event) {
105 switch (native_event->type) {
106 case WAYLAND_BUTTON:
107 return gfx::Point(native_event->button.x, native_event->button.y);
108 case WAYLAND_MOTION:
109 return gfx::Point(native_event->motion.x, native_event->motion.y);
110 case WAYLAND_POINTER_FOCUS:
111 return gfx::Point(native_event->pointer_focus.x,
112 native_event->pointer_focus.y);
113 default:
114 return gfx::Point();
115 }
116 }
117
118 KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) {
119 return KeyboardCodeFromXKeysym(native_event->key.sym);
120 }
121
122 bool IsMouseEvent(const NativeEvent& native_event) {
123 return native_event->type == WAYLAND_BUTTON ||
124 native_event->type == WAYLAND_MOTION ||
125 native_event->type == WAYLAND_POINTER_FOCUS;
126 }
127
128 int GetMouseWheelOffset(const NativeEvent& native_event) {
129 return native_event->button.button == ui::SCROLL_UP ?
130 kWheelScrollAmount : -kWheelScrollAmount;
131 }
132
133 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/touch/touch_factory.cc ('k') | ui/base/win/events_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698