Bug 1346983 - Add a new nsColumnSetWrapperFrame class to the build to be used as a wrapper for columnset and column span frames. r?dbaron draft
authorNeerja Pancholi <npancholi@mozilla.com>
Thu, 01 Mar 2018 15:38:55 -0800
changeset 762307 8b6bd1f07599e1346a757d5f7fc2e4a80410b980
parent 762095 714a94df1a99b933a4eef2149819d2af319a1ed5
child 762312 6ae6d80634b7cc07d50f22fba35876ea661624ca
push id101130
push userbmo:npancholi@mozilla.com
push dateFri, 02 Mar 2018 00:55:57 +0000
reviewersdbaron
bugs1346983
milestone60.0a1
Bug 1346983 - Add a new nsColumnSetWrapperFrame class to the build to be used as a wrapper for columnset and column span frames. r?dbaron MozReview-Commit-ID: J8cpsBKjWFX
layout/generic/FrameTypeList.h
layout/generic/moz.build
layout/generic/nsColumnSetWrapperFrame.cpp
layout/generic/nsColumnSetWrapperFrame.h
layout/generic/nsFrameIdList.h
layout/generic/nsHTMLParts.h
--- a/layout/generic/FrameTypeList.h
+++ b/layout/generic/FrameTypeList.h
@@ -13,16 +13,17 @@ FRAME_TYPE(Block)
 FRAME_TYPE(Box)
 FRAME_TYPE(Br)
 FRAME_TYPE(Bullet)
 FRAME_TYPE(BCTableCell)
 FRAME_TYPE(Canvas)
 FRAME_TYPE(CheckboxRadio)
 FRAME_TYPE(ColorControl)
 FRAME_TYPE(ColumnSet)
+FRAME_TYPE(ColumnSetWrapper)
 FRAME_TYPE(ComboboxControl)
 FRAME_TYPE(ComboboxDisplay)
 FRAME_TYPE(Deck)
 FRAME_TYPE(DateTimeControl)
 FRAME_TYPE(Details)
 FRAME_TYPE(FieldSet)
 FRAME_TYPE(FlexContainer)
 FRAME_TYPE(FrameSet)
