Commit 3f19324a authored by chinsenj's avatar chinsenj Committed by Commit Bot

cros: Clicking outside of window cycle list (alt-tab) closes it.

As a part of making the window cycle list more interactive, mouse
behavior has been added.

This CL adds to this ongoing effort by making user clicks outside of
the list close it.

      MousePressOutsideOfListCancelsCycling

Test: InteractiveWindowCycleControllerTest.
Bug: 1067327
Change-Id: I25b3696a96ff5834a68bc503ed805a005b52e4bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414125Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Commit-Queue: Jeremy Chinsen <chinsenj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808627}
parent ab4e5a22
......@@ -133,6 +133,10 @@ bool WindowCycleController::IsEventInCycleView(ui::LocatedEvent* event) {
return window_cycle_list_ && window_cycle_list_->IsEventInCycleView(event);
}
bool WindowCycleController::IsWindowListVisible() {
return window_cycle_list_ && window_cycle_list_->ShouldShowUi();
}
//////////////////////////////////////////////////////////////////////////////
// WindowCycleController, private:
......
......@@ -66,6 +66,9 @@ class ASH_EXPORT WindowCycleController {
// Checks whether |event| occurs within the cycle view.
bool IsEventInCycleView(ui::LocatedEvent* event);
// Returns whether or not the window cycle view is visible.
bool IsWindowListVisible();
// Returns the WindowCycleList.
const WindowCycleList* window_cycle_list() const {
return window_cycle_list_.get();
......
......@@ -1046,6 +1046,49 @@ TEST_F(InteractiveWindowCycleControllerTest, TapSelect) {
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
}
// When a user has the window cycle list open and clicks outside of it, it
// should cancel cycling.
TEST_F(InteractiveWindowCycleControllerTest,
MousePressOutsideOfListCancelsCycling) {
std::unique_ptr<Window> w0 = CreateTestWindow();
std::unique_ptr<Window> w1 = CreateTestWindow();
std::unique_ptr<Window> w2 = CreateTestWindow();
ui::test::EventGenerator* generator = GetEventGenerator();
WindowCycleController* controller = Shell::Get()->window_cycle_controller();
// Cycle to second item, move to above the window cycle list, and click.
controller->StartCycling();
controller->HandleCycleWindow(WindowCycleController::FORWARD);
gfx::Point above_window_cycle_list =
GetWindowCycleListWidget()->GetWindowBoundsInScreen().top_center();
above_window_cycle_list.Offset(0, 100);
generator->MoveMouseTo(above_window_cycle_list);
generator->ClickLeftButton();
EXPECT_FALSE(controller->IsCycling());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
}
// When the user has one window open, the window cycle view isn't shown. In this
// case we should not eat mouse events.
TEST_F(InteractiveWindowCycleControllerTest,
MouseEventsNotEatenWhenCycleViewNotVisible) {
std::unique_ptr<Window> w0 = CreateTestWindow();
EventCounter event_count;
w0->AddPreTargetHandler(&event_count);
ui::test::EventGenerator* generator = GetEventGenerator();
// Start cycling. Since there's only one window the cycle view shouldn't be
// visible.
WindowCycleController* controller = Shell::Get()->window_cycle_controller();
controller->HandleCycleWindow(WindowCycleController::FORWARD);
ASSERT_TRUE(controller->IsCycling());
ASSERT_FALSE(controller->IsWindowListVisible());
generator->MoveMouseToCenterOf(w0.get());
generator->ClickLeftButton();
EXPECT_LT(0, event_count.GetMouseEventCountAndReset());
}
// Tests that frame throttling starts and ends accordingly when window cycling
// starts and ends.
TEST_F(WindowCycleControllerTest, FrameThrottling) {
......
......@@ -103,9 +103,18 @@ WindowCycleController::Direction WindowCycleEventFilter::GetDirection(
}
void WindowCycleEventFilter::OnMouseEvent(ui::MouseEvent* event) {
if (features::IsInteractiveWindowCycleListEnabled() &&
Shell::Get()->window_cycle_controller()->IsEventInCycleView(event)) {
return;
if (features::IsInteractiveWindowCycleListEnabled()) {
WindowCycleController* window_cycle_controller =
Shell::Get()->window_cycle_controller();
const bool cycle_list_is_visible =
window_cycle_controller->IsWindowListVisible();
if (window_cycle_controller->IsEventInCycleView(event) ||
!cycle_list_is_visible) {
return;
} else if (event->type() == ui::ET_MOUSE_PRESSED && cycle_list_is_visible) {
// Close the window cycle list if a user clicks outside of it.
window_cycle_controller->CancelCycling();
}
}
// Prevent mouse clicks from doing anything while the Alt+Tab UI is active
......
......@@ -541,6 +541,10 @@ bool WindowCycleList::IsEventInCycleView(ui::LocatedEvent* event) {
return cycle_view_->GetBoundsInScreen().Contains(event_screen_point);
}
bool WindowCycleList::ShouldShowUi() {
return windows_.size() > 1u;
}
// static
void WindowCycleList::DisableInitialDelayForTesting() {
g_disable_initial_delay = true;
......@@ -585,10 +589,6 @@ void WindowCycleList::OnDisplayMetricsChanged(const display::Display& display,
}
}
bool WindowCycleList::ShouldShowUi() {
return windows_.size() > 1u;
}
void WindowCycleList::InitWindowCycleView() {
if (cycle_view_)
return;
......
......@@ -54,6 +54,9 @@ class ASH_EXPORT WindowCycleList : public aura::WindowObserver,
// |cycle_view_| does not exist.
bool IsEventInCycleView(ui::LocatedEvent* event);
// Returns true if the window list overlay should be shown.
bool ShouldShowUi();
void set_user_did_accept(bool user_did_accept) {
user_did_accept_ = user_did_accept;
}
......@@ -77,9 +80,6 @@ class ASH_EXPORT WindowCycleList : public aura::WindowObserver,
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override;
// Returns true if the window list overlay should be shown.
bool ShouldShowUi();
// Initializes and shows |cycle_view_|.
void InitWindowCycleView();
......
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