Commit f60e1079 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Fix double-click handling in RootView

If RootView::OnMousePressed() receives a mouse press that is handled
by a child view, than a subsequent double-click mouse press that is
*not* handled, it should still report it as handled to the caller.

My previous CL crrev.com/c/2029087 broke this behavior, always
reporting a double-click as handled regardless of whether the first
click was handled. This CL fixes it and adds regression test coverage.

Fixed: 1055674
Change-Id: Ib2289a47b94ffa268160face6d4b6ebaf0dc504c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086259Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746873}
parent 3cf7cb9b
......@@ -427,13 +427,15 @@ bool RootView::OnMousePressed(const ui::MouseEvent& event) {
// Reset mouse_pressed_handler_ to indicate that no processing is occurring.
mouse_pressed_handler_ = nullptr;
const bool last_click_was_handled = (last_click_handler_ != nullptr);
last_click_handler_ = nullptr;
// In the event that a double-click is not handled after traversing the
// entire hierarchy (even as a single-click when sent to a different view),
// it must be marked as handled to avoid anything happening from default
// processing if it the first click-part was handled by us.
return event.flags() & ui::EF_IS_DOUBLE_CLICK;
return last_click_was_handled && (event.flags() & ui::EF_IS_DOUBLE_CLICK);
}
bool RootView::OnMouseDragged(const ui::MouseEvent& event) {
......
......@@ -860,5 +860,57 @@ TEST_F(RootViewTest, MouseEventDispatchedToClosestEnabledView) {
EXPECT_EQ(1, v3->GetEventCount(ui::ET_MOUSE_PRESSED));
}
// If RootView::OnMousePressed() receives a double-click event that isn't
// handled by any views, it should still report it as handled if the first click
// was handled. However, it should *not* if the first click was unhandled.
// Regression test for https://crbug.com/1055674.
TEST_F(RootViewTest, DoubleClickHandledIffFirstClickHandled) {
Widget widget;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.bounds = {100, 100, 100, 100};
widget.Init(std::move(init_params));
widget.Show();
internal::RootView* root_view =
static_cast<internal::RootView*>(widget.GetRootView());
root_view->SetContentsView(new View());
View* const contents_view = root_view->GetContentsView();
EventCountView* const v1 =
contents_view->AddChildView(std::make_unique<EventCountView>());
contents_view->SetBoundsRect(gfx::Rect(0, 0, 10, 10));
v1->SetBoundsRect(gfx::Rect(0, 0, 10, 10));
ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(5, 5),
gfx::Point(5, 5), ui::EventTimeForNow(), 0, 0);
ui::MouseEvent released_event(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5),
gfx::Point(5, 5), ui::EventTimeForNow(), 0, 0);
// First click handled, second click unhandled.
v1->set_handle_mode(EventCountView::CONSUME_EVENTS);
pressed_event.SetClickCount(1);
released_event.SetClickCount(1);
EXPECT_TRUE(root_view->OnMousePressed(pressed_event));
root_view->OnMouseReleased(released_event);
v1->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
pressed_event.SetClickCount(2);
released_event.SetClickCount(2);
EXPECT_TRUE(root_view->OnMousePressed(pressed_event));
root_view->OnMouseReleased(released_event);
// Both clicks unhandled.
v1->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
pressed_event.SetClickCount(1);
released_event.SetClickCount(1);
EXPECT_FALSE(root_view->OnMousePressed(pressed_event));
root_view->OnMouseReleased(released_event);
pressed_event.SetClickCount(2);
released_event.SetClickCount(2);
EXPECT_FALSE(root_view->OnMousePressed(pressed_event));
root_view->OnMouseReleased(released_event);
}
} // namespace test
} // namespace views
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