Implement zooming when non-font inflated pages draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 25 Dec 2016 23:03:19 +0100
changeset 453932 3a2b201c66c02eb973cfa1e504194a9e75173109
parent 453931 525f563669efb7ebe2efd167ff13bf1f5125f5d4
child 453933 4f9050aaefe5125477c992c550ba9210217b2f62
push id39769
push usermozilla@buttercookie.de
push dateMon, 26 Dec 2016 18:12:31 +0000
milestone53.0a1
Implement zooming when non-font inflated pages MozReview-Commit-ID: 3BtPMWZvxtq
layout/base/PresShell.cpp
layout/base/nsIPresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -8864,16 +8864,20 @@ PresShell::Thaw()
 
   if (mDocument)
     mDocument->EnumerateSubDocuments(ThawSubDocument, nullptr);
 
   // Get the activeness of our presshell, as this might have changed
   // while we were in the bfcache
   QueryIsActive();
 
+  // The zoom factor might have changed while we were in the bfache,
+  // so we might need to set it again.
+  HandleGlobalZoom();
+
   // We're now unfrozen
   mFrozen = false;
   UpdateImageLockingState();
 
   UnsuppressPainting();
 }
 
 //--------------------------------------------------------
@@ -10857,20 +10861,24 @@ PresShell::SetupFontInflation()
   NotifyFontSizeInflationEnabledIsDirty();
 }
 
 void
 nsIPresShell::RecomputeFontSizeInflationEnabled()
 {
   mFontSizeInflationEnabledIsDirty = false;
 
-  RecomputeDocEligibleForFontSizeInflation();
-  if (!mDocIsFontSizeInflationEligible) {
-    mFontSizeInflationEnabled = false;
-    return;
+  // When not doing global zooming, we can defer updating this bit of state
+  // to the end of the calculation, if we still need to know it by then.
+  if (nsLayoutUtils::BrowserGlobalZoom() != 0) {
+    RecomputeDocEligibleForFontSizeInflation();
+    if (!mDocIsFontSizeInflationEligible) {
+      mFontSizeInflationEnabled = false;
+      return;
+    }
   }
 
   MOZ_ASSERT(mPresContext, "our pres context should not be null");
   if ((FontSizeInflationEmPerLine() == 0 &&
       FontSizeInflationMinTwips() == 0) || mPresContext->IsChrome()) {
     mFontSizeInflationEnabled = false;
     return;
   }
@@ -10889,16 +10897,24 @@ nsIPresShell::RecomputeFontSizeInflation
       // explicitly disabled.
       if (FontSizeInflationDisabledInMasterProcess()) {
         mFontSizeInflationEnabled = false;
         return;
       }
     }
   }
 
+  if (nsLayoutUtils::BrowserGlobalZoom() == 0) {
+    RecomputeDocEligibleForFontSizeInflation();
+    if (!mDocIsFontSizeInflationEligible) {
+      mFontSizeInflationEnabled = false;
+      return;
+    }
+  }
+
   mFontSizeInflationEnabled = true;
 }
 
 void
 nsIPresShell::RecomputeDocEligibleForFontSizeInflation()
 {
   // XXXjwir3:
   // See bug 706918, comment 23 for more information on this particular section
@@ -10943,22 +10959,56 @@ nsIPresShell::RecomputeDocEligibleForFon
 }
 
 bool
 nsIPresShell::FontSizeInflationEnabled()
 {
   if (mFontSizeInflationEnabledIsDirty) {
     RecomputeFontSizeInflationEnabled();
     PRES_LOG("%p: recomputed FontSizeInflationEnabled: %s\n", this, mFontSizeInflationEnabled?"true":"false");
+
+    HandleGlobalZoom();
   }
   // PRES_LOG("%p: FSIE: %s\n", this, mFontSizeInflationEnabled?"true":"false");
   return mFontSizeInflationEnabled;
 }
 
 void
+nsIPresShell::HandleGlobalZoom()
+{
+  if (nsLayoutUtils::BrowserGlobalZoom() == 0) {
+    return;
+  }
+
+  float zoomFactor = nsLayoutUtils::BrowserGlobalZoom() / 100.0f;
+
+  MOZ_ASSERT(mDocument, "our document should not be null");
+
+  if (!mDocIsFontSizeInflationEligible && !(mDocument->IsSyntheticDocument())) {
+    SetGlobalZoom(zoomFactor);
+  } else {
+    SetGlobalZoom(1.0f);
+  }
+}
+
+void
+nsIPresShell::SetGlobalZoom(const float& aZoomFactor)
+{
+  MOZ_ASSERT(mPresContext, "our pres context should not be null");
+
+  if (nsLayoutUtils::BrowserGlobalZoomFull()) {
+    mPresContext->SetFullZoom(aZoomFactor);
+    mPresContext->SetTextZoom(1.0f);
+  } else {
+    mPresContext->SetFullZoom(1.0f);
+    mPresContext->SetTextZoom(aZoomFactor);
+  }
+}
+
+void
 PresShell::PausePainting()
 {
   if (GetPresContext()->RefreshDriver()->GetPresContext() != GetPresContext())
     return;
 
   mPaintingIsFrozen = true;
   GetPresContext()->RefreshDriver()->Freeze();
 }
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -1635,16 +1635,24 @@ protected:
 
   /**
     * Determine if the underlying document is eligible for font size inflation.
     * This value is cached after computation, as the computation is somewhat
     * expensive.
     */
   void RecomputeDocEligibleForFontSizeInflation();
 
+  /**
+    * Handle global page/text zooming on pages that are not eligible for
+    * font size inflation.
+    */
+  void HandleGlobalZoom();
+
+  void SetGlobalZoom(const float& aZoomFactor);
+
   void RecordAlloc(void* aPtr) {
 #ifdef DEBUG
     MOZ_ASSERT(!mAllocatedPointers.Contains(aPtr));
     mAllocatedPointers.PutEntry(aPtr);
 #endif
   }
 
   void RecordFree(void* aPtr) {