Bug 974242 - Bring FullZoom into nsDocument::GetViewportInfo. r=mbrubeck, r=kats

--HG--
extra : rebase_source : 4fd84defb47c9eb5bcea849fde61e6e09dc5e9a3
This commit is contained in:
C.J. Ku 2014-08-10 02:50:07 +08:00
parent 11654569cc
commit c9284798c3
2 changed files with 40 additions and 11 deletions

View File

@ -26,8 +26,10 @@ class MOZ_STACK_CLASS nsViewportInfo
{
public:
nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
bool aAllowZoom = true, bool aAllowDoubleTapZoom = true) :
mDefaultZoom(1.0),
const mozilla::CSSToScreenScale& aDefaultZoom,
bool aAllowZoom,
bool aAllowDoubleTapZoom) :
mDefaultZoom(aDefaultZoom),
mAutoSize(true),
mAllowZoom(aAllowZoom),
mAllowDoubleTapZoom(aAllowDoubleTapZoom)

View File

@ -7501,15 +7501,27 @@ nsIDocument::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv)
nsViewportInfo
nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
{
nsPresContext* context = mPresShell->GetPresContext();
float fullZoom = context ? context->GetFullZoom() : 1.0;
fullZoom = (fullZoom == 0.0) ? 1.0 : fullZoom;
CSSToScreenScale defaultScale = CSSToLayoutDeviceScale(fullZoom) *
LayoutDeviceToScreenScale(1.0);
// In cases where the width of the CSS viewport is less than or equal to the width
// of the display (i.e. width <= device-width) then we disable double-tap-to-zoom
// behaviour. See bug 941995 for details.
switch (mViewportType) {
case DisplayWidthHeight:
return nsViewportInfo(aDisplaySize);
return nsViewportInfo(aDisplaySize,
defaultScale,
/*allowZoom*/ true,
/*allowDoubleTapZoom*/ true);
case DisplayWidthHeightNoZoom:
return nsViewportInfo(aDisplaySize, /*allowZoom*/ false, /*allowDoubleTapZoom*/ false);
return nsViewportInfo(aDisplaySize,
defaultScale,
/*allowZoom*/ false,
/*allowDoubleTapZoom*/ false);
case Unknown:
{
nsAutoString viewport;
@ -7529,7 +7541,10 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
{
// We're making an assumption that the docType can't change here
mViewportType = DisplayWidthHeight;
return nsViewportInfo(aDisplaySize, /*allowZoom*/true, /*allowDoubleTapZoom*/false);
return nsViewportInfo(aDisplaySize,
defaultScale,
/*allowZoom*/true,
/*allowDoubleTapZoom*/false);
}
}
}
@ -7538,7 +7553,10 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
GetHeaderData(nsGkAtoms::handheldFriendly, handheldFriendly);
if (handheldFriendly.EqualsLiteral("true")) {
mViewportType = DisplayWidthHeight;
return nsViewportInfo(aDisplaySize, /*allowZoom*/true, /*allowDoubleTapZoom*/false);
return nsViewportInfo(aDisplaySize,
defaultScale,
/*allowZoom*/true,
/*allowDoubleTapZoom*/false);
}
// Bug 940036. This is bad. When FirefoxOS was built, apps installed
@ -7561,7 +7579,10 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
"ImplicitMetaViewportTagFallback");
}
mViewportType = DisplayWidthHeightNoZoom;
return nsViewportInfo(aDisplaySize, /*allowZoom*/false, /*allowDoubleTapZoom*/false);
return nsViewportInfo(aDisplaySize,
defaultScale,
/*allowZoom*/false,
/*allowDoubleTapZoom*/false);
}
}
@ -7652,8 +7673,11 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
if (mValidHeight && !aDisplaySize.IsEmpty()) {
size.width = size.height * aDisplaySize.width / aDisplaySize.height;
} else {
// Stretch CSS pixel size of viewport to keep device pixel size
// unchanged after full zoom applied.
// See bug 974242.
size.width = Preferences::GetInt("browser.viewport.desktopWidth",
kViewportDefaultScreenWidth);
kViewportDefaultScreenWidth) / fullZoom;
}
}
@ -7664,10 +7688,13 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
size.height = size.width;
}
}
// Now convert the scale into device pixels per CSS pixel.
// Now convert the scale into device pixels per CSS pixel base on this formula
// CSSPixel x widget scale x full zoom = LayoutDevicePixel
nsIWidget *widget = nsContentUtils::WidgetForDocument(this);
CSSToLayoutDeviceScale pixelRatio = widget ? widget->GetDefaultScale()
: CSSToLayoutDeviceScale(1.0f);
CSSToLayoutDeviceScale pixelRatio = CSSToLayoutDeviceScale(
(widget ? widget->GetDefaultScale().scale : 1.0f) * fullZoom);
CSSToScreenScale scaleFloat = mScaleFloat * pixelRatio;
CSSToScreenScale scaleMinFloat = mScaleMinFloat * pixelRatio;
CSSToScreenScale scaleMaxFloat = mScaleMaxFloat * pixelRatio;