Bug 1346983 - Part2: Insert the new nsColumnSetWrapperFrame into the frame hierarchy and reflow children. r?dholbert draft
authorNeerja Pancholi <npancholi@mozilla.com>
Thu, 09 Mar 2017 18:13:01 -0800
changeset 499468 86c15ac7ba53cd9b05c3100f849b22caeee4d6f1
parent 499467 15e104168702dabb7481d28db16676969f106052
child 549360 46587d9841e6cef942235c3e32b4b6f02db63374
push id49418
push userbmo:npancholi@mozilla.com
push dateWed, 15 Mar 2017 20:42:09 +0000
reviewersdholbert
bugs1346983
milestone55.0a1
Bug 1346983 - Part2: Insert the new nsColumnSetWrapperFrame into the frame hierarchy and reflow children. r?dholbert MozReview-Commit-ID: lWT4KrxwJo
layout/base/nsCSSFrameConstructor.cpp
layout/generic/nsColumnSetWrapperFrame.cpp
layout/generic/nsColumnSetWrapperFrame.h
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -12029,29 +12029,33 @@ nsCSSFrameConstructor::ConstructBlock(ns
                 blockFrame->GetType() == nsGkAtoms::detailsFrame),
                "not a block frame nor a details frame?");
   nsContainerFrame* parent = aParentFrame;
   RefPtr<nsStyleContext> blockStyle = aStyleContext;
   const nsStyleColumn* columns = aStyleContext->StyleColumn();
 
   if (columns->mColumnCount != NS_STYLE_COLUMN_COUNT_AUTO
       || columns->mColumnWidth.GetUnit() != eStyleUnit_Auto) {
+    nsContainerFrame* columnSetWrapper =
+      NS_NewColumnSetWrapperFrame(mPresShell, aStyleContext);
+    InitAndRestoreFrame(aState, aContent, aParentFrame, columnSetWrapper);
+
     nsContainerFrame* columnSetFrame =
       NS_NewColumnSetFrame(mPresShell, aStyleContext, nsFrameState(0));
-
-    InitAndRestoreFrame(aState, aContent, aParentFrame, columnSetFrame);
+    InitAndRestoreFrame(aState, aContent, columnSetWrapper, columnSetFrame);
+    SetInitialSingleChild(columnSetWrapper, columnSetFrame);
+
     blockStyle = mPresShell->StyleSet()->
       ResolveInheritingAnonymousBoxStyle(nsCSSAnonBoxes::columnContent,
                                          aStyleContext);
     parent = columnSetFrame;
-    *aNewFrame = columnSetFrame;
+    *aNewFrame = columnSetWrapper;
     if (aPositionedFrameForAbsPosContainer == blockFrame) {
       aPositionedFrameForAbsPosContainer = columnSetFrame;
     }
-
     SetInitialSingleChild(columnSetFrame, blockFrame);
   }
 
   blockFrame->SetStyleContextWithoutNotification(blockStyle);
   InitAndRestoreFrame(aState, aContent, parent, blockFrame);
 
   aState.AddChild(*aNewFrame, aFrameItems, aContent, aStyleContext,
                   aContentParentFrame ? aContentParentFrame :
--- a/layout/generic/nsColumnSetWrapperFrame.cpp
+++ b/layout/generic/nsColumnSetWrapperFrame.cpp
@@ -19,8 +19,86 @@ NS_NewColumnSetWrapperFrame(nsIPresShell
 
 NS_IMPL_FRAMEARENA_HELPERS(nsColumnSetWrapperFrame)
 
 nsColumnSetWrapperFrame::nsColumnSetWrapperFrame(nsStyleContext* aContext)
 : nsContainerFrame(aContext)
 {
 }
 
+// XXX decide what happens here when we have multiple nsColumnSetFrames and
+// spanning elements.
+nscoord
+nsColumnSetWrapperFrame::GetMinISize(nsRenderingContext* aRenderingContext)
+{
+  // What is the point of a wrapper without any children? If this is the case
+  // then the wrapper should not have been created.
+  // The call to SetInitialChildList() in nsCSSFrameConstructor should ensure
+  // that this has a child upon creation.
+  MOZ_ASSERT(mFrames.FirstChild() ,
+             "There cannot be an ColumnSetWrapper without any children!");
+  return mFrames.FirstChild()->GetMinISize(aRenderingContext);
+}
+
+// XXX decide what happens here when we have multiple nsColumnSetFrames and
+// spanning elements.
+nscoord
+nsColumnSetWrapperFrame::GetPrefISize(nsRenderingContext* aRenderingContext)
+{
+  // What is the point of a wrapper without any children? If this is the case
+  // then the wrapper should not have been created.
+  // The call to SetInitialChildList() in nsCSSFrameConstructor should ensure
+  // that this has a child upon creation.
+  MOZ_ASSERT(mFrames.FirstChild() ,
+             "There cannot be an ColumnSetWrapper without any children!");
+  return mFrames.FirstChild()->GetPrefISize(aRenderingContext);
+}
+
+void
+nsColumnSetWrapperFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
+                                          const nsRect&           aDirtyRect,
+                                          const nsDisplayListSet& aLists)
+{
+  DisplayBorderBackgroundOutline(aBuilder, aLists);
+
+  // Our children won't have backgrounds so it doesn't matter where we put them.
+  for (nsIFrame* childFrame : mFrames) {
+    BuildDisplayListForChild(aBuilder, childFrame, aDirtyRect, aLists);
+  }
+}
+
+void
+nsColumnSetWrapperFrame::Reflow(nsPresContext*     aPresContext,
+                                ReflowOutput&      aDesiredSize,
+                                const ReflowInput& aReflowInput,
+                                nsReflowStatus&    aStatus)
+{
+  MarkInReflow();
+  DO_GLOBAL_REFLOW_COUNT("nsColumnSetWrapperFrame");
+  DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
+  MOZ_ASSERT(aStatus.IsEmpty(), "Expecting outparam to be initially empty");
+
+  WritingMode wm = GetWritingMode();
+  LogicalMargin borderPadding = aReflowInput.ComputedLogicalBorderPadding();
+  LogicalSize computedSize = aReflowInput.ComputedSize(wm);
+  LogicalSize availableSize = aReflowInput.AvailableSize(wm);
+  LogicalSize childCBSize(wm, availableSize.ISize(wm), computedSize.BSize(wm));
+  nsSize containerSize = aReflowInput.ComputedSizeAsContainerIfConstrained();
+
+  for (nsIFrame* childFrame : mFrames) {
+    nsReflowStatus childStatus;
+    LogicalPoint childOrigin(wm,
+                             borderPadding.IStart(wm),
+                             borderPadding.BStart(wm));
+    ReflowInput childReflowInput(aPresContext, aReflowInput, childFrame,
+                                 availableSize, &childCBSize);
+    ReflowOutput childDesiredSize(wm, aDesiredSize.mFlags);
+
+    ReflowChild(childFrame, aPresContext, childDesiredSize, childReflowInput,
+                wm, childOrigin, containerSize, 0, childStatus);
+
+    FinishReflowChild(childFrame, aPresContext, childDesiredSize,
+                      &childReflowInput, wm, childOrigin, containerSize, 0);
+
+    aDesiredSize.SetSize(wm, childDesiredSize.Size(wm));
+    aStatus.MergeCompletionStatusFrom(childStatus);
+  }
+}
--- a/layout/generic/nsColumnSetWrapperFrame.h
+++ b/layout/generic/nsColumnSetWrapperFrame.h
@@ -22,26 +22,37 @@
 class nsColumnSetWrapperFrame final : public nsContainerFrame
 {
 public:
   NS_DECL_FRAMEARENA_HELPERS
 
   friend nsContainerFrame* NS_NewColumnSetWrapperFrame(nsIPresShell* aPresShell,
                                                        nsStyleContext* aContext);
 
+  void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
+                        const nsRect&           aDirtyRect,
+                        const nsDisplayListSet& aLists) override;
+
   nsIAtom* GetType() const override {
     return nsGkAtoms::columnSetWrapperFrame;
   }
 
 #ifdef DEBUG_FRAME_DUMP
   nsresult GetFrameName(nsAString& aResult) const override {
     return MakeFrameName(NS_LITERAL_STRING("ColumnSetWrapper"), aResult);
   }
 #endif
 
+  nscoord GetMinISize(nsRenderingContext* aRenderingContext) override;
+  nscoord GetPrefISize(nsRenderingContext* aRenderingContext) override;
+
+  void Reflow(nsPresContext* aPresContext,
+              ReflowOutput&      aDesiredSize,
+              const ReflowInput& aReflowInput,
+              nsReflowStatus&    aStatus) override;
 private:
   explicit nsColumnSetWrapperFrame(nsStyleContext* aContext);
   ~nsColumnSetWrapperFrame() override
   {
   }
 
 };