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

Fix the issue that app icons have no response after alignment change

In ShelfContainerView::Layout, |shelf_view_|'s bounds are set to be
its preferred size, a.k.a ShelfView::GetPreferredSize. However, during
the calculation of the preferred size, the app icon's bounds are used
and they may be updated by animation. As a result, when change the
alignment, the app icon's bounds are not updated yet. It is the reason
why the shelf view's size after alignment change is always 56x56.

This CL fixes the issue by calculating the preferred size manually.

Bug: 1009334
Change-Id: Ifd09fa8b595cfff581133dd38cb34d0abaaf43ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1833080Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701860}
parent 8f0d8589
...@@ -24,14 +24,7 @@ void ShelfContainerView::Initialize() { ...@@ -24,14 +24,7 @@ void ShelfContainerView::Initialize() {
} }
gfx::Size ShelfContainerView::CalculatePreferredSize() const { gfx::Size ShelfContainerView::CalculatePreferredSize() const {
const int width = return CalculateIdealSize();
ShelfView::GetSizeOfAppIcons(shelf_view_->last_visible_index() -
shelf_view_->first_visible_index() + 1,
false);
const int height = ShelfConfig::Get()->button_size();
return shelf_view_->shelf()->IsHorizontalAlignment()
? gfx::Size(width, height)
: gfx::Size(height, width);
} }
void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) { void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) {
...@@ -39,7 +32,11 @@ void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) { ...@@ -39,7 +32,11 @@ void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) {
} }
void ShelfContainerView::Layout() { void ShelfContainerView::Layout() {
shelf_view_->SetBoundsRect(gfx::Rect(shelf_view_->GetPreferredSize())); // 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.
shelf_view_->SetBoundsRect(gfx::Rect(CalculateIdealSize()));
} }
const char* ShelfContainerView::GetClassName() const { const char* ShelfContainerView::GetClassName() const {
...@@ -52,4 +49,15 @@ void ShelfContainerView::TranslateShelfView(const gfx::Vector2dF& offset) { ...@@ -52,4 +49,15 @@ void ShelfContainerView::TranslateShelfView(const gfx::Vector2dF& offset) {
shelf_view_->SetTransform(transform_matrix); shelf_view_->SetTransform(transform_matrix);
} }
gfx::Size ShelfContainerView::CalculateIdealSize() const {
const int width =
ShelfView::GetSizeOfAppIcons(shelf_view_->last_visible_index() -
shelf_view_->first_visible_index() + 1,
false);
const int height = ShelfConfig::Get()->button_size();
return shelf_view_->shelf()->IsHorizontalAlignment()
? gfx::Size(width, height)
: gfx::Size(height, width);
}
} // namespace ash } // namespace ash
...@@ -35,6 +35,10 @@ class ASH_EXPORT ShelfContainerView : public views::View { ...@@ -35,6 +35,10 @@ class ASH_EXPORT ShelfContainerView : public views::View {
ShelfView* shelf_view_ = nullptr; ShelfView* shelf_view_ = nullptr;
private: private:
// Calculates the ideal size of |shelf_view_| to accommodate all of app icons
// without scrolling.
gfx::Size CalculateIdealSize() const;
DISALLOW_COPY_AND_ASSIGN(ShelfContainerView); DISALLOW_COPY_AND_ASSIGN(ShelfContainerView);
}; };
......
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