Bug 1640108 - Move nsPrintJob::SetPrintPO into nsPrintObject class and rename it to EnablePrinting. r=jwatt
authorHiroyuki Ikezoe <hikezoe.birchill@mozilla.com>
Fri, 22 May 2020 09:57:12 +0000
changeset 531605 76186c5df6b85b0baa82e37a491fbe3253f105ec
parent 531604 5655f21c7c037e04e58bc7cd4b97e5747908bd5d
child 531606 9fd14281791905a085a85cf79de8a5f1c64bce4b
push id37441
push userapavel@mozilla.com
push dateFri, 22 May 2020 21:38:53 +0000
treeherdermozilla-central@d6abd35b54ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1640108
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1640108 - Move nsPrintJob::SetPrintPO into nsPrintObject class and rename it to EnablePrinting. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D76456
layout/printing/nsPrintJob.cpp
layout/printing/nsPrintObject.cpp
layout/printing/nsPrintObject.h
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -1214,30 +1214,16 @@ bool nsPrintJob::IsThereAnIFrameSelected
         }
       }
     }
   }
 
   return iFrameIsSelected;
 }
 
-//---------------------------------------------------------------------
-// Recursively sets all the PO items to be printed
-// from the given item down into the tree
-void nsPrintJob::SetPrintPO(nsPrintObject* aPO, bool aPrint) {
-  NS_ASSERTION(aPO, "Pointer is null!");
-
-  // Set whether to print flag
-  aPO->mDontPrint = !aPrint;
-
-  for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) {
-    SetPrintPO(kid.get(), aPrint);
-  }
-}
-
 // static
 void nsPrintJob::GetDisplayTitleAndURL(Document& aDoc,
                                        nsIPrintSettings* aSettings,
                                        DocTitleDefault aTitleDefault,
                                        nsAString& aTitle, nsAString& aURLStr) {
   aTitle.Truncate();
   aURLStr.Truncate();
 
@@ -1687,17 +1673,17 @@ nsresult nsPrintJob::ReflowDocList(const
   NS_ENSURE_ARG_POINTER(aPO);
 
   // Check to see if the subdocument's element has been hidden by the parent
   // document
   if (aPO->mParent && aPO->mParent->mPresShell) {
     nsIFrame* frame =
         aPO->mContent ? aPO->mContent->GetPrimaryFrame() : nullptr;
     if (!frame || !frame->StyleVisibility()->IsVisible()) {
-      SetPrintPO(aPO.get(), false);
+      aPO->EnablePrinting(false);
       aPO->mInvisible = true;
       return NS_OK;
     }
   }
 
   UpdateZoomRatio(aPO.get(), aSetPixelScale);
 
   nsresult rv;
@@ -1948,17 +1934,17 @@ nsresult nsPrintJob::SetRootView(nsPrint
   doReturn = false;
 
   if (aPO->mParent && aPO->mParent->IsPrintable()) {
     nsIFrame* frame =
         aPO->mContent ? aPO->mContent->GetPrimaryFrame() : nullptr;
     // Without a frame, this document can't be displayed; therefore, there is no
     // point to reflowing it
     if (!frame) {
-      SetPrintPO(aPO, false);
+      aPO->EnablePrinting(false);
       doReturn = true;
       return NS_OK;
     }
 
     // XXX If printing supported printing document hierarchies with non-constant
     // zoom this would be wrong as we use the same mPrt->mPrintDC for all
     // subdocuments.
     adjSize = frame->GetContentRect().Size();
@@ -2694,17 +2680,17 @@ nsresult nsPrintJob::EnablePOsForPrintin
   PR_PL(("----\n"));
 
   bool treatAsNonFrameset = !printData->mIsParentAFrameSet ||
                             printRangeType == nsIPrintSettings::kRangeSelection;
 
   if (treatAsNonFrameset &&
       (printRangeType == nsIPrintSettings::kRangeAllPages ||
        printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange)) {
-    SetPrintPO(printData->mPrintObject.get(), true);
+    printData->mPrintObject->EnablePrinting(true);
 
     // Set the children so they are PrinAsIs
     // In this case, the children are probably IFrames
     if (printData->mPrintObject->mKids.Length() > 0) {
       for (const UniquePtr<nsPrintObject>& po :
            printData->mPrintObject->mKids) {
         NS_ASSERTION(po, "nsPrintObject can't be null!");
         po->SetPrintAsIs(true);
@@ -2722,17 +2708,17 @@ nsresult nsPrintJob::EnablePOsForPrintin
       // Find the selected IFrame
       nsPrintObject* po = FindPrintObjectByDOMWin(printData->mPrintObject.get(),
                                                   printData->mCurrentFocusWin);
       if (po) {
         // Makes sure all of its children are be printed "AsIs"
         po->SetPrintAsIs(true);
 
         // Now, only enable this POs (the selected PO) and all of its children
-        SetPrintPO(po, true);
+        po->EnablePrinting(true);
 
         // check to see if we have a range selection,
         // as oppose to a insert selection
         // this means if the user just clicked on the IFrame then
         // there will not be a selection so we want the entire page to print
         //
         // XXX this is sort of a hack right here to make the page
         // not try to reposition itself when printing selection
@@ -2747,27 +2733,27 @@ nsresult nsPrintJob::EnablePOsForPrintin
       }
     } else if (treatAsNonFrameset) {
       for (uint32_t i = 0; i < printData->mPrintDocList.Length(); i++) {
         nsPrintObject* po = printData->mPrintDocList.ElementAt(i);
         NS_ASSERTION(po, "nsPrintObject can't be null!");
         nsCOMPtr<nsPIDOMWindowOuter> domWin = po->mDocShell->GetWindow();
         if (IsThereARangeSelection(domWin)) {
           printData->mCurrentFocusWin = std::move(domWin);
-          SetPrintPO(po, true);
+          po->EnablePrinting(true);
           break;
         }
       }
       return NS_OK;
     }
   }
 
   if (printRangeType != nsIPrintSettings::kRangeSelection) {
     printData->mPrintObject->SetPrintAsIs(true);
-    SetPrintPO(printData->mPrintObject.get(), true);
+    printData->mPrintObject->EnablePrinting(true);
     return NS_OK;
   }
 
   if ((printData->mIsParentAFrameSet && printData->mCurrentFocusWin) ||
       printData->mIsIFrameSelected) {
     nsPrintObject* po = FindPrintObjectByDOMWin(printData->mPrintObject.get(),
                                                 printData->mCurrentFocusWin);
     if (po) {
@@ -2775,17 +2761,17 @@ nsresult nsPrintJob::EnablePOsForPrintin
       // we don't want to do this for documents that have no children,
       // because then the "DoEndPage" gets called and it shouldn't
       if (po->mKids.Length() > 0) {
         // Makes sure that itself, and all of its children are printed "AsIs"
         po->SetPrintAsIs(true);
       }
 
       // Now, only enable this POs (the selected PO) and all of its children
-      SetPrintPO(po, true);
+      po->EnablePrinting(true);
     }
   }
 
   return NS_OK;
 }
 
 //-------------------------------------------------------
 // Return the nsPrintObject with that is XMost (The widest frameset frame) AND
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -240,8 +240,17 @@ void nsPrintObject::DestroyPresentation(
 }
 
 void nsPrintObject::SetPrintAsIs(bool aAsIs) {
   mPrintAsIs = aAsIs;
   for (const UniquePtr<nsPrintObject>& kid : mKids) {
     kid->SetPrintAsIs(aAsIs);
   }
 }
+
+void nsPrintObject::EnablePrinting(bool aEnable) {
+  // Set whether to print flag
+  mDontPrint = !aEnable;
+
+  for (const UniquePtr<nsPrintObject>& kid : mKids) {
+    kid->EnablePrinting(aEnable);
+  }
+}
--- a/layout/printing/nsPrintObject.h
+++ b/layout/printing/nsPrintObject.h
@@ -44,16 +44,22 @@ class nsPrintObject {
   void DestroyPresentation();
 
   /**
    * Recursively sets the PO items to be printed "As Is"
    * from the given item down into the treei
    */
   void SetPrintAsIs(bool aAsIs);
 
+  /**
+   * Recursively sets all the PO items to be printed
+   * from the given item down into the tree
+   */
+  void EnablePrinting(bool aEnable);
+
   // Data Members
   nsCOMPtr<nsIDocShell> mDocShell;
   nsCOMPtr<nsIDocShellTreeOwner> mTreeOwner;
   RefPtr<mozilla::dom::Document> mDocument;
 
   RefPtr<nsPresContext> mPresContext;
   RefPtr<mozilla::PresShell> mPresShell;
   RefPtr<nsViewManager> mViewManager;