Bug 1376931 Part 2: Extend ContentViewer to allow reporting of effective full zoom level as determined by the device context. draft
authorBrad Werth <bwerth@mozilla.com>
Wed, 27 Sep 2017 14:06:37 -0700
changeset 675195 463fc741a109bc8109f8bb496efc2bc8bec6951a
parent 675194 c3b7759671deae73e40ebca01d7f23a326a4b8c2
child 675196 a8a1b08a3e4d6d8881b4aff763fd453f8cd6b6c5
push id83058
push userbwerth@mozilla.com
push dateWed, 04 Oct 2017 23:14:13 +0000
bugs1376931
milestone58.0a1
Bug 1376931 Part 2: Extend ContentViewer to allow reporting of effective full zoom level as determined by the device context. MozReview-Commit-ID: EoVp1DwAl0j
docshell/base/nsIContentViewer.idl
layout/base/nsDocumentViewer.cpp
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
testing/specialpowers/content/specialpowersAPI.js
toolkit/content/widgets/browser.xml
--- a/docshell/base/nsIContentViewer.idl
+++ b/docshell/base/nsIContentViewer.idl
@@ -208,16 +208,28 @@ interface nsIContentViewer : nsISupports
 
   /** The actual text zoom in effect, as modified by the system font scale. */
   readonly attribute float effectiveTextZoom;
 
   /** 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
    * is applied).
    */
   attribute float overrideDPPX;
 
   /** Disable entire author style level (including HTML presentation hints) */
   attribute boolean authorStyleDisabled;
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3222,16 +3222,35 @@ nsDocumentViewer::GetFullZoom(float* aFu
   // Check the prescontext first because it might have a temporary
   // setting for print-preview
   nsPresContext* pc = GetPresContext();
   *aFullZoom = pc ? pc->GetFullZoom() : mPageZoom;
   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)
 {
   // If we don't have a document, then we need to bail.
   if (!mDocument) {
     return NS_ERROR_FAILURE;
   }
 
   mOverrideDPPX = aDPPX;
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -1359,16 +1359,22 @@ nsPresContext::UpdateEffectiveTextZoom()
   if (HasCachedStyleData()) {
     // Media queries could have changed, since we changed the meaning
     // of 'em' units in them.
     MediaFeatureValuesChanged(eRestyle_ForceDescendants,
                               NS_STYLE_HINT_REFLOW);
   }
 }
 
+float
+nsPresContext::GetDeviceFullZoom()
+{
+  return mDeviceContext->GetFullZoom();
+}
+
 void
 nsPresContext::SetFullZoom(float aZoom)
 {
   if (!mShell || mFullZoom == aZoom) {
     return;
   }
 
   // Re-fetch the view manager's window dimensions in case there's a deferred
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -599,16 +599,22 @@ public:
       // Media queries could have changed, since we changed the meaning
       // of 'em' units in them.
       MediaFeatureValuesChanged(eRestyle_ForceDescendants,
                                 NS_STYLE_HINT_REFLOW);
     }
   }
 
   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; }
   void SetOverrideDPPX(float aDPPX);
 
   nscoord GetAutoQualityMinFontSize() {
     return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
   }
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -1417,16 +1417,19 @@ SpecialPowersAPI.prototype = {
   },
   resetConsole() {
     Services.console.reset();
   },
 
   getFullZoom(window) {
     return this._getMUDV(window).fullZoom;
   },
+  getDeviceFullZoom(window) {
+    return this._getMUDV(window).deviceFullZoom;
+  },
   setFullZoom(window, zoom) {
     this._getMUDV(window).fullZoom = zoom;
   },
   getTextZoom(window) {
     return this._getMUDV(window).textZoom;
   },
   setTextZoom(window, zoom) {
     this._getMUDV(window).textZoom = zoom;
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -549,16 +549,23 @@
         <getter><![CDATA[
           return this.markupDocumentViewer.fullZoom;
         ]]></getter>
         <setter><![CDATA[
           this.markupDocumentViewer.fullZoom = val;
         ]]></setter>
       </property>
 
+      <property name="deviceFullZoom"
+                readonly="true">
+        <getter><![CDATA[
+          return this.markupDocumentViewer.deviceFullZoom;
+        ]]></getter>
+      </property>
+
       <property name="textZoom">
         <getter><![CDATA[
           return this.markupDocumentViewer.textZoom;
         ]]></getter>
         <setter><![CDATA[
           this.markupDocumentViewer.textZoom = val;
         ]]></setter>
       </property>