author | Jonathan Watt <jwatt@jwatt.org> |
Sun, 22 May 2022 09:37:57 +0000 | |
changeset 618498 | f907e3b915ede8be7e3efc8888ea26fb095a331e |
parent 618497 | 4e05361c6b08aad43b939c33f5aa608a3d9ccbc8 |
child 618499 | 2448004443d5d97127fe3e972bae95f2efb2c958 |
push id | 163296 |
push user | jwatt@jwatt.org |
push date | Sun, 22 May 2022 09:41:02 +0000 |
treeherder | autoland@d0bb4f6201a0 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | emilio |
bugs | 1770539 |
milestone | 102.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
|
--- a/layout/printing/nsPrintData.cpp +++ b/layout/printing/nsPrintData.cpp @@ -19,17 +19,17 @@ extern mozilla::LazyLogModule gPrintingLog; #define PR_PL(_p1) MOZ_LOG(gPrintingLog, mozilla::LogLevel::Debug, _p1); //--------------------------------------------------- //-- nsPrintData Class Impl //--------------------------------------------------- nsPrintData::nsPrintData(ePrintDataType aType) - : mType(aType), mPrintDocList(0), mOnStartSent(false), mIsAborted(false) {} + : mType(aType), mOnStartSent(false), mIsAborted(false) {} nsPrintData::~nsPrintData() { // Only Send an OnEndPrinting if we have started printing if (mOnStartSent && mType != eIsPrintPreview) { OnEndPrinting(); } if (mPrintDC) {
--- a/layout/printing/nsPrintData.h +++ b/layout/printing/nsPrintData.h @@ -9,17 +9,16 @@ #include "mozilla/Attributes.h" #include "mozilla/UniquePtr.h" // Interfaces #include "nsDeviceContext.h" #include "nsIPrintSettings.h" #include "nsISupportsImpl.h" -#include "nsTArray.h" #include "nsCOMArray.h" class nsPrintObject; class nsIWebProgressListener; class nsPrintData { public: typedef enum { eIsPrinting, eIsPrintPreview } ePrintDataType; @@ -43,21 +42,16 @@ class nsPrintData { nsCOMArray<nsIWebProgressListener> mPrintProgressListeners; // If there is a focused iframe, mSelectionRoot is set to its nsPrintObject. // Otherwise, if there is a selection, it is set to the root nsPrintObject. // Otherwise, it is unset. nsPrintObject* mSelectionRoot = nullptr; - // Array of non-owning pointers to all the nsPrintObjects owned by this - // nsPrintData. This includes this->mPrintObject, as well as all of its - // mKids (and their mKids, etc.) - nsTArray<nsPrintObject*> mPrintDocList; - bool mOnStartSent; bool mIsAborted; // tells us the document is being aborted private: nsPrintData() = delete; nsPrintData& operator=(const nsPrintData& aOther) = delete; ~nsPrintData(); // non-virtual
--- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -129,33 +129,33 @@ static void DumpPrintObjectsListStart(co const nsTArray<nsPrintObject*>& aDocList); static void DumpPrintObjectsTree(nsPrintObject* aPO, int aLevel = 0, FILE* aFD = nullptr); static void DumpPrintObjectsTreeLayout(const UniquePtr<nsPrintObject>& aPO, nsDeviceContext* aDC, int aLevel = 0, FILE* aFD = nullptr); # define DUMP_DOC_LIST(_title) \ - DumpPrintObjectsListStart((_title), mPrt->mPrintDocList); + DumpPrintObjectsListStart((_title), mPrintDocList); # define DUMP_DOC_TREE DumpPrintObjectsTree(mPrt->mPrintObject.get()); # define DUMP_DOC_TREELAYOUT \ DumpPrintObjectsTreeLayout(mPrt->mPrintObject, mPrt->mPrintDC); #else # define DUMP_DOC_LIST(_title) # define DUMP_DOC_TREE # define DUMP_DOC_TREELAYOUT #endif // ------------------------------------------------------- // Helpers // ------------------------------------------------------- /** * Build a tree of nsPrintObjects under aPO. It also appends a (depth first) - * flat list of all the nsPrintObjects created to mPrt->mPrintDocList. If + * flat list of all the nsPrintObjects created to mPrintDocList. If * one of the nsPrintObject's document is the focused document, then the print * object is set as mPrt->mSelectionRoot. * @param aParentPO The parent nsPrintObject to populate, must not be null. */ void nsPrintJob::BuildNestedPrintObjects( const UniquePtr<nsPrintObject>& aParentPO) { MOZ_ASSERT(aParentPO); @@ -196,17 +196,17 @@ void nsPrintJob::BuildNestedPrintObjects } auto childPO = MakeUnique<nsPrintObject>(); nsresult rv = childPO->InitAsNestedObject(docShell, doc, aParentPO.get()); if (NS_FAILED(rv)) { MOZ_ASSERT_UNREACHABLE("Init failed?"); } - mPrt->mPrintDocList.AppendElement(childPO.get()); + mPrintDocList.AppendElement(childPO.get()); BuildNestedPrintObjects(childPO); aParentPO->mKids.AppendElement(std::move(childPO)); } } static nsresult GetDefaultPrintSettings(nsIPrintSettings** aSettings) { *aSettings = nullptr; @@ -407,17 +407,17 @@ nsresult nsPrintJob::DoCommonPrint(bool { nsAutoScriptBlocker scriptBlocker; printData->mPrintObject = MakeUnique<nsPrintObject>(); rv = printData->mPrintObject->InitAsRootObject(docShell, aDoc, mIsCreatingPrintPreview); NS_ENSURE_SUCCESS(rv, rv); - printData->mPrintDocList.AppendElement(printData->mPrintObject.get()); + mPrintDocList.AppendElement(printData->mPrintObject.get()); printData->mPrintObject->mFrameType = eDoc; BuildNestedPrintObjects(printData->mPrintObject); } // The nsAutoScriptBlocker above will now have been destroyed, which may // cause our print/print-preview operation to finish. In this case, we @@ -694,20 +694,17 @@ nsresult nsPrintJob::ReconstructAndReflo gDumpLOFileNameCnt = 0; } #endif // In this loop, it's conceivable that one of our helpers might clear mPrt, // while we're using it & its members! So we capture it in an owning local // reference & use that instead of using mPrt directly. RefPtr<nsPrintData> printData = mPrt; - for (uint32_t i = 0; i < printData->mPrintDocList.Length(); ++i) { - nsPrintObject* po = printData->mPrintDocList.ElementAt(i); - NS_ASSERTION(po, "nsPrintObject can't be null!"); - + for (nsPrintObject* po : mPrintDocList) { if (!po->PrintingIsEnabled() || po->mInvisible) { continue; } // When the print object has been marked as "print the document" (i.e, // po->PrintingIsEnabled() is true), mPresContext and mPresShell should be // non-nullptr (i.e., should've been created for the print) since they // are necessary to print the document. @@ -736,17 +733,17 @@ nsresult nsPrintJob::ReconstructAndReflo // let's stop doing this printing. if (NS_WARN_IF(mPrt != printData)) { return NS_ERROR_FAILURE; } // For all views except the first one, setup the root view. // ??? Can there be multiple po for the top-level-document? bool documentIsTopLevel = true; - if (i != 0) { + if (po->mParent) { nsSize adjSize; bool doReturn; nsresult rv = SetRootView(po, doReturn, documentIsTopLevel, adjSize); MOZ_ASSERT(!documentIsTopLevel, "How could this happen?"); if (NS_FAILED(rv) || doReturn) { return rv; @@ -1440,21 +1437,18 @@ nsresult nsPrintJob::ReflowPrintObject(c return NS_OK; } //------------------------------------------------------- // Figure out how many documents and how many total pages we are printing void nsPrintJob::CalcNumPrintablePages(int32_t& aNumPages) { aNumPages = 0; - // Count the number of printable documents - // and printable pages - for (uint32_t i = 0; i < mPrt->mPrintDocList.Length(); i++) { - nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i); - NS_ASSERTION(po, "nsPrintObject can't be null!"); + // Count the number of printable documents and printable pages + for (nsPrintObject* po : mPrintDocList) { // Note: The po->mPresContext null-check below is necessary, because it's // possible po->mPresContext might never have been set. (e.g., if // PrintingIsEnabled() returns false, ReflowPrintObject bails before setting // mPresContext) if (po->mPresContext && po->mPresContext->IsRootPaginatedDocument()) { nsPageSequenceFrame* seqFrame = po->mPresShell->GetPageSequenceFrame(); if (seqFrame) { aNumPages += seqFrame->PrincipalChildList().GetLength();
--- a/layout/printing/nsPrintJob.h +++ b/layout/printing/nsPrintJob.h @@ -10,16 +10,17 @@ #include "mozilla/layout/RemotePrintJobChild.h" #include "mozilla/UniquePtr.h" #include "nsCOMPtr.h" #include "nsHashKeys.h" #include "nsIFrame.h" // For WeakFrame #include "nsSize.h" +#include "nsTArray.h" #include "nsTHashtable.h" #include "nsWeakReference.h" // Interfaces #include "nsIWebProgress.h" #include "nsIWebProgressListener.h" // Classes @@ -249,16 +250,21 @@ class nsPrintJob final : public nsIWebPr // member-data. RefPtr<nsPrintData> mPrt; RefPtr<nsPagePrintTimer> mPagePrintTimer; // Only set if this nsPrintJob was created for a real print. RefPtr<RemotePrintJobChild> mRemotePrintJob; + // Array of non-owning pointers to all the nsPrintObjects owned by this + // nsPrintJob. This includes mPrintObject, as well as all of its mKids (and + // their mKids, etc.) + nsTArray<nsPrintObject*> mPrintDocList; + // If the code that initiates a print preview passes a PrintPreviewResolver // (a std::function) to be notified of the final sheet/page counts (once // we've sufficiently laid out the document to know what those are), that // callback is stored here. PrintPreviewResolver mPrintPreviewCallback; // The scale factor that would need to be applied to all pages to make the // widest page fit without overflowing/clipping.