Bug 1575093 - Ensure initial-scale in a meta viewport tag is respected. r=hiro

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Botond Ballo 2019-08-21 22:00:43 +00:00
Родитель bdddbfd43c
Коммит 9d1532ac71
5 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@ -74,6 +74,7 @@ class MockMVMContext : public MVMContext {
return Some(mDisplaySize);
}
bool AllowZoomingForDocument() const { return true; }
bool IsDocumentLoading() const { return false; }
void SetResolutionAndScaleTo(float aResolution,
ResolutionChangeOrigin aOrigin) {

Просмотреть файл

@ -124,6 +124,11 @@ bool GeckoMVMContext::AllowZoomingForDocument() const {
return nsLayoutUtils::AllowZoomingForDocument(mDocument);
}
bool GeckoMVMContext::IsDocumentLoading() const {
MOZ_ASSERT(mDocument);
return mDocument->GetReadyStateEnum() == Document::READYSTATE_LOADING;
}
void GeckoMVMContext::SetResolutionAndScaleTo(float aResolution,
ResolutionChangeOrigin aOrigin) {
MOZ_ASSERT(mPresShell);

Просмотреть файл

@ -47,6 +47,7 @@ class GeckoMVMContext : public MVMContext {
const override;
Maybe<LayoutDeviceIntSize> GetContentViewerSize() const override;
bool AllowZoomingForDocument() const override;
bool IsDocumentLoading() const override;
void SetResolutionAndScaleTo(float aResolution,
ResolutionChangeOrigin aOrigin) override;

Просмотреть файл

@ -51,6 +51,7 @@ class MVMContext {
const = 0;
virtual Maybe<LayoutDeviceIntSize> GetContentViewerSize() const = 0;
virtual bool AllowZoomingForDocument() const = 0;
virtual bool IsDocumentLoading() const = 0;
virtual void SetResolutionAndScaleTo(float aResolution,
ResolutionChangeOrigin aOrigin) = 0;

Просмотреть файл

@ -147,7 +147,23 @@ MobileViewportManager::HandleEvent(dom::Event* event) {
void MobileViewportManager::HandleDOMMetaAdded() {
MVM_LOG("%p: got a dom-meta-added event\n", this);
RefreshViewportSize(mPainted);
if (mPainted && mContext->IsDocumentLoading()) {
// It's possible that we get a DOMMetaAdded event after the page
// has already been painted, but before the document finishes loading.
// In such a case, we've already run SetInitialViewport() on
// "before-first-paint", and won't run it again on "load" (because
// mPainted=true). But that SetInitialViewport() call didn't know the
// "initial-scale" from this meta viewport tag. To ensure we respect
// the "initial-scale", call SetInitialViewport() again.
// Note: It's important that we only do this if mPainted=true. In the
// usual case, we get the DOMMetaAdded before the first paint, sometimes
// even before we have a frame tree, and calling SetInitialViewport()
// before we have a frame tree will skip some important steps (e.g.
// updating display port margins).
SetInitialViewport();
} else {
RefreshViewportSize(mPainted);
}
}
NS_IMETHODIMP