| Index: ui/events/x/events_x.cc
|
| diff --git a/ui/events/x/events_x.cc b/ui/events/x/events_x.cc
|
| index 301431655a32b2b6abf4291b91cebe079d2da7d0..dc4400c9fd3ac63cd63c50c56b066b260f42fb7a 100644
|
| --- a/ui/events/x/events_x.cc
|
| +++ b/ui/events/x/events_x.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "ui/events/event_constants.h"
|
| +#include "ui/events/x/events_x.h"
|
|
|
| #include <cmath>
|
| #include <string.h>
|
| @@ -27,6 +27,12 @@
|
| #include "ui/gfx/x/x11_atom_cache.h"
|
| #include "ui/gfx/x/x11_types.h"
|
|
|
| +#if defined(USE_OZONE)
|
| +#include "ui/ozone/platform/x11/x11_surface_factory.h"
|
| +#endif
|
| +
|
| +#include "ui/platform_window/x11/x11_window.h"
|
| +
|
| namespace {
|
|
|
| // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
|
| @@ -59,7 +65,7 @@ class XModifierStateWatcher{
|
| }
|
| }
|
|
|
| - void UpdateStateFromXEvent(const base::NativeEvent& native_event) {
|
| + void UpdateStateFromXEvent(const XEvent* native_event) {
|
| ui::KeyboardCode keyboard_code = ui::KeyboardCodeFromNative(native_event);
|
| unsigned int mask = StateFromKeyboardCode(keyboard_code);
|
| // Floating device can't access the modifer state from master device.
|
| @@ -113,7 +119,7 @@ class XModifierStateWatcher{
|
| // A 'special event' is a touch event with maximum radius and pressure at
|
| // location (0, 0).
|
| // This needs to be done in a cleaner way: http://crbug.com/169256
|
| -bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) {
|
| +bool TouchEventIsGeneratedHack(const XEvent* native_event) {
|
| XIDeviceEvent* event =
|
| static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| CHECK(event->evtype == XI_TouchBegin ||
|
| @@ -164,7 +170,7 @@ int GetEventFlagsFromXState(unsigned int state) {
|
| return flags;
|
| }
|
|
|
| -int GetEventFlagsFromXKeyEvent(XEvent* xevent) {
|
| +int GetEventFlagsFromXKeyEvent(const XEvent* xevent) {
|
| DCHECK(xevent->type == KeyPress || xevent->type == KeyRelease);
|
|
|
| #if defined(OS_CHROMEOS)
|
| @@ -187,17 +193,18 @@ int GetEventFlagsFromXKeyEvent(XEvent* xevent) {
|
| fabricated_by_xim ? ui::EF_IME_FABRICATED_KEY : 0;
|
| #endif
|
|
|
| + KeySym key = XLookupKeysym(const_cast<XKeyEvent*>(&xevent->xkey), 0);
|
| +
|
| return GetEventFlagsFromXState(xevent->xkey.state) |
|
| - (xevent->xkey.send_event ? ui::EF_FINAL : 0) |
|
| - (IsKeypadKey(XLookupKeysym(&xevent->xkey, 0)) ? ui::EF_NUMPAD_KEY : 0) |
|
| - (IsFunctionKey(XLookupKeysym(&xevent->xkey, 0)) ?
|
| - ui::EF_FUNCTION_KEY : 0) |
|
| - ime_fabricated_flag;
|
| + (xevent->xkey.send_event ? ui::EF_FINAL : 0) |
|
| + (IsKeypadKey(key) ? ui::EF_NUMPAD_KEY : 0) |
|
| + (IsFunctionKey(key) ? ui::EF_FUNCTION_KEY : 0) | ime_fabricated_flag;
|
| }
|
|
|
| -int GetEventFlagsFromXGenericEvent(XEvent* xevent) {
|
| +int GetEventFlagsFromXGenericEvent(const XEvent* xevent) {
|
| DCHECK(xevent->type == GenericEvent);
|
| - XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data);
|
| + const XIDeviceEvent* xievent =
|
| + static_cast<const XIDeviceEvent*>(xevent->xcookie.data);
|
| DCHECK((xievent->evtype == XI_KeyPress) ||
|
| (xievent->evtype == XI_KeyRelease));
|
| return GetEventFlagsFromXState(xievent->mods.effective) |
|
| @@ -241,7 +248,7 @@ int GetButtonMaskForX2Event(XIDeviceEvent* xievent) {
|
| return buttonflags;
|
| }
|
|
|
| -ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
|
| +ui::EventType GetTouchEventType(const XEvent* native_event) {
|
| XIDeviceEvent* event =
|
| static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| switch(event->evtype) {
|
| @@ -275,21 +282,22 @@ ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
|
| return ui::ET_UNKNOWN;
|
| }
|
|
|
| -double GetTouchParamFromXEvent(XEvent* xev,
|
| - ui::DeviceDataManagerX11::DataType val,
|
| - double default_value) {
|
| +double GetTouchParamFromXEvent(const XEvent* xev,
|
| + ui::DeviceDataManagerX11::DataType val,
|
| + double default_value) {
|
| ui::DeviceDataManagerX11::GetInstance()->GetEventData(
|
| *xev, val, &default_value);
|
| return default_value;
|
| }
|
|
|
| -void ScaleTouchRadius(XEvent* xev, double* radius) {
|
| +void ScaleTouchRadius(const XEvent* xev, double* radius) {
|
| DCHECK_EQ(GenericEvent, xev->type);
|
| XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data);
|
| ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale(
|
| xiev->sourceid, radius);
|
| }
|
|
|
| +#if defined(USE_X11)
|
| unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) {
|
| static struct {
|
| int ui;
|
| @@ -330,8 +338,9 @@ unsigned int UpdateX11EventButton(int ui_flag, unsigned int old_x_button) {
|
| }
|
| NOTREACHED();
|
| }
|
| +#endif
|
|
|
| -bool GetGestureTimes(const base::NativeEvent& native_event,
|
| +bool GetGestureTimes(const XEvent* native_event,
|
| double* start_time,
|
| double* end_time) {
|
| if (!ui::DeviceDataManagerX11::GetInstance()->HasGestureTimes(native_event))
|
| @@ -359,7 +368,7 @@ void UpdateDeviceList() {
|
| DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display);
|
| }
|
|
|
| -EventType EventTypeFromNative(const base::NativeEvent& native_event) {
|
| +EventType EventTypeFromNative(const XEvent* native_event) {
|
| // Allow the DeviceDataManager to block the event. If blocked return
|
| // ET_UNKNOWN as the type so this event will not be further processed.
|
| // NOTE: During some events unittests there is no device data manager.
|
| @@ -458,7 +467,7 @@ EventType EventTypeFromNative(const base::NativeEvent& native_event) {
|
| return ET_UNKNOWN;
|
| }
|
|
|
| -int EventFlagsFromNative(const base::NativeEvent& native_event) {
|
| +int EventFlagsFromNative(const XEvent* native_event) {
|
| switch (native_event->type) {
|
| case KeyPress:
|
| case KeyRelease: {
|
| @@ -523,7 +532,7 @@ int EventFlagsFromNative(const base::NativeEvent& native_event) {
|
| return 0;
|
| }
|
|
|
| -base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
|
| +base::TimeDelta EventTimeFromNative(const XEvent* native_event) {
|
| switch(native_event->type) {
|
| case KeyPress:
|
| case KeyRelease:
|
| @@ -562,7 +571,7 @@ base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
|
| return base::TimeDelta();
|
| }
|
|
|
| -gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
|
| +gfx::Point EventLocationFromNative(const XEvent* native_event) {
|
| switch (native_event->type) {
|
| case EnterNotify:
|
| case LeaveNotify:
|
| @@ -595,8 +604,7 @@ gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
|
| return gfx::Point();
|
| }
|
|
|
| -gfx::Point EventSystemLocationFromNative(
|
| - const base::NativeEvent& native_event) {
|
| +gfx::Point EventSystemLocationFromNative(const XEvent* native_event) {
|
| switch (native_event->type) {
|
| case EnterNotify:
|
| case LeaveNotify: {
|
| @@ -622,7 +630,7 @@ gfx::Point EventSystemLocationFromNative(
|
| return gfx::Point();
|
| }
|
|
|
| -int EventButtonFromNative(const base::NativeEvent& native_event) {
|
| +int EventButtonFromNative(const XEvent* native_event) {
|
| CHECK_EQ(GenericEvent, native_event->type);
|
| XIDeviceEvent* xievent =
|
| static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| @@ -632,16 +640,16 @@ int EventButtonFromNative(const base::NativeEvent& native_event) {
|
| DeviceDataManagerX11::GetInstance()->GetMappedButton(button) : button;
|
| }
|
|
|
| -KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
|
| +KeyboardCode KeyboardCodeFromNative(const XEvent* native_event) {
|
| return KeyboardCodeFromXKeyEvent(native_event);
|
| }
|
|
|
| -DomCode CodeFromNative(const base::NativeEvent& native_event) {
|
| +DomCode CodeFromNative(const XEvent* native_event) {
|
| return CodeFromXEvent(native_event);
|
| }
|
|
|
| -uint32 PlatformKeycodeFromNative(const base::NativeEvent& native_event) {
|
| - XKeyEvent* xkey = NULL;
|
| +uint32 PlatformKeycodeFromNative(const XEvent* native_event) {
|
| + const XKeyEvent* xkey = NULL;
|
| XEvent xkey_from_xi2;
|
| switch (native_event->type) {
|
| case KeyPress:
|
| @@ -671,16 +679,15 @@ uint32 PlatformKeycodeFromNative(const base::NativeEvent& native_event) {
|
| }
|
| KeySym keysym = XK_VoidSymbol;
|
| if (xkey)
|
| - XLookupString(xkey, NULL, 0, &keysym, NULL);
|
| + XLookupString(const_cast<XKeyEvent*>(xkey), NULL, 0, &keysym, NULL);
|
| return keysym;
|
| }
|
|
|
| -bool IsCharFromNative(const base::NativeEvent& native_event) {
|
| +bool IsCharFromNative(const XEvent* native_event) {
|
| return false;
|
| }
|
|
|
| -int GetChangedMouseButtonFlagsFromNative(
|
| - const base::NativeEvent& native_event) {
|
| +int GetChangedMouseButtonFlagsFromNative(const XEvent* native_event) {
|
| switch (native_event->type) {
|
| case ButtonPress:
|
| case ButtonRelease:
|
| @@ -702,7 +709,7 @@ int GetChangedMouseButtonFlagsFromNative(
|
| return 0;
|
| }
|
|
|
| -gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) {
|
| +gfx::Vector2d GetMouseWheelOffset(const XEvent* native_event) {
|
| float x_offset, y_offset;
|
| if (GetScrollOffsets(
|
| native_event, &x_offset, &y_offset, NULL, NULL, NULL)) {
|
| @@ -727,7 +734,7 @@ gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) {
|
| }
|
| }
|
|
|
| -base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
|
| +XEvent* CopyNativeEvent(const XEvent* event) {
|
| if (!event || event->type == GenericEvent)
|
| return NULL;
|
| XEvent* copy = new XEvent;
|
| @@ -735,11 +742,11 @@ base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
|
| return copy;
|
| }
|
|
|
| -void ReleaseCopiedNativeEvent(const base::NativeEvent& event) {
|
| +void ReleaseCopiedNativeEvent(const XEvent* event) {
|
| delete event;
|
| }
|
|
|
| -void IncrementTouchIdRefCount(const base::NativeEvent& xev) {
|
| +void IncrementTouchIdRefCount(const XEvent* xev) {
|
| ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
|
| double tracking_id;
|
| if (!manager->GetEventData(
|
| @@ -751,7 +758,7 @@ void IncrementTouchIdRefCount(const base::NativeEvent& xev) {
|
| factory->AcquireSlotForTrackingID(tracking_id);
|
| }
|
|
|
| -void ClearTouchIdIfReleased(const base::NativeEvent& xev) {
|
| +void ClearTouchIdIfReleased(const XEvent* xev) {
|
| ui::EventType type = ui::EventTypeFromNative(xev);
|
| if (type == ui::ET_TOUCH_CANCELLED ||
|
| type == ui::ET_TOUCH_RELEASED) {
|
| @@ -765,7 +772,7 @@ void ClearTouchIdIfReleased(const base::NativeEvent& xev) {
|
| }
|
| }
|
|
|
| -int GetTouchId(const base::NativeEvent& xev) {
|
| +int GetTouchId(const XEvent* xev) {
|
| double slot = 0;
|
| ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
|
| double tracking_id;
|
| @@ -779,26 +786,26 @@ int GetTouchId(const base::NativeEvent& xev) {
|
| return slot;
|
| }
|
|
|
| -float GetTouchRadiusX(const base::NativeEvent& native_event) {
|
| +float GetTouchRadiusX(const XEvent* native_event) {
|
| double radius = GetTouchParamFromXEvent(native_event,
|
| ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) / 2.0;
|
| ScaleTouchRadius(native_event, &radius);
|
| return radius;
|
| }
|
|
|
| -float GetTouchRadiusY(const base::NativeEvent& native_event) {
|
| +float GetTouchRadiusY(const XEvent* native_event) {
|
| double radius = GetTouchParamFromXEvent(native_event,
|
| ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) / 2.0;
|
| ScaleTouchRadius(native_event, &radius);
|
| return radius;
|
| }
|
|
|
| -float GetTouchAngle(const base::NativeEvent& native_event) {
|
| +float GetTouchAngle(const XEvent* native_event) {
|
| return GetTouchParamFromXEvent(native_event,
|
| ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.0) / 2.0;
|
| }
|
|
|
| -float GetTouchForce(const base::NativeEvent& native_event) {
|
| +float GetTouchForce(const XEvent* native_event) {
|
| double force = 0.0;
|
| force = GetTouchParamFromXEvent(native_event,
|
| ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0);
|
| @@ -811,7 +818,7 @@ float GetTouchForce(const base::NativeEvent& native_event) {
|
| return force;
|
| }
|
|
|
| -bool GetScrollOffsets(const base::NativeEvent& native_event,
|
| +bool GetScrollOffsets(const XEvent* native_event,
|
| float* x_offset,
|
| float* y_offset,
|
| float* x_offset_ordinal,
|
| @@ -843,7 +850,7 @@ bool GetScrollOffsets(const base::NativeEvent& native_event,
|
| return true;
|
| }
|
|
|
| -bool GetFlingData(const base::NativeEvent& native_event,
|
| +bool GetFlingData(const XEvent* native_event,
|
| float* vx,
|
| float* vy,
|
| float* vx_ordinal,
|
| @@ -871,6 +878,7 @@ bool GetFlingData(const base::NativeEvent& native_event,
|
| return true;
|
| }
|
|
|
| +#if defined(USE_X11)
|
| void UpdateX11EventForFlags(Event* event) {
|
| XEvent* xev = event->native_event();
|
| if (!xev)
|
| @@ -919,5 +927,124 @@ void UpdateX11EventForChangedButtonFlags(MouseEvent* event) {
|
| break;
|
| }
|
| }
|
| +#endif
|
| +
|
| +#if defined(USE_OZONE) && !defined(USE_X11)
|
| +
|
| +base::NativeEvent TranslateXI2Event(XEvent* xev) {
|
| + XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
|
| + EventType event_type = EventTypeFromNative(xev);
|
| + gfx::PointF location = gfx::PointF(xievent->event_x, xievent->event_y);
|
| + gfx::PointF root_location = gfx::PointF(xievent->root_x, xievent->root_y);
|
| + int flags = EventFlagsFromNative(xev);
|
| + switch (event_type) {
|
| + case ET_KEY_PRESSED:
|
| + case ET_KEY_RELEASED:
|
| + return new KeyEvent(event_type, KeyboardCodeFromNative(xev), flags);
|
| + case ET_MOUSE_PRESSED:
|
| + case ET_MOUSE_MOVED:
|
| + case ET_MOUSE_DRAGGED:
|
| + case ET_MOUSE_RELEASED:
|
| + return new MouseEvent(event_type, location, root_location, flags,
|
| + GetChangedMouseButtonFlagsFromNative(xev));
|
| + case ET_MOUSEWHEEL:
|
| + return new MouseWheelEvent(GetMouseWheelOffset(xev), location,
|
| + root_location, flags,
|
| + GetChangedMouseButtonFlagsFromNative(xev));
|
| + case ET_SCROLL_FLING_START:
|
| + case ET_SCROLL_FLING_CANCEL: {
|
| + float x_offset, y_offset, x_offset_ordinal, y_offset_ordinal;
|
| + GetFlingData(xev, &x_offset, &y_offset, &x_offset_ordinal,
|
| + &y_offset_ordinal, nullptr);
|
| + return new ScrollEvent(event_type, location, EventTimeFromNative(xev),
|
| + flags, x_offset, y_offset, x_offset_ordinal,
|
| + y_offset_ordinal, 0);
|
| + }
|
| + case ET_SCROLL: {
|
| + float x_offset, y_offset, x_offset_ordinal, y_offset_ordinal;
|
| + int finger_count;
|
| + GetScrollOffsets(xev, &x_offset, &y_offset, &x_offset_ordinal,
|
| + &y_offset_ordinal, &finger_count);
|
| + return new ScrollEvent(event_type, location, EventTimeFromNative(xev),
|
| + flags, x_offset, y_offset, x_offset_ordinal,
|
| + y_offset_ordinal, finger_count);
|
| + }
|
| + case ET_TOUCH_MOVED:
|
| + case ET_TOUCH_PRESSED:
|
| + case ET_TOUCH_CANCELLED:
|
| + case ET_TOUCH_RELEASED:
|
| + return new TouchEvent(event_type, location, GetTouchId(xev),
|
| + EventTimeFromNative(xev));
|
| + case ET_UNKNOWN:
|
| + return nullptr;
|
| + default:
|
| + break;
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| +base::NativeEvent TranslateXEventToNativeEvent(XEvent* xev) {
|
| + int flags = EventFlagsFromNative(xev);
|
| + switch (xev->type) {
|
| + case LeaveNotify:
|
| + case EnterNotify:
|
| + // EnterNotify creates ET_MOUSE_MOVED. Mark as synthesized as this is
|
| + // not real mouse move event.
|
| + // int flags = GetEventFlagsFromXState(xev->xcrossing.state);
|
| + if (xev->type == EnterNotify)
|
| + flags |= EF_IS_SYNTHESIZED;
|
| + return new MouseEvent(
|
| + ET_MOUSE_MOVED, gfx::PointF(xev->xcrossing.x, xev->xcrossing.y),
|
| + gfx::PointF(xev->xcrossing.x_root, xev->xcrossing.y_root), flags, 0);
|
| +
|
| + case KeyPress:
|
| + case KeyRelease:
|
| + return new KeyEvent(EventTypeFromNative(xev), KeyboardCodeFromNative(xev),
|
| + flags);
|
| +
|
| + case ButtonPress:
|
| + case ButtonRelease: {
|
| + gfx::PointF location = gfx::PointF(xev->xbutton.x, xev->xbutton.y);
|
| + gfx::PointF root_location =
|
| + gfx::PointF(xev->xbutton.x_root, xev->xbutton.y_root);
|
| + switch (EventTypeFromNative(xev)) {
|
| + case ET_MOUSEWHEEL:
|
| + return new MouseWheelEvent(GetMouseWheelOffset(xev), location,
|
| + root_location, flags, 0);
|
| + case ET_MOUSE_PRESSED:
|
| + case ET_MOUSE_RELEASED:
|
| + return new MouseEvent(EventTypeFromNative(xev), location,
|
| + root_location, flags,
|
| + GetChangedMouseButtonFlagsFromNative(xev));
|
| + case ET_UNKNOWN:
|
| + // No event is created for X11-release events for mouse-wheel
|
| + // buttons.
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| + break;
|
| + }
|
| +
|
| + case FocusOut:
|
| + case Expose:
|
| + case ConfigureNotify:
|
| + case ClientMessage: {
|
| + // This is a windowing message that needs to be passed to the platform
|
| + // window directly.
|
| + X11Window* window =
|
| + static_cast<X11SurfaceFactory*>(SurfaceFactoryOzone::GetInstance())
|
| + ->FindWindow(xev->xany.window);
|
| + if (window)
|
| + window->ProcessWindowEvent(xev);
|
| + return nullptr;
|
| + }
|
| +
|
| + case GenericEvent:
|
| + return TranslateXI2Event(xev);
|
| + }
|
| + return nullptr;
|
| +}
|
| +#endif
|
|
|
| } // namespace ui
|
|
|