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 672189 c3e89ba97e7ae4b6ffaf97862f88593594501479
parent 672182 b6061e5f1659887edb49e0476d20a2df4d520123
child 672190 07418aa0d09680417704814bab7e20a8c250a286
push id82185
push userbwerth@mozilla.com
push dateThu, 28 Sep 2017 21:48:21 +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
@@ -207,16 +207,19 @@ interface nsIContentViewer : nsISupports
   attribute float textZoom;
 
   /** 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. */
+  readonly attribute float effectiveFullZoom;
+
   /**
    * 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) */
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3222,16 +3222,31 @@ 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::GetEffectiveFullZoom(float* aEffectiveFullZoom)
+{
+  NS_ENSURE_ARG_POINTER(aEffectiveFullZoom);
+#ifdef NS_PRINT_PREVIEW
+  if (GetIsPrintPreview()) {
+    *aEffectiveFullZoom = mPrintPreviewZoom;
+    return NS_OK;
+  }
+#endif
+  nsPresContext* pc = GetPresContext();
+  *aEffectiveFullZoom = pc ? pc->GetEffectiveFullZoom() : 1.0f;
+  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::GetEffectiveFullZoom()
+{
+  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,17 @@ 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; }
+  float GetEffectiveFullZoom();
   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;
   },
+  getEffectiveFullZoom(window) {
+    return this._getMUDV(window).effectiveFullZoom;
+  },
   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="effectiveFullZoom"
+                readonly="true">
+        <getter><![CDATA[
+          return this.markupDocumentViewer.effectiveFullZoom;
+        ]]></getter>
+      </property>
+
       <property name="textZoom">
         <getter><![CDATA[
           return this.markupDocumentViewer.textZoom;
         ]]></getter>
         <setter><![CDATA[
           this.markupDocumentViewer.textZoom = val;
         ]]></setter>
       </property>