Commit ae1b701e authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

wayland: fix MouseEvent flags

WaylandPointer was supplying the complete set of flags to MouseEvent
rather than the button that actually changed.

BUG=none
TEST=covered by test

Change-Id: Ib44585549d67001fdab847205819cea4cd646544
Reviewed-on: https://chromium-review.googlesource.com/996924Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548468}
parent 50e2b393
...@@ -92,22 +92,22 @@ void WaylandPointer::Button(void* data, ...@@ -92,22 +92,22 @@ void WaylandPointer::Button(void* data,
uint32_t button, uint32_t button,
uint32_t state) { uint32_t state) {
WaylandPointer* pointer = static_cast<WaylandPointer*>(data); WaylandPointer* pointer = static_cast<WaylandPointer*>(data);
int flag; int changed_button;
switch (button) { switch (button) {
case BTN_LEFT: case BTN_LEFT:
flag = EF_LEFT_MOUSE_BUTTON; changed_button = EF_LEFT_MOUSE_BUTTON;
break; break;
case BTN_MIDDLE: case BTN_MIDDLE:
flag = EF_MIDDLE_MOUSE_BUTTON; changed_button = EF_MIDDLE_MOUSE_BUTTON;
break; break;
case BTN_RIGHT: case BTN_RIGHT:
flag = EF_RIGHT_MOUSE_BUTTON; changed_button = EF_RIGHT_MOUSE_BUTTON;
break; break;
case BTN_BACK: case BTN_BACK:
flag = EF_BACK_MOUSE_BUTTON; changed_button = EF_BACK_MOUSE_BUTTON;
break; break;
case BTN_FORWARD: case BTN_FORWARD:
flag = EF_FORWARD_MOUSE_BUTTON; changed_button = EF_FORWARD_MOUSE_BUTTON;
break; break;
default: default:
return; return;
...@@ -116,17 +116,19 @@ void WaylandPointer::Button(void* data, ...@@ -116,17 +116,19 @@ void WaylandPointer::Button(void* data,
EventType type; EventType type;
if (state == WL_POINTER_BUTTON_STATE_PRESSED) { if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
type = ET_MOUSE_PRESSED; type = ET_MOUSE_PRESSED;
pointer->flags_ |= flag; pointer->flags_ |= changed_button;
pointer->connection_->set_serial(serial); pointer->connection_->set_serial(serial);
} else { } else {
type = ET_MOUSE_RELEASED; type = ET_MOUSE_RELEASED;
pointer->flags_ &= ~flag; pointer->flags_ &= ~changed_button;
} }
int flags = pointer->GetFlagsWithKeyboardModifiers() | flag; // MouseEvent's flags should contain the button that was released too.
const int flags = pointer->GetFlagsWithKeyboardModifiers() | changed_button;
MouseEvent event(type, gfx::Point(), gfx::Point(), MouseEvent event(type, gfx::Point(), gfx::Point(),
base::TimeTicks() + base::TimeDelta::FromMilliseconds(time), base::TimeTicks() + base::TimeDelta::FromMilliseconds(time),
flags, flag); flags, changed_button);
event.set_location_f(pointer->location_); event.set_location_f(pointer->location_);
event.set_root_location_f(pointer->location_); event.set_root_location_f(pointer->location_);
pointer->callback_.Run(&event); pointer->callback_.Run(&event);
......
...@@ -122,27 +122,42 @@ TEST_P(WaylandPointerTest, MotionDragged) { ...@@ -122,27 +122,42 @@ TEST_P(WaylandPointerTest, MotionDragged) {
TEST_P(WaylandPointerTest, ButtonPress) { TEST_P(WaylandPointerTest, ButtonPress) {
wl_pointer_send_enter(pointer_->resource(), 1, surface_->resource(), wl_pointer_send_enter(pointer_->resource(), 1, surface_->resource(),
wl_fixed_from_int(200), wl_fixed_from_int(150)); wl_fixed_from_int(200), wl_fixed_from_int(150));
Sync();
wl_pointer_send_button(pointer_->resource(), 2, 1002, BTN_RIGHT, wl_pointer_send_button(pointer_->resource(), 2, 1002, BTN_RIGHT,
WL_POINTER_BUTTON_STATE_PRESSED); WL_POINTER_BUTTON_STATE_PRESSED);
std::unique_ptr<Event> right_press_event;
EXPECT_CALL(delegate_, DispatchEvent(_))
.WillOnce(CloneEvent(&right_press_event));
Sync(); Sync();
ASSERT_TRUE(right_press_event);
std::unique_ptr<Event> event; ASSERT_TRUE(right_press_event->IsMouseEvent());
EXPECT_CALL(delegate_, DispatchEvent(_)).WillOnce(CloneEvent(&event)); auto* right_press_mouse_event = right_press_event->AsMouseEvent();
EXPECT_EQ(ET_MOUSE_PRESSED, right_press_mouse_event->type());
EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, right_press_mouse_event->button_flags());
EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON,
right_press_mouse_event->changed_button_flags());
std::unique_ptr<Event> left_press_event;
EXPECT_CALL(delegate_, DispatchEvent(_))
.WillOnce(CloneEvent(&left_press_event));
wl_pointer_send_button(pointer_->resource(), 3, 1003, BTN_LEFT, wl_pointer_send_button(pointer_->resource(), 3, 1003, BTN_LEFT,
WL_POINTER_BUTTON_STATE_PRESSED); WL_POINTER_BUTTON_STATE_PRESSED);
Sync(); Sync();
ASSERT_TRUE(event); ASSERT_TRUE(left_press_event);
ASSERT_TRUE(event->IsMouseEvent()); ASSERT_TRUE(left_press_event->IsMouseEvent());
auto* mouse_event = event->AsMouseEvent(); auto* left_press_mouse_event = left_press_event->AsMouseEvent();
EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type()); EXPECT_EQ(ET_MOUSE_PRESSED, left_press_mouse_event->type());
EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON,
mouse_event->button_flags()); left_press_mouse_event->button_flags());
EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); EXPECT_EQ(EF_LEFT_MOUSE_BUTTON,
EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f()); left_press_mouse_event->changed_button_flags());
EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f()); EXPECT_EQ(EF_LEFT_MOUSE_BUTTON,
left_press_mouse_event->changed_button_flags());
EXPECT_EQ(gfx::PointF(200, 150), left_press_mouse_event->location_f());
EXPECT_EQ(gfx::PointF(200, 150), left_press_mouse_event->root_location_f());
} }
TEST_P(WaylandPointerTest, ButtonRelease) { TEST_P(WaylandPointerTest, ButtonRelease) {
......
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