Commit 9dcc69a7 authored by minch's avatar minch Committed by Chromium LUCI CQ

bento: Scrollable virtual desks

The contents of DesksBarView is put inside the ScrollView to support the
scrollable desks. And the customized BentoDesksBarLayout is used to
layout the contents.

The follow up work will include new style of new desk button, define
the minimum width of the mini view to make sure the desk's name can
always be seen, etc.

Bug: 1147245
Change-Id: Ic75f21d1b534723a551f3e56ab0edbfac4e07d4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566350Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836219}
parent f0c4e5df
......@@ -37,6 +37,7 @@ constexpr int kDeskPreviewHeightInCompactLayout = 48;
// |kDeskPreviewMaxHeight| dips.
constexpr int kRootHeightDivider = 12;
constexpr int kDeskPreviewMaxHeight = 140;
constexpr int kDeskPreviewMinHeight = 48;
// The corner radius of the border in dips.
constexpr int kBorderCornerRadius = 6;
......@@ -261,7 +262,8 @@ int DeskPreviewView::GetHeight(aura::Window* root, bool compact) {
DCHECK(root);
DCHECK(root->IsRootWindow());
return std::min(kDeskPreviewMaxHeight,
root->bounds().height() / kRootHeightDivider);
std::max(kDeskPreviewMinHeight,
root->bounds().height() / kRootHeightDivider));
}
void DeskPreviewView::SetBorderColor(SkColor color) {
......
This diff is collapsed.
......@@ -84,7 +84,6 @@ class ASH_EXPORT DesksBarView : public views::View,
// views::View:
const char* GetClassName() const override;
void Layout() override;
bool OnMousePressed(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
void OnThemeChanged() override;
......@@ -122,6 +121,10 @@ class ASH_EXPORT DesksBarView : public views::View,
// Updates the cached minimum width required to fit all contents.
void UpdateMinimumWidthToFitContents();
// Adds |mini_view| as the DesksBarView's child or |scroll_view_content_|'s
// child if Bento is enabled.
DeskMiniView* AddMiniViewAsChild(std::unique_ptr<DeskMiniView> mini_view);
// A view that shows a dark gary transparent background that can be animated
// when the very first mini_views are created.
views::View* background_view_;
......@@ -149,6 +152,14 @@ class ASH_EXPORT DesksBarView : public views::View,
// Caches the calculated minimum width to fit contents.
int min_width_to_fit_contents_ = 0;
// Puts the contents in a ScrollView to support scrollable desks. Used only
// when Bento is enabled.
views::ScrollView* scroll_view_ = nullptr;
// Contents of |scroll_view_|, which includes |mini_views_| and
// |new_desk_button_| currently. Used only when Bento is enabled.
views::View* scroll_view_contents_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(DesksBarView);
};
......
......@@ -3821,6 +3821,48 @@ TEST_F(DesksBentoTest, NameNudges) {
}
}
TEST_F(DesksBentoTest, ScrollableDesks) {
UpdateDisplay("301x600");
auto* overview_controller = Shell::Get()->overview_controller();
overview_controller->StartOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
auto* root_window = Shell::GetPrimaryRootWindow();
const auto* desks_bar_view =
GetOverviewGridForRoot(root_window)->desks_bar_view();
auto* new_desk_button = desks_bar_view->new_desk_button();
// Set the scroll delta large enough to make sure the desks bar can be
// scrolled to the end each time.
const int x_scroll_delta = 200;
gfx::Rect display_bounds =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
root_window);
auto* event_generator = GetEventGenerator();
for (size_t i = 1; i < desks_util::GetMaxNumberOfDesks(); i++) {
gfx::Rect new_desk_button_bounds = new_desk_button->GetBoundsInScreen();
event_generator->MoveMouseTo(new_desk_button_bounds.CenterPoint());
EXPECT_TRUE(display_bounds.Contains(new_desk_button_bounds));
event_generator->ClickLeftButton();
// Scroll right to make sure the new desk button is always inside the
// display.
event_generator->MoveMouseWheel(-x_scroll_delta, 0);
}
auto* controller = DesksController::Get();
EXPECT_EQ(desks_util::GetMaxNumberOfDesks(), controller->desks().size());
EXPECT_FALSE(controller->CanCreateDesks());
EXPECT_TRUE(display_bounds.Contains(new_desk_button->GetBoundsInScreen()));
EXPECT_FALSE(display_bounds.Contains(
desks_bar_view->mini_views()[0]->GetBoundsInScreen()));
event_generator->MoveMouseWheel(x_scroll_delta, 0);
// Tests that scroll to the left will put the first desk inside the display.
EXPECT_TRUE(display_bounds.Contains(
desks_bar_view->mini_views()[0]->GetBoundsInScreen()));
EXPECT_FALSE(display_bounds.Contains(new_desk_button->GetBoundsInScreen()));
}
// TODO(afakhry): Add more tests:
// - Always on top windows are not tracked by any desk.
// - Reusing containers when desks are removed and created.
......
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