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"
10 #include "nsContainerFrame.h"
12 #include "nsILineIterator.h"
13 #include "nsTablePainter.h"
17 class nsTableRowFrame
;
18 class nsTableCellFrame
;
20 struct nsRowGroupReflowState
{
21 const nsHTMLReflowState
& reflowState
; // Our reflow state
23 nsTableFrame
* tableFrame
;
25 // The available size (computed from the parent)
31 nsRowGroupReflowState(const nsHTMLReflowState
& aReflowState
,
32 nsTableFrame
* aTableFrame
)
33 :reflowState(aReflowState
), tableFrame(aTableFrame
)
35 availSize
.width
= reflowState
.AvailableWidth();
36 availSize
.height
= reflowState
.AvailableHeight();
40 ~nsRowGroupReflowState() {}
43 #define MIN_ROWS_NEEDING_CURSOR 20
46 * nsTableRowGroupFrame is the frame that maps row groups
47 * (HTML tags THEAD, TFOOT, and TBODY). This class cannot be reused
48 * outside of an nsTableFrame. It assumes that its parent is an nsTableFrame, and
49 * its children are nsTableRowFrames.
52 * @see nsTableRowFrame
54 class nsTableRowGroupFrame MOZ_FINAL
55 : public nsContainerFrame
56 , public nsILineIterator
59 NS_DECL_QUERYFRAME_TARGET(nsTableRowGroupFrame
)
61 NS_DECL_FRAMEARENA_HELPERS
63 /** instantiate a new instance of nsTableRowFrame.
64 * @param aPresShell the pres shell for this frame
66 * @return the frame that was created
68 friend nsTableRowGroupFrame
* NS_NewTableRowGroupFrame(nsIPresShell
* aPresShell
,
69 nsStyleContext
* aContext
);
70 virtual ~nsTableRowGroupFrame();
72 virtual void DestroyFrom(nsIFrame
* aDestructRoot
) MOZ_OVERRIDE
;
74 /** @see nsIFrame::DidSetStyleContext */
75 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
) MOZ_OVERRIDE
;
77 virtual void AppendFrames(ChildListID aListID
,
78 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
79 virtual void InsertFrames(ChildListID aListID
,
81 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
82 virtual void RemoveFrame(ChildListID aListID
,
83 nsIFrame
* aOldFrame
) MOZ_OVERRIDE
;
85 virtual nsMargin
GetUsedMargin() const MOZ_OVERRIDE
;
86 virtual nsMargin
GetUsedBorder() const MOZ_OVERRIDE
;
87 virtual nsMargin
GetUsedPadding() const MOZ_OVERRIDE
;
89 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
90 const nsRect
& aDirtyRect
,
91 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
93 /** calls Reflow for all of its child rows.
94 * Rows are all set to the same width and stacked vertically.
95 * <P> rows are not split unless absolutely necessary.
97 * @param aDesiredSize width set to width of rows, height set to
98 * sum of height of rows that fit in aMaxSize.height.
100 * @see nsIFrame::Reflow
102 virtual void Reflow(nsPresContext
* aPresContext
,
103 nsHTMLReflowMetrics
& aDesiredSize
,
104 const nsHTMLReflowState
& aReflowState
,
105 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
107 virtual bool UpdateOverflow() MOZ_OVERRIDE
;
110 * Get the "type" of the frame
112 * @see nsGkAtoms::tableRowGroupFrame
114 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
116 nsTableRowFrame
* GetFirstRow();
118 #ifdef DEBUG_FRAME_DUMP
119 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
122 /** return the number of child rows (not necessarily == number of child frames) */
123 int32_t GetRowCount();
125 /** return the table-relative row index of the first row in this rowgroup.
126 * if there are no rows, -1 is returned.
128 int32_t GetStartRowIndex();
130 /** Adjust the row indices of all rows whose index is >= aRowIndex.
131 * @param aRowIndex - start adjusting with this index
132 * @param aAdjustment - shift the row index by this amount
134 void AdjustRowIndices(int32_t aRowIndex
,
135 int32_t anAdjustment
);
138 * Used for header and footer row group frames that are repeated when
139 * splitting a table frame.
141 * Performs any table specific initialization
143 * @param aHeaderFooterFrame the original header or footer row group frame
146 nsresult
InitRepeatedFrame(nsPresContext
* aPresContext
,
147 nsTableRowGroupFrame
* aHeaderFooterFrame
);
151 * Get the total height of all the row rects
153 nscoord
GetHeightBasis(const nsHTMLReflowState
& aReflowState
);
155 nsMargin
* GetBCBorderWidth(nsMargin
& aBorder
);
158 * Gets inner border widths before collapsing with cell borders
159 * Caller must get top border from previous row group or from table
160 * GetContinuousBCBorderWidth will not overwrite aBorder.top
161 * see nsTablePainter about continuous borders
163 void GetContinuousBCBorderWidth(nsMargin
& aBorder
);
165 * Sets full border widths before collapsing with cell borders
166 * @param aForSide - side to set; only right, left, and bottom valid
168 void SetContinuousBCBorderWidth(uint8_t aForSide
,
169 BCPixelSize aPixelValue
);
171 * Adjust to the effect of visibibility:collapse on the row group and
173 * @return additional shift upward that should be applied to
174 * subsequent rowgroups due to rows and this rowgroup
176 * @param aYTotalOffset the total amount that the rowgroup is shifted up
177 * @param aWidth new width of the rowgroup
179 nscoord
CollapseRowGroupIfNecessary(nscoord aYTotalOffset
,
182 // nsILineIterator methods
184 virtual void DisposeLineIterator() MOZ_OVERRIDE
{ }
186 // The table row is the equivalent to a line in block layout.
187 // The nsILineIterator assumes that a line resides in a block, this role is
188 // fullfilled by the row group. Rows in table are counted relative to the
189 // table. The row index of row corresponds to the cellmap coordinates. The
190 // line index with respect to a row group can be computed by substracting the
191 // row index of the first row in the row group.
193 /** Get the number of rows in a row group
194 * @return the number of lines in a row group
196 virtual int32_t GetNumLines() MOZ_OVERRIDE
;
198 /** @see nsILineIterator.h GetDirection
199 * @return true if the table is rtl
201 virtual bool GetDirection() MOZ_OVERRIDE
;
203 /** Return structural information about a line.
204 * @param aLineNumber - the index of the row relative to the row group
205 * If the line-number is invalid then
206 * aFirstFrameOnLine will be nullptr and
207 * aNumFramesOnLine will be zero.
208 * @param aFirstFrameOnLine - the first cell frame that originates in row
209 * with a rowindex that matches a line number
210 * @param aNumFramesOnLine - return the numbers of cells originating in
212 * @param aLineBounds - rect of the row
213 * @param aLineFlags - unused set to 0
215 NS_IMETHOD
GetLine(int32_t aLineNumber
,
216 nsIFrame
** aFirstFrameOnLine
,
217 int32_t* aNumFramesOnLine
,
219 uint32_t* aLineFlags
) MOZ_OVERRIDE
;
221 /** Given a frame that's a child of the rowgroup, find which line its on.
222 * @param aFrame - frame, should be a row
223 * @param aStartLine - minimal index to return
224 * @return row index relative to the row group if this a row
225 * frame and the index is at least aStartLine.
226 * -1 if the frame cannot be found.
228 virtual int32_t FindLineContaining(nsIFrame
* aFrame
, int32_t aStartLine
= 0) MOZ_OVERRIDE
;
230 /** Find the orginating cell frame on a row that is the nearest to the
232 * @param aLineNumber - the index of the row relative to the row group
233 * @param aX - X coordinate in twips relative to the
234 * origin of the row group
235 * @param aFrameFound - pointer to the cellframe
236 * @param aXIsBeforeFirstFrame - the point is before the first originating
238 * @param aXIsAfterLastFrame - the point is after the last originating
241 NS_IMETHOD
FindFrameAt(int32_t aLineNumber
,
243 nsIFrame
** aFrameFound
,
244 bool* aXIsBeforeFirstFrame
,
245 bool* aXIsAfterLastFrame
) MOZ_OVERRIDE
;
247 /** Check whether visual and logical order of cell frames within a line are
248 * identical. As the layout will reorder them this is always the case
249 * @param aLine - the index of the row relative to the table
250 * @param aIsReordered - returns false
251 * @param aFirstVisual - if the table is rtl first originating cell frame
252 * @param aLastVisual - if the table is rtl last originating cell frame
255 NS_IMETHOD
CheckLineOrder(int32_t aLine
,
257 nsIFrame
**aFirstVisual
,
258 nsIFrame
**aLastVisual
) MOZ_OVERRIDE
;
260 /** Find the next originating cell frame that originates in the row.
261 * @param aFrame - cell frame to start with, will return the next cell
262 * originating in a row
263 * @param aLineNumber - the index of the row relative to the table
265 NS_IMETHOD
GetNextSiblingOnLine(nsIFrame
*& aFrame
, int32_t aLineNumber
) MOZ_OVERRIDE
;
267 // row cursor methods to speed up searching for the row(s)
268 // containing a point. The basic idea is that we set the cursor
269 // property if the rows' y and yMosts are non-decreasing (considering only
270 // rows with nonempty overflowAreas --- empty overflowAreas never participate
271 // in event handling or painting), and the rowgroup has sufficient number of
272 // rows. The cursor property points to a "recently used" row. If we get a
273 // series of requests that work on rows "near" the cursor, then we can find
274 // those nearby rows quickly by starting our search at the cursor.
275 // This code is based on the line cursor code in nsBlockFrame. It's more general
276 // though, and could be extracted and used elsewhere.
277 struct FrameCursorData
{
278 nsTArray
<nsIFrame
*> mFrames
;
279 uint32_t mCursorIndex
;
280 nscoord mOverflowAbove
;
281 nscoord mOverflowBelow
;
284 : mFrames(MIN_ROWS_NEEDING_CURSOR
), mCursorIndex(0), mOverflowAbove(0),
287 bool AppendFrame(nsIFrame
* aFrame
);
289 void FinishBuildingCursor() {
294 // Clear out row cursor because we're disturbing the rows (e.g., Reflow)
295 void ClearRowCursor();
298 * Get the first row that might contain y-coord 'aY', or nullptr if you must search
300 * The actual row returned might not contain 'aY', but if not, it is guaranteed
301 * to be before any row which does contain 'aY'.
302 * aOverflowAbove is the maximum over all rows of -row.GetOverflowRect().y.
303 * To find all rows that intersect the vertical interval aY/aYMost, call
304 * GetFirstRowContaining(aY, &overflowAbove), and then iterate through all
305 * rows until reaching a row where row->GetRect().y - overflowAbove >= aYMost.
306 * That row and all subsequent rows cannot intersect the interval.
308 nsIFrame
* GetFirstRowContaining(nscoord aY
, nscoord
* aOverflowAbove
);
311 * Set up the row cursor. After this, call AppendFrame for every
312 * child frame in sibling order. Ensure that the child frame y and YMost values
313 * form non-decreasing sequences (should always be true for table rows);
314 * if this is violated, call ClearRowCursor(). If we return nullptr, then we
315 * decided not to use a cursor or we already have one set up.
317 FrameCursorData
* SetupRowCursor();
319 virtual nsILineIterator
* GetLineIterator() MOZ_OVERRIDE
{ return this; }
321 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
323 return nsContainerFrame::IsFrameOfType(aFlags
& ~(nsIFrame::eTablePart
));
326 virtual void InvalidateFrame(uint32_t aDisplayItemKey
= 0) MOZ_OVERRIDE
;
327 virtual void InvalidateFrameWithRect(const nsRect
& aRect
, uint32_t aDisplayItemKey
= 0) MOZ_OVERRIDE
;
328 virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE
{ InvalidateFrameSubtree(); }
331 explicit nsTableRowGroupFrame(nsStyleContext
* aContext
);
333 void InitChildReflowState(nsPresContext
& aPresContext
,
334 bool aBorderCollapse
,
335 nsHTMLReflowState
& aReflowState
);
337 virtual LogicalSides
GetLogicalSkipSides(const nsHTMLReflowState
* aReflowState
= nullptr) const MOZ_OVERRIDE
;
339 void PlaceChild(nsPresContext
* aPresContext
,
340 nsRowGroupReflowState
& aReflowState
,
342 nsHTMLReflowMetrics
& aDesiredSize
,
343 const nsRect
& aOriginalKidRect
,
344 const nsRect
& aOriginalKidVisualOverflow
);
346 void CalculateRowHeights(nsPresContext
* aPresContext
,
347 nsHTMLReflowMetrics
& aDesiredSize
,
348 const nsHTMLReflowState
& aReflowState
);
350 void DidResizeRows(nsHTMLReflowMetrics
& aDesiredSize
);
352 void SlideChild(nsRowGroupReflowState
& aReflowState
,
353 nsIFrame
* aKidFrame
);
356 * Reflow the frames we've already created
358 * @param aPresContext presentation context to use
359 * @param aReflowState current inline state
361 void ReflowChildren(nsPresContext
* aPresContext
,
362 nsHTMLReflowMetrics
& aDesiredSize
,
363 nsRowGroupReflowState
& aReflowState
,
364 nsReflowStatus
& aStatus
,
365 bool* aPageBreakBeforeEnd
= nullptr);
367 nsresult
SplitRowGroup(nsPresContext
* aPresContext
,
368 nsHTMLReflowMetrics
& aDesiredSize
,
369 const nsHTMLReflowState
& aReflowState
,
370 nsTableFrame
* aTableFrame
,
371 nsReflowStatus
& aStatus
,
372 bool aRowForcedPageBreak
);
374 void SplitSpanningCells(nsPresContext
& aPresContext
,
375 const nsHTMLReflowState
& aReflowState
,
376 nsTableFrame
& aTableFrame
,
377 nsTableRowFrame
& aFirstRow
,
378 nsTableRowFrame
& aLastRow
,
379 bool aFirstRowIsTopOfPage
,
380 nscoord aSpanningRowBottom
,
381 nsTableRowFrame
*& aContRowFrame
,
382 nsTableRowFrame
*& aFirstTruncatedRow
,
383 nscoord
& aDesiredHeight
);
385 void CreateContinuingRowFrame(nsPresContext
& aPresContext
,
387 nsIFrame
** aContRowFrame
);
389 bool IsSimpleRowFrame(nsTableFrame
* aTableFrame
,
392 void GetNextRowSibling(nsIFrame
** aRowFrame
);
394 void UndoContinuedRow(nsPresContext
* aPresContext
,
395 nsTableRowFrame
* aRow
);
398 // border widths in pixels in the collapsing border model
399 BCPixelSize mRightContBorderWidth
;
400 BCPixelSize mBottomContBorderWidth
;
401 BCPixelSize mLeftContBorderWidth
;
404 bool IsRepeatable() const;
405 void SetRepeatable(bool aRepeatable
);
406 bool HasStyleHeight() const;
407 void SetHasStyleHeight(bool aValue
);
408 bool HasInternalBreakBefore() const;
409 bool HasInternalBreakAfter() const;
413 inline bool nsTableRowGroupFrame::IsRepeatable() const
415 return (mState
& NS_ROWGROUP_REPEATABLE
) == NS_ROWGROUP_REPEATABLE
;
418 inline void nsTableRowGroupFrame::SetRepeatable(bool aRepeatable
)
421 mState
|= NS_ROWGROUP_REPEATABLE
;
423 mState
&= ~NS_ROWGROUP_REPEATABLE
;
427 inline bool nsTableRowGroupFrame::HasStyleHeight() const
429 return (mState
& NS_ROWGROUP_HAS_STYLE_HEIGHT
) == NS_ROWGROUP_HAS_STYLE_HEIGHT
;
432 inline void nsTableRowGroupFrame::SetHasStyleHeight(bool aValue
)
435 mState
|= NS_ROWGROUP_HAS_STYLE_HEIGHT
;
437 mState
&= ~NS_ROWGROUP_HAS_STYLE_HEIGHT
;
442 nsTableRowGroupFrame::GetContinuousBCBorderWidth(nsMargin
& aBorder
)
444 int32_t aPixelsToTwips
= nsPresContext::AppUnitsPerCSSPixel();
445 aBorder
.right
= BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips
,
446 mRightContBorderWidth
);
447 aBorder
.bottom
= BC_BORDER_TOP_HALF_COORD(aPixelsToTwips
,
448 mBottomContBorderWidth
);
449 aBorder
.left
= BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips
,
450 mLeftContBorderWidth
);