Commit 6805486f authored by Cattalyya Nuengsigkapian's avatar Cattalyya Nuengsigkapian Committed by Chromium LUCI CQ

Bento: AltTabMode: Hide interactive alt-tab mode for one desk

- When user has only one desk, mode switching should be off and
the tab slider should be hidden.
- Add Ash unit tests to check visibility and existence of the
interactive component when the number of desks changes.

Bug: 1161243
Test: Manual test (see a video in crbug) and Ash unit tests
`ash_unittests --gtest_filter=ModeSelectionWindowCycleControllerTest.SingleDeskHidesInteractiveMode`

Change-Id: I32708306cd310d4075ee9bbb20991e3bad20531f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2603854
Commit-Queue: Cattalyya Nuengsigkapian <cattalyya@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarMin Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840903}
parent 2049a4d3
...@@ -173,8 +173,7 @@ WindowCycleController::WindowList WindowCycleController::CreateWindowList() { ...@@ -173,8 +173,7 @@ WindowCycleController::WindowList WindowCycleController::CreateWindowList() {
} }
void WindowCycleController::SetAltTabMode(DesksMruType alt_tab_mode) { void WindowCycleController::SetAltTabMode(DesksMruType alt_tab_mode) {
DCHECK(features::IsBentoEnabled()); if (!IsInteractiveAltTabModeAllowed() || alt_tab_mode_ == alt_tab_mode)
if (alt_tab_mode_ == alt_tab_mode)
return; return;
alt_tab_mode_ = alt_tab_mode; alt_tab_mode_ = alt_tab_mode;
MaybeResetCycleList(); MaybeResetCycleList();
...@@ -192,9 +191,15 @@ bool WindowCycleController::IsSwitchingMode() { ...@@ -192,9 +191,15 @@ bool WindowCycleController::IsSwitchingMode() {
return features::IsBentoEnabled() && is_switching_mode_; return features::IsBentoEnabled() && is_switching_mode_;
} }
bool WindowCycleController::IsInteractiveAltTabModeAllowed() {
return features::IsBentoEnabled() &&
Shell::Get()->desks_controller()->GetNumberOfDesks() > 1;
}
bool WindowCycleController::IsAltTabPerActiveDesk() { bool WindowCycleController::IsAltTabPerActiveDesk() {
return features::IsBentoEnabled() ? alt_tab_mode_ == kActiveDesk return IsInteractiveAltTabModeAllowed()
: features::IsAltTabLimitedToActiveDesk(); ? alt_tab_mode_ == kActiveDesk
: features::IsAltTabLimitedToActiveDesk();
} }
void WindowCycleController::SaveCurrentActiveDeskAndWindow( void WindowCycleController::SaveCurrentActiveDeskAndWindow(
......
...@@ -90,9 +90,14 @@ class ASH_EXPORT WindowCycleController { ...@@ -90,9 +90,14 @@ class ASH_EXPORT WindowCycleController {
// Sets alt-tab mode to all desks (default) or active desk. // Sets alt-tab mode to all desks (default) or active desk.
void SetAltTabMode(DesksMruType alt_tab_mode_); void SetAltTabMode(DesksMruType alt_tab_mode_);
// Checks if alt-tab should be per active desk. If Bento is enabled, alt-tab // Checks if switching between alt-tab mode via the tab slider is allowed.
// mode depends on users' alt_tab_mode_ selection. Otherwise, it'll default // Returns true if Bento flag is enabled and users have multiple desks.
// to all desk unless LimitAltTabToActiveDesk flag is explicitly enabled. bool IsInteractiveAltTabModeAllowed();
// Checks if alt-tab should be per active desk. If
// `IsInteractiveAltTabModeAllowed()`, alt-tab mode depends on users'
// |alt_tab_mode_| selection. Otherwise, it'll default to all desk unless
// LimitAltTabToActiveDesk flag is explicitly enabled.
bool IsAltTabPerActiveDesk(); bool IsAltTabPerActiveDesk();
// Returns true while switching the alt-tab mode and Bento flag is enabled. // Returns true while switching the alt-tab mode and Bento flag is enabled.
......
...@@ -1386,6 +1386,63 @@ class ModeSelectionWindowCycleControllerTest ...@@ -1386,6 +1386,63 @@ class ModeSelectionWindowCycleControllerTest
ui::test::EventGenerator* generator_; ui::test::EventGenerator* generator_;
}; };
// Tests that if user uses only one desk, the tab slider and no recent items
// are not shown. Moreover, `SetAltTabMode()` should not change the windows
// list.
TEST_F(ModeSelectionWindowCycleControllerTest, SingleDeskHidesInteractiveMode) {
WindowCycleController* cycle_controller =
Shell::Get()->window_cycle_controller();
// Create two windows in the current desk.
auto win0 = CreateAppWindow(gfx::Rect(0, 0, 250, 100));
auto win1 = CreateAppWindow(gfx::Rect(50, 50, 200, 200));
auto* desks_controller = DesksController::Get();
ASSERT_EQ(1u, desks_controller->desks().size());
// Alt-tab should contain windows from all desks without any the tab slider
// and no-recent-items view.
cycle_controller->StartCycling();
EXPECT_TRUE(!GetWindowCycleNoRecentItemsLabel());
EXPECT_FALSE(cycle_controller->IsAltTabPerActiveDesk());
auto cycle_windows = GetWindows(cycle_controller);
EXPECT_EQ(2u, cycle_windows.size());
EXPECT_EQ(cycle_windows.size(), GetWindowCycleItemViews().size());
const gfx::Rect alttab_bounds_without_tab_slider =
GetWindowCycleListWidget()->GetWindowBoundsInScreen();
cycle_controller->CompleteCycling();
// Create an empty desk_2 and start alt-tab to enter the all-desks mode.
desks_controller->NewDesk(DesksCreationRemovalSource::kButton);
const Desk* desk_2 = desks_controller->desks()[1].get();
ActivateDesk(desk_2);
EXPECT_EQ(desk_2, desks_controller->active_desk());
cycle_controller->StartCycling();
EXPECT_FALSE(cycle_controller->IsAltTabPerActiveDesk());
EXPECT_EQ(2u, cycle_windows.size());
EXPECT_EQ(cycle_windows.size(), GetWindowCycleItemViews().size());
// Expect mode-switching buttons and no-recent-item label to exist.
EXPECT_FALSE(!GetWindowCycleNoRecentItemsLabel());
auto tab_slider_buttons = GetWindowCycleTabSliderViews();
EXPECT_EQ(2u, tab_slider_buttons.size());
const gfx::Rect alttab_bounds_with_tab_slider =
GetWindowCycleListWidget()->GetWindowBoundsInScreen();
const int window_cycle_list_y =
GetWindowCycleItemViews()[0]->GetBoundsInScreen().y();
const gfx::Rect tab_slider_button_bound =
tab_slider_buttons[0]->GetBoundsInScreen();
// Expect that alt-tab views height is larger due to the tab slider insertion
// and expect that window cycle list is placed below the tab slider.
EXPECT_LT(alttab_bounds_without_tab_slider.height(),
alttab_bounds_with_tab_slider.height());
EXPECT_LT(tab_slider_button_bound.y() + tab_slider_button_bound.height(),
window_cycle_list_y);
DeskSwitchAnimationWaiter waiter;
cycle_controller->CompleteCycling();
waiter.Wait();
}
// Tests that alt-tab shows all windows in an all-desk mode by default and // Tests that alt-tab shows all windows in an all-desk mode by default and
// shows only windows in the current desk in a current-desk mode. Switching // shows only windows in the current desk in a current-desk mode. Switching
// between two modes should refresh the window list, while re-entering alt-tab // between two modes should refresh the window list, while re-entering alt-tab
......
...@@ -279,7 +279,9 @@ class WindowCycleView : public views::WidgetDelegateView, ...@@ -279,7 +279,9 @@ class WindowCycleView : public views::WidgetDelegateView,
layer->SetBackdropFilterQuality(kBackgroundBlurQuality); layer->SetBackdropFilterQuality(kBackgroundBlurQuality);
layer->SetName("WindowCycleView"); layer->SetName("WindowCycleView");
if (features::IsBentoEnabled()) { if (Shell::Get()
->window_cycle_controller()
->IsInteractiveAltTabModeAllowed()) {
tab_slider_container_ = tab_slider_container_ =
AddChildView(std::make_unique<WindowCycleTabSlider>()); AddChildView(std::make_unique<WindowCycleTabSlider>());
...@@ -312,7 +314,9 @@ class WindowCycleView : public views::WidgetDelegateView, ...@@ -312,7 +314,9 @@ class WindowCycleView : public views::WidgetDelegateView,
views::BoxLayout* layout = views::BoxLayout* layout =
mirror_container_->SetLayoutManager(std::make_unique<views::BoxLayout>( mirror_container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(features::IsBentoEnabled() gfx::Insets(Shell::Get()
->window_cycle_controller()
->IsInteractiveAltTabModeAllowed()
? kMirrorContainerVerticalPaddingDp ? kMirrorContainerVerticalPaddingDp
: kInsideBorderVerticalPaddingDp, : kInsideBorderVerticalPaddingDp,
kInsideBorderHorizontalPaddingDp, kInsideBorderHorizontalPaddingDp,
...@@ -347,14 +351,13 @@ class WindowCycleView : public views::WidgetDelegateView, ...@@ -347,14 +351,13 @@ class WindowCycleView : public views::WidgetDelegateView,
void UpdateWindows(const WindowCycleList::WindowList& windows) { void UpdateWindows(const WindowCycleList::WindowList& windows) {
const bool no_windows = windows.empty(); const bool no_windows = windows.empty();
if (features::IsBentoEnabled()) { if (Shell::Get()
->window_cycle_controller()
->IsInteractiveAltTabModeAllowed()) {
no_recent_items_label_->SetVisible(no_windows); no_recent_items_label_->SetVisible(no_windows);
} }
if (no_windows) if (no_windows)
return; return;
if (features::IsBentoEnabled())
no_recent_items_label_->SetVisible(false);
for (auto* window : windows) { for (auto* window : windows) {
auto* view = mirror_container_->AddChildView( auto* view = mirror_container_->AddChildView(
std::make_unique<WindowCycleItemView>(window)); std::make_unique<WindowCycleItemView>(window));
...@@ -449,7 +452,9 @@ class WindowCycleView : public views::WidgetDelegateView, ...@@ -449,7 +452,9 @@ class WindowCycleView : public views::WidgetDelegateView,
// views::WidgetDelegateView: // views::WidgetDelegateView:
gfx::Size CalculatePreferredSize() const override { gfx::Size CalculatePreferredSize() const override {
gfx::Size size = mirror_container_->GetPreferredSize(); gfx::Size size = mirror_container_->GetPreferredSize();
if (features::IsBentoEnabled()) { if (Shell::Get()
->window_cycle_controller()
->IsInteractiveAltTabModeAllowed()) {
size.Enlarge(0, tab_slider_container_->GetPreferredSize().height() + size.Enlarge(0, tab_slider_container_->GetPreferredSize().height() +
kTabSliderContainerVerticalPaddingDp); kTabSliderContainerVerticalPaddingDp);
} }
...@@ -496,7 +501,9 @@ class WindowCycleView : public views::WidgetDelegateView, ...@@ -496,7 +501,9 @@ class WindowCycleView : public views::WidgetDelegateView,
container_bounds.set_x(x_offset); container_bounds.set_x(x_offset);
// Layout a tab slider if Bento is enabled. // Layout a tab slider if Bento is enabled.
if (features::IsBentoEnabled()) { if (Shell::Get()
->window_cycle_controller()
->IsInteractiveAltTabModeAllowed()) {
// Layout the tab slider. // Layout the tab slider.
const gfx::Size tab_slider_size = const gfx::Size tab_slider_size =
tab_slider_container_->GetPreferredSize(); tab_slider_container_->GetPreferredSize();
......
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