Bug 1328868 - Part 4 - Don't zoom Contentviewer children when setting the zoom from the PresShell. r?tnikkel draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 05 Feb 2017 21:45:19 +0100
changeset 485472 a4d204027389b65648eb22f6b37b7cb40381d921
parent 485471 c1ab99a0156f83adff7eb9795b168d7ee0767b93
child 485473 573fbaa6c82b4b6e06a35a09b94d508ef62699a7
push id45741
push usermozilla@buttercookie.de
push dateThu, 16 Feb 2017 19:05:17 +0000
reviewerstnikkel
bugs1328868
milestone54.0a1
Bug 1328868 - Part 4 - Don't zoom Contentviewer children when setting the zoom from the PresShell. r?tnikkel Normally, setting the zoom via the ContentViewer will also set the zoom of all the ContentViewer's children. Here however this is not necessary, since each PresShell is already running the code to set the zoom according to the system font scale and will therefore call its ContentViewer's zoom function on its own. Alternatively, we could simply bypass the ContentViewer and set the zoom directly on the PresContext, however doing it the way we are doing it now means that the ContentViewer will be able to report the actual text zoom factor that has been applied if anybody queries it, which we'll make use of later in testing. MozReview-Commit-ID: 7nk5EDNY2FZ
docshell/base/nsIContentViewer.idl
layout/base/PresShell.cpp
layout/base/nsDocumentViewer.cpp
--- a/docshell/base/nsIContentViewer.idl
+++ b/docshell/base/nsIContentViewer.idl
@@ -195,19 +195,23 @@ interface nsIContentViewer : nsISupports
   /*
   Scrolls to a given DOM content node. 
   */
   void scrollToNode(in nsIDOMNode node);
 
   /** The amount by which to scale all text. Default is 1.0. */
   attribute float textZoom;
 
+  [noscript] void setTextZoomInternal(in float aTextZoom, in boolean aUpdateChildren);
+
   /** The amount by which to scale all lengths. Default is 1.0. */
   attribute float fullZoom;
 
+  [noscript] void setFullZoomInternal(in float aFullZoom, in boolean aUpdateChildren);
+
   /**
    * 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/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -11150,17 +11150,19 @@ nsIPresShell::SetGlobalZoom(float aZoomF
   }
 
   nsCOMPtr<nsIContentViewer> cv;
   docShell->GetContentViewer(getter_AddRefs(cv));
   if (!cv) {
     return;
   }
 
-  cv->SetTextZoom(aZoomFactor);
+  // Each PresShell will be running this code, so even though we're going
+  // via the ContentViewer, we don't want to update the zoom of any children.
+  cv->SetTextZoomInternal(aZoomFactor, false /* aUpdateChildren */);
 }
 
 void
 PresShell::PausePainting()
 {
   if (GetPresContext()->RefreshDriver()->GetPresContext() != GetPresContext())
     return;
 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2975,42 +2975,52 @@ SetExtResourceOverrideDPPX(nsIDocument* 
   }
 
   return true;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetTextZoom(float aTextZoom)
 {
+  return SetTextZoomInternal(aTextZoom, true);
+}
+
+NS_IMETHODIMP
+nsDocumentViewer::SetTextZoomInternal(float aTextZoom, bool aUpdateChildren)
+{
   // If we don't have a document, then we need to bail.
   if (!mDocument) {
     return NS_ERROR_FAILURE;
   }
 
   if (GetIsPrintPreview()) {
     return NS_OK;
   }
 
   mTextZoom = aTextZoom;
 
-  // Set the text zoom on all children of mContainer (even if our zoom didn't
-  // change, our children's zoom may be different, though it would be unusual).
-  // Do this first, in case kids are auto-sizing and post reflow commands on
-  // our presshell (which should be subsumed into our own style change reflow).
   struct ZoomInfo ZoomInfo = { aTextZoom };
-  CallChildren(SetChildTextZoom, &ZoomInfo);
+  if (aUpdateChildren) {
+    // Set the text zoom on all children of mContainer (even if our zoom didn't
+    // change, our children's zoom may be different, though it would be unusual).
+    // Do this first, in case kids are auto-sizing and post reflow commands on
+    // our presshell (which should be subsumed into our own style change reflow).
+    CallChildren(SetChildTextZoom, &ZoomInfo);
+  }
 
   // Now change our own zoom
   nsPresContext* pc = GetPresContext();
   if (pc && aTextZoom != mPresContext->TextZoom()) {
       pc->SetTextZoom(aTextZoom);
   }
 
-  // And do the external resources
-  mDocument->EnumerateExternalResources(SetExtResourceTextZoom, &ZoomInfo);
+  if (aUpdateChildren) {
+    // And do the external resources
+    mDocument->EnumerateExternalResources(SetExtResourceTextZoom, &ZoomInfo);
+  }
 
   nsContentUtils::DispatchChromeEvent(mDocument, static_cast<nsIDocument*>(mDocument),
                                       NS_LITERAL_STRING("TextZoomChange"),
                                       true, true);
 
   return NS_OK;
 }
 
@@ -3063,16 +3073,22 @@ nsDocumentViewer::GetMinFontSize(int32_t
   nsPresContext* pc = GetPresContext();
   *aMinFontSize = pc ? pc->BaseMinFontSize() : 0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetFullZoom(float aFullZoom)
 {
+  return SetFullZoomInternal(aFullZoom, true);
+}
+
+NS_IMETHODIMP
+nsDocumentViewer::SetFullZoomInternal(float aFullZoom, bool aUpdateChildren)
+{
 #ifdef NS_PRINT_PREVIEW
   if (GetIsPrintPreview()) {
     nsPresContext* pc = GetPresContext();
     NS_ENSURE_TRUE(pc, NS_OK);
     nsCOMPtr<nsIPresShell> shell = pc->GetPresShell();
     NS_ENSURE_TRUE(shell, NS_OK);
 
     if (!mPrintPreviewZoomed) {
@@ -3100,25 +3116,29 @@ nsDocumentViewer::SetFullZoom(float aFul
   if (!mDocument) {
     return NS_ERROR_FAILURE;
   }
 
   bool fullZoomChange = (mPageZoom != aFullZoom);
   mPageZoom = aFullZoom;
 
   struct ZoomInfo ZoomInfo = { aFullZoom };
-  CallChildren(SetChildFullZoom, &ZoomInfo);
+  if (aUpdateChildren) {
+    CallChildren(SetChildFullZoom, &ZoomInfo);
+  }
 
   nsPresContext* pc = GetPresContext();
   if (pc) {
     pc->SetFullZoom(aFullZoom);
   }
 
-  // And do the external resources
-  mDocument->EnumerateExternalResources(SetExtResourceFullZoom, &ZoomInfo);
+  if (aUpdateChildren) {
+    // And do the external resources
+    mDocument->EnumerateExternalResources(SetExtResourceFullZoom, &ZoomInfo);
+  }
 
   // Dispatch FullZoomChange event only if fullzoom value really was been changed
   if (fullZoomChange) {
     nsContentUtils::DispatchChromeEvent(mDocument, static_cast<nsIDocument*>(mDocument),
                                         NS_LITERAL_STRING("FullZoomChange"),
                                         true, true);
   }