Commit 2a5dd6cd authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Part 1 of the arrow button implementation

This CL is the first part of code to implement the arrow button in
the overflow bubble view.
See more details from the below doc link:
https://docs.google.com/document/d/1dO4H_4T6ttWFc75nCNi2Uh18k-3_M8-eOHcfMTcNwd0/edit?usp=sharing

Bug: 918024
Change-Id: I6f8bf2dfe4871e2457947468696834adbd5d264d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1686782
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676253}
parent ed15e91e
......@@ -105,6 +105,8 @@ aggregate_vector_icons("ash_vector_icons") {
"notification_timer.icon",
"overview_window_close.icon",
"overview_drop_target_plus.icon",
"overflow_shelf_left.icon",
"overflow_shelf_right.icon",
"palette_action_capture_region.icon",
"palette_action_capture_screen.icon",
"palette_action_create_note.icon",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 20,
MOVE_TO, 13.34f, 13.83f,
LINE_TO, 12.07f, 15,
LINE_TO, 6.67f, 10,
R_LINE_TO, 5.4f, -5,
R_LINE_TO, 1.27f, 1.18f,
LINE_TO, 9.22f, 10,
CLOSE
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 20,
MOVE_TO, 6.67f, 13.83f,
LINE_TO, 10.79f, 10,
LINE_TO, 6.67f, 6.18f,
LINE_TO, 7.94f, 5,
R_LINE_TO, 5.4f, 5,
R_LINE_TO, -5.4f, 5,
CLOSE
This diff is collapsed.
......@@ -17,6 +17,21 @@ class ShelfView;
// Exports to access this class from OverflowBubbleViewTestAPI.
class ASH_EXPORT OverflowBubbleView : public ShelfBubble {
public:
enum LayoutStrategy {
// The arrow buttons are not shown. It means that there is enough space to
// accommodate all of shelf icons.
NOT_SHOW_ARROW_BUTTON,
// Only the left arrow button is shown.
SHOW_LEFT_ARROW_BUTTON,
// Only the right arrow button is shown.
SHOW_RIGHT_ARROW_BUTTON,
// Both buttons are shown.
SHOW_BUTTONS
};
// |anchor| is the overflow button on the main shelf. |shelf_view| is the
// ShelfView containing the overflow items.
OverflowBubbleView(ShelfView* shelf_view,
......@@ -36,7 +51,10 @@ class ASH_EXPORT OverflowBubbleView : public ShelfBubble {
gfx::Rect GetBubbleBounds() override;
bool CanActivate() const override;
ShelfView* shelf_view() { return shelf_view_; }
ShelfView* shelf_view() { return shelf_container_view_->shelf_view(); }
View* left_arrow() { return left_arrow_; }
View* right_arrow() { return right_arrow_; }
LayoutStrategy layout_strategy() { return layout_strategy_; }
// ShelfBubble:
bool ShouldCloseOnPressDown() override;
......@@ -45,6 +63,56 @@ class ASH_EXPORT OverflowBubbleView : public ShelfBubble {
private:
friend class OverflowBubbleViewTestAPI;
class ScrollArrowView : public views::View {
public:
enum ArrowType { LEFT, RIGHT };
ScrollArrowView(ArrowType arrow_type, bool is_horizontal_alignment);
~ScrollArrowView() override = default;
// Overridden from views::View:
void OnPaint(gfx::Canvas* canvas) override;
const char* GetClassName() const override;
private:
ArrowType arrow_type_;
bool is_horizontal_alignment_;
};
class OverflowShelfContainerView : public views::View {
public:
explicit OverflowShelfContainerView(ShelfView* shelf_view);
~OverflowShelfContainerView() override = default;
void Initialize();
// Translate |shelf_view_| by |offset|.
void TranslateShelfView(const gfx::Vector2d& offset);
// views::View:
gfx::Size CalculatePreferredSize() const override;
void ChildPreferredSizeChanged(views::View* child) override;
void Layout() override;
const char* GetClassName() const override;
ShelfView* shelf_view() { return shelf_view_; }
private:
ShelfView* shelf_view_;
};
// Returns the maximum scroll distance.
int CalculateScrollUpperBound() const;
// Updates the overflow bubble view's layout strategy after scrolling by the
// distance of |scroll|. Returns the adapted scroll offset.
int CalculateLayoutStrategyAfterScroll(int scroll);
// Ensures that the width of |bubble_bounds| (if it is not horizontally
// aligned, adjust |bubble_bounds|'s height) is the multiple of the sum
// between kShelfButtonSize and kShelfButtonSpacing. It helps that all of
// shelf icons are fully visible.
void AdjustToEnsureIconsFullyVisible(gfx::Rect* bubble_bounds) const;
// views::View:
gfx::Size CalculatePreferredSize() const override;
void Layout() override;
......@@ -55,8 +123,14 @@ class ASH_EXPORT OverflowBubbleView : public ShelfBubble {
// ui::EventHandler:
void OnScrollEvent(ui::ScrollEvent* event) override;
mutable LayoutStrategy layout_strategy_;
// Child views Owned by views hierarchy.
ScrollArrowView* left_arrow_ = nullptr;
ScrollArrowView* right_arrow_ = nullptr;
OverflowShelfContainerView* shelf_container_view_ = nullptr;
Shelf* shelf_;
ShelfView* shelf_view_; // Owned by views hierarchy.
gfx::Vector2d scroll_offset_;
DISALLOW_COPY_AND_ASSIGN(OverflowBubbleView);
......
......@@ -16,7 +16,7 @@ OverflowBubbleViewTestAPI::OverflowBubbleViewTestAPI(
OverflowBubbleViewTestAPI::~OverflowBubbleViewTestAPI() = default;
gfx::Size OverflowBubbleViewTestAPI::GetContentsSize() {
return bubble_view_->shelf_view_->GetPreferredSize();
return bubble_view_->shelf_view()->GetPreferredSize();
}
void OverflowBubbleViewTestAPI::ScrollByXOffset(int x_offset) {
......
......@@ -1654,12 +1654,13 @@ TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) {
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
ShelfViewTestAPI test_for_overflow_view(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
ShelfViewTestAPI test_for_overflow_view(bubble_view->shelf_view());
const ShelfView* overflow_shelf_view = shelf_view_->overflow_shelf();
int first_index = overflow_shelf_view->first_visible_index();
int last_index = overflow_shelf_view->last_visible_index();
views::View* left_arrow_button = bubble_view->left_arrow();
views::View* right_arrow_button = bubble_view->right_arrow();
ShelfAppButton* first_button = test_for_overflow_view.GetButton(first_index);
ShelfAppButton* last_button = test_for_overflow_view.GetButton(last_index);
gfx::Point first_point = first_button->GetBoundsInScreen().CenterPoint();
......@@ -1669,6 +1670,20 @@ TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) {
EXPECT_TRUE(drag_reinsert_bounds.Contains(first_point));
EXPECT_FALSE(drag_reinsert_bounds.Contains(last_point));
// Verfies that at the beginning, the left button is invisible while the right
// button shows.
EXPECT_EQ(OverflowBubbleView::SHOW_RIGHT_ARROW_BUTTON,
bubble_view->layout_strategy());
EXPECT_FALSE(left_arrow_button->GetVisible());
EXPECT_TRUE(right_arrow_button->GetVisible());
// Scroll the overflow shelf view a little bit. Then verifies that both arrow
// buttons show.
bubble_view_api.ScrollByXOffset(item_width);
EXPECT_EQ(OverflowBubbleView::SHOW_BUTTONS, bubble_view->layout_strategy());
EXPECT_TRUE(left_arrow_button->GetVisible());
EXPECT_TRUE(right_arrow_button->GetVisible());
// Scroll sufficiently to completely show last item.
bubble_view_api.ScrollByXOffset(bubble_view_api.GetContentsSize().width() -
bubble_view->GetContentsBounds().width());
......@@ -1678,6 +1693,13 @@ TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) {
last_point = last_button->GetBoundsInScreen().CenterPoint();
EXPECT_FALSE(drag_reinsert_bounds.Contains(first_point));
EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point));
// Verifies that when the last item shows, the right arrow button is invisible
// while the left one shows.
EXPECT_EQ(OverflowBubbleView::SHOW_LEFT_ARROW_BUTTON,
bubble_view->layout_strategy());
EXPECT_TRUE(left_arrow_button->GetVisible());
EXPECT_FALSE(right_arrow_button->GetVisible());
}
// Check the drag insertion bounds of shelf view in multi monitor environment.
......
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