Bug 1374761 part 2. Properly restyle the various paginated-presentation anonymous boxes. r?heycam draft
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 21 Jun 2017 11:45:14 -0400
changeset 598300 22243043e91381d2e2297e875de991a1b06f1c88
parent 598299 a0e55f2264b812115cb8f09b8e7a43ceb78183a3
child 634442 1210beba192ae477003b07d45cd5548a108647b6
push id65167
push userbzbarsky@mozilla.com
push dateWed, 21 Jun 2017 15:46:49 +0000
reviewersheycam
bugs1374761
milestone56.0a1
Bug 1374761 part 2. Properly restyle the various paginated-presentation anonymous boxes. r?heycam MozReview-Commit-ID: LJqWbyRKp3b
layout/base/nsCSSFrameConstructor.cpp
layout/generic/nsPageContentFrame.cpp
layout/generic/nsPageContentFrame.h
layout/generic/nsPageFrame.cpp
layout/generic/nsPageFrame.h
layout/generic/nsSimplePageSequenceFrame.cpp
layout/generic/nsSimplePageSequenceFrame.h
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2871,16 +2871,17 @@ nsCSSFrameConstructor::SetUpDocElementCo
 
     rootPseudo = nsCSSAnonBoxes::canvas;
     mDocElementContainingBlock = rootFrame;
   } else {
     // Create a page sequence frame
     rootFrame = NS_NewSimplePageSequenceFrame(mPresShell, viewportPseudoStyle);
     mPageSequenceFrame = rootFrame;
     rootPseudo = nsCSSAnonBoxes::pageSequence;
+    rootFrame->AddStateBits(NS_FRAME_OWNS_ANON_BOXES);
   }
 
 
   // --------- IF SCROLLABLE WRAP IN SCROLLFRAME --------
 
   // If the device supports scrolling (e.g., in galley mode on the screen and
   // for print-preview, but not when printing), then create a scroll frame that
   // will act as the scrolling mechanism for the viewport.
@@ -2964,16 +2965,17 @@ nsCSSFrameConstructor::SetUpDocElementCo
   }
 
   if (isPaginated) {
     // Create the first page
     // Set the initial child lists
     nsContainerFrame* canvasFrame;
     nsContainerFrame* pageFrame =
       ConstructPageFrame(mPresShell, rootFrame, nullptr, canvasFrame);
+    pageFrame->AddStateBits(NS_FRAME_OWNS_ANON_BOXES);
     SetInitialSingleChild(rootFrame, pageFrame);
 
     // The eventual parent of the document element frame.
     // XXX should this be set for every new page (in ConstructPageFrame)?
     mDocElementContainingBlock = canvasFrame;
     mHasRootAbsPosContainingBlock = true;
   }
 
@@ -3038,16 +3040,19 @@ nsCSSFrameConstructor::ConstructPageFram
   // Initialize the page content frame and force it to have a view. Also make it the
   // containing block for fixed elements which are repeated on every page.
   nsIFrame* prevPageContentFrame = nullptr;
   if (aPrevPageFrame) {
     prevPageContentFrame = aPrevPageFrame->PrincipalChildList().FirstChild();
     NS_ASSERTION(prevPageContentFrame, "missing page content frame");
   }
   pageContentFrame->Init(nullptr, pageFrame, prevPageContentFrame);
+  if (!prevPageContentFrame) {
+    pageContentFrame->AddStateBits(NS_FRAME_OWNS_ANON_BOXES);
+  }
   SetInitialSingleChild(pageFrame, pageContentFrame);
   // Make it an absolute container for fixed-pos elements
   pageContentFrame->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);
   pageContentFrame->MarkAsAbsoluteContainingBlock();
 
   RefPtr<nsStyleContext> canvasPseudoStyle;
   canvasPseudoStyle =
     styleSet->ResolveInheritingAnonymousBoxStyle(nsCSSAnonBoxes::canvas,
--- a/layout/generic/nsPageContentFrame.cpp
+++ b/layout/generic/nsPageContentFrame.cpp
@@ -103,15 +103,24 @@ nsPageContentFrame::Reflow(nsPresContext
   if (aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE) {
     aDesiredSize.BSize(wm) = aReflowInput.ComputedBSize();
   }
   FinishAndStoreOverflow(&aDesiredSize);
 
   NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
 }
 
+void
+nsPageContentFrame::AppendDirectlyOwnedAnonBoxes(
+  nsTArray<OwnedAnonBox>& aResult)
+{
+  MOZ_ASSERT(mFrames.FirstChild(),
+             "pageContentFrame must have a canvasFrame child");
+  aResult.AppendElement(mFrames.FirstChild());
+}
+
 #ifdef DEBUG_FRAME_DUMP
 nsresult
 nsPageContentFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
 }
 #endif
