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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/wayland/events_wayland.cc
diff --git a/ui/base/wayland/events_wayland.cc b/ui/base/wayland/events_wayland.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d07619de6e6d5d4ce88d3ce9ca1f357897cdf45a
--- /dev/null
+++ b/ui/base/wayland/events_wayland.cc
@@ -0,0 +1,211 @@
+// 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/event.h"
+#include "ui/base/events/event_constants.h"
+
+#include <linux/input.h>
+#include <X11/extensions/XInput2.h>
+
+#include "base/event_types.h"
+#include "base/logging.h"
+#include "base/time.h"
+#include "ui/base/keycodes/keyboard_code_conversion_x.h"
+#include "ui/gfx/point.h"
+#include "base/wayland/wayland_event.h"
+
+using namespace base::wayland;
+
+namespace ui {
+
+// These are the mouse events expected. The event type Wayland sends is an
+// evdev event. The following is the correct mapping from evdev to expected
+// events type.
+enum WaylandEventButtonType {
+ LEFT_BUTTON = BTN_LEFT,
+ MIDDLE_BUTTON = BTN_RIGHT,
+ RIGHT_BUTTON = BTN_MIDDLE,
+ SCROLL_UP = BTN_SIDE,
+ SCROLL_DOWN = BTN_EXTRA,
+};
+
+} // namespace ui
+
+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_MOUSE_BUTTON;
+ if (state & Button2Mask)
+ flags |= ui::EF_MIDDLE_MOUSE_BUTTON;
+ if (state & Button3Mask)
+ flags |= ui::EF_RIGHT_MOUSE_BUTTON;
+
+ 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_MOUSE_BUTTON;
+ case ui::MIDDLE_BUTTON:
+ return flags | ui::EF_MIDDLE_MOUSE_BUTTON;
+ case ui::RIGHT_BUTTON:
+ return flags | ui::EF_RIGHT_MOUSE_BUTTON;
+ }
+ 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 VKEY_UNKNOWN; // TODO: use 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 GetChangedMouseButtonFlagsFromNative(
+ const base::NativeEvent& native_event) {
+ return 0;
+}
+
+int GetMouseWheelOffset(const base::NativeEvent& native_event) {
+ return native_event->button.button == SCROLL_UP ?
+ kWheelScrollAmount : -kWheelScrollAmount;
+}
+
+int GetTouchId(const base::NativeEvent& wev) {
+ return 0;
+}
+
+float GetTouchRadiusX(const base::NativeEvent& native_event) {
+ return 0.0;
+}
+
+float GetTouchRadiusY(const base::NativeEvent& native_event) {
+ return 0.0;
+}
+
+float GetTouchAngle(const base::NativeEvent& native_event) {
+ return 0.0;
+}
+
+float GetTouchForce(const base::NativeEvent& native_event) {
+ return 0.0;
+}
+
+bool GetScrollOffsets(const base::NativeEvent& native_event,
+ float* x_offset,
+ float* y_offset,
+ float* x_offset_ordinal,
+ float* y_offset_ordinal,
+ int* finger_count) {
+ return false;
+}
+
+bool GetFlingData(const base::NativeEvent& native_event,
+ float* vx,
+ float* vy,
+ float* vx_ordinal,
+ float* vy_ordinal,
+ bool* is_cancel) {
+ return false;
+}
+
+bool GetGestureTimes(const base::NativeEvent& native_event,
+ double* start_time,
+ double* end_time) {
+ return false;
+}
+
+base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
+ return base::TimeDelta();
+}
+
+base::NativeEvent CreateNoopEvent() {
+ return NULL;
+}
+
+} // namespace ui
« 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