Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / tables / nsTableRowGroupFrame.h
blob5eda8332363c106bd43042d94144dcb33e474e82
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 nsTableRowGroupFrame_h__
6 #define nsTableRowGroupFrame_h__
8 #include "mozilla/Attributes.h"
9 #include "nscore.h"
10 #include "nsContainerFrame.h"
11 #include "nsAtom.h"
12 #include "nsILineIterator.h"
13 #include "nsTArray.h"
14 #include "nsTableFrame.h"
15 #include "mozilla/WritingModes.h"
17 class nsTableRowFrame;
18 namespace mozilla {
19 class PresShell;
20 struct TableRowGroupReflowInput;
21 } // namespace mozilla
23 #define MIN_ROWS_NEEDING_CURSOR 20
25 /**
26 * nsTableRowGroupFrame is the frame that maps row groups
27 * (HTML tags THEAD, TFOOT, and TBODY). This class cannot be reused
28 * outside of an nsTableFrame. It assumes that its parent is an nsTableFrame,
29 * and its children are nsTableRowFrames.
31 * @see nsTableFrame
32 * @see nsTableRowFrame
34 class nsTableRowGroupFrame final : public nsContainerFrame,
35 public nsILineIterator {
36 public:
37 NS_DECL_QUERYFRAME
38 NS_DECL_FRAMEARENA_HELPERS(nsTableRowGroupFrame)
40 /** instantiate a new instance of nsTableRowFrame.
41 * @param aPresShell the pres shell for this frame
43 * @return the frame that was created
45 friend nsTableRowGroupFrame* NS_NewTableRowGroupFrame(
46 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
47 virtual ~nsTableRowGroupFrame();
49 // nsIFrame overrides
50 void Init(nsIContent* aContent, nsContainerFrame* aParent,
51 nsIFrame* aPrevInFlow) override {
52 nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
53 if (!aPrevInFlow) {
54 mWritingMode = GetTableFrame()->GetWritingMode();
58 void Destroy(DestroyContext&) override;
60 /** @see nsIFrame::DidSetComputedStyle */
61 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
63 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
64 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
65 const nsLineList::iterator* aPrevFrameLine,
66 nsFrameList&& aFrameList) override;
67 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
69 nsMargin GetUsedMargin() const override;
70 nsMargin GetUsedBorder() const override;
71 nsMargin GetUsedPadding() const override;
73 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
74 const nsDisplayListSet& aLists) override;
76 /**
77 * Calls Reflow for all of its child rows.
79 * Rows are all set to the same isize and stacked in the block direction.
81 * Rows are not split unless absolutely necessary.
83 * @param aDesiredSize isize set to isize of rows, bsize set to
84 * sum of bsize of rows that fit in AvailableBSize.
86 * @see nsIFrame::Reflow
88 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
89 const ReflowInput& aReflowInput,
90 nsReflowStatus& aStatus) override;
92 bool ComputeCustomOverflow(mozilla::OverflowAreas& aOverflowAreas) override;
94 #ifdef DEBUG_FRAME_DUMP
95 nsresult GetFrameName(nsAString& aResult) const override;
96 #endif
98 nsTableRowFrame* GetFirstRow() const;
99 nsTableRowFrame* GetLastRow() const;
101 nsTableFrame* GetTableFrame() const {
102 nsIFrame* parent = GetParent();
103 MOZ_ASSERT(parent && parent->IsTableFrame());
104 return static_cast<nsTableFrame*>(parent);
107 /** return the number of child rows (not necessarily == number of child
108 * frames) */
109 int32_t GetRowCount() const;
111 /** return the table-relative row index of the first row in this rowgroup.
112 * if there are no rows, -1 is returned.
114 int32_t GetStartRowIndex() const;
116 /** Adjust the row indices of all rows whose index is >= aRowIndex.
117 * @param aRowIndex - start adjusting with this index
118 * @param aAdjustment - shift the row index by this amount
120 void AdjustRowIndices(int32_t aRowIndex, int32_t anAdjustment);
122 // See nsTableFrame.h
123 int32_t GetAdjustmentForStoredIndex(int32_t aStoredIndex);
125 /* mark rows starting from aStartRowFrame to the next 'aNumRowsToRemove-1'
126 * number of rows as deleted
128 void MarkRowsAsDeleted(nsTableRowFrame& aStartRowFrame,
129 int32_t aNumRowsToDelete);
131 // See nsTableFrame.h
132 void AddDeletedRowIndex(int32_t aDeletedRowStoredIndex);
135 * Used for header and footer row group frames that are repeated when
136 * splitting a table frame.
138 * Performs any table specific initialization
140 * @param aHeaderFooterFrame the original header or footer row group frame
141 * that was repeated
143 void InitRepeatedFrame(nsTableRowGroupFrame* aHeaderFooterFrame);
146 * Get the total bsize of all the row rects
148 nscoord GetBSizeBasis(const ReflowInput& aReflowInput);
150 mozilla::LogicalMargin GetBCBorderWidth(mozilla::WritingMode aWM);
153 * Gets inner border widths before collapsing with cell borders
154 * Caller must get bstart border from previous row group or from table
155 * GetContinuousBCBorderWidth will not overwrite aBorder.BStart()
156 * see nsTablePainter about continuous borders
158 void GetContinuousBCBorderWidth(mozilla::WritingMode aWM,
159 mozilla::LogicalMargin& aBorder);
162 * Sets full border widths before collapsing with cell borders
163 * @param aForSide - side to set; only IEnd, IStart, BEnd are valid
165 void SetContinuousBCBorderWidth(mozilla::LogicalSide aForSide,
166 BCPixelSize aPixelValue);
168 * Adjust to the effect of visibility:collapse on the row group and
169 * its children
170 * @return additional shift bstart-wards that should be applied
171 * to subsequent rowgroups due to rows and this
172 * rowgroup being collapsed
173 * @param aBTotalOffset the total amount that the rowgroup is shifted
174 * @param aISize new isize of the rowgroup
175 * @param aWM the table's writing mode
177 nscoord CollapseRowGroupIfNecessary(nscoord aBTotalOffset, nscoord aISize,
178 mozilla::WritingMode aWM);
180 // nsILineIterator methods
181 public:
182 // The table row is the equivalent to a line in block layout.
183 // The nsILineIterator assumes that a line resides in a block, this role is
184 // fullfilled by the row group. Rows in table are counted relative to the
185 // table. The row index of row corresponds to the cellmap coordinates. The
186 // line index with respect to a row group can be computed by substracting the
187 // row index of the first row in the row group.
189 /** Get the number of rows in a row group
190 * @return the number of lines in a row group
192 int32_t GetNumLines() const final;
194 /** @see nsILineIterator.h IsLineIteratorFlowRTL */
195 bool IsLineIteratorFlowRTL() final;
197 /** Return structural information about a line. */
198 Result<LineInfo, nsresult> GetLine(int32_t aLineNumber) final;
200 /** Given a frame that's a child of the rowgroup, find which line its on.
201 * @param aFrame - frame, should be a row
202 * @param aStartLine - minimal index to return
203 * @return row index relative to the row group if this a row
204 * frame and the index is at least aStartLine.
205 * -1 if the frame cannot be found.
207 int32_t FindLineContaining(nsIFrame* aFrame, int32_t aStartLine = 0) final;
209 /** Find the orginating cell frame on a row that is the nearest to the
210 * inline-dir coordinate of aPos.
211 * @param aLineNumber - the index of the row relative to the row group
212 * @param aPos - coordinate in twips relative to the
213 * origin of the row group
214 * @param aFrameFound - pointer to the cellframe
215 * @param aPosIsBeforeFirstFrame - the point is before the first originating
216 * cellframe
217 * @param aPosIsAfterLastFrame - the point is after the last originating
218 * cellframe
220 NS_IMETHOD FindFrameAt(int32_t aLineNumber, nsPoint aPos,
221 nsIFrame** aFrameFound, bool* aPosIsBeforeFirstFrame,
222 bool* aPosIsAfterLastFrame) final;
224 /** Check whether visual and logical order of cell frames within a line are
225 * identical. As the layout will reorder them this is always the case
226 * @param aLine - the index of the row relative to the table
227 * @param aIsReordered - returns false
228 * @param aFirstVisual - if the table is rtl first originating cell frame
229 * @param aLastVisual - if the table is rtl last originating cell frame
232 NS_IMETHOD CheckLineOrder(int32_t aLine, bool* aIsReordered,
233 nsIFrame** aFirstVisual,
234 nsIFrame** aLastVisual) final;
236 // row cursor methods to speed up searching for the row(s)
237 // containing a point. The basic idea is that we set the cursor
238 // property if the rows' y and yMosts are non-decreasing (considering only
239 // rows with nonempty overflowAreas --- empty overflowAreas never participate
240 // in event handling or painting), and the rowgroup has sufficient number of
241 // rows. The cursor property points to a "recently used" row. If we get a
242 // series of requests that work on rows "near" the cursor, then we can find
243 // those nearby rows quickly by starting our search at the cursor.
244 // This code is based on the line cursor code in nsBlockFrame. It's more
245 // general though, and could be extracted and used elsewhere.
246 struct FrameCursorData {
247 nsTArray<nsIFrame*> mFrames;
248 uint32_t mCursorIndex;
249 nscoord mOverflowAbove;
250 nscoord mOverflowBelow;
252 FrameCursorData()
253 : mFrames(MIN_ROWS_NEEDING_CURSOR),
254 mCursorIndex(0),
255 mOverflowAbove(0),
256 mOverflowBelow(0) {}
258 bool AppendFrame(nsIFrame* aFrame);
260 void FinishBuildingCursor() { mFrames.Compact(); }
263 // Clear out row cursor because we're disturbing the rows (e.g., Reflow)
264 void ClearRowCursor();
267 * Get the first row that might contain y-coord 'aY', or nullptr if you must
268 * search all rows.
269 * The actual row returned might not contain 'aY', but if not, it is
270 * guaranteed to be before any row which does contain 'aY'.
271 * aOverflowAbove is the maximum over all rows of -row.GetOverflowRect().y.
272 * To find all rows that intersect the vertical interval aY/aYMost, call
273 * GetFirstRowContaining(aY, &overflowAbove), and then iterate through all
274 * rows until reaching a row where row->GetRect().y - overflowAbove >= aYMost.
275 * That row and all subsequent rows cannot intersect the interval.
277 nsIFrame* GetFirstRowContaining(nscoord aY, nscoord* aOverflowAbove);
280 * Set up the row cursor. After this, call AppendFrame for every
281 * child frame in sibling order. Ensure that the child frame y and YMost
282 * values form non-decreasing sequences (should always be true for table
283 * rows); if this is violated, call ClearRowCursor(). If we return nullptr,
284 * then we decided not to use a cursor or we already have one set up.
286 FrameCursorData* SetupRowCursor();
288 bool CanProvideLineIterator() const final { return true; }
289 nsILineIterator* GetLineIterator() final { return this; }
291 void InvalidateFrame(uint32_t aDisplayItemKey = 0,
292 bool aRebuildDisplayItems = true) override;
293 void InvalidateFrameWithRect(const nsRect& aRect,
294 uint32_t aDisplayItemKey = 0,
295 bool aRebuildDisplayItems = true) override;
296 void InvalidateFrameForRemoval() override { InvalidateFrameSubtree(); }
298 protected:
299 explicit nsTableRowGroupFrame(ComputedStyle* aStyle,
300 nsPresContext* aPresContext);
302 void InitChildReflowInput(nsPresContext* aPresContext, bool aBorderCollapse,
303 ReflowInput& aReflowInput);
305 LogicalSides GetLogicalSkipSides() const override;
307 void PlaceChild(nsPresContext* aPresContext,
308 mozilla::TableRowGroupReflowInput& aReflowInput,
309 nsIFrame* aKidFrame, const ReflowInput& aKidReflowInput,
310 mozilla::WritingMode aWM,
311 const mozilla::LogicalPoint& aKidPosition,
312 const nsSize& aContainerSize, ReflowOutput& aDesiredSize,
313 const nsRect& aOriginalKidRect,
314 const nsRect& aOriginalKidInkOverflow);
316 void CalculateRowBSizes(nsPresContext* aPresContext,
317 ReflowOutput& aDesiredSize,
318 const ReflowInput& aReflowInput);
320 void DidResizeRows(ReflowOutput& aDesiredSize);
323 * Reflow the frames we've already created
325 * @param aPresContext presentation context to use
326 * @param aReflowInput current inline state
328 void ReflowChildren(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
329 mozilla::TableRowGroupReflowInput& aReflowInput,
330 nsReflowStatus& aStatus,
331 bool* aPageBreakBeforeEnd = nullptr);
333 void SplitRowGroup(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
334 const ReflowInput& aReflowInput, nsTableFrame* aTableFrame,
335 nsReflowStatus& aStatus, bool aRowForcedPageBreak);
337 void SplitSpanningCells(nsPresContext* aPresContext,
338 const ReflowInput& aReflowInput,
339 nsTableFrame* aTableFrame, nsTableRowFrame* aFirstRow,
340 nsTableRowFrame* aLastRow, bool aFirstRowIsTopOfPage,
341 nscoord aSpanningRowBEnd,
342 const nsSize& aContainerSize,
343 nsTableRowFrame*& aContRowFrame,
344 nsTableRowFrame*& aFirstTruncatedRow,
345 nscoord& aDesiredBSize);
348 * Create a continuing table row frame, add it to the child list, and then
349 * push it and its later siblings to our overflow frames list.
351 nsTableRowFrame* CreateContinuingRowFrame(nsIFrame* aRowFrame);
353 bool IsSimpleRowFrame(nsTableFrame* aTableFrame, nsTableRowFrame* aRowFrame);
355 void GetNextRowSibling(nsIFrame** aRowFrame);
357 void UndoContinuedRow(nsPresContext* aPresContext, nsTableRowFrame* aRow);
359 private:
360 // border widths in pixels in the collapsing border model
361 BCPixelSize mIEndContBorderWidth = 0;
362 BCPixelSize mBEndContBorderWidth = 0;
363 BCPixelSize mIStartContBorderWidth = 0;
365 public:
366 bool IsRepeatable() const;
367 void SetRepeatable(bool aRepeatable);
368 bool HasStyleBSize() const;
369 void SetHasStyleBSize(bool aValue);
370 bool HasInternalBreakBefore() const;
371 bool HasInternalBreakAfter() const;
374 inline bool nsTableRowGroupFrame::IsRepeatable() const {
375 return HasAnyStateBits(NS_ROWGROUP_REPEATABLE);
378 inline void nsTableRowGroupFrame::SetRepeatable(bool aRepeatable) {
379 if (aRepeatable) {
380 AddStateBits(NS_ROWGROUP_REPEATABLE);
381 } else {
382 RemoveStateBits(NS_ROWGROUP_REPEATABLE);
386 inline bool nsTableRowGroupFrame::HasStyleBSize() const {
387 return HasAnyStateBits(NS_ROWGROUP_HAS_STYLE_BSIZE);
390 inline void nsTableRowGroupFrame::SetHasStyleBSize(bool aValue) {
391 if (aValue) {
392 AddStateBits(NS_ROWGROUP_HAS_STYLE_BSIZE);
393 } else {
394 RemoveStateBits(NS_ROWGROUP_HAS_STYLE_BSIZE);
398 inline void nsTableRowGroupFrame::GetContinuousBCBorderWidth(
399 mozilla::WritingMode aWM, mozilla::LogicalMargin& aBorder) {
400 int32_t d2a = PresContext()->AppUnitsPerDevPixel();
401 aBorder.IEnd(aWM) = BC_BORDER_START_HALF_COORD(d2a, mIEndContBorderWidth);
402 aBorder.BEnd(aWM) = BC_BORDER_START_HALF_COORD(d2a, mBEndContBorderWidth);
403 aBorder.IStart(aWM) = BC_BORDER_END_HALF_COORD(d2a, mIStartContBorderWidth);
405 #endif