--- a/layout/generic/nsPageContentFrame.h
+++ b/layout/generic/nsPageContentFrame.h
@@ -32,16 +32,21 @@ public:
     return ViewportFrame::IsFrameOfType(aFlags &
              ~(nsIFrame::eCanContainOverflowContainers));
   }
 
   virtual void SetSharedPageData(nsSharedPageData* aPD) { mPD = aPD; }
 
   virtual bool HasTransformGetter() const override { return true; }
 
+  /**
+   * Return our canvas frame.
+   */
+  void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
+
 #ifdef DEBUG_FRAME_DUMP
   // Debugging
   virtual nsresult  GetFrameName(nsAString& aResult) const override;
 #endif
 
 protected:
   explicit nsPageContentFrame(nsStyleContext* aContext)
     : ViewportFrame(aContext, kClassID)
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -663,16 +663,25 @@ nsPageFrame::SetSharedPageData(nsSharedP
   // Set the shared data into the page frame before reflow
   nsPageContentFrame * pcf = static_cast<nsPageContentFrame*>(mFrames.FirstChild());
   if (pcf) {
     pcf->SetSharedPageData(mPD);
   }
 
 }
 
+void
+nsPageFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult)
+{
+  MOZ_ASSERT(mFrames.FirstChild() &&
+             mFrames.FirstChild()->IsPageContentFrame(),
+             "pageFrame must have a pageContentFrame child");
+  aResult.AppendElement(mFrames.FirstChild());
+}
+
 nsIFrame*
 NS_NewPageBreakFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   NS_PRECONDITION(aPresShell, "null PresShell");
   //check that we are only creating page break frames when printing
   NS_ASSERTION(aPresShell->GetPresContext()->IsPaginated(), "created a page break frame while not printing");
 
   return new (aPresShell) nsPageBreakFrame(aContext);
--- a/layout/generic/nsPageFrame.h
+++ b/layout/generic/nsPageFrame.h
@@ -46,16 +46,21 @@ public:
 
   // We must allow Print Preview UI to have a background, no matter what the
   // user's settings
   virtual bool HonorPrintBackgroundSettings() override { return false; }
 
   void PaintHeaderFooter(gfxContext& aRenderingContext,
                          nsPoint aPt, bool aSubpixelAA);
 
+  /**
+   * Return our page content frame.
+   */
+  void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
+
 protected:
   explicit nsPageFrame(nsStyleContext* aContext);
   virtual ~nsPageFrame();
 
   typedef enum {
     eHeader,
     eFooter
   } nsHeaderFooterEnum;
--- a/layout/generic/nsSimplePageSequenceFrame.cpp
+++ b/layout/generic/nsSimplePageSequenceFrame.cpp
@@ -890,8 +890,17 @@ nsSimplePageSequenceFrame::SetDateTimeSt
 //
 NS_IMETHODIMP
 nsSimplePageSequenceFrame::GetSTFPercent(float& aSTFPercent)
 {
   NS_ENSURE_TRUE(mPageData, NS_ERROR_UNEXPECTED);
   aSTFPercent = mPageData->mShrinkToFitRatio;
   return NS_OK;
 }
+
+void
+nsSimplePageSequenceFrame::AppendDirectlyOwnedAnonBoxes(
+  nsTArray<OwnedAnonBox>& aResult)
+{
+  if (mFrames.NotEmpty()) {
+    aResult.AppendElement(mFrames.FirstChild());
+  }
+}
--- a/layout/generic/nsSimplePageSequenceFrame.h
+++ b/layout/generic/nsSimplePageSequenceFrame.h
@@ -95,16 +95,21 @@ public:
   NS_IMETHOD DoPageEnd() override;
 
   // We must allow Print Preview UI to have a background, no matter what the
   // user's settings
   bool HonorPrintBackgroundSettings() override { return false; }
 
   bool HasTransformGetter() const override { return true; }
 
+  /**
+   * Return our first page frame.
+   */
+  void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
+
 #ifdef DEBUG_FRAME_DUMP
   nsresult GetFrameName(nsAString& aResult) const override;
 #endif
 
 protected:
   explicit nsSimplePageSequenceFrame(nsStyleContext* aContext);
   virtual ~nsSimplePageSequenceFrame();