Commit f02dbfca authored by Nicholas Hollingum's avatar Nicholas Hollingum Committed by Commit Bot

Use set MouseEvent.movement() on CrOS with ordinal_movement

MouseEvent.movement() stores the platoform-dependant "Raw mouse motion"
values, as reported by hardware. It is currently only available on
windows. Support for the value is indicated by the presence of the flag
EF_UNADJUSTED_MOUSE.

In this CL, we add support for this on CrOS. We intend to use this in
order to improve the relative pointer handling in Exo, which requires
unaccelerated mouse motion (and currently we only have access to
accelerated motion).

This change is only implemented for CrOS (for now) because:
 1) previously it was only implemented for windows, so cross-platform
    is not a hard requirement.
 2) For our use case, the intended user is zwp_relative_pointer.cc,
    which is only compiled for CrOS.

Bug: 957455
Change-Id: I9b6ca1740dcfb6aaba60c32f268270b3b0d386a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2277694Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Nic Hollingum <hollingum@google.com>
Cr-Commit-Position: refs/heads/master@{#804117}
parent 091b9c32
...@@ -469,6 +469,9 @@ std::string LocatedEvent::ToString() const { ...@@ -469,6 +469,9 @@ std::string LocatedEvent::ToString() const {
MouseEvent::MouseEvent(const PlatformEvent& native_event) MouseEvent::MouseEvent(const PlatformEvent& native_event)
: LocatedEvent(native_event), : LocatedEvent(native_event),
changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)),
#if defined(OS_CHROMEOS) || defined(OS_LINUX)
movement_(GetMouseMovementFromNative(native_event)),
#endif
pointer_details_(GetMousePointerDetailsFromNative(native_event)) { pointer_details_(GetMousePointerDetailsFromNative(native_event)) {
latency()->set_source_event_type(SourceEventType::MOUSE); latency()->set_source_event_type(SourceEventType::MOUSE);
latency()->AddLatencyNumberWithTimestamp( latency()->AddLatencyNumberWithTimestamp(
......
...@@ -433,6 +433,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { ...@@ -433,6 +433,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
MouseEvent(const MouseEvent& model, T* source, T* target) MouseEvent(const MouseEvent& model, T* source, T* target)
: LocatedEvent(model, source, target), : LocatedEvent(model, source, target),
changed_button_flags_(model.changed_button_flags_), changed_button_flags_(model.changed_button_flags_),
movement_(model.movement_),
pointer_details_(model.pointer_details_) {} pointer_details_(model.pointer_details_) {}
template <class T> template <class T>
...@@ -443,6 +444,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { ...@@ -443,6 +444,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
int flags) int flags)
: LocatedEvent(model, source, target), : LocatedEvent(model, source, target),
changed_button_flags_(model.changed_button_flags_), changed_button_flags_(model.changed_button_flags_),
movement_(model.movement_),
pointer_details_(model.pointer_details_) { pointer_details_(model.pointer_details_) {
SetType(type); SetType(type);
set_flags(flags); set_flags(flags);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/dom_code.h" #include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h" #include "ui/events/keycodes/dom/keycode_converter.h"
...@@ -799,6 +800,36 @@ TEST(EventTest, MouseWheelEventLinearTickCalculation) { ...@@ -799,6 +800,36 @@ TEST(EventTest, MouseWheelEventLinearTickCalculation) {
EXPECT_EQ(mouse_wheel_ev.tick_120ths().y(), 120); EXPECT_EQ(mouse_wheel_ev.tick_120ths().y(), 120);
} }
TEST(EventTest, OrdinalMotionConversion) {
const gfx::Point origin(0, 0);
const gfx::Vector2dF movement(2.67, 3.14);
// Model conversion depends on the class having a specific static method.
struct OrdinalMotionConversionModel {
static void ConvertPointToTarget(const OrdinalMotionConversionModel*,
const OrdinalMotionConversionModel*,
gfx::Point*) {
// Do nothing.
}
} src, dst;
MouseEvent mouseev1(ET_MOUSE_PRESSED, origin, origin, EventTimeForNow(), 0,
0);
MouseEvent::DispatcherApi(&mouseev1).set_movement(movement);
EXPECT_EQ(mouseev1.movement(), movement);
EXPECT_TRUE(mouseev1.flags() & EF_UNADJUSTED_MOUSE);
MouseEvent mouseev2(mouseev1, &src, &dst);
EXPECT_EQ(mouseev2.movement(), movement);
EXPECT_TRUE(mouseev2.flags() & EF_UNADJUSTED_MOUSE);
// Setting the flags in construction should override the model's.
MouseEvent mouseev3(mouseev1, &src, &dst, EventType::ET_MOUSE_MOVED,
/* flags */ 0);
EXPECT_EQ(mouseev3.movement(), movement);
EXPECT_FALSE(mouseev3.flags() & EF_UNADJUSTED_MOUSE);
}
// Checks that Event.Latency.OS.TOUCH_PRESSED, TOUCH_MOVED, // Checks that Event.Latency.OS.TOUCH_PRESSED, TOUCH_MOVED,
// and TOUCH_RELEASED histograms are computed properly. // and TOUCH_RELEASED histograms are computed properly.
#if defined(USE_X11) #if defined(USE_X11)
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
namespace gfx { namespace gfx {
class Point; class Point;
class Vector2d; class Vector2d;
} } // namespace gfx
namespace base { namespace base {
class TimeTicks; class TimeTicks;
...@@ -107,6 +107,10 @@ EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative( ...@@ -107,6 +107,10 @@ EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
EVENTS_EXPORT PointerDetails EVENTS_EXPORT PointerDetails
GetMousePointerDetailsFromNative(const PlatformEvent& native_event); GetMousePointerDetailsFromNative(const PlatformEvent& native_event);
// Returns the movement vector associated with this mouse movement event.
EVENTS_EXPORT const gfx::Vector2dF& GetMouseMovementFromNative(
const PlatformEvent& native_event);
// Gets the mouse wheel offsets from a native event. // Gets the mouse wheel offsets from a native event.
EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset( EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
const PlatformEvent& native_event); const PlatformEvent& native_event);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ui/events/event_constants.h" #include "ui/events/event_constants.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/types/event_type.h" #include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace ui { namespace ui {
...@@ -57,6 +58,14 @@ PointerDetails GetMousePointerDetailsFromNative( ...@@ -57,6 +58,14 @@ PointerDetails GetMousePointerDetailsFromNative(
return pointer_detail; return pointer_detail;
} }
const gfx::Vector2dF& GetMouseMovementFromNative(
const PlatformEvent& native_event) {
DCHECK(native_event->IsMouseEvent());
const ui::MouseEvent* event =
static_cast<const ui::MouseEvent*>(native_event);
return event->movement();
}
KeyboardCode KeyboardCodeFromNative(const PlatformEvent& native_event) { KeyboardCode KeyboardCodeFromNative(const PlatformEvent& native_event) {
const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event); const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event);
DCHECK(event->IsKeyEvent()); DCHECK(event->IsKeyEvent());
......
...@@ -167,6 +167,7 @@ source_set("unittests") { ...@@ -167,6 +167,7 @@ source_set("unittests") {
"event_device_info_unittest.cc", "event_device_info_unittest.cc",
"event_device_test_util.cc", "event_device_test_util.cc",
"event_device_test_util.h", "event_device_test_util.h",
"event_factory_evdev_unittest.cc",
"gamepad_event_converter_evdev_unittest.cc", "gamepad_event_converter_evdev_unittest.cc",
"input_injector_evdev_unittest.cc", "input_injector_evdev_unittest.cc",
"stylus_button_event_converter_evdev_unittest.cc", "stylus_button_event_converter_evdev_unittest.cc",
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
#include "base/optional.h"
namespace ui { namespace ui {
...@@ -23,25 +24,27 @@ KeyEventParams::KeyEventParams(int device_id, ...@@ -23,25 +24,27 @@ KeyEventParams::KeyEventParams(int device_id,
KeyEventParams::KeyEventParams(const KeyEventParams& other) = default; KeyEventParams::KeyEventParams(const KeyEventParams& other) = default;
KeyEventParams::~KeyEventParams() { KeyEventParams::~KeyEventParams() {}
}
MouseMoveEventParams::MouseMoveEventParams(int device_id, MouseMoveEventParams::MouseMoveEventParams(int device_id,
int flags, int flags,
const gfx::PointF& location, const gfx::PointF& location,
gfx::Vector2dF* ordinal_delta,
const PointerDetails& details, const PointerDetails& details,
base::TimeTicks timestamp) base::TimeTicks timestamp)
: device_id(device_id), : device_id(device_id),
flags(flags), flags(flags),
location(location), location(location),
ordinal_delta(ordinal_delta
? base::Optional<gfx::Vector2dF>(*ordinal_delta)
: base::nullopt),
pointer_details(details), pointer_details(details),
timestamp(timestamp) {} timestamp(timestamp) {}
MouseMoveEventParams::MouseMoveEventParams(const MouseMoveEventParams& other) = MouseMoveEventParams::MouseMoveEventParams(const MouseMoveEventParams& other) =
default; default;
MouseMoveEventParams::~MouseMoveEventParams() { MouseMoveEventParams::~MouseMoveEventParams() {}
}
MouseButtonEventParams::MouseButtonEventParams(int device_id, MouseButtonEventParams::MouseButtonEventParams(int device_id,
int flags, int flags,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "base/component_export.h" #include "base/component_export.h"
#include "base/optional.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/events/devices/gamepad_device.h" #include "ui/events/devices/gamepad_device.h"
#include "ui/events/devices/input_device.h" #include "ui/events/devices/input_device.h"
...@@ -48,15 +49,17 @@ struct COMPONENT_EXPORT(EVDEV) MouseMoveEventParams { ...@@ -48,15 +49,17 @@ struct COMPONENT_EXPORT(EVDEV) MouseMoveEventParams {
MouseMoveEventParams(int device_id, MouseMoveEventParams(int device_id,
int flags, int flags,
const gfx::PointF& location, const gfx::PointF& location,
gfx::Vector2dF* ordinal_delta,
const PointerDetails& details, const PointerDetails& details,
base::TimeTicks timestamp); base::TimeTicks timestamp);
MouseMoveEventParams(const MouseMoveEventParams& other); MouseMoveEventParams(const MouseMoveEventParams& other);
MouseMoveEventParams() {} MouseMoveEventParams();
~MouseMoveEventParams(); ~MouseMoveEventParams();
int device_id; int device_id;
int flags; int flags;
gfx::PointF location; gfx::PointF location;
base::Optional<gfx::Vector2dF> ordinal_delta;
PointerDetails pointer_details; PointerDetails pointer_details;
base::TimeTicks timestamp; base::TimeTicks timestamp;
}; };
......
...@@ -256,10 +256,10 @@ void EventConverterEvdevImpl::FlushEvents(const input_event& input) { ...@@ -256,10 +256,10 @@ void EventConverterEvdevImpl::FlushEvents(const input_event& input) {
cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_));
dispatcher_->DispatchMouseMoveEvent( dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams(
MouseMoveEventParams(input_device_.id, EF_NONE, cursor_->GetLocation(), input_device_.id, EF_NONE, cursor_->GetLocation(),
PointerDetails(EventPointerType::kMouse), nullptr /* ordinal_delta*/, PointerDetails(EventPointerType::kMouse),
TimeTicksFromInputEvent(input))); TimeTicksFromInputEvent(input)));
x_offset_ = 0; x_offset_ = 0;
y_offset_ = 0; y_offset_ = 0;
......
...@@ -242,6 +242,10 @@ void EventFactoryEvdev::DispatchMouseMoveEvent( ...@@ -242,6 +242,10 @@ void EventFactoryEvdev::DispatchMouseMoveEvent(
event.set_location_f(location); event.set_location_f(location);
event.set_root_location_f(location); event.set_root_location_f(location);
event.set_source_device_id(params.device_id); event.set_source_device_id(params.device_id);
if (params.ordinal_delta.has_value()) {
ui::MouseEvent::DispatcherApi(&event).set_movement(
params.ordinal_delta.value());
}
DispatchUiEvent(&event); DispatchUiEvent(&event);
} }
...@@ -471,6 +475,7 @@ void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, ...@@ -471,6 +475,7 @@ void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
MouseMoveEventParams( MouseMoveEventParams(
-1 /* device_id */, EF_NONE, cursor_->GetLocation(), -1 /* device_id */, EF_NONE, cursor_->GetLocation(),
nullptr /* ordinal_delta */,
PointerDetails(EventPointerType::kMouse), EventTimeForNow()))); PointerDetails(EventPointerType::kMouse), EventTimeForNow())));
} }
......
// Copyright 2020 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/events/ozone/evdev/event_factory_evdev.h"
#include "base/optional.h"
#include "base/test/task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
#include "ui/events/platform/platform_event_observer.h"
#include "ui/events/platform_event.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace ui {
namespace {
class MockDeviceManager : public DeviceManager {
public:
MOCK_METHOD(void, ScanDevices, (DeviceEventObserver*));
MOCK_METHOD(void, AddObserver, (DeviceEventObserver*));
MOCK_METHOD(void, RemoveObserver, (DeviceEventObserver*));
};
class MockPlatformEventObserver : public PlatformEventObserver {
public:
MOCK_METHOD(void, WillProcessEvent, (const PlatformEvent& event));
MOCK_METHOD(void, DidProcessEvent, (const PlatformEvent& event));
};
class EventFactoryEvdevTest : public testing::Test {
protected:
EventFactoryEvdevTest() : event_factory_(nullptr, &device_manager_, nullptr) {
event_factory_.Init();
event_factory_.AddPlatformEventObserver(&event_observer_);
}
base::test::SingleThreadTaskEnvironment task_environment_;
testing::StrictMock<MockDeviceManager> device_manager_;
testing::NiceMock<MockPlatformEventObserver> event_observer_;
EventFactoryEvdev event_factory_;
};
TEST_F(EventFactoryEvdevTest, OrdinalImpliesFlag) {
EXPECT_CALL(event_observer_, WillProcessEvent)
.WillOnce([](const PlatformEvent& platform_event) {
MouseEvent mouse_event(platform_event);
EXPECT_TRUE(mouse_event.flags() & MouseEventFlags::EF_UNADJUSTED_MOUSE);
EXPECT_EQ(mouse_event.movement(), gfx::Vector2dF(2.67, 3.14));
});
gfx::Vector2dF ordinal_movement(2.67, 3.14);
event_factory_.DispatchMouseMoveEvent(
MouseMoveEventParams{0,
0,
{},
&ordinal_movement,
PointerDetails(EventPointerType::kMouse),
EventTimeForNow()});
}
TEST_F(EventFactoryEvdevTest, NoOrdinalImpliesNoFlag) {
EXPECT_CALL(event_observer_, WillProcessEvent)
.WillOnce([](const PlatformEvent& platform_event) {
MouseEvent mouse_event(platform_event);
EXPECT_FALSE(mouse_event.flags() &
MouseEventFlags::EF_UNADJUSTED_MOUSE);
});
event_factory_.DispatchMouseMoveEvent(
MouseMoveEventParams{0,
0,
{},
/*ordinal_movement=*/nullptr,
PointerDetails(EventPointerType::kMouse),
EventTimeForNow()});
}
} // namespace
} // namespace ui
...@@ -29,8 +29,7 @@ InputInjectorEvdev::InputInjectorEvdev( ...@@ -29,8 +29,7 @@ InputInjectorEvdev::InputInjectorEvdev(
CursorDelegateEvdev* cursor) CursorDelegateEvdev* cursor)
: cursor_(cursor), dispatcher_(std::move(dispatcher)) {} : cursor_(cursor), dispatcher_(std::move(dispatcher)) {}
InputInjectorEvdev::~InputInjectorEvdev() { InputInjectorEvdev::~InputInjectorEvdev() {}
}
void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) { void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) {
unsigned int code; unsigned int code;
...@@ -69,7 +68,8 @@ void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) { ...@@ -69,7 +68,8 @@ void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) {
dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams( dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams(
kDeviceIdForInjection, EF_NONE, cursor_->GetLocation(), kDeviceIdForInjection, EF_NONE, cursor_->GetLocation(),
PointerDetails(EventPointerType::kMouse), EventTimeForNow())); nullptr /* ordinal_delta */, PointerDetails(EventPointerType::kMouse),
EventTimeForNow()));
} }
void InputInjectorEvdev::InjectKeyEvent(DomCode physical_key, void InputInjectorEvdev::InjectKeyEvent(DomCode physical_key,
...@@ -87,4 +87,3 @@ void InputInjectorEvdev::InjectKeyEvent(DomCode physical_key, ...@@ -87,4 +87,3 @@ void InputInjectorEvdev::InjectKeyEvent(DomCode physical_key,
} }
} // namespace ui } // namespace ui
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h"
#include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
#ifndef REL_WHEEL_HI_RES #ifndef REL_WHEEL_HI_RES
#define REL_WHEEL_HI_RES 0x0b #define REL_WHEEL_HI_RES 0x0b
...@@ -296,9 +297,9 @@ void GestureInterpreterLibevdevCros::OnGestureMove(const Gesture* gesture, ...@@ -296,9 +297,9 @@ void GestureInterpreterLibevdevCros::OnGestureMove(const Gesture* gesture,
return; // No cursor! return; // No cursor!
cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy));
// TODO(spang): Use move->ordinal_dx, move->ordinal_dy gfx::Vector2dF ordinal_delta(move->ordinal_dx, move->ordinal_dy);
dispatcher_->DispatchMouseMoveEvent( dispatcher_->DispatchMouseMoveEvent(
MouseMoveEventParams(id_, EF_NONE, cursor_->GetLocation(), MouseMoveEventParams(id_, EF_NONE, cursor_->GetLocation(), &ordinal_delta,
PointerDetails(EventPointerType::kMouse), PointerDetails(EventPointerType::kMouse),
StimeToTimeTicks(gesture->end_time))); StimeToTimeTicks(gesture->end_time)));
} }
......
...@@ -220,6 +220,7 @@ void TabletEventConverterEvdev::FlushEvents(const input_event& input) { ...@@ -220,6 +220,7 @@ void TabletEventConverterEvdev::FlushEvents(const input_event& input) {
dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams( dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams(
input_device_.id, EF_NONE, cursor_->GetLocation(), input_device_.id, EF_NONE, cursor_->GetLocation(),
/* ordinal_delta */ nullptr,
PointerDetails(GetToolType(stylus_), /* pointer_id*/ 0, PointerDetails(GetToolType(stylus_), /* pointer_id*/ 0,
/* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_, /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_,
/* twist */ 0.0f, tilt_x_, tilt_y_), /* twist */ 0.0f, tilt_x_, tilt_y_),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment