Bug 889219. Part 5: Remove nsSimplePageSequenceFrame::mCurrentPageFrame. r=mats
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 24 Jul 2013 23:48:55 +1200
changeset 152109 c450b3ab891502cb5fd2940f9bda4e7720a3fc9c
parent 152108 a745c57499ffed6c8037fdc4d69721ea61d8acc4
child 152110 e36551e9cd271c1f81c4314c26d043d8037f790c
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs889219
milestone25.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 889219. Part 5: Remove nsSimplePageSequenceFrame::mCurrentPageFrame. r=mats Holding onto frame pointers is potentially dangerous. It's not really necessary to do so here.
layout/generic/nsSimplePageSequence.cpp
layout/generic/nsSimplePageSequence.h
--- a/layout/generic/nsSimplePageSequence.cpp
+++ b/layout/generic/nsSimplePageSequence.cpp
@@ -434,18 +434,17 @@ nsSimplePageSequenceFrame::StartPrint(ns
     }
 
     // adjust total number of pages
     if (nsIPrintSettings::kRangeSelection != mPrintRangeType) {
       totalPages = pageNum - 1;
     }
   }
 
-  mPageNum          = 1;
-  mCurrentPageFrame = mFrames.FirstChild();
+  mPageNum = 1;
 
   if (mTotalPages == -1) {
     mTotalPages = totalPages;
   }
 
   return rv;
 }
 
@@ -505,17 +504,16 @@ nsSimplePageSequenceFrame::DetermineWhet
 
   // If printing a range of pages check whether the page number is in the
   // range of pages to print
   if (mDoingPageRange) {
     if (mPageNum < mFromPageNum) {
       mPrintThisPage = false;
     } else if (mPageNum > mToPageNum) {
       mPageNum++;
-      mCurrentPageFrame = nullptr;
       mPrintThisPage = false;
       return;
     } else {
       int32_t length = mPageRanges.Length();
     
       // Page ranges are pairs (start, end)
       if (length && (length % 2 == 0)) {
         mPrintThisPage = false;
@@ -542,20 +540,35 @@ nsSimplePageSequenceFrame::DetermineWhet
     }
   }
   
   if (nsIPrintSettings::kRangeSelection == mPrintRangeType) {
     mPrintThisPage = true;
   }
 }
 
