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

Side by Side Diff: ui/base/wayland/events_wayland.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 18 matching lines...) Expand all
29 if (state & Button1Mask) 29 if (state & Button1Mask)
30 flags |= ui::EF_LEFT_BUTTON_DOWN; 30 flags |= ui::EF_LEFT_BUTTON_DOWN;
31 if (state & Button2Mask) 31 if (state & Button2Mask)
32 flags |= ui::EF_MIDDLE_BUTTON_DOWN; 32 flags |= ui::EF_MIDDLE_BUTTON_DOWN;
33 if (state & Button3Mask) 33 if (state & Button3Mask)
34 flags |= ui::EF_RIGHT_BUTTON_DOWN; 34 flags |= ui::EF_RIGHT_BUTTON_DOWN;
35 35
36 return flags; 36 return flags;
37 } 37 }
38 38
39 int GetButtonEventFlagsFromNativeEvent(const ui::NativeEvent& native_event) { 39 int GetButtonEventFlagsFromNativeEvent(const base::NativeEvent& native_event) {
40 // TODO(dnicoara): Need to add double click. 40 // TODO(dnicoara): Need to add double click.
41 int flags = 0; 41 int flags = 0;
42 switch (native_event->button.button) { 42 switch (native_event->button.button) {
43 case ui::LEFT_BUTTON: 43 case ui::LEFT_BUTTON:
44 return flags | ui::EF_LEFT_BUTTON_DOWN; 44 return flags | ui::EF_LEFT_BUTTON_DOWN;
45 case ui::MIDDLE_BUTTON: 45 case ui::MIDDLE_BUTTON:
46 return flags | ui::EF_MIDDLE_BUTTON_DOWN; 46 return flags | ui::EF_MIDDLE_BUTTON_DOWN;
47 case ui::RIGHT_BUTTON: 47 case ui::RIGHT_BUTTON:
48 return flags | ui::EF_RIGHT_BUTTON_DOWN; 48 return flags | ui::EF_RIGHT_BUTTON_DOWN;
49 } 49 }
50 return flags; 50 return flags;
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 namespace ui { 55 namespace ui {
56 56
57 EventType EventTypeFromNative(const NativeEvent& native_event) { 57 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
58 switch (native_event->type) { 58 switch (native_event->type) {
59 case WAYLAND_BUTTON: 59 case WAYLAND_BUTTON:
60 switch (native_event->button.button) { 60 switch (native_event->button.button) {
61 case LEFT_BUTTON: 61 case LEFT_BUTTON:
62 case RIGHT_BUTTON: 62 case RIGHT_BUTTON:
63 case MIDDLE_BUTTON: 63 case MIDDLE_BUTTON:
64 return native_event->button.state ? ET_MOUSE_PRESSED 64 return native_event->button.state ? ET_MOUSE_PRESSED
65 : ET_MOUSE_RELEASED; 65 : ET_MOUSE_RELEASED;
66 case SCROLL_UP: 66 case SCROLL_UP:
67 case SCROLL_DOWN: 67 case SCROLL_DOWN:
(...skipping 10 matching lines...) Expand all
78 return native_event->pointer_focus.state ? ET_MOUSE_ENTERED 78 return native_event->pointer_focus.state ? ET_MOUSE_ENTERED
79 : ET_MOUSE_EXITED; 79 : ET_MOUSE_EXITED;
80 case WAYLAND_KEYBOARD_FOCUS: 80 case WAYLAND_KEYBOARD_FOCUS:
81 return ET_UNKNOWN; 81 return ET_UNKNOWN;
82 default: 82 default:
83 break; 83 break;
84 } 84 }
85 return ET_UNKNOWN; 85 return ET_UNKNOWN;
86 } 86 }
87 87
88 int EventFlagsFromNative(const NativeEvent& native_event) { 88 int EventFlagsFromNative(const base::NativeEvent& native_event) {
89 switch (native_event->type) { 89 switch (native_event->type) {
90 case WAYLAND_BUTTON: 90 case WAYLAND_BUTTON:
91 return GetButtonEventFlagsFromNativeEvent(native_event) | 91 return GetButtonEventFlagsFromNativeEvent(native_event) |
92 GetEventFlagsFromState(native_event->button.modifiers); 92 GetEventFlagsFromState(native_event->button.modifiers);
93 case WAYLAND_KEY: 93 case WAYLAND_KEY:
94 return GetEventFlagsFromState(native_event->key.modifiers); 94 return GetEventFlagsFromState(native_event->key.modifiers);
95 case WAYLAND_MOTION: 95 case WAYLAND_MOTION:
96 return GetEventFlagsFromState(native_event->motion.modifiers); 96 return GetEventFlagsFromState(native_event->motion.modifiers);
97 case WAYLAND_KEYBOARD_FOCUS: 97 case WAYLAND_KEYBOARD_FOCUS:
98 return GetEventFlagsFromState(native_event->keyboard_focus.modifiers); 98 return GetEventFlagsFromState(native_event->keyboard_focus.modifiers);
99 default: 99 default:
100 return 0; 100 return 0;
101 } 101 }
102 } 102 }
103 103
104 gfx::Point EventLocationFromNative(const NativeEvent& native_event) { 104 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
105 switch (native_event->type) { 105 switch (native_event->type) {
106 case WAYLAND_BUTTON: 106 case WAYLAND_BUTTON:
107 return gfx::Point(native_event->button.x, native_event->button.y); 107 return gfx::Point(native_event->button.x, native_event->button.y);
108 case WAYLAND_MOTION: 108 case WAYLAND_MOTION:
109 return gfx::Point(native_event->motion.x, native_event->motion.y); 109 return gfx::Point(native_event->motion.x, native_event->motion.y);
110 case WAYLAND_POINTER_FOCUS: 110 case WAYLAND_POINTER_FOCUS:
111 return gfx::Point(native_event->pointer_focus.x, 111 return gfx::Point(native_event->pointer_focus.x,
112 native_event->pointer_focus.y); 112 native_event->pointer_focus.y);
113 default: 113 default:
114 return gfx::Point(); 114 return gfx::Point();
115 } 115 }
116 } 116 }
117 117
118 KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) { 118 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
119 return KeyboardCodeFromXKeysym(native_event->key.sym); 119 return KeyboardCodeFromXKeysym(native_event->key.sym);
120 } 120 }
121 121
122 bool IsMouseEvent(const NativeEvent& native_event) { 122 bool IsMouseEvent(const base::NativeEvent& native_event) {
123 return native_event->type == WAYLAND_BUTTON || 123 return native_event->type == WAYLAND_BUTTON ||
124 native_event->type == WAYLAND_MOTION || 124 native_event->type == WAYLAND_MOTION ||
125 native_event->type == WAYLAND_POINTER_FOCUS; 125 native_event->type == WAYLAND_POINTER_FOCUS;
126 } 126 }
127 127
128 int GetMouseWheelOffset(const NativeEvent& native_event) { 128 int GetMouseWheelOffset(const base::NativeEvent& native_event) {
129 return native_event->button.button == ui::SCROLL_UP ? 129 return native_event->button.button == ui::SCROLL_UP ?
130 kWheelScrollAmount : -kWheelScrollAmount; 130 kWheelScrollAmount : -kWheelScrollAmount;
131 } 131 }
132 132
133 } // namespace ui 133 } // namespace ui
OLDNEW
« ui/base/events.h ('K') | « ui/base/events.h ('k') | ui/base/win/events_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698