зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1290420 Part 4: Make the PresShell create a MobileViewportManager on demand. r=botond,smaug
Depends on D3376 Differential Revision: https://phabricator.services.mozilla.com/D3377 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
55fbd36216
Коммит
79b8525535
|
@ -2662,6 +2662,13 @@ nsDocShell::SetMetaViewportOverride(uint32_t aMetaViewportOverride)
|
|||
|
||||
mMetaViewportOverride = aMetaViewportOverride;
|
||||
|
||||
// Inform our presShell that it needs to re-check its need for a viewport
|
||||
// override.
|
||||
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
||||
if (presShell) {
|
||||
presShell->UpdateViewportOverridden(true);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,13 +56,14 @@ public:
|
|||
* updated, and the SPCSPS needs to be updated. */
|
||||
void ResolutionUpdated();
|
||||
|
||||
private:
|
||||
~MobileViewportManager();
|
||||
|
||||
/* Called to compute the initial viewport on page load or before-first-paint,
|
||||
* whichever happens first. */
|
||||
* whichever happens first. Also called directly if we are created after the
|
||||
* presShell is initialized. */
|
||||
void SetInitialViewport();
|
||||
|
||||
private:
|
||||
~MobileViewportManager();
|
||||
|
||||
/* Main helper method to update the CSS viewport and any other properties that
|
||||
* need updating. */
|
||||
void RefreshViewportSize(bool aForceAdjustResolution);
|
||||
|
|
|
@ -1045,9 +1045,9 @@ PresShell::Init(nsIDocument* aDocument,
|
|||
if (mPresContext->IsRootContentDocument()) {
|
||||
mZoomConstraintsClient = new ZoomConstraintsClient();
|
||||
mZoomConstraintsClient->Init(this, mDocument);
|
||||
if (nsLayoutUtils::ShouldHandleMetaViewport(mDocument) || gfxPrefs::APZAllowZooming()) {
|
||||
mMobileViewportManager = new MobileViewportManager(this, mDocument);
|
||||
}
|
||||
|
||||
// We call this to create mMobileViewportManager, if it is needed.
|
||||
UpdateViewportOverridden(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10496,6 +10496,49 @@ PresShell::SetIsActive(bool aIsActive)
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
PresShell::UpdateViewportOverridden(bool aAfterInitialization)
|
||||
{
|
||||
// Determine if we require a MobileViewportManager.
|
||||
bool needMVM = nsLayoutUtils::ShouldHandleMetaViewport(mDocument) ||
|
||||
gfxPrefs::APZAllowZooming();
|
||||
|
||||
if (needMVM == !!mMobileViewportManager) {
|
||||
// Either we've need one and we've already got it, or we don't need one
|
||||
// and don't have it. Either way, we're done.
|
||||
return;
|
||||
}
|
||||
|
||||
if (needMVM) {
|
||||
if (mPresContext->IsRootContentDocument()) {
|
||||
mMobileViewportManager = new MobileViewportManager(this, mDocument);
|
||||
|
||||
if (aAfterInitialization) {
|
||||
// Setting the initial viewport will trigger a reflow.
|
||||
mMobileViewportManager->SetInitialViewport();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mMobileViewportManager, "Shouldn't reach this without a "
|
||||
"MobileViewportManager.");
|
||||
mMobileViewportManager->Destroy();
|
||||
mMobileViewportManager = nullptr;
|
||||
|
||||
if (aAfterInitialization) {
|
||||
// Force a reflow to our correct size by going back to the docShell
|
||||
// and asking it to reassert its size. This is necessary because
|
||||
// everything underneath the docShell, like the ViewManager, has been
|
||||
// altered by the MobileViewportManager in an irreversible way.
|
||||
nsDocShell* docShell =
|
||||
static_cast<nsDocShell*>(GetPresContext()->GetDocShell());
|
||||
int32_t width, height;
|
||||
docShell->GetSize(&width, &height);
|
||||
docShell->SetSize(width, height, false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines the current image locking state. Called when one of the
|
||||
* dependent factors changes.
|
||||
|
|
|
@ -345,6 +345,8 @@ public:
|
|||
return (mMobileViewportManager != nullptr);
|
||||
}
|
||||
|
||||
void UpdateViewportOverridden(bool aAfterInitialization) override;
|
||||
|
||||
bool IsLayoutFlushObserver() override
|
||||
{
|
||||
return GetPresContext()->RefreshDriver()->
|
||||
|
|
|
@ -366,10 +366,16 @@ public:
|
|||
ResizeReflowOptions::eBSizeExact) = 0;
|
||||
|
||||
/**
|
||||
* Returns true if ResizeReflowOverride has been called.
|
||||
* Returns true if the platform/pref or docshell require a meta viewport.
|
||||
*/
|
||||
virtual bool GetIsViewportOverridden() = 0;
|
||||
|
||||
/**
|
||||
* Note that the assumptions that determine the need for a meta viewport
|
||||
* may have changed.
|
||||
*/
|
||||
virtual void UpdateViewportOverridden(bool aAfterInitialization) = 0;
|
||||
|
||||
/**
|
||||
* Return true if the presshell expects layout flush.
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче