Backed out changeset c20fe6f0a048 (bug 1825384) for causing table related reftest...
[gecko.git] / layout / tables / nsTableColGroupFrame.h
blob901c693f8ccd98daf098f37f92dc93f00fb87354
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsTableColGroupFrame_h__
6 #define nsTableColGroupFrame_h__
8 #include "mozilla/Attributes.h"
9 #include "nscore.h"
10 #include "nsContainerFrame.h"
11 #include "nsTableFrame.h"
12 #include "mozilla/WritingModes.h"
14 class nsTableColFrame;
16 namespace mozilla {
17 class PresShell;
18 } // namespace mozilla
20 /**
21 * nsTableColGroupFrame
22 * data structure to maintain information about a single table cell's frame
24 class nsTableColGroupFrame final : public nsContainerFrame {
25 public:
26 NS_DECL_FRAMEARENA_HELPERS(nsTableColGroupFrame)
28 /**
29 * instantiate a new instance of nsTableRowFrame.
31 * @param aPresShell the pres shell for this frame
33 * @return the frame that was created
35 friend nsTableColGroupFrame* NS_NewTableColGroupFrame(
36 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
38 // nsIFrame overrides
39 void Init(nsIContent* aContent, nsContainerFrame* aParent,
40 nsIFrame* aPrevInFlow) override {
41 nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
42 if (!aPrevInFlow) {
43 mWritingMode = GetTableFrame()->GetWritingMode();
47 nsTableFrame* GetTableFrame() const {
48 nsIFrame* parent = GetParent();
49 MOZ_ASSERT(parent && parent->IsTableFrame());
50 MOZ_ASSERT(!parent->GetPrevInFlow(),
51 "Col group should always be in a first-in-flow table frame");
52 return static_cast<nsTableFrame*>(parent);
55 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
56 const nsDisplayListSet& aLists) override;
58 /** A colgroup can be caused by three things:
59 * 1) An element with table-column-group display
60 * 2) An element with a table-column display without a
61 * table-column-group parent
62 * 3) Cells that are not in a column (and hence get an anonymous
63 * column and colgroup).
65 * In practice, we don't need to differentiate between cases (1) and (2),
66 * because they both correspond to table-column-group boxes in the spec and
67 * hence have observably identical behavior. Case three is flagged as a
68 * synthetic colgroup, because it may need to have different behavior in some
69 * cases.
71 bool IsSynthetic() const;
72 void SetIsSynthetic();
74 /** Real in this context are colgroups that come from an element
75 * with table-column-group display or wrap around columns that
76 * come from an element with table-column display. Colgroups
77 * that are the result of wrapping cells in an anonymous
78 * column and colgroup are not considered real here.
79 * @param aTableFrame - the table parent of the colgroups
80 * @return the last real colgroup
82 static nsTableColGroupFrame* GetLastRealColGroup(nsTableFrame* aTableFrame);
84 /** @see nsIFrame::DidSetComputedStyle */
85 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
87 void SetInitialChildList(ChildListID aListID,
88 nsFrameList&& aChildList) override;
89 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
90 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
91 const nsLineList::iterator* aPrevFrameLine,
92 nsFrameList&& aFrameList) override;
93 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
95 /** remove the column aChild from the column group, if requested renumber
96 * the subsequent columns in this column group and all following column
97 * groups. see also ResetColIndices for this
98 * @param aChild - the column frame that needs to be removed
99 * @param aResetSubsequentColIndices - if true the columns that follow
100 * after aChild will be reenumerated
102 void RemoveChild(DestroyContext& aContext, nsTableColFrame& aChild,
103 bool aResetSubsequentColIndices);
105 /** reflow of a column group is a trivial matter of reflowing
106 * the col group's children (columns), and setting this frame
107 * to 0-size. Since tables are row-centric, column group frames
108 * don't play directly in the rendering game. They do however
109 * maintain important state that effects table and cell layout.
111 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
112 const ReflowInput& aReflowInput,
113 nsReflowStatus& aStatus) override;
115 /** Add column frames to the table storages: colframe cache and cellmap
116 * this doesn't change the mFrames of the colgroup frame.
117 * @param aFirstColIndex - the index at which aFirstFrame should be inserted
118 * into the colframe cache.
119 * @param aResetSubsequentColIndices - the indices of the col frames
120 * after the insertion might need
121 * an update
122 * @param aCols - an iterator that can be used to iterate over the col
123 * frames to be added. Once this is done, the frames on the
124 * sbling chain of its .get() at that point will still need
125 * their col indices updated.
126 * @result - if there is no table frame or the table frame is not
127 * the first in flow it will return an error
129 nsresult AddColsToTable(int32_t aFirstColIndex,
130 bool aResetSubsequentColIndices,
131 const nsFrameList::Slice& aCols);
133 #ifdef DEBUG_FRAME_DUMP
134 nsresult GetFrameName(nsAString& aResult) const override;
135 void Dump(int32_t aIndent);
136 #endif
138 /** returns the number of columns represented by this group.
139 * if there are col children, count them (taking into account the span of
140 * each) else, check my own span attribute.
142 int32_t GetColCount() const;
144 /** first column on the child list */
145 nsTableColFrame* GetFirstColumn();
146 /** next sibling to aChildFrame that is a column frame, first column frame
147 * in the column group if aChildFrame is null
149 nsTableColFrame* GetNextColumn(nsIFrame* aChildFrame);
151 /** @return - the position of the first column in this colgroup in the table
152 * colframe cache.
154 int32_t GetStartColumnIndex();
156 /** set the position of the first column in this colgroup in the table
157 * colframe cache.
159 void SetStartColumnIndex(int32_t aIndex);
161 /** helper method to get the span attribute for this colgroup */
162 int32_t GetSpan();
164 /** provide access to the mFrames list
166 nsFrameList& GetWritableChildList();
168 /** set the column index for all frames starting at aStartColFrame, it
169 * will also reset the column indices in all subsequent colgroups
170 * @param aFirstColGroup - start the reset operation inside this colgroup
171 * @param aFirstColIndex - first column that is reset should get this index
172 * @param aStartColFrame - if specified the reset starts with this column
173 * inside the colgroup; if not specified, the reset
174 * starts with the first column
176 static void ResetColIndices(nsIFrame* aFirstColGroup, int32_t aFirstColIndex,
177 nsIFrame* aStartColFrame = nullptr);
180 * Gets inner border widths before collapsing with cell borders
181 * Caller must get istart border from previous column
182 * GetContinuousBCBorderWidth will not overwrite aBorder.IStart
183 * see nsTablePainter about continuous borders
185 void GetContinuousBCBorderWidth(mozilla::WritingMode aWM,
186 mozilla::LogicalMargin& aBorder);
188 * Set full border widths before collapsing with cell borders
189 * @param aForSide - side to set; only accepts bstart and bend
191 void SetContinuousBCBorderWidth(mozilla::LogicalSide aForSide,
192 BCPixelSize aPixelValue);
194 bool IsFrameOfType(uint32_t aFlags) const override {
195 if (aFlags & (eSupportsContainLayoutAndPaint | eSupportsAspectRatio)) {
196 return false;
199 return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
202 void InvalidateFrame(uint32_t aDisplayItemKey = 0,
203 bool aRebuildDisplayItems = true) override;
204 void InvalidateFrameWithRect(const nsRect& aRect,
205 uint32_t aDisplayItemKey = 0,
206 bool aRebuildDisplayItems = true) override;
207 void InvalidateFrameForRemoval() override { InvalidateFrameSubtree(); }
209 protected:
210 nsTableColGroupFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
212 void InsertColsReflow(int32_t aColIndex, const nsFrameList::Slice& aCols);
214 LogicalSides GetLogicalSkipSides() const override;
216 // data members
217 int32_t mColCount;
218 // the starting column index this col group represents. Must be >= 0.
219 int32_t mStartColIndex;
221 // border width in pixels
222 BCPixelSize mBStartContBorderWidth;
223 BCPixelSize mBEndContBorderWidth;
226 inline nsTableColGroupFrame::nsTableColGroupFrame(ComputedStyle* aStyle,
227 nsPresContext* aPresContext)
228 : nsContainerFrame(aStyle, aPresContext, kClassID),
229 mColCount(0),
230 mStartColIndex(0) {}
232 inline int32_t nsTableColGroupFrame::GetStartColumnIndex() {
233 return mStartColIndex;
236 inline void nsTableColGroupFrame::SetStartColumnIndex(int32_t aIndex) {
237 mStartColIndex = aIndex;
240 inline int32_t nsTableColGroupFrame::GetColCount() const { return mColCount; }
242 inline nsFrameList& nsTableColGroupFrame::GetWritableChildList() {
243 return mFrames;
246 #endif