Bug 1328868 - Part 3 - Copy the global zoom state over into new presShell when navigating/reloading. r?tnikkel draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 04 Feb 2017 23:04:59 +0100
changeset 486556 ee2e5b5342f2dfa1754cdaec15a8b5dcb83aa6d5
parent 486555 f7004b004c2fb9e630ce045dcdc8064b2564bcda
child 486557 cef5a77cecd1e785d97ffb9d554a25c0d5dd2d90
push id46022
push usermozilla@buttercookie.de
push dateSat, 18 Feb 2017 15:01:14 +0000
reviewerstnikkel
bugs1328868
milestone54.0a1
Bug 1328868 - Part 3 - Copy the global zoom state over into new presShell when navigating/reloading. r?tnikkel When the global zoom factor is set to 1.0f, i.e. when this feature has been turned back off or simply was never enabled, we want to be able to return early and not set any zoom factor. To that effect, we need to call setTextZoom(1.0f) once when going from systemFontScale != 1.0f to systemFontScale == 1.0f in order to reset the text zoom to its default value. We do this by keeping track of the global zoom state of each PresShell via mGlobalZoomWasEnabled, however for this to properly work, we need to copy this bit of state over into any new presShell that gets created when reloading the document or navigating back-/forward (with or without the bfcache) . MozReview-Commit-ID: AqNOGIMsRt
docshell/base/nsDocShell.cpp
dom/base/nsDocument.cpp
layout/base/nsIPresShell.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -8696,29 +8696,33 @@ nsDocShell::RestoreFromHistory()
   // Save off the root view's parent and sibling so that we can insert the
   // new content viewer's root view at the same position.  Also save the
   // bounds of the root view's widget.
 
   nsView* rootViewSibling = nullptr;
   nsView* rootViewParent = nullptr;
   nsIntRect newBounds(0, 0, 0, 0);
 
+  // Also save whether global font scaling was active on the previous shell.
+  bool globalZoomState = false;
+
   nsCOMPtr<nsIPresShell> oldPresShell = GetPresShell();
   if (oldPresShell) {
     nsViewManager* vm = oldPresShell->GetViewManager();
     if (vm) {
       nsView* oldRootView = vm->GetRootView();
 
       if (oldRootView) {
         rootViewSibling = oldRootView->GetNextSibling();
         rootViewParent = oldRootView->GetParent();
 
         mContentViewer->GetBounds(newBounds);
       }
     }
+    globalZoomState = oldPresShell->GetGlobalZoomState();
   }
 
   nsCOMPtr<nsIContent> container;
   nsCOMPtr<nsIDocument> sibling;
   if (rootViewParent && rootViewParent->GetParent()) {
     nsIFrame* frame = rootViewParent->GetParent()->GetFrame();
     container = frame ? frame->GetContent() : nullptr;
   }
@@ -9058,16 +9062,17 @@ nsDocShell::RestoreFromHistory()
   newRootView = rootViewSibling = rootViewParent = nullptr;
   newVM = nullptr;
 
   // Simulate the completion of the load.
   nsDocShell::FinishRestore();
 
   // Restart plugins, and paint the content.
   if (shell) {
+    shell->SetGlobalZoomState(globalZoomState);
     shell->Thaw();
   }
 
   return privWin->FireDelayedDOMEvents();
 }
 
 nsresult
 nsDocShell::CreateContentViewer(const nsACString& aContentType,
@@ -9391,30 +9396,33 @@ nsDocShell::SetupNewViewer(nsIContentVie
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(oldCv->GetAuthorStyleDisabled(&styleDisabled),
                           NS_ERROR_FAILURE);
       }
     }
   }
 
   nscolor bgcolor = NS_RGBA(0, 0, 0, 0);
+  bool globalZoomState = false;
   // Ensure that the content viewer is destroyed *after* the GC - bug 71515
   nsCOMPtr<nsIContentViewer> contentViewer = mContentViewer;
   if (contentViewer) {
     // Stop any activity that may be happening in the old document before
     // releasing it...
     contentViewer->Stop();
 
     // Try to extract the canvas background color from the old
     // presentation shell, so we can use it for the next document.
     nsCOMPtr<nsIPresShell> shell;
     contentViewer->GetPresShell(getter_AddRefs(shell));
 
     if (shell) {
       bgcolor = shell->GetCanvasBackground();
+      // Also copy the global zoom state over.
+      globalZoomState = shell->GetGlobalZoomState();
     }
 
     contentViewer->Close(mSavingOldViewer ? mOSHE.get() : nullptr);
     aNewViewer->SetPreviousViewer(contentViewer);
   }
   if (mOSHE && (!mContentViewer || !mSavingOldViewer)) {
     // We don't plan to save a viewer in mOSHE; tell it to drop
     // any other state it's holding.
@@ -9465,16 +9473,17 @@ nsDocShell::SetupNewViewer(nsIContentVie
 
   // Stuff the bgcolor from the old pres shell into the new
   // pres shell. This improves page load continuity.
   nsCOMPtr<nsIPresShell> shell;
   mContentViewer->GetPresShell(getter_AddRefs(shell));
 
   if (shell) {
     shell->SetCanvasBackground(bgcolor);
+    shell->SetGlobalZoomState(globalZoomState);
   }
 
   // XXX: It looks like the LayoutState gets restored again in Embed()
   //      right after the call to SetupNewViewer(...)
 
   // We don't show the mContentViewer yet, since we want to draw the old page
   // until we have enough of the new page to show.  Just return with the new
   // viewer still set to hidden.
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -836,16 +836,17 @@ TransferZoomLevels(nsIDocument* aFromDoc
   nsPresContext* toCtxt = toShell->GetPresContext();
   if (!toCtxt)
     return;
 
   toCtxt->SetFullZoom(fromCtxt->GetFullZoom());
   toCtxt->SetBaseMinFontSize(fromCtxt->BaseMinFontSize());
   toCtxt->SetTextZoom(fromCtxt->TextZoom());
   toCtxt->SetOverrideDPPX(fromCtxt->GetOverrideDPPX());
+  toShell->SetGlobalZoomState(fromShell->GetGlobalZoomState());
 }
 
 void
 TransferShowingState(nsIDocument* aFromDoc, nsIDocument* aToDoc)
 {
   MOZ_ASSERT(aFromDoc && aToDoc,
              "transferring showing state from/to null doc");
 
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -1591,16 +1591,19 @@ public:
    * whether font size inflation is enabled on the next call to
    * FontSizeInflationEnabled().
    */
   void NotifyFontSizeInflationEnabledIsDirty()
   {
     mFontSizeInflationEnabledIsDirty = true;
   }
 
+  void SetGlobalZoomState(bool aEnabled) { mGlobalZoomWasEnabled = aEnabled; }
+  bool GetGlobalZoomState() { return mGlobalZoomWasEnabled; }
+
   virtual void AddInvalidateHiddenPresShellObserver(nsRefreshDriver *aDriver) = 0;
 
   void InvalidatePresShellIfHidden();
   void CancelInvalidatePresShellIfHidden();
 
 
   //////////////////////////////////////////////////////////////////////////////
   // Approximate frame visibility tracking public API.