Bug 1509552 - MobileViewportManager::UpdateResolution cleanup, part 2. r=kats

* Call SetResolutionAndScaleTo() in just one place
* Call UpdateVisualViewportSize() in UpdateResolution() rather than
  requiring the caller to do it (and on non-first paints, only call it
  if the resolution has actually changed)

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Botond Ballo 2018-11-30 00:56:49 +00:00
Родитель 3c27a3d1e2
Коммит 51c7ddc4f7
2 изменённых файлов: 48 добавлений и 51 удалений

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

@ -239,7 +239,7 @@ ZoomToResolution(CSSToScreenScale aZoom,
/ aCssToDev * ParentLayerToLayerScale(1);
}
CSSToScreenScale
void
MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
const ScreenIntSize& aDisplaySize,
const CSSSize& aViewport,
@ -249,6 +249,7 @@ MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
mPresShell->GetPresContext()->CSSToDevPixelScale();
LayoutDeviceToLayerScale res(mPresShell->GetResolution());
CSSToScreenScale zoom = ResolutionToZoom(res, cssToDev);
Maybe<CSSToScreenScale> newZoom;
if (mIsFirstPaint) {
ScreenIntSize compositionSize = GetCompositionSize(aDisplaySize);
@ -283,15 +284,9 @@ MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
MOZ_ASSERT(aViewportInfo.GetMinZoom() <= defaultZoom &&
defaultZoom <= aViewportInfo.GetMaxZoom());
zoom = defaultZoom;
LayoutDeviceToLayerScale resolution = ZoomToResolution(zoom, cssToDev);
MVM_LOG("%p: setting resolution %f\n", this, resolution.scale);
mPresShell->SetResolutionAndScaleTo(resolution.scale);
return zoom;
}
// On first paint, we always consider the zoom to have changed.
newZoom = Some(defaultZoom);
} else {
// If this is not a first paint, then in some cases we want to update the pre-
// existing resolution so as to maintain how much actual content is visible
// within the display width. Note that "actual content" may be different with
@ -318,12 +313,21 @@ MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
// tag is added or removed)
// 4. neither screen size nor CSS viewport changes
if (aDisplayWidthChangeRatio) {
zoom = ScaleZoomWithDisplayWidth(zoom, aDisplayWidthChangeRatio.value(),
aViewport, mMobileViewportSize);
mPresShell->SetResolutionAndScaleTo(ZoomToResolution(zoom, cssToDev).scale);
newZoom = Some(ScaleZoomWithDisplayWidth(zoom, aDisplayWidthChangeRatio.value(),
aViewport, mMobileViewportSize));
}
}
return zoom;
// If the zoom has changed, update the pres shell resolution and the
// visual viewport size accordingly.
if (newZoom) {
LayoutDeviceToLayerScale resolution = ZoomToResolution(*newZoom, cssToDev);
MVM_LOG("%p: setting resolution %f\n", this, resolution.scale);
mPresShell->SetResolutionAndScaleTo(resolution.scale);
MVM_LOG("%p: New zoom is %f\n", this, newZoom->scale);
UpdateVisualViewportSize(aDisplaySize, *newZoom);
}
}
@ -463,10 +467,7 @@ MobileViewportManager::RefreshViewportSize(bool aForceAdjustResolution)
mIsFirstPaint, mMobileViewportSize != viewport);
if (gfxPrefs::APZAllowZooming()) {
CSSToScreenScale zoom = UpdateResolution(viewportInfo, displaySize, viewport,
displayWidthChangeRatio);
MVM_LOG("%p: New zoom is %f\n", this, zoom.scale);
UpdateVisualViewportSize(displaySize, zoom);
UpdateResolution(viewportInfo, displaySize, viewport, displayWidthChangeRatio);
}
if (gfxPlatform::AsyncPanZoomEnabled()) {
UpdateDisplayPortMargins();
@ -517,10 +518,6 @@ MobileViewportManager::ShrinkToDisplaySizeIfNeeded(
nsLayoutUtils::CalculateScrollableRectForFrame(rootScrollableFrame,
nullptr);
CSSSize contentSize = CSSSize::FromAppUnits(scrollableRect.Size());
CSSToScreenScale zoom =
UpdateResolution(aViewportInfo, aDisplaySize, contentSize, Nothing());
MVM_LOG("%p: Adapted zoom is %f\n", this, zoom.scale);
UpdateVisualViewportSize(aDisplaySize, zoom);
}
}

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

@ -93,8 +93,8 @@ public:
const mozilla::CSSSize& aNewViewport,
const mozilla::CSSSize& aOldViewport);
/* Updates the presShell resolution and returns the new zoom. */
mozilla::CSSToScreenScale UpdateResolution(const nsViewportInfo& aViewportInfo,
/* Updates the presShell resolution and the visual viewport size. */
void UpdateResolution(const nsViewportInfo& aViewportInfo,
const mozilla::ScreenIntSize& aDisplaySize,
const mozilla::CSSSize& aViewport,
const mozilla::Maybe<float>& aDisplayWidthChangeRatio);