Bug 1642162. Remove nsPrintJob.cpp's MapContentToWebShells and MapContentForPO functions. r=bobowen
authorJonathan Watt <jwatt@jwatt.org>
Tue, 02 Jun 2020 21:03:20 +0000
changeset 597703 be077884a27439f51737192dbb805f9474c2d3d6
parent 597702 480ec262bae2ad526cd41b46d149182f9f2f4be6
child 597704 9bc32e3ba97ab3b150c1bc38a120cdd6d9c14139
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1642162
milestone79.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 1642162. Remove nsPrintJob.cpp's MapContentToWebShells and MapContentForPO functions. r=bobowen We nowadays already directly set nsPrintObject->mContent in nsPrintObject::InitAsNestedObject. This patch adds the setting of mFrameType and PrintAsIs that MapContentForPO does, making MapContentToWebShells and MapContentForPO redundant. Differential Revision: https://phabricator.services.mozilla.com/D77597
layout/printing/nsPrintJob.cpp
layout/printing/nsPrintObject.cpp
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -289,115 +289,16 @@ static nsresult GetSeqFrameAndCountPages
 
   // count the total number of pages
   aCount = aSeqFrame->PrincipalChildList().GetLength();
 
   return NS_OK;
 }
 
 /**
- * This method is key to the entire print mechanism.
- *
- * This "maps" or figures out which sub-doc represents a
- * given Frame or IFrame in its parent sub-doc.
- *
- * So the Mcontent pointer in the child sub-doc points to the
- * content in the its parent document, that caused it to be printed.
- * This is used later to (after reflow) to find the absolute location
- * of the sub-doc on its parent's page frame so it can be
- * printed in the correct location.
- *
- * This method recursvely "walks" the content for a document finding
- * all the Frames and IFrames, then sets the "mFrameType" data member
- * which tells us what type of PO we have
- */
-static void MapContentForPO(const UniquePtr<nsPrintObject>& aPO,
-                            nsIContent* aContent) {
-  MOZ_ASSERT(aPO && aContent, "Null argument");
-
-  Document* doc = aContent->GetComposedDoc();
-
-  NS_ASSERTION(doc, "Content without a document from a document tree?");
-
-  Document* subDoc = doc->GetSubDocumentFor(aContent);
-
-  if (subDoc) {
-    nsCOMPtr<nsIDocShell> docShell(subDoc->GetDocShell());
-
-    if (docShell) {
-      nsPrintObject* po = nullptr;
-      for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) {
-        if (kid->mDocument == subDoc) {
-          po = kid.get();
-          break;
-        }
-      }
-
-      // XXX If a subdocument has no onscreen presentation, there will be no PO
-      //     This is even if there should be a print presentation
-      if (po) {
-        // "frame" elements not in a frameset context should be treated
-        // as iframes
-        if (aContent->IsHTMLElement(nsGkAtoms::frame) &&
-            po->mParent->mFrameType == eFrameSet) {
-          po->mFrameType = eFrame;
-        } else {
-          // Assume something iframe-like, i.e. iframe, object, or embed
-          po->mFrameType = eIFrame;
-          po->SetPrintAsIs(true);
-          NS_ASSERTION(po->mParent, "The root must be a parent");
-          po->mParent->mPrintAsIs = true;
-        }
-      }
-    }
-  }
-
-  // walk children content
-  for (nsIContent* child = aContent->GetFirstChild(); child;
-       child = child->GetNextSibling()) {
-    MapContentForPO(aPO, child);
-  }
-}
-
-/**
- * The walks the PO tree and for each document it walks the content
- * tree looking for any content that are sub-shells
- *
- * It then sets the mContent pointer in the "found" PO object back to the
- * the document that contained it.
- */
-static void MapContentToWebShells(const UniquePtr<nsPrintObject>& aRootPO,
-                                  const UniquePtr<nsPrintObject>& aPO) {
-  NS_ASSERTION(aRootPO, "Pointer is null!");
-  NS_ASSERTION(aPO, "Pointer is null!");
-
-  // Recursively walk the content from the root item
-  // XXX Would be faster to enumerate the subdocuments, although right now
-  //     Document doesn't expose quite what would be needed.
-  nsCOMPtr<nsIContentViewer> viewer;
-  aPO->mDocShell->GetContentViewer(getter_AddRefs(viewer));
-  if (!viewer) return;
-
-  nsCOMPtr<Document> doc = viewer->GetDocument();
-  if (!doc) return;
-
-  Element* rootElement = doc->GetRootElement();
-  if (rootElement) {
-    MapContentForPO(aPO, rootElement);
-  } else {
-    NS_WARNING("Null root content on (sub)document.");
-  }
-
-  // Continue recursively walking the chilren of this PO
-  for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) {
-    MapContentToWebShells(aRootPO, kid);
-  }
-}
-
-/**
  * The outparam aDocList returns a (depth first) flat list of all the
  * nsPrintObjects created.
  */
 static void BuildNestedPrintObjects(Document* aDocument,
                                     const UniquePtr<nsPrintObject>& aPO,
                                     nsTArray<nsPrintObject*>* aDocList) {
   MOZ_ASSERT(aDocument, "Pointer is null!");
   MOZ_ASSERT(aDocList, "Pointer is null!");
@@ -751,19 +652,16 @@ nsresult nsPrintJob::DoCommonPrint(bool 
     printData->mPrintProgressListeners.AppendObject(aWebProgressListener);
   }
 
   // Get the currently focused window and cache it
   // because the Print Dialog will "steal" focus and later when you try
   // to get the currently focused windows it will be nullptr
   printData->mCurrentFocusWin = FindFocusedDOMWindow();
 
-  // Check to see if there is a "regular" selection
-  bool isSelection = IsThereARangeSelection(printData->mCurrentFocusWin);
-
   // Get the docshell for this documentviewer
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   {
     nsAutoScriptBlocker scriptBlocker;
     printData->mPrintObject = MakeUnique<nsPrintObject>();
     rv = printData->mPrintObject->InitAsRootObject(docShell, aSourceDoc,
@@ -792,24 +690,20 @@ nsresult nsPrintJob::DoCommonPrint(bool 
     SetIsPrinting(true);
   }
 
   // XXX This isn't really correct...
   if (!printData->mPrintObject->mDocument ||
       !printData->mPrintObject->mDocument->GetRootElement())
     return NS_ERROR_GFX_PRINTER_STARTDOC;
 
-  // Create the linkage from the sub-docs back to the content element
-  // in the parent document
-  MapContentToWebShells(printData->mPrintObject, printData->mPrintObject);
-
+  // Now determine how to set up the Frame print UI
+  bool isSelection = IsThereARangeSelection(printData->mCurrentFocusWin);
   bool isIFrameSelected = IsThereAnIFrameSelected(
       docShell, printData->mCurrentFocusWin, printData->mIsParentAFrameSet);
-
-  // Now determine how to set up the Frame print UI
   printData->mPrintSettings->SetPrintOptions(
       nsIPrintSettings::kEnableSelectionRB, isSelection || isIFrameSelected);
 
   bool printingViaParent =
       XRE_IsContentProcess() && Preferences::GetBool("print.print_via_parent");
   nsCOMPtr<nsIDeviceContextSpec> devspec;
   if (printingViaParent) {
     devspec = new nsDeviceContextSpecProxy();
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -216,16 +216,28 @@ nsresult nsPrintObject::InitAsNestedObje
 
   mParent = aParent;
   mDocShell = aDocShell;
   mDocument = aDoc;
 
   nsCOMPtr<nsPIDOMWindowOuter> window = aDoc->GetWindow();
   mContent = window->GetFrameElementInternal();
 
+  // "frame" elements not in a frameset context should be treated
+  // as iframes
+  if (mContent->IsHTMLElement(nsGkAtoms::frame) &&
+      mParent->mFrameType == eFrameSet) {
+    mFrameType = eFrame;
+  } else {
+    // Assume something iframe-like, i.e. iframe, object, or embed
+    mFrameType = eIFrame;
+    mParent->mPrintAsIs = true;
+    SetPrintAsIs(true);
+  }
+
   return NS_OK;
 }
 
 //------------------------------------------------------------------
 // Resets PO by destroying the presentation
 void nsPrintObject::DestroyPresentation() {
   if (mPresShell) {
     mPresShell->EndObservingDocument();