blob: df6ffacc048a0972f40f54cf10ff46ca0fcd8d5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/events.h"
#include <X11/extensions/XInput2.h>
#include "base/logging.h"
#include "ui/base/keycodes/keyboard_code_conversion_x.h"
#include "ui/wayland/events/wayland_event.h"
#include "ui/gfx/point.h"
namespace {
// Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
static int kWheelScrollAmount = 53;
int GetEventFlagsFromState(unsigned int state) {
int flags = 0;
if (state & ControlMask)
flags |= ui::EF_CONTROL_DOWN;
if (state & ShiftMask)
flags |= ui::EF_SHIFT_DOWN;
if (state & Mod1Mask)
flags |= ui::EF_ALT_DOWN;
if (state & LockMask)
flags |= ui::EF_CAPS_LOCK_DOWN;
if (state & Button1Mask)
flags |= ui::EF_LEFT_BUTTON_DOWN;
if (state & Button2Mask)
flags |= ui::EF_MIDDLE_BUTTON_DOWN;
if (state & Button3Mask)
flags |= ui::EF_RIGHT_BUTTON_DOWN;
return flags;
}
int GetButtonEventFlagsFromNativeEvent(const base::NativeEvent& native_event) {
// TODO(dnicoara): Need to add double click.
int flags = 0;
switch (native_event->button.button) {
case ui::LEFT_BUTTON:
return flags | ui::EF_LEFT_BUTTON_DOWN;
case ui::MIDDLE_BUTTON:
return flags | ui::EF_MIDDLE_BUTTON_DOWN;
case ui::RIGHT_BUTTON:
return flags | ui::EF_RIGHT_BUTTON_DOWN;
}
return flags;
}
} // namespace
namespace ui {
EventType EventTypeFromNative(const base::NativeEvent& native_event) {
switch (native_event->type) {
case WAYLAND_BUTTON:
switch (native_event->button.button) {
case LEFT_BUTTON:
case RIGHT_BUTTON:
case MIDDLE_BUTTON:
return native_event->button.state ? ET_MOUSE_PRESSED
: ET_MOUSE_RELEASED;
case SCROLL_UP:
case SCROLL_DOWN:
return ET_MOUSEWHEEL;
default:
break;
}
break;
case WAYLAND_KEY:
return native_event->key.state ? ET_KEY_PRESSED : ET_KEY_RELEASED;
case WAYLAND_MOTION:
return ET_MOUSE_MOVED;
case WAYLAND_POINTER_FOCUS:
return native_event->pointer_focus.state ? ET_MOUSE_ENTERED
: ET_MOUSE_EXITED;
case WAYLAND_KEYBOARD_FOCUS:
return ET_UNKNOWN;
default:
break;
}
return ET_UNKNOWN;
}
int EventFlagsFromNative(const base::NativeEvent& native_event) {
switch (native_event->type) {
case WAYLAND_BUTTON:
return GetButtonEventFlagsFromNativeEvent(native_event) |
GetEventFlagsFromState(native_event->button.modifiers);
case WAYLAND_KEY:
return GetEventFlagsFromState(native_event->key.modifiers);
case WAYLAND_MOTION:
return GetEventFlagsFromState(native_event->motion.modifiers);
case WAYLAND_KEYBOARD_FOCUS:
return GetEventFlagsFromState(native_event->keyboard_focus.modifiers);
default:
return 0;
}
}
gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
switch (native_event->type) {
case WAYLAND_BUTTON:
return gfx::Point(native_event->button.x, native_event->button.y);
case WAYLAND_MOTION:
return gfx::Point(native_event->motion.x, native_event->motion.y);
case WAYLAND_POINTER_FOCUS:
return gfx::Point(native_event->pointer_focus.x,
native_event->pointer_focus.y);
default:
return gfx::Point();
}
}
KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
return KeyboardCodeFromXKeysym(native_event->key.sym);
}
bool IsMouseEvent(const base::NativeEvent& native_event) {
return native_event->type == WAYLAND_BUTTON ||
native_event->type == WAYLAND_MOTION ||
native_event->type == WAYLAND_POINTER_FOCUS;
}
int GetMouseWheelOffset(const base::NativeEvent& native_event) {
return native_event->button.button == ui::SCROLL_UP ?
kWheelScrollAmount : -kWheelScrollAmount;
}
} // namespace ui
|