Commit 8694ad26 authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

events: Make it difficult to set the wrong flag.

Validate that the |changed_button_flags_| field is allowed only the
set of flags that makes sense.

BUG=779372, 824629

Change-Id: I5e4d8b8f07fbf6d881d8510f45414814d074278d
Reviewed-on: https://chromium-review.googlesource.com/974078
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545120}
parent dc6be551
......@@ -85,10 +85,12 @@ ui::LocatedEvent* DragDropTracker::ConvertEvent(aura::Window* target,
aura::Window::ConvertPointToTarget(capture_window_->GetRootWindow(),
wm::GetRootWindowAt(location_in_screen),
&target_root_location);
return new ui::MouseEvent(
event.type(), target_location, target_root_location,
ui::EventTimeForNow(), event.flags(),
static_cast<const ui::MouseEvent&>(event).changed_button_flags());
int changed_button_flags = 0;
if (event.IsMouseEvent())
changed_button_flags = event.AsMouseEvent()->changed_button_flags();
return new ui::MouseEvent(event.type(), target_location, target_root_location,
ui::EventTimeForNow(), event.flags(),
changed_button_flags);
}
} // namespace ash
......@@ -198,6 +198,11 @@ bool X11EventHasNonStandardState(const base::NativeEvent& event) {
}
#endif
constexpr int kChangedButtonFlagMask =
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON | ui::EF_BACK_MOUSE_BUTTON |
ui::EF_FORWARD_MOUSE_BUTTON;
} // namespace
////////////////////////////////////////////////////////////////////////////////
......@@ -624,6 +629,8 @@ MouseEvent::MouseEvent(EventType type,
changed_button_flags_(changed_button_flags),
pointer_details_(pointer_details) {
DCHECK_NE(ET_MOUSEWHEEL, type);
DCHECK_EQ(changed_button_flags_,
changed_button_flags_ & kChangedButtonFlagMask);
latency()->set_source_event_type(ui::SourceEventType::MOUSE);
latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
......
......@@ -193,7 +193,7 @@ class LabelSelectionTest : public LabelTest {
void PerformMousePress(const gfx::Point& point, int extra_flags = 0) {
ui::MouseEvent pressed_event = ui::MouseEvent(
ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON | extra_flags);
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
label()->OnMousePressed(pressed_event);
}
......
......@@ -731,7 +731,7 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
void PressMouseButton(ui::EventFlags mouse_button_flags, int extra_flags) {
ui::MouseEvent press(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_,
ui::EventTimeForNow(), mouse_button_flags,
mouse_button_flags | extra_flags);
mouse_button_flags);
textfield_->OnMousePressed(press);
}
......
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