Commit bd2231e3 authored by Alex Danilo's avatar Alex Danilo Committed by Commit Bot

Change menus on menu button to use more space

CL:1549297 adds scrolling to the top level menus hanging off a menu
button. The calculation for limiting the height of the menu allowed the
menu to sit inside the viewport with a large number of pixels gap
resulting in a scroll-bar and scrollable region when the menu could
fit inside the viewport without scrolling.

Changes the calculation of positioning the top level menu so that more
vertical space is used - limiting the height to 2 pixels less than the
viewport. The 2 pixel gap at the bottom of the menu serves as a visual
indicator for the user so they can see the menu ends there, rather than
it appearing to be clipped.

Bug: 1040058
Tests: browser_tests --gtest_filter="FileManagerJsTest.MultiMenu"
Change-Id: Idb7d1199095d5d5e7482cc5b8eaa228439202bf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2018364Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735659}
parent be244d99
...@@ -586,29 +586,24 @@ cr.define('cr.ui', () => { ...@@ -586,29 +586,24 @@ cr.define('cr.ui', () => {
* @private * @private
*/ */
positionMenu_() { positionMenu_() {
const style = this.menu.style;
// Clear any maxHeight we've set from previous calls into here.
style.maxHeight = 'none';
cr.ui.positionPopupAroundElement( cr.ui.positionPopupAroundElement(
this, this.menu, this.anchorType, this.invertLeftRight); this, this.menu, this.anchorType, this.invertLeftRight);
// Check if menu is larger than the viewport and adjust its height // Check if menu is larger than the viewport and adjust its height to
// and enable scrolling if so. Note: style.bottom would have been set to // enable scrolling if so. Note: style.bottom would have been set to 0.
// 0.
const viewportHeight = window.innerHeight; const viewportHeight = window.innerHeight;
const menuRect = this.menu.getBoundingClientRect(); const menuRect = this.menu.getBoundingClientRect();
const style = this.menu.style;
// Make sure the top of the menu is in the viewport.
let top = menuRect.top;
if (top < 0) {
top = 0;
}
// Limit the height to fit in the viewport. // Limit the height to fit in the viewport.
style.maxHeight = (viewportHeight - top - this.menuEndGap_) + 'px'; style.maxHeight = (viewportHeight - this.menuEndGap_) + 'px';
// Make the menu scrollable if needed. // If the menu is too tall, position 2px from the bottom of the viewport
if ((top + menuRect.height + this.menuEndGap_) > viewportHeight) { // so users can see the end of the menu (helps when scroll is needed).
style.overflowY = 'scroll'; if ((menuRect.height + this.menuEndGap_) > viewportHeight) {
style.top = '0'; style.bottom = '2px';
style.bottom = 'auto';
} else {
style.overflowY = 'auto';
} }
// Let the browser deal with scroll bar generation.
style.overflowY = 'auto';
} }
/** /**
......
...@@ -272,7 +272,7 @@ function testGrowWindowSizesSubMenu() { ...@@ -272,7 +272,7 @@ function testGrowWindowSizesSubMenu() {
// Test that the height of the sub-menu is the same as // Test that the height of the sub-menu is the same as
// the height at the start of this test (before we // the height at the start of this test (before we
// deliberately shrank it). // deliberately shrank it).
assertTrue(grownPosition.bottom === subMenuPosition.bottom); assertTrue(grownPosition.height === subMenuPosition.height);
} }
/** /**
...@@ -359,12 +359,12 @@ function testShrinkWindowSizesTopMenu() { ...@@ -359,12 +359,12 @@ function testShrinkWindowSizesTopMenu() {
menubutton.showMenu(true); menubutton.showMenu(true);
const menuPosition = topMenu.getBoundingClientRect(); const menuPosition = topMenu.getBoundingClientRect();
// Reduce window innerHeight so the menu won't fit. // Reduce window innerHeight so the menu won't fit.
window.innerHeight = menuPosition.bottom - 10; window.innerHeight = menuPosition.height - 10;
// Call showMenu() which will first hide it, then re-open // Call showMenu() which will first hide it, then re-open
// it to force the resizing behavior. // it to force the resizing behavior.
menubutton.showMenu(true); menubutton.showMenu(true);
const shrunkPosition = topMenu.getBoundingClientRect(); const shrunkPosition = topMenu.getBoundingClientRect();
assertTrue(shrunkPosition.bottom < window.innerHeight); assertTrue(shrunkPosition.height == (window.innerHeight - 2));
} }
/** /**
......
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