Commit b5ed2435 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Fix a crash when the display is extremely narrow

The crash happens when the display width is less than about 210 pixels,
and one clicks on the overflow button.

Add a test to prevent future regressions.

Bug: 977043
Change-Id: I8d1fa02eee829bf4ca0d45000b66842dcd2e65a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808378Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697218}
parent b5cdb387
......@@ -1233,8 +1233,10 @@ ShelfView::AppCenteringStrategy ShelfView::CalculateAppCenteringStrategy() {
last_visible_index_++;
} else {
strategy.overflow = true;
// Make space for the overflow button by showing one fewer app icon.
last_visible_index_--;
// Make space for the overflow button by showing one fewer app icon. If
// we already don't have enough space, don't decrement the last visible
// index further than -1.
last_visible_index_ = std::max(-1, last_visible_index_ - 1);
break;
}
}
......
......@@ -575,7 +575,8 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
int first_visible_index_ = -1;
// Last index of an app launcher button that is visible (does not go into
// overflow), or -1 if there are no apps.
// overflow), or -1 if there are no apps (or if only the overflow button is
// visible).
int last_visible_index_ = -1;
std::unique_ptr<views::BoundsAnimator> bounds_animator_;
......
......@@ -2049,6 +2049,27 @@ TEST_F(ShelfViewTest, TestDragWithinOverflow) {
test_api_->HideOverflowBubble();
}
// Checks how the overflow button and menu get laid out when the display is
// very narrow.
TEST_F(ShelfViewTest, TestOverflowWithNarrowDisplay) {
// No overflow bubble when scrollable shelf enabled.
// TODO(https://crbug.com/1002576): revisit when scrollable shelf is launched.
if (chromeos::switches::ShouldShowScrollableShelf())
return;
UpdateDisplay("200x600");
AddAppShortcutsUntilOverflow();
OverflowButton* overflow_button = shelf_view_->GetOverflowButton();
EXPECT_TRUE(overflow_button->GetVisible());
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(
overflow_button->GetBoundsInScreen().CenterPoint());
generator->ClickLeftButton();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
// Checks creating app shortcut for an opened platform app in overflow bubble
// should be invisible to the shelf. See crbug.com/605793.
TEST_F(ShelfViewTest, CheckOverflowStatusPinOpenedAppToShelf) {
......
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