Bug 1566991: Add some assertions to sanity-check that our mobile viewport zoom factors are positive. r=botond

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daniel Holbert 2019-07-23 18:07:26 +00:00
parent a63f0a1fc3
commit dd66dfe12b
2 changed files with 13 additions and 0 deletions

View file

@ -11,6 +11,11 @@
using namespace mozilla; using namespace mozilla;
void nsViewportInfo::ConstrainViewportValues() { void nsViewportInfo::ConstrainViewportValues() {
// Non-positive zoom factors can produce NaN or negative viewport sizes,
// so we better be sure our constraints will produce positive zoom factors.
MOZ_ASSERT(mMinZoom > CSSToScreenScale(0.0f), "zoom factor must be positive");
MOZ_ASSERT(mMaxZoom > CSSToScreenScale(0.0f), "zoom factor must be positive");
if (mDefaultZoom > mMaxZoom) { if (mDefaultZoom > mMaxZoom) {
mDefaultZoomValid = false; mDefaultZoomValid = false;
mDefaultZoom = mMaxZoom; mDefaultZoom = mMaxZoom;

View file

@ -219,6 +219,10 @@ void MobileViewportManager::UpdateResolution(
CSSToLayoutDeviceScale cssToDev = mContext->CSSToDevPixelScale(); CSSToLayoutDeviceScale cssToDev = mContext->CSSToDevPixelScale();
LayoutDeviceToLayerScale res(mContext->GetResolution()); LayoutDeviceToLayerScale res(mContext->GetResolution());
CSSToScreenScale zoom = ResolutionToZoom(res, cssToDev); CSSToScreenScale zoom = ResolutionToZoom(res, cssToDev);
// Non-positive zoom factors can produce NaN or negative viewport sizes,
// so we better be sure we've got a positive zoom factor.
MOZ_ASSERT(zoom > CSSToScreenScale(0.0f), "zoom factor must be positive");
Maybe<CSSToScreenScale> newZoom; Maybe<CSSToScreenScale> newZoom;
ScreenIntSize compositionSize = GetCompositionSize(aDisplaySize); ScreenIntSize compositionSize = GetCompositionSize(aDisplaySize);
@ -391,6 +395,10 @@ void MobileViewportManager::UpdateResolution(
// If the zoom has changed, update the pres shell resolution accordingly. // If the zoom has changed, update the pres shell resolution accordingly.
if (newZoom) { if (newZoom) {
// Non-positive zoom factors can produce NaN or negative viewport sizes,
// so we better be sure we've got a positive zoom factor.
MOZ_ASSERT(*newZoom > CSSToScreenScale(0.0f),
"zoom factor must be positive");
LayoutDeviceToLayerScale resolution = ZoomToResolution(*newZoom, cssToDev); LayoutDeviceToLayerScale resolution = ZoomToResolution(*newZoom, cssToDev);
MVM_LOG("%p: setting resolution %f\n", this, resolution.scale); MVM_LOG("%p: setting resolution %f\n", this, resolution.scale);
mContext->SetResolutionAndScaleTo(resolution.scale); mContext->SetResolutionAndScaleTo(resolution.scale);