Commit 18940be9 authored by bokan's avatar bokan Committed by Commit bot

Use full viewport height for layout if URL bar is locked shown or hidden.

With inert-top-controls turned on by default, we don't change the layout height
when the top controls are normally hidden. That is, if a user hides the URL bar
by scrolling, the page won't resize to use the newly available space. It'll lay
out as though the URL bar was still showing.

This patch makes an exception for cases where Chrome locks the URL bar in the
hidden state. e.g. Fullscreen or WebApp mode. In those cases, since the URL bar
can't be shown at all, there's no reason not to use the full height.

BUG=678649

Review-Url: https://codereview.chromium.org/2614993002
Cr-Commit-Position: refs/heads/master@{#441995}
parent a8ac477c
......@@ -49,6 +49,8 @@ class CORE_EXPORT BrowserControls final
// scroll amount.
FloatSize scrollBy(FloatSize scrollDelta);
WebBrowserControlsState permittedState() const { return m_permittedState; }
private:
explicit BrowserControls(const FrameHost&);
void resetBaseline();
......
......@@ -1776,6 +1776,7 @@ void WebViewImpl::performResize() {
// viewport with the browser controls shown.
IntSize ICBSize = m_size;
if (RuntimeEnabledFeatures::inertTopControlsEnabled() &&
browserControls().permittedState() == WebBrowserControlsBoth &&
!browserControls().shrinkViewport())
ICBSize.expand(0, -browserControls().height());
......@@ -1797,8 +1798,20 @@ void WebViewImpl::performResize() {
void WebViewImpl::updateBrowserControlsState(WebBrowserControlsState constraint,
WebBrowserControlsState current,
bool animate) {
WebBrowserControlsState oldPermittedState =
browserControls().permittedState();
browserControls().updateConstraintsAndState(constraint, current, animate);
// If the controls are going from a locked to an unlocked state, or
// vice-versa, then we need to force a recompute of the ICB size since that
// depends on the permitted browser controls state.
if (oldPermittedState != constraint &&
(oldPermittedState == WebBrowserControlsBoth ||
constraint == WebBrowserControlsBoth)) {
performResize();
}
if (m_layerTreeView)
m_layerTreeView->updateBrowserControlsState(constraint, current, animate);
}
......@@ -1845,8 +1858,7 @@ BrowserControls& WebViewImpl::browserControls() {
return page()->frameHost().browserControls();
}
void WebViewImpl::resizeViewWhileAnchored(FrameView* view,
float browserControlsHeight,
void WebViewImpl::resizeViewWhileAnchored(float browserControlsHeight,
bool browserControlsShrinkLayout) {
DCHECK(mainFrameImpl());
......@@ -1910,12 +1922,10 @@ void WebViewImpl::resizeWithBrowserControls(const WebSize& newSize,
if (isRotation) {
RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoords,
pageScaleConstraintsSet());
resizeViewWhileAnchored(view, browserControlsHeight,
browserControlsShrinkLayout);
resizeViewWhileAnchored(browserControlsHeight, browserControlsShrinkLayout);
} else {
ResizeViewportAnchor::ResizeScope resizeScope(*m_resizeViewportAnchor);
resizeViewWhileAnchored(view, browserControlsHeight,
browserControlsShrinkLayout);
resizeViewWhileAnchored(browserControlsHeight, browserControlsShrinkLayout);
}
sendResizeEventAndRepaint();
}
......
......@@ -519,8 +519,7 @@ class WEB_EXPORT WebViewImpl final
IntSize contentsSize() const;
void performResize();
void resizeViewWhileAnchored(FrameView*,
float browserControlsHeight,
void resizeViewWhileAnchored(float browserControlsHeight,
bool browserControlsShrinkLayout);
// Overrides the compositor visibility. See the description of
......
......@@ -726,6 +726,86 @@ TEST_F(BrowserControlsTest, MAYBE(DontAffectLayoutHeight)) {
EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
}
// Ensure that browser controls do not affect the layout by showing and hiding
// except for position: fixed elements.
TEST_F(BrowserControlsTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
// Initialize with the browser controls showing.
WebViewImpl* webView = initialize("percent-height.html");
webView->resizeWithBrowserControls(WebSize(400, 300), 100.f, true);
webView->updateBrowserControlsState(WebBrowserControlsBoth,
WebBrowserControlsShown, false);
webView->browserControls().setShownRatio(1);
webView->updateAllLifecyclePhases();
Element* absPos = getElementById(WebString::fromUTF8("abs"));
Element* fixedPos = getElementById(WebString::fromUTF8("fixed"));
ASSERT_EQ(100.f, webView->browserControls().contentOffset());
// Hide the browser controls.
verticalScroll(-100.f);
webView->resizeWithBrowserControls(WebSize(400, 400), 100.f, false);
webView->updateAllLifecyclePhases();
ASSERT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
// Now lock the controls in a hidden state. The layout and elements should
// resize without a WebView::resize.
webView->updateBrowserControlsState(WebBrowserControlsHidden,
WebBrowserControlsBoth, false);
EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
EXPECT_EQ(400, frame()->view()->layoutSize(IncludeScrollbars).height());
// Unlock the controls, the sizes should change even though the controls are
// still hidden.
webView->updateBrowserControlsState(WebBrowserControlsBoth,
WebBrowserControlsBoth, false);
EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
// Now lock the controls in a shown state.
webView->updateBrowserControlsState(WebBrowserControlsShown,
WebBrowserControlsBoth, false);
webView->resizeWithBrowserControls(WebSize(400, 300), 100.f, true);
EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height());
EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
// Shown -> Hidden
webView->resizeWithBrowserControls(WebSize(400, 400), 100.f, false);
webView->updateBrowserControlsState(WebBrowserControlsHidden,
WebBrowserControlsBoth, false);
EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
EXPECT_EQ(400, frame()->view()->layoutSize(IncludeScrollbars).height());
// Go from Unlocked and showing, to locked and hidden but issue the resize
// before the constraint update to check for race issues.
webView->updateBrowserControlsState(WebBrowserControlsBoth,
WebBrowserControlsShown, false);
webView->resizeWithBrowserControls(WebSize(400, 300), 100.f, true);
ASSERT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
webView->updateAllLifecyclePhases();
webView->resizeWithBrowserControls(WebSize(400, 400), 100.f, false);
webView->updateBrowserControlsState(WebBrowserControlsHidden,
WebBrowserControlsHidden, false);
EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
EXPECT_EQ(400, frame()->view()->layoutSize(IncludeScrollbars).height());
}
// Ensure that browser controls do not affect vh units.
TEST_F(BrowserControlsTest, MAYBE(DontAffectVHUnits)) {
// Initialize with the browser controls showing.
......
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