зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1016682 - Store CSS viewport size as floating-point to avoid rounding errors. r=tn
This commit is contained in:
Родитель
b5ac06a0e7
Коммит
208521ef2b
|
@ -32,7 +32,7 @@ class MOZ_STACK_CLASS nsViewportInfo
|
|||
mAllowZoom(aAllowZoom),
|
||||
mAllowDoubleTapZoom(aAllowDoubleTapZoom)
|
||||
{
|
||||
mSize = mozilla::gfx::RoundedToInt(mozilla::ScreenSize(aDisplaySize) / mDefaultZoom);
|
||||
mSize = mozilla::ScreenSize(aDisplaySize) / mDefaultZoom;
|
||||
mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
|
||||
mMinZoom = pixelRatio * kViewportMinScale;
|
||||
mMaxZoom = pixelRatio * kViewportMaxScale;
|
||||
|
@ -42,7 +42,7 @@ class MOZ_STACK_CLASS nsViewportInfo
|
|||
nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
|
||||
const mozilla::CSSToScreenScale& aMinZoom,
|
||||
const mozilla::CSSToScreenScale& aMaxZoom,
|
||||
const mozilla::CSSIntSize& aSize,
|
||||
const mozilla::CSSSize& aSize,
|
||||
bool aAutoSize,
|
||||
bool aAllowZoom,
|
||||
bool aAllowDoubleTapZoom) :
|
||||
|
@ -62,7 +62,7 @@ class MOZ_STACK_CLASS nsViewportInfo
|
|||
mozilla::CSSToScreenScale GetMinZoom() { return mMinZoom; }
|
||||
mozilla::CSSToScreenScale GetMaxZoom() { return mMaxZoom; }
|
||||
|
||||
mozilla::CSSIntSize GetSize() { return mSize; }
|
||||
mozilla::CSSSize GetSize() { return mSize; }
|
||||
|
||||
bool IsAutoSizeEnabled() { return mAutoSize; }
|
||||
bool IsZoomAllowed() { return mAllowZoom; }
|
||||
|
@ -90,7 +90,7 @@ class MOZ_STACK_CLASS nsViewportInfo
|
|||
mozilla::CSSToScreenScale mMaxZoom;
|
||||
|
||||
// The size of the viewport, specified by the <meta name="viewport"> tag.
|
||||
mozilla::CSSIntSize mSize;
|
||||
mozilla::CSSSize mSize;
|
||||
|
||||
// Whether or not we should automatically size the viewport to the device's
|
||||
// width. This is true if the document has been optimized for mobile, and
|
||||
|
|
|
@ -7625,11 +7625,11 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
|
|||
}
|
||||
case Specified:
|
||||
default:
|
||||
CSSIntSize size = mViewportSize;
|
||||
CSSSize size = mViewportSize;
|
||||
|
||||
if (!mValidWidth) {
|
||||
if (mValidHeight && !aDisplaySize.IsEmpty()) {
|
||||
size.width = int32_t(size.height * aDisplaySize.width / aDisplaySize.height);
|
||||
size.width = size.height * aDisplaySize.width / aDisplaySize.height;
|
||||
} else {
|
||||
size.width = Preferences::GetInt("browser.viewport.desktopWidth",
|
||||
kViewportDefaultScreenWidth);
|
||||
|
@ -7638,7 +7638,7 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
|
|||
|
||||
if (!mValidHeight) {
|
||||
if (!aDisplaySize.IsEmpty()) {
|
||||
size.height = int32_t(size.width * aDisplaySize.height / aDisplaySize.width);
|
||||
size.height = size.width * aDisplaySize.height / aDisplaySize.width;
|
||||
} else {
|
||||
size.height = size.width;
|
||||
}
|
||||
|
@ -7654,28 +7654,28 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
|
|||
if (mAutoSize) {
|
||||
// aDisplaySize is in screen pixels; convert them to CSS pixels for the viewport size.
|
||||
CSSToScreenScale defaultPixelScale = pixelRatio * LayoutDeviceToScreenScale(1.0f);
|
||||
size = mozilla::gfx::RoundedToInt(ScreenSize(aDisplaySize) / defaultPixelScale);
|
||||
size = ScreenSize(aDisplaySize) / defaultPixelScale;
|
||||
}
|
||||
|
||||
size.width = clamped(size.width, kViewportMinSize.width, kViewportMaxSize.width);
|
||||
size.width = clamped(size.width, float(kViewportMinSize.width), float(kViewportMaxSize.width));
|
||||
|
||||
// Also recalculate the default zoom, if it wasn't specified in the metadata,
|
||||
// and the width is specified.
|
||||
if (mScaleStrEmpty && !mWidthStrEmpty) {
|
||||
CSSToScreenScale defaultScale(float(aDisplaySize.width) / float(size.width));
|
||||
CSSToScreenScale defaultScale(float(aDisplaySize.width) / size.width);
|
||||
scaleFloat = (scaleFloat > defaultScale) ? scaleFloat : defaultScale;
|
||||
}
|
||||
|
||||
size.height = clamped(size.height, kViewportMinSize.height, kViewportMaxSize.height);
|
||||
size.height = clamped(size.height, float(kViewportMinSize.height), float(kViewportMaxSize.height));
|
||||
|
||||
// We need to perform a conversion, but only if the initial or maximum
|
||||
// scale were set explicitly by the user.
|
||||
if (mValidScaleFloat) {
|
||||
CSSIntSize displaySize = RoundedToInt(ScreenSize(aDisplaySize) / scaleFloat);
|
||||
CSSSize displaySize = ScreenSize(aDisplaySize) / scaleFloat;
|
||||
size.width = std::max(size.width, displaySize.width);
|
||||
size.height = std::max(size.height, displaySize.height);
|
||||
} else if (mValidMaxScale) {
|
||||
CSSIntSize displaySize = RoundedToInt(ScreenSize(aDisplaySize) / scaleMaxFloat);
|
||||
CSSSize displaySize = ScreenSize(aDisplaySize) / scaleMaxFloat;
|
||||
size.width = std::max(size.width, displaySize.width);
|
||||
size.height = std::max(size.height, displaySize.height);
|
||||
}
|
||||
|
|
|
@ -1692,7 +1692,7 @@ private:
|
|||
mozilla::LayoutDeviceToScreenScale mScaleFloat;
|
||||
mozilla::CSSToLayoutDeviceScale mPixelRatio;
|
||||
bool mAutoSize, mAllowZoom, mAllowDoubleTapZoom, mValidScaleFloat, mValidMaxScale, mScaleStrEmpty, mWidthStrEmpty;
|
||||
mozilla::CSSIntSize mViewportSize;
|
||||
mozilla::CSSSize mViewportSize;
|
||||
|
||||
nsrefcnt mStackRefCnt;
|
||||
bool mNeedsReleaseAfterStackRefCntRelease;
|
||||
|
|
|
@ -318,8 +318,9 @@ nsDOMWindowUtils::GetViewportInfo(uint32_t aDisplayWidth,
|
|||
*aAllowZoom = info.IsZoomAllowed();
|
||||
*aMinZoom = info.GetMinZoom().scale;
|
||||
*aMaxZoom = info.GetMaxZoom().scale;
|
||||
*aWidth = info.GetSize().width;
|
||||
*aHeight = info.GetSize().height;
|
||||
CSSIntSize size = gfx::RoundedToInt(info.GetSize());
|
||||
*aWidth = size.width;
|
||||
*aHeight = size.height;
|
||||
*aAutoSize = info.IsAutoSizeEnabled();
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче