From 1450446d110c90a2e80434feff49314b14afdc78 Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Wed, 27 Sep 2017 14:06:37 -0700 Subject: [PATCH] Bug 1376931 Part 2: Extend ContentViewer to allow reporting of effective full zoom level as determined by the device context. r=bz,heycam MozReview-Commit-ID: EoVp1DwAl0j --HG-- extra : rebase_source : b0bdf52adb0e44b51c4bbeb33668c35f559b8464 --- docshell/base/nsIContentViewer.idl | 12 ++++++++++++ layout/base/nsDocumentViewer.cpp | 19 +++++++++++++++++++ layout/base/nsPresContext.cpp | 6 ++++++ layout/base/nsPresContext.h | 6 ++++++ .../specialpowers/content/specialpowersAPI.js | 3 +++ toolkit/content/widgets/browser.xml | 7 +++++++ 6 files changed, 53 insertions(+) diff --git a/docshell/base/nsIContentViewer.idl b/docshell/base/nsIContentViewer.idl index 75f457d2d9c7..8cfe7955533e 100644 --- a/docshell/base/nsIContentViewer.idl +++ b/docshell/base/nsIContentViewer.idl @@ -212,6 +212,18 @@ interface nsIContentViewer : nsISupports /** The amount by which to scale all lengths. Default is 1.0. */ attribute float fullZoom; + /** + * The actual full zoom in effect, as modified by the device context. + * For a requested full zoom, the device context may choose a slightly + * different effectiveFullZoom to accomodate integer rounding of app units + * per dev pixel. This property returns the actual zoom amount in use, + * though it may not be good user experience to report that a requested zoom + * of 90% is actually 89.1%, for example. This value is provided primarily to + * support media queries of dppx values, because those queries are matched + * against the actual native device pixel ratio and the actual full zoom. + */ + readonly attribute float deviceFullZoom; + /** * The value used to override devicePixelRatio and media queries dppx. * Default is 0.0, that means no overriding is done (only a positive value diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 1d4242d12996..856e6957292b 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -3226,6 +3226,25 @@ nsDocumentViewer::GetFullZoom(float* aFullZoom) return NS_OK; } +NS_IMETHODIMP +nsDocumentViewer::GetDeviceFullZoom(float* aDeviceFullZoom) +{ + NS_ENSURE_ARG_POINTER(aDeviceFullZoom); +#ifdef NS_PRINT_PREVIEW + if (GetIsPrintPreview()) { + // Print Preview overrides all zoom; if specified, we use the print preview + // zoom, no matter what. + *aDeviceFullZoom = mPrintPreviewZoom; + return NS_OK; + } +#endif + // If not in print preview, ask the prescontext for the device zoom, if a + // prescontext is available. + nsPresContext* pc = GetPresContext(); + *aDeviceFullZoom = pc ? pc->GetDeviceFullZoom() : mPageZoom; + return NS_OK; +} + NS_IMETHODIMP nsDocumentViewer::SetOverrideDPPX(float aDPPX) { diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 71d5b1e30eb9..c0b59693abf5 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1364,6 +1364,12 @@ nsPresContext::UpdateEffectiveTextZoom() } } +float +nsPresContext::GetDeviceFullZoom() +{ + return mDeviceContext->GetFullZoom(); +} + void nsPresContext::SetFullZoom(float aZoom) { diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 32fc9ac1eed4..d654b259a936 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -604,6 +604,12 @@ public: } float GetFullZoom() { return mFullZoom; } + /** + * Device full zoom differs from full zoom because it gets the zoom from + * the device context, which may be using a different zoom due to rounding + * of app units to device pixels. + */ + float GetDeviceFullZoom(); void SetFullZoom(float aZoom); float GetOverrideDPPX() { return mOverrideDPPX; } diff --git a/testing/specialpowers/content/specialpowersAPI.js b/testing/specialpowers/content/specialpowersAPI.js index a528bd6a8183..df009255c765 100644 --- a/testing/specialpowers/content/specialpowersAPI.js +++ b/testing/specialpowers/content/specialpowersAPI.js @@ -1422,6 +1422,9 @@ SpecialPowersAPI.prototype = { getFullZoom(window) { return this._getMUDV(window).fullZoom; }, + getDeviceFullZoom(window) { + return this._getMUDV(window).deviceFullZoom; + }, setFullZoom(window, zoom) { this._getMUDV(window).fullZoom = zoom; }, diff --git a/toolkit/content/widgets/browser.xml b/toolkit/content/widgets/browser.xml index 8ac9d3adacc0..74c3b2ca6092 100644 --- a/toolkit/content/widgets/browser.xml +++ b/toolkit/content/widgets/browser.xml @@ -554,6 +554,13 @@ ]]> + + + +