--- a/layout/generic/moz.build
+++ b/layout/generic/moz.build
@@ -132,16 +132,17 @@ UNIFIED_SOURCES += [
     'MathMLTextRunFactory.cpp',
     'nsAbsoluteContainingBlock.cpp',
     'nsBackdropFrame.cpp',
     'nsBlockFrame.cpp',
     'nsBlockReflowContext.cpp',
     'nsBulletFrame.cpp',
     'nsCanvasFrame.cpp',
     'nsColumnSetFrame.cpp',
+    'nsColumnSetWrapperFrame.cpp',
     'nsContainerFrame.cpp',
     'nsFirstLetterFrame.cpp',
     'nsFlexContainerFrame.cpp',
     'nsFloatManager.cpp',
     'nsFontInflationData.cpp',
     'nsFrame.cpp',
     'nsFrameList.cpp',
     'nsFrameSelection.cpp',
new file mode 100644
--- /dev/null
+++ b/layout/generic/nsColumnSetWrapperFrame.cpp
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* Frame for css multi-column layout that contains column sets and column spans. */
+
+#include "nsColumnSetWrapperFrame.h"
+
+using namespace mozilla;
+
+nsBlockFrame*
+NS_NewColumnSetWrapperFrame(nsIPresShell*   aPresShell,
+                            nsStyleContext* aContext,
+                            nsFrameState    aStateFlags)
+{
+  nsColumnSetWrapperFrame* frame =
+    new (aPresShell) nsColumnSetWrapperFrame(aContext);
+  frame->AddStateBits(aStateFlags | NS_BLOCK_MARGIN_ROOT);
+  return frame;
+}
+
+NS_IMPL_FRAMEARENA_HELPERS(nsColumnSetWrapperFrame)
+
+nsColumnSetWrapperFrame::nsColumnSetWrapperFrame(nsStyleContext* aContext)
+: nsBlockFrame(aContext, kClassID)
+{
+}
+
+/*
+ * Any append, insert or remove operation is disallowed on ColumnSetWrapperFrame
+ * because in that case we must recreate the entire frame hierarchy under this
+ * wrapper to account for the added/removed element changing the breaking of
+ * frames across column-spans. This is handled in nsCSSFrameConstructor's
+ * ContentAppended/ContentRemoved/ContentInserted path.
+ * See nsCSSFrameConstructor::WipeContainingBlock.
+ */
+void
+nsColumnSetWrapperFrame::AppendFrames(ChildListID     aListID,
+                                      nsFrameList&    aFrameList)
+{
+  MOZ_CRASH("unsupported operation");
+}
+
+void
+nsColumnSetWrapperFrame::InsertFrames(ChildListID     aListID,
+                                      nsIFrame*       aPrevFrame,
+                                      nsFrameList&    aFrameList)
+{
+  MOZ_CRASH("unsupported operation");
+}
+
+void
+nsColumnSetWrapperFrame::RemoveFrame(ChildListID     aListID,
+                                     nsIFrame*       aOldFrame)
+{
+  MOZ_CRASH("unsupported operation");
+}
new file mode 100644
--- /dev/null
+++ b/layout/generic/nsColumnSetWrapperFrame.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* Frame for css multi-column layout that contains column sets and column spans. */
+
+#ifndef nsColumnSetWrapperFrame_h_
+#define nsColumnSetWrapperFrame_h_
+
+#include "nsContainerFrame.h"
+
+/* This class is a wrapper for nsColumnSetFrames and column-span elements i.e.
+ * spanners. Essentially, we divide the *original* nsColumnSetFrame
+ * into multiple nsColumnSetFrames on the basis of the number and position of
+ * spanning elements.
+ * This wrapper is necessary for implementing column-span as it allows us to
+ * maintain each nsColumnSetFrame as an independent set of columns and each
+ * spanning element then becomes just a block level element.
+ */
+class nsColumnSetWrapperFrame final : public nsBlockFrame
+{
+public:
+  NS_DECL_FRAMEARENA_HELPERS(nsColumnSetWrapperFrame)
+
+  friend nsBlockFrame* NS_NewColumnSetWrapperFrame(nsIPresShell* aPresShell,
+                                                   nsStyleContext* aContext,
+                                                   nsFrameState aStateFlags);
+
+  virtual nsContainerFrame* GetContentInsertionFrame() override {
+    MOZ_ASSERT_UNREACHABLE("Should not be called because we don't know whether"
+                           " we're inserting a column-span or not.");
+  }
+
+#ifdef DEBUG_FRAME_DUMP
+  nsresult GetFrameName(nsAString& aResult) const override {
+    return MakeFrameName(NS_LITERAL_STRING("ColumnSetWrapper"), aResult);
+  }
+#endif
+
+  void AppendFrames(ChildListID aListID, nsFrameList& aFrameList) override;
+
+  void InsertFrames(ChildListID  aListID,
+                    nsIFrame*    aPrevFrame,
+                    nsFrameList& aFrameList) override;
+
+  void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
+
+private:
+  explicit nsColumnSetWrapperFrame(nsStyleContext* aContext);
+  ~nsColumnSetWrapperFrame() override
+  {
+  }
+
+};
+
+#endif /* nsColumnSetWrapperFrame_h_ */
--- a/layout/generic/nsFrameIdList.h
+++ b/layout/generic/nsFrameIdList.h
@@ -13,16 +13,17 @@ FRAME_ID(nsBlockFrame, Block, NotLeaf)
 FRAME_ID(nsBox, None, NotLeaf)
 FRAME_ID(nsBoxFrame, Box, NotLeaf)
 FRAME_ID(nsBulletFrame, Bullet, Leaf)
 FRAME_ID(nsButtonBoxFrame, Box, NotLeaf)
 FRAME_ID(nsCanvasFrame, Canvas, NotLeaf)
 FRAME_ID(nsCheckboxRadioFrame, CheckboxRadio, Leaf)
 FRAME_ID(nsColorControlFrame, ColorControl, Leaf)
 FRAME_ID(nsColumnSetFrame, ColumnSet, NotLeaf)
+FRAME_ID(nsColumnSetWrapperFrame, ColumnSetWrapper, NotLeaf)
 FRAME_ID(nsComboboxControlFrame, ComboboxControl, NotLeaf)
 FRAME_ID(nsComboboxDisplayFrame, ComboboxDisplay, NotLeaf)
 FRAME_ID(nsContinuingTextFrame, Text, Leaf)
 FRAME_ID(nsDateTimeControlFrame, DateTimeControl, NotLeaf)
 FRAME_ID(nsDeckFrame, Deck, NotLeaf)
 FRAME_ID(nsDocElementBoxFrame, Box, NotLeaf)
 FRAME_ID(nsFieldSetFrame, FieldSet, NotLeaf)
 FRAME_ID(nsFileControlFrame, Block, Leaf)
--- a/layout/generic/nsHTMLParts.h
+++ b/layout/generic/nsHTMLParts.h
@@ -104,16 +104,18 @@ nsIFrame*
 NS_NewContinuingTextFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame*
 NS_NewEmptyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 inline nsIFrame*
 NS_NewWBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) {
   return NS_NewEmptyFrame(aPresShell, aContext);
 }
 
+nsBlockFrame*
+NS_NewColumnSetWrapperFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsFrameState aStateFlags);
 nsContainerFrame*
 NS_NewColumnSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsFrameState aStateFlags);
 
 class nsSimplePageSequenceFrame;
 nsSimplePageSequenceFrame*
 NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 class nsPageFrame;
 nsPageFrame*