Commit 0ebe1eb8 authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Do not try to reduce app menu height if only 1.5 menu item can be shown

If screen space is limited, app menu should show one and an half of the
menu item at least.

Bug: 1132258
Change-Id: I4721c4fb5d4eacf415c56e1aa112d8f7647a5227
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2432764
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811062}
parent a8ce33c8
......@@ -481,21 +481,22 @@ class AppMenu implements OnItemClickListener, OnKeyListener, AppMenuClickHandler
if (availableScreenSpace < spaceForFullItems) {
int spaceForItems = 0;
int lastItem = 0;
for (; lastItem < heightList.size(); lastItem++) {
// App menu should show 1 full item at least.
do {
spaceForItems += heightList.get(lastItem++);
if (spaceForItems + heightList.get(lastItem) > availableScreenSpace) {
break;
}
spaceForItems += heightList.get(lastItem);
}
assert lastItem > 0;
} while (lastItem < heightList.size() - 1);
int spaceForPartialItem = (int) (LAST_ITEM_SHOW_FRACTION * heightList.get(lastItem));
// Determine which item needs hiding. We only show Partial of the last item, if there is
// not enough screen space to partially show the last identified item, then partially
// show the second to last item instead. We also do not show the partial divider line.
assert menuItems.size() == heightList.size();
while (spaceForItems + spaceForPartialItem > availableScreenSpace
|| menuItems.get(lastItem).getItemId() == groupDividerResourceId) {
while (lastItem > 1
&& (spaceForItems + spaceForPartialItem > availableScreenSpace
|| menuItems.get(lastItem).getItemId() == groupDividerResourceId)) {
spaceForItems -= heightList.get(lastItem - 1);
spaceForPartialItem =
(int) (LAST_ITEM_SHOW_FRACTION * heightList.get(lastItem - 1));
......
......@@ -695,12 +695,13 @@ public class AppMenuTest extends DummyUiActivityTestCase {
createMenuItem(menuItems, heightList, 0 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 1 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 2 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 3 /* id */, 10 /* height */);
int height = mAppMenuHandler.getAppMenu().calculateHeightForItems(menuItems, heightList,
1 /* groupDividerResourceId */, 16 /* availableScreenSpace */);
// The space only can fit the 1st and the partial 2nd item. But 2nd item is divider line, so
// we only show the partial 1st item.
Assert.assertEquals(5, height);
2 /* groupDividerResourceId */, 26 /* availableScreenSpace */);
// The space only can fit the 1st, 2nd and the partial 3rd item. But 3rd item is divider
// line, so we only show the partial 2nd item.
Assert.assertEquals(15, height);
}
@Test
......@@ -713,14 +714,50 @@ public class AppMenuTest extends DummyUiActivityTestCase {
createMenuItem(menuItems, heightList, 0 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 1 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 2 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 3 /* id */, 10 /* height */);
int height = mAppMenuHandler.getAppMenu().calculateHeightForItems(menuItems, heightList,
1 /* groupDividerResourceId */, 24 /* availableScreenSpace */);
// The space only can fit the full 1st item, the full 2nd items and the partial 3rd item.
// But the space for 3rd item is 4, which is not enough to show partial 3rd item(5 =
// LAST_ITEM_SHOW_FRACTION * 10), so we should show the partial 2nd item instead. But 2nd
// item is divider line, so we should partial 1st item instead.
Assert.assertEquals(5, height);
2 /* groupDividerResourceId */, 34 /* availableScreenSpace */);
// The space only can fit the full 1st, 2nd and 3rd item and the partial 4th item.
// But the space for 4th item is 4, which is not enough to show partial 4th item(5 =
// LAST_ITEM_SHOW_FRACTION * 10), so we should show the partial 3rd item instead. But 3rd
// item is divider line, so we should partial 2nd item instead.
Assert.assertEquals(15, height);
}
@Test
@SmallTest
public void testCalculateHeightForItems_minimalHight() throws Exception {
showMenuAndAssert();
List<MenuItem> menuItems = new ArrayList<MenuItem>();
List<Integer> heightList = new ArrayList<Integer>();
createMenuItem(menuItems, heightList, 0 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 1 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 2 /* id */, 10 /* height */);
int height = mAppMenuHandler.getAppMenu().calculateHeightForItems(menuItems, heightList,
-1 /* groupDividerResourceId */, 4 /* availableScreenSpace */);
// The space is not enough for any item, but we still show 1 and half items at least.
Assert.assertEquals(15, height);
}
@Test
@SmallTest
public void testCalculateHeightForItems_minimalHight_notEnoughSpaceForDivider()
throws Exception {
showMenuAndAssert();
List<MenuItem> menuItems = new ArrayList<MenuItem>();
List<Integer> heightList = new ArrayList<Integer>();
createMenuItem(menuItems, heightList, 0 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 1 /* id */, 10 /* height */);
createMenuItem(menuItems, heightList, 2 /* id */, 10 /* height */);
int height = mAppMenuHandler.getAppMenu().calculateHeightForItems(menuItems, heightList,
1 /* groupDividerResourceId */, 6 /* availableScreenSpace */);
// The space is not enough for any item, but we still show 1 and half items at least.
Assert.assertEquals(15, height);
}
private void createMenuItem(
......
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