Commit 396aeae0 authored by bokan's avatar bokan Committed by Commit bot

Perform layout when viewport size is queried.

If a Frame has non-overlay scrollbars, the visualViewport's dimensions
should exclude them. In order to know whether the Frame has scrollbars,
we need to perform any pending layouts.

This was only broken for iframes as the main frame viewport size
depends on page scale. Page scale depends on layout to determine
the minimum/initial page scale so we already performed layout when the
main frame's viewport was queried.

BUG=714829

Review-Url: https://codereview.chromium.org/2842343002
Cr-Commit-Position: refs/heads/master@{#467718}
parent 1bf0b01f
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
html {
height: 100%;
}
</style>
<h4>This test checks that requesting the viewport size causes any pending layout to occur.</h4>
<script>
async_test(function(t) {
window.onload = t.step_func(function() {
assert_equals(visualViewport.clientWidth, document.documentElement.clientWidth,
"window.visualViewport.width should match the window width.");
assert_equals(visualViewport.clientHeight, document.documentElement.clientHeight,
"window.visualViewport.height should match the window height.");
// Add overflow so scrollbars appear.
document.body.style.width = "2000px";
document.body.style.height = "2000px";
var viewportWidth = window.visualViewport.clientWidth;
var viewportHeight = window.visualViewport.clientHeight;
assert_equals(viewportWidth, document.documentElement.clientWidth,
"Reading viewport width should cause a layout and exclude the new scrollbar.");
assert_equals(viewportHeight, document.documentElement.clientHeight,
"Reading viewport height should cause a layout and exclude the new scrollbar.");
t.done();
});
});
</script>
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
iframe {
width: 200px;
height: 300px;
}
</style>
<h4>This test checks that requesting the viewport size in an iframe causes any pending layout to occur.</h4>
<iframe srcdoc="<!DOCTYPE html><style>html{height:100%}</style>"></iframe>
<script>
async_test(function(t) {
window.onload = t.step_func(function() {
assert_equals(frames[0].window.visualViewport.clientWidth, 200,
"Reading width of iframe viewport should match iframe width.");
assert_equals(frames[0].window.visualViewport.clientHeight, 300,
"Reading height of iframe viewport should match iframe height.");
// Add overflow so scrollbars appear.
frames[0].window.document.body.style.width = "2000px";
frames[0].window.document.body.style.height = "2000px";
var viewportWidth = frames[0].window.visualViewport.clientWidth;
var viewportHeight = frames[0].window.visualViewport.clientHeight;
assert_equals(viewportWidth, frames[0].window.document.documentElement.clientWidth,
"Reading width of iframe viewport should cause a layout and exclude the new scrollbar.");
assert_equals(viewportHeight, frames[0].window.document.documentElement.clientHeight,
"Reading height of iframe viewport should cause a layout and exclude the new scrollbar.");
t.done();
});
});
</script>
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
#include "platform/Histogram.h" #include "platform/Histogram.h"
#include "platform/WebFrameScheduler.h" #include "platform/WebFrameScheduler.h"
#include "platform/loader/fetch/ResourceFetcher.h" #include "platform/loader/fetch/ResourceFetcher.h"
#include "platform/scroll/ScrollbarTheme.h"
#include "platform/weborigin/SecurityOrigin.h" #include "platform/weborigin/SecurityOrigin.h"
#include "platform/weborigin/Suborigin.h" #include "platform/weborigin/Suborigin.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
...@@ -975,11 +976,17 @@ FloatSize LocalDOMWindow::GetViewportSize( ...@@ -975,11 +976,17 @@ FloatSize LocalDOMWindow::GetViewportSize(
if (!page) if (!page)
return FloatSize(); return FloatSize();
// The main frame's viewport size depends on the page scale. Since the // The main frame's viewport size depends on the page scale. If viewport is
// initial page scale depends on the content width and is set after a // enabled, the initial page scale depends on the content width and is set
// layout, perform one now so queries during page load will use the up to // after a layout, perform one now so queries during page load will use the
// date viewport. // up to date viewport.
if (page->GetSettings().GetViewportEnabled() && GetFrame()->IsMainFrame()) bool affectedByScale =
page->GetSettings().GetViewportEnabled() && GetFrame()->IsMainFrame();
bool affectedByScrollbars =
scrollbar_inclusion == kExcludeScrollbars &&
!ScrollbarTheme::GetTheme().UsesOverlayScrollbars();
if (affectedByScale || affectedByScrollbars)
document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); document()->UpdateStyleAndLayoutIgnorePendingStylesheets();
// FIXME: This is potentially too much work. We really only need to know the // FIXME: This is potentially too much work. We really only need to know the
......
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