+nsIFrame*
+nsSimplePageSequenceFrame::GetCurrentPageFrame()
+{
+  int32_t i = 1;
+  for (nsFrameList::Enumerator childFrames(mFrames); !childFrames.AtEnd();
+       childFrames.Next()) {
+    if (i == mPageNum) {
+      return childFrames.get();
+    }
+    ++i;
+  }
+  return nullptr;
+}
+
 NS_IMETHODIMP
 nsSimplePageSequenceFrame::PrePrintNextPage(nsITimerCallback* aCallback, bool* aDone)
 {
-  if (!mCurrentPageFrame) {
+  nsIFrame* currentPage = GetCurrentPageFrame();
+  if (!currentPage) {
     *aDone = true;
     return NS_ERROR_FAILURE;
   }
   
   DetermineWhetherToPrintPage();
   // Nothing to do if the current page doesn't get printed OR rendering to
   // preview. For preview, the `CallPrintCallback` is called from within the
   // HTMLCanvasElement::HandlePrintCallback.
@@ -563,17 +576,17 @@ nsSimplePageSequenceFrame::PrePrintNextP
     *aDone = true;
     return NS_OK;
   }
 
   // If the canvasList is null, then generate it and start the render
   // process for all the canvas.
   if (!mCurrentCanvasListSetup) {
     mCurrentCanvasListSetup = true;
-    GetPrintCanvasElementsInFrame(mCurrentPageFrame, &mCurrentCanvasList);
+    GetPrintCanvasElementsInFrame(currentPage, &mCurrentCanvasList);
 
     if (mCurrentCanvasList.Length() != 0) {
       nsresult rv = NS_OK;
 
       // Begin printing of the document
       nsDeviceContext *dc = PresContext()->DeviceContext();
       PR_PL(("\n"));
       PR_PL(("***************** BeginPage *****************\n"));
@@ -656,17 +669,18 @@ nsSimplePageSequenceFrame::PrintNextPage
   // printedPageNum keeps track of the current page number to be printed
   // Note: When print al the pages or a page range the printed page shows the
   // actual page number, when printing selection it prints the page number starting
   // with the first page of the selection. For example if the user has a 
   // selection that starts on page 2 and ends on page 3, the page numbers when
   // print are 1 and then two (which is different than printing a page range, where
   // the page numbers would have been 2 and then 3)
 
-  if (!mCurrentPageFrame) {
+  nsIFrame* currentPage = GetCurrentPageFrame();
+  if (!currentPage) {
     return NS_ERROR_FAILURE;
   }
 
   nsresult rv = NS_OK;
 
   DetermineWhetherToPrintPage();
 
   if (mPrintThisPage) {
@@ -681,24 +695,24 @@ nsSimplePageSequenceFrame::PrintNextPage
     // I will soon improve this to work with IFrames 
     bool    continuePrinting = true;
     nscoord width, height;
     width = PresContext()->GetPageSize().width;
     height = PresContext()->GetPageSize().height;
     height -= mMargin.top + mMargin.bottom;
     width  -= mMargin.left + mMargin.right;
     nscoord selectionY = height;
-    nsIFrame* conFrame = mCurrentPageFrame->GetFirstPrincipalChild();
+    nsIFrame* conFrame = currentPage->GetFirstPrincipalChild();
     if (mSelectionHeight >= 0) {
       conFrame->SetPosition(conFrame->GetPosition() + nsPoint(0, -mYSelOffset));
       nsContainerFrame::PositionChildViews(conFrame);
     }
 
     // cast the frame to be a page frame
-    nsPageFrame * pf = static_cast<nsPageFrame*>(mCurrentPageFrame);
+    nsPageFrame * pf = static_cast<nsPageFrame*>(currentPage);
     pf->SetPageNumInfo(mPageNum, mTotalPages);
     pf->SetSharedPageData(mPageData);
 
     int32_t printedPageNum = 1;
     while (continuePrinting) {
       if (PresContext()->IsRootPaginatedDocument()) {
         if (!mCalledBeginPage) {
           PR_PL(("\n"));
@@ -711,20 +725,19 @@ nsSimplePageSequenceFrame::PrintNextPage
       }
 
       PR_PL(("SeqFr::PrintNextPage -> %p PageNo: %d", pf, mPageNum));
 
       nsRefPtr<nsRenderingContext> renderingContext;
       dc->CreateRenderingContext(*getter_AddRefs(renderingContext));
       NS_ENSURE_TRUE(renderingContext, NS_ERROR_OUT_OF_MEMORY);
 
-      nsRect drawingRect(nsPoint(0, 0),
-                         mCurrentPageFrame->GetSize());
+      nsRect drawingRect(nsPoint(0, 0), currentPage->GetSize());
       nsRegion drawingRegion(drawingRect);
-      nsLayoutUtils::PaintFrame(renderingContext, mCurrentPageFrame,
+      nsLayoutUtils::PaintFrame(renderingContext, currentPage,
                                 drawingRegion, NS_RGBA(0,0,0,0),
                                 nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES);
 
       if (mSelectionHeight >= 0 && selectionY < mSelectionHeight) {
         selectionY += height;
         printedPageNum++;
         pf->SetPageNumInfo(printedPageNum, mTotalPages);
         conFrame->SetPosition(conFrame->GetPosition() + nsPoint(0, -height));
@@ -749,20 +762,16 @@ nsSimplePageSequenceFrame::DoPageEnd()
     PR_PL(("***************** End Page (DoPageEnd) *****************\n"));
     rv = PresContext()->DeviceContext()->EndPage();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   ResetPrintCanvasList();
 
   mPageNum++;
-
-  if (mCurrentPageFrame) {
-    mCurrentPageFrame = mCurrentPageFrame->GetNextSibling();
-  }
   
   return rv;
 }
 
 static gfx3DMatrix
 ComputePageSequenceTransform(nsIFrame* aFrame, float aAppUnitsPerPixel)
 {
   float scale = aFrame->PresContext()->GetPrintPreviewScale();
--- a/layout/generic/nsSimplePageSequence.h
+++ b/layout/generic/nsSimplePageSequence.h
@@ -117,28 +117,28 @@ protected:
   void SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly);
 
   // Sets the frame desired size to the size of the viewport, or the given
   // nscoords, whichever is larger. Print scaling is applied in this function.
   void SetDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
                       const nsHTMLReflowState& aReflowState,
                       nscoord aWidth, nscoord aHeight);
 
-  void         DetermineWhetherToPrintPage();
+  void DetermineWhetherToPrintPage();
+  nsIFrame* GetCurrentPageFrame();
 
   nsMargin mMargin;
 
   // I18N date formatter service which we'll want to cache locally.
   nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
 
   nsSize       mSize;
   nsSharedPageData* mPageData; // data shared by all the nsPageFrames
 
   // Asynch Printing
-  nsIFrame *   mCurrentPageFrame;
   int32_t      mPageNum;
   int32_t      mTotalPages;
   int32_t      mPrintRangeType;
   int32_t      mFromPageNum;
   int32_t      mToPageNum;
   nsTArray<int32_t> mPageRanges;
   nsTArray<nsRefPtr<mozilla::dom::HTMLCanvasElement> > mCurrentCanvasList;