Commit d2c567fe authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

[scrollable shelf] Utilize layer clip for shelf container view

Now in ScrollableShelfView, |shelf_container_view_|'s bounds change
depending on the layout strategy. In this CL, |shelf_container_view_|'s
bounds are never changed. Instead, its layer is clipped and the clip
rectangle is calculated with the layout strategy. It lays the basis to
solve the issue 1009368. This CL should not introduce any visual change

In detail, this CL does the following things:
(1) For |shelf_container_view_|, use layer clip instead of setting
bounds.
(2) Handles the tooltip correctly. In the current code, we use
|shelf_container_view_|'s bounds to decide whether to show/hide the
app icon's tooltip.
(3) Handles located events correctly. |shelf_container_view_| should
only handle those events within the area after clip.

Bug: 1009368
Change-Id: Iead6a53da1d06d831d13a7847722f51ea5c9b9cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849096
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705230}
parent 8aa6280c
This diff is collapsed.
...@@ -86,6 +86,8 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -86,6 +86,8 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
default_last_focusable_child_ = default_last_focusable_child; default_last_focusable_child_ = default_last_focusable_child;
} }
const gfx::Rect& visible_space() const { return visible_space_; }
// Size of the arrow button. // Size of the arrow button.
static int GetArrowButtonSize(); static int GetArrowButtonSize();
...@@ -257,6 +259,12 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -257,6 +259,12 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// the correct UI. // the correct UI.
int CalculateAdjustedOffset() const; int CalculateAdjustedOffset() const;
void UpdateVisibleSpace();
// Calculates the padding insets which help to show the edging app icon's
// ripple ring correctly.
gfx::Insets CalculateRipplePaddingInsets() const;
LayoutStrategy layout_strategy_ = kNotShowArrowButtons; LayoutStrategy layout_strategy_ = kNotShowArrowButtons;
// Child views Owned by views hierarchy. // Child views Owned by views hierarchy.
...@@ -264,9 +272,14 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -264,9 +272,14 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
ScrollArrowView* right_arrow_ = nullptr; ScrollArrowView* right_arrow_ = nullptr;
ShelfContainerView* shelf_container_view_ = nullptr; ShelfContainerView* shelf_container_view_ = nullptr;
// Available space to accommodate shelf icons. // Available space to accommodate child views.
gfx::Rect available_space_; gfx::Rect available_space_;
// Visible space of |shelf_container_view| in ScrollableShelfView's local
// coordinates. Different from |available_space_|, |visible_space_| only
// contains app icons and is mirrored for horizontal shelf under RTL.
gfx::Rect visible_space_;
ShelfView* shelf_view_ = nullptr; ShelfView* shelf_view_ = nullptr;
gfx::Vector2dF scroll_offset_; gfx::Vector2dF scroll_offset_;
......
...@@ -125,11 +125,11 @@ TEST_F(ScrollableShelfViewTest, CorrectUIAfterDisplayRotationShortToLong) { ...@@ -125,11 +125,11 @@ TEST_F(ScrollableShelfViewTest, CorrectUIAfterDisplayRotationShortToLong) {
const views::View* last_visible_icon = const views::View* last_visible_icon =
view_model->view_at(scrollable_shelf_view_->last_tappable_app_index()); view_model->view_at(scrollable_shelf_view_->last_tappable_app_index());
const gfx::Rect icon_bounds = last_visible_icon->GetBoundsInScreen(); const gfx::Rect icon_bounds = last_visible_icon->GetBoundsInScreen();
const gfx::Rect shelf_container_bounds = gfx::Rect visible_space = scrollable_shelf_view_->visible_space();
scrollable_shelf_view_->shelf_container_view()->GetBoundsInScreen(); views::View::ConvertRectToScreen(scrollable_shelf_view_, &visible_space);
EXPECT_EQ(icon_bounds.right() + EXPECT_EQ(icon_bounds.right() +
ShelfConfig::Get()->scrollable_shelf_ripple_padding(), ShelfConfig::Get()->scrollable_shelf_ripple_padding(),
shelf_container_bounds.right()); visible_space.right());
EXPECT_FALSE(scrollable_shelf_view_->ShouldAdjustForTest()); EXPECT_FALSE(scrollable_shelf_view_->ShouldAdjustForTest());
} }
......
...@@ -31,29 +31,6 @@ void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) { ...@@ -31,29 +31,6 @@ void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) {
PreferredSizeChanged(); PreferredSizeChanged();
} }
void ShelfContainerView::Layout() {
// Should not use ShelfView::GetPreferredSize in replace of
// CalculateIdealSize. Because ShelfView::CalculatePreferredSize relies on the
// bounds of app icon. Meanwhile, the icon's bounds may be updated by
// animation.
const gfx::Rect ideal_bounds = gfx::Rect(CalculateIdealSize());
const gfx::Rect local_bounds = GetLocalBounds();
gfx::Rect shelf_view_bounds =
local_bounds.Contains(ideal_bounds) ? local_bounds : ideal_bounds;
// Offsets |shelf_view_bounds| to ensure the sufficient space for the ripple
// ring of the first shelf item.
if (shelf_view_->shelf()->IsHorizontalAlignment())
shelf_view_bounds.Offset(
ShelfConfig::Get()->scrollable_shelf_ripple_padding(), 0);
else
shelf_view_bounds.Offset(
0, ShelfConfig::Get()->scrollable_shelf_ripple_padding());
shelf_view_->SetBoundsRect(shelf_view_bounds);
}
const char* ShelfContainerView::GetClassName() const { const char* ShelfContainerView::GetClassName() const {
return "ShelfContainerView"; return "ShelfContainerView";
} }
......
...@@ -27,7 +27,6 @@ class ASH_EXPORT ShelfContainerView : public views::View { ...@@ -27,7 +27,6 @@ class ASH_EXPORT ShelfContainerView : public views::View {
// views::View: // views::View:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void ChildPreferredSizeChanged(views::View* child) override; void ChildPreferredSizeChanged(views::View* child) override;
void Layout() override;
const char* GetClassName() const override; const char* GetClassName() const override;
protected: protected:
......
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