Skip to content

Commit

Permalink
[Merge to M90]bento_v1: Adjustment of the scroll buttons on new spec
Browse files Browse the repository at this point in the history
- Showing the gradient only when the scroll view has been scrolled to
  start or end position.
- Set minimum width for the scroll view's horizontal padding.
- Update the behavior while clicking the scroll buttons.

(cherry picked from commit 747c5d7)

Bug: 1163681
Change-Id: Ifb374ee2ada94b7d3cc08fecc100848f9b5a2e62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2725186
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#859905}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2740055
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/branch-heads/4430@{#160}
Cr-Branched-From: e5ce7dc-refs/heads/master@{#857950}
  • Loading branch information
minch authored and Chromium LUCI CQ committed Mar 5, 2021
1 parent 909cc16 commit 0cf3ff2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 82 deletions.
69 changes: 43 additions & 26 deletions ash/wm/desks/desks_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ constexpr int kZeroStateButtonSpacing = 8;
// The local Y coordinate of the zero state desk buttons.
constexpr int kZeroStateY = 6;

// Size of the scroll button.
constexpr int kScrollButtonSize = 20;
// The minimum horizontal padding of the scroll view. This is set to make sure
// there is enough space for the scroll buttons.
constexpr int kScrollViewMinimumHorizontalPadding = 32;

// Padding between the scroll view and the scroll buttons.
constexpr int kScrollButtonHorizontalPadding = 4;
constexpr int kScrollButtonWidth = 36;

constexpr int kGradientZoneLength = 24;
constexpr int kGradientZoneLength = 40;

gfx::Rect GetGestureEventScreenRect(const ui::Event& event) {
DCHECK(event.IsGestureEvent());
Expand Down Expand Up @@ -263,22 +263,29 @@ class BentoDesksBarLayout : public views::LayoutManager {
void Layout(views::View* host) override {
const gfx::Rect bar_bounds = bar_view_->bounds();
bar_view_->background_view()->SetBoundsRect(bar_bounds);
// Scroll buttons are kept |kScrollViewMinimumHorizontalPadding| away from
// the edge of the scroll view. So the horizontal padding of the scroll view
// is set to guarantee enough space for the scroll buttons.
const gfx::Insets insets = bar_view_->overview_grid_->GetGridInsets();
DCHECK(insets.left() == insets.right());
const int horizontal_padding =
std::max(kScrollViewMinimumHorizontalPadding, insets.left());
bar_view_->left_scroll_button_->SetBounds(
horizontal_padding - kScrollViewMinimumHorizontalPadding,
bar_bounds.y(), kScrollButtonWidth, bar_bounds.height());
bar_view_->right_scroll_button_->SetBounds(
bar_bounds.right() - horizontal_padding -
(kScrollButtonWidth - kScrollViewMinimumHorizontalPadding),
bar_bounds.y(), kScrollButtonWidth, bar_bounds.height());

gfx::Rect scroll_bounds = bar_bounds;
// Align with the overview grid in horizontal, so only horizontal insets are
// needed here.
const gfx::Insets insets = bar_view_->overview_grid_->GetGridInsets();
scroll_bounds.Inset(insets.left(), 0, insets.right(), 0);
scroll_bounds.Inset(horizontal_padding, 0);
bar_view_->scroll_view_->SetBoundsRect(scroll_bounds);

// Clip the contents that are outside of the |scroll_view_|'s bounds.
bar_view_->scroll_view_->layer()->SetMasksToBounds(true);

bar_view_->left_scroll_button_->SetBounds(
scroll_bounds.x() - kScrollButtonSize - kScrollButtonHorizontalPadding,
scroll_bounds.y(), kScrollButtonSize, scroll_bounds.height());
bar_view_->right_scroll_button_->SetBounds(
scroll_bounds.right() + kScrollButtonHorizontalPadding,
scroll_bounds.y(), kScrollButtonSize, scroll_bounds.height());
bar_view_->UpdateScrollButtonsVisibility();
bar_view_->UpdateGradientZone();

Expand Down Expand Up @@ -414,11 +421,11 @@ DesksBarView::DesksBarView(OverviewGrid* overview_grid)
scroll_view_->SetTreatAllScrollEventsAsHorizontal(true);

left_scroll_button_ = AddChildView(std::make_unique<ScrollArrowButton>(
base::BindRepeating(&DesksBarView::ClickOnLeftScrollButton,
base::BindRepeating(&DesksBarView::ScrollToPreviousPage,
base::Unretained(this)),
/*is_left_arrow=*/true, this));
right_scroll_button_ = AddChildView(std::make_unique<ScrollArrowButton>(
base::BindRepeating(&DesksBarView::ClickOnRightScrollButton,
base::BindRepeating(&DesksBarView::ScrollToNextPage,
base::Unretained(this)),
/*is_left_arrow=*/false, this));

Expand Down Expand Up @@ -938,20 +945,27 @@ void DesksBarView::UpdateScrollButtonsVisibility() {
}

void DesksBarView::UpdateGradientZone() {
const gfx::Rect bounds = scroll_view_->bounds();
const bool is_rtl = base::i18n::IsRTL();
const bool is_left_scroll_button_visible = left_scroll_button_->GetVisible();
const bool is_right_scroll_button_visible =
right_scroll_button_->GetVisible();
const bool is_left_visible_only =
is_left_scroll_button_visible && !is_right_scroll_button_visible;
const bool is_right_visible_only =
!is_left_scroll_button_visible && is_right_scroll_button_visible;

// Only showing the gradient while scrolled to the start or end position of
// the scroll view.
const bool should_show_start_gradient =
is_rtl ? is_right_visible_only : is_left_visible_only;
const bool should_show_end_gradient =
is_rtl ? is_left_visible_only : is_right_visible_only;

// The bounds of the start and end gradient will be the same regardless it is
// LTR or RTL layout. While the |left_scroll_button_| will be changed from
// left to right and |right_scroll_button_| will be changed from right to left
// if it is RTL layout.
const bool should_show_start_gradient =
is_rtl ? is_right_scroll_button_visible : is_left_scroll_button_visible;
const bool should_show_end_gradient =
is_rtl ? is_left_scroll_button_visible : is_right_scroll_button_visible;
const gfx::Rect bounds = scroll_view_->bounds();
gfx::Rect start_gradient_bounds, end_gradient_bounds;
if (should_show_start_gradient) {
start_gradient_bounds =
Expand All @@ -974,13 +988,16 @@ void DesksBarView::UpdateGradientZone() {
gradient_layer_delegate_->layer()->SetBounds(scroll_view_->layer()->bounds());
}

void DesksBarView::ClickOnLeftScrollButton() {
scroll_view_->ScrollToPosition(scroll_view_->horizontal_scroll_bar(), 0);
void DesksBarView::ScrollToPreviousPage() {
scroll_view_->ScrollToPosition(
scroll_view_->horizontal_scroll_bar(),
scroll_view_->GetVisibleRect().x() - scroll_view_->width());
}

void DesksBarView::ClickOnRightScrollButton() {
scroll_view_->ScrollToPosition(scroll_view_->horizontal_scroll_bar(),
scroll_view_contents_->bounds().width());
void DesksBarView::ScrollToNextPage() {
scroll_view_->ScrollToPosition(
scroll_view_->horizontal_scroll_bar(),
scroll_view_->GetVisibleRect().x() + scroll_view_->width());
}

} // namespace ash
12 changes: 5 additions & 7 deletions ash/wm/desks/desks_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,11 @@ class ASH_EXPORT DesksBarView : public views::View,
// the corresponding scroll button is visible.
void UpdateGradientZone();

// Performs on clicking the |left_scroll_button_|, scrolls to the start
// position of the scroll view.
void ClickOnLeftScrollButton();

// Performs on clicking the |right_scroll_button_|, scrolls to the end
// position of the scroll view.
void ClickOnRightScrollButton();
// Scrolls the desks bar to the previous or next page. The page size is the
// width of the scroll view, the contents that are outside of the scroll view
// will be clipped and can not be seen.
void ScrollToPreviousPage();
void ScrollToNextPage();

// A view that shows a dark gary transparent background that can be animated
// when the very first mini_views are created.
Expand Down
93 changes: 44 additions & 49 deletions ash/wm/desks/desks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ash/wm/splitview/split_view_utils.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
Expand Down Expand Up @@ -2080,7 +2080,7 @@ class TabletModeDesksTest : public DesksTest {
// Enter tablet mode. Avoid TabletModeController::OnGetSwitchStates() from
// disabling tablet mode.
base::RunLoop().RunUntilIdle();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
TabletModeControllerTestApi().EnterTabletMode();
}

SplitViewController* split_view_controller() {
Expand Down Expand Up @@ -2159,7 +2159,7 @@ TEST_F(TabletModeDesksTest, Backdrops) {
EXPECT_TRUE(desk_2_backdrop_controller->backdrop_window()->IsVisible());

// No backdrops after exiting tablet mode.
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_FALSE(desk_1_backdrop_controller->backdrop_window());
EXPECT_FALSE(desk_2_backdrop_controller->backdrop_window());
}
Expand Down Expand Up @@ -4107,58 +4107,53 @@ TEST_F(DesksBentoTest, ScrollableDesks) {
// Tests the visibility of the scroll buttons and behavior while clicking the
// corresponding scroll button.
TEST_F(DesksBentoTest, ScrollButtons) {
UpdateDisplay("201x400");
auto* overview_controller = Shell::Get()->overview_controller();
overview_controller->StartOverview();
UpdateDisplay("501x600");
for (size_t i = 1; i < desks_util::GetMaxNumberOfDesks(); i++)
NewDesk();

EXPECT_EQ(DesksController::Get()->desks().size(),
desks_util::GetMaxNumberOfDesks());
auto window = CreateAppWindow(gfx::Rect(0, 0, 100, 100));
TabletModeControllerTestApi().EnterTabletMode();
// Snap the window to left and then right side of the display should enter
// overview mode.
auto* root_window = Shell::GetPrimaryRootWindow();
auto* desks_bar_view = GetOverviewGridForRoot(root_window)->desks_bar_view();
ASSERT_TRUE(desks_bar_view->IsZeroState());
SplitViewController::Get(root_window)
->SnapWindow(window.get(), SplitViewController::LEFT);
auto* overview_controller = Shell::Get()->overview_controller();
EXPECT_TRUE(overview_controller->InOverviewSession());
auto* desks_bar = GetOverviewGridForRoot(root_window)->desks_bar_view();
auto* event_generator = GetEventGenerator();
ClickOnView(desks_bar_view->zero_state_new_desk_button(), event_generator);
event_generator->MoveMouseTo(desks_bar->GetBoundsInScreen().CenterPoint());

// Click the new desk button to create maximum number of desks.
auto* new_desk_button =
desks_bar_view->expanded_state_new_desk_button()->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;
for (size_t i = 1; i < desks_util::GetMaxNumberOfDesks(); i++) {
ClickOnView(new_desk_button, event_generator);
event_generator->MoveMouseWheel(-x_scroll_delta, 0);
}

auto* controller = DesksController::Get();
EXPECT_EQ(desks_util::GetMaxNumberOfDesks(), controller->desks().size());
EXPECT_FALSE(controller->CanCreateDesks());

// Scroll to the end position should show the left scroll button and hide the
// right scroll button.
event_generator->MoveMouseWheel(-x_scroll_delta, 0);
EXPECT_TRUE(desks_bar_view->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_FALSE(desks_bar_view->GetRightScrollButtonForTesting()->GetVisible());

// Scroll to the start position should show the right scroll button and hide
// the left scroll button.
const int x_scroll_delta = 500;
// Left scroll button should be hidden and right scroll button should be
// visible while at the start position.
event_generator->MoveMouseWheel(x_scroll_delta, 0);
EXPECT_FALSE(desks_bar_view->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_TRUE(desks_bar_view->GetRightScrollButtonForTesting()->GetVisible());

// Scroll to the middle position should show both left scroll button and right
// scroll button.
event_generator->MoveMouseWheel(-x_scroll_delta / 4, 0);
EXPECT_TRUE(desks_bar_view->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_TRUE(desks_bar_view->GetRightScrollButtonForTesting()->GetVisible());

// Clicking the left scroll button should scroll to the start position.
ClickOnView(desks_bar_view->GetLeftScrollButtonForTesting(), event_generator);
EXPECT_FALSE(desks_bar_view->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_TRUE(desks_bar_view->GetRightScrollButtonForTesting()->GetVisible());

// Clicking the right scroll button should scroll to the end position.
ClickOnView(desks_bar_view->GetRightScrollButtonForTesting(),
event_generator);
EXPECT_TRUE(desks_bar_view->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_FALSE(desks_bar_view->GetRightScrollButtonForTesting()->GetVisible());
EXPECT_FALSE(desks_bar->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_TRUE(desks_bar->GetRightScrollButtonForTesting()->GetVisible());

// Click the right scroll button should scroll to the next page. And left and
// right scroll buttons should both be visible while at the middle position.
ClickOnView(desks_bar->GetRightScrollButtonForTesting(), event_generator);
EXPECT_TRUE(desks_bar->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_TRUE(desks_bar->GetRightScrollButtonForTesting()->GetVisible());

// Click the left scroll button should scroll to the previous page. In this
// case, it will scroll back to the start position and left scroll button
// should be hidden and right scroll button should be visible.
ClickOnView(desks_bar->GetLeftScrollButtonForTesting(), event_generator);
EXPECT_FALSE(desks_bar->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_TRUE(desks_bar->GetRightScrollButtonForTesting()->GetVisible());

// Left scroll button should be visible and right scroll button should be
// hidden while at the end position.
event_generator->MoveMouseTo(desks_bar->GetBoundsInScreen().CenterPoint());
event_generator->MoveMouseWheel(-x_scroll_delta, 0);
EXPECT_TRUE(desks_bar->GetLeftScrollButtonForTesting()->GetVisible());
EXPECT_FALSE(desks_bar->GetRightScrollButtonForTesting()->GetVisible());
}

// Tests that the bounds of a window that is visible on all desks is shared
Expand Down

0 comments on commit 0cf3ff2

Please sign in to comment.