Bug 1562503 - Create GeckoMVMContext and ZoomConstraintsClient only for the root top level document. r=botond

browserElement_ScrollEvent.js is affected by this change. Before this change
the document for iframe mozbrowser was not considered as the root content
document, but after this change, it's considered as the root content document.
Given the nature of iframe mozbrowser, I believe it's the right behavior.

The browser mochitest in this commit fails without this change since
the minimum-scale size is used in the out-of-process iframe so that the visual
viewport size gets 3x bigger than the expected size.

Differential Revision: https://phabricator.services.mozilla.com/D36547

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2019-07-08 22:39:31 +00:00
parent ecf2505849
commit 901885347c
9 changed files with 115 additions and 9 deletions

View File

@ -19,13 +19,16 @@ function runTest() {
iframe.addEventListener("mozbrowserscroll", function(e) {
ok(true, "got mozbrowserscroll event.");
ok(e.detail, "event.detail is not null.");
ok(Math.round(e.detail.top) == 4000, "top position is correct.");
ok(Math.round(e.detail.left) == 4000, "left position is correct.");
is(Math.round(e.detail.top), 4000, "top position is correct.");
is(Math.round(e.detail.left), 4000, "left position is correct.");
SimpleTest.finish();
});
// We need a viewport meta tag to allow us to scroll to (4000, 4000). Without
// the viewport meta tag, we shrink the (5000, 5000) content so that we can't
// have enough space to scroll to the point in the layout viewport.
iframe.src =
"data:text/html,<html><body style='min-height: 5000px; min-width: 5000px;'></body><script>window.scrollTo(4000, 4000);</script></html>";
"data:text/html,<html><meta name='viewport' content='width=device-width,minimum-scale=1,initial-scale=1'><body style='min-height: 5000px; min-width: 5000px;'></body><script>window.scrollTo(4000, 4000);</script></html>";
}
addEventListener("testready", runTest);

View File

@ -151,7 +151,8 @@ void GeckoMVMContext::UpdateDisplayPortMargins() {
// We only create MobileViewportManager for root content documents. If that
// ever changes we'd need to limit the size of this displayport base rect
// because non-toplevel documents have no limit on their size.
MOZ_ASSERT(mPresShell->GetPresContext()->IsRootContentDocument());
MOZ_ASSERT(
mPresShell->GetPresContext()->IsRootContentDocumentCrossProcess());
nsLayoutUtils::SetDisplayPortBaseIfNotSet(root->GetContent(),
displayportBase);
nsIScrollableFrame* scrollable = do_QueryFrame(root);

View File

@ -33,7 +33,6 @@
#include "mozilla/TouchEvents.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h"
#include "MobileViewportManager.h"
#include <algorithm>
#ifdef XP_WIN
@ -1051,7 +1050,7 @@ void PresShell::Init(Document* aDocument, nsPresContext* aPresContext,
mTouchManager.Init(this, mDocument);
if (mPresContext->IsRootContentDocument()) {
if (mPresContext->IsRootContentDocumentCrossProcess()) {
mZoomConstraintsClient = new ZoomConstraintsClient();
mZoomConstraintsClient->Init(this, mDocument);
@ -10566,7 +10565,7 @@ void PresShell::UpdateViewportOverridden(bool aAfterInitialization) {
}
if (needMVM) {
if (mPresContext->IsRootContentDocument()) {
if (mPresContext->IsRootContentDocumentCrossProcess()) {
mMVMContext = new GeckoMVMContext(mDocument, this);
mMobileViewportManager = new MobileViewportManager(mMVMContext);

View File

@ -230,7 +230,7 @@ void ZoomConstraintsClient::RefreshZoomConstraints() {
// We only ever create a ZoomConstraintsClient for an RCD, so the RSF of
// the presShell must be the RCD-RSF (if it exists).
MOZ_ASSERT(mPresShell->GetPresContext()->IsRootContentDocument());
MOZ_ASSERT(mPresShell->GetPresContext()->IsRootContentDocumentCrossProcess());
if (nsIScrollableFrame* rcdrsf =
mPresShell->GetRootScrollFrameAsScrollable()) {
ZCC_LOG("Notifying RCD-RSF that it is zoomable: %d\n",

View File

@ -4,3 +4,7 @@
[browser_disableDialogs_onbeforeunload.js]
[browser_onbeforeunload_only_after_interaction.js]
[browser_onbeforeunload_only_after_interaction_in_frame.js]
[browser_visual_viewport_iframe.js]
support-files =
test_visual_viewport_in_oopif.html
visual_viewport_in_child.html

View File

@ -0,0 +1,63 @@
"use strict";
add_task(async () => {
function httpURL(filename, host = "https://example.com/") {
let root = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content/",
host
);
return root + filename;
}
await SpecialPowers.pushPrefEnv({
set: [
["apz.allow_zooming", true],
["dom.meta-viewport.enabled", true],
["dom.visualviewport.enabled,", true],
],
});
const fissionWindow = await BrowserTestUtils.openNewBrowserWindow({
fission: true,
});
const url = httpURL(
"test_visual_viewport_in_oopif.html",
"http://mochi.test:8888/"
);
const crossOriginIframeUrl = httpURL("visual_viewport_in_child.html");
try {
await BrowserTestUtils.withNewTab(
{ gBrowser: fissionWindow.gBrowser, url },
async browser => {
await ContentTask.spawn(
browser,
crossOriginIframeUrl,
async iframeUrl => {
const iframe = content.document.getElementById("iframe");
iframe.setAttribute("src", iframeUrl);
let { width, height } = await new Promise(resolve => {
content.window.addEventListener("message", msg => {
resolve(msg.data);
});
});
is(
width,
300,
"visualViewport.width shouldn't be affected in out-of-process iframes"
);
is(
height,
300,
"visualViewport.height shouldn't be affected in out-of-process iframes"
);
}
);
}
);
} finally {
await BrowserTestUtils.closeWindow(fissionWindow);
}
});

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style>
#iframe {
width: 300px;
height: 300px;
overflow: scroll;
}
</style>
<iframe id="iframe"></iframe>

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width, minimum-scale=0.25">
<style>
html {
overflow: hidden;
}
html, body {
margin: 0;
width: 100%;
height: 100%;
}
div {
position: absolute;
}
</style>
<div style="background: red; width: 300%; height: 300%;"></div>
<div style="background: green; width: 200%; height: 200%;"></div>
<div style="background: blue; width: 100%; height: 100%;"></div>
<script>
window.onload = () => {
parent.postMessage({ width: window.visualViewport.width,
height: window.visualViewport.height } , "*");
};
</script>

View File

@ -5806,7 +5806,7 @@ void ScrollFrameHelper::UpdateMinimumScaleSize(
}
nsPresContext* pc = mOuter->PresContext();
MOZ_ASSERT(pc->IsRootContentDocument(),
MOZ_ASSERT(pc->IsRootContentDocumentCrossProcess(),
"The pres context should be for the root content document");
RefPtr<MobileViewportManager> manager =