Bug 1208023 - Ensure the minimum scale is a sane value greater than zero and add a separate flag to track if the default zoom is valid. r=botond

This commit is contained in:
Kartikaya Gupta 2015-10-02 23:08:18 -04:00
parent ecb4c526c5
commit 87fbc89c7d
4 changed files with 31 additions and 9 deletions

View File

@ -17,6 +17,12 @@ nsViewportInfo::ConstrainViewportValues()
// dev.w3.org/csswg/css-device-adapt section 6.2
mMaxZoom = std::max(mMinZoom, mMaxZoom);
mDefaultZoom = mDefaultZoom < mMaxZoom ? mDefaultZoom : mMaxZoom;
mDefaultZoom = mDefaultZoom > mMinZoom ? mDefaultZoom : mMinZoom;
if (mDefaultZoom > mMaxZoom) {
mDefaultZoomValid = false;
mDefaultZoom = mMaxZoom;
}
if (mDefaultZoom < mMinZoom) {
mDefaultZoomValid = false;
mDefaultZoom = mMinZoom;
}
}

View File

@ -12,7 +12,7 @@
/**
* Default values for the nsViewportInfo class.
*/
static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.0f);
static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.1f);
static const mozilla::LayoutDeviceToScreenScale kViewportMaxScale(10.0f);
static const mozilla::CSSIntSize kViewportMinSize(200, 40);
static const mozilla::CSSIntSize kViewportMaxSize(10000, 10000);
@ -27,6 +27,7 @@ class MOZ_STACK_CLASS nsViewportInfo
nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
const mozilla::CSSToScreenScale& aDefaultZoom,
bool aAllowZoom) :
mDefaultZoomValid(true),
mDefaultZoom(aDefaultZoom),
mAutoSize(true),
mAllowZoom(aAllowZoom)
@ -44,6 +45,7 @@ class MOZ_STACK_CLASS nsViewportInfo
const mozilla::CSSSize& aSize,
bool aAutoSize,
bool aAllowZoom) :
mDefaultZoomValid(true),
mDefaultZoom(aDefaultZoom),
mMinZoom(aMinZoom),
mMaxZoom(aMaxZoom),
@ -54,6 +56,7 @@ class MOZ_STACK_CLASS nsViewportInfo
ConstrainViewportValues();
}
bool IsDefaultZoomValid() const { return mDefaultZoomValid; }
mozilla::CSSToScreenScale GetDefaultZoom() const { return mDefaultZoom; }
mozilla::CSSToScreenScale GetMinZoom() const { return mMinZoom; }
mozilla::CSSToScreenScale GetMaxZoom() const { return mMaxZoom; }
@ -72,6 +75,10 @@ class MOZ_STACK_CLASS nsViewportInfo
*/
void ConstrainViewportValues();
// If the default zoom was specified and was between the min and max
// zoom values.
bool mDefaultZoomValid;
// Default zoom indicates the level at which the display is 'zoomed in'
// initially for the user, upon loading of the page.
mozilla::CSSToScreenScale mDefaultZoom;

View File

@ -16,12 +16,16 @@
let tests = [];
function fuzzeq(a, b, msg) {
ok(Math.abs(a - b) < 1e-6, msg);
}
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 0, "initial scale is unspecified");
is(info.minZoom, 0, "minumum scale defaults to the absolute minumum");
fuzzeq(info.defaultZoom, 0.1, "initial scale is unspecified");
fuzzeq(info.minZoom, 0.1, "minimum scale defaults to the absolute minimum");
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
is(info.width, 980, "width is the default width");
is(info.height, 588, "height is proportional to displayHeight");

View File

@ -125,12 +125,17 @@ MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
if (mIsFirstPaint) {
CSSToScreenScale defaultZoom = aViewportInfo.GetDefaultZoom();
MVM_LOG("%p: default zoom from viewport is %f\n", this, defaultZoom.scale);
// FIXME/bug 799585(?): GetViewportInfo() returns a default zoom of
// 0.0 to mean "did not calculate a zoom". In that case, we default
// it to the intrinsic scale.
if (defaultZoom.scale < 0.01f) {
if (!aViewportInfo.IsDefaultZoomValid()) {
defaultZoom = MaxScaleRatio(ScreenSize(aDisplaySize), aViewport);
MVM_LOG("%p: Intrinsic computed zoom is %f\n", this, defaultZoom.scale);
if (defaultZoom < aViewportInfo.GetMinZoom()) {
defaultZoom = aViewportInfo.GetMinZoom();
MVM_LOG("%p: Clamped to %f\n", this, defaultZoom.scale);
}
if (defaultZoom > aViewportInfo.GetMaxZoom()) {
defaultZoom = aViewportInfo.GetMaxZoom();
MVM_LOG("%p: Clamped to %f\n", this, defaultZoom.scale);
}
}
MOZ_ASSERT(aViewportInfo.GetMinZoom() <= defaultZoom &&
defaultZoom <= aViewportInfo.GetMaxZoom());