Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / tables / nsTableRowFrame.h
blob0c1666052a04d2928cd1e1d67b6375f5a1182d6e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsTableRowFrame_h__
38 #define nsTableRowFrame_h__
40 #include "nscore.h"
41 #include "nsHTMLContainerFrame.h"
42 #include "nsTablePainter.h"
44 class nsTableFrame;
45 class nsTableCellFrame;
46 struct nsTableCellReflowState;
48 // This is also used on rows, from nsTableRowGroupFrame.h
49 // #define NS_REPEATED_ROW_OR_ROWGROUP 0x10000000
51 // Indicates whether this row has any cells that have
52 // non-auto-height and rowspan=1
53 #define NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT 0x20000000
55 #define NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT 0x40000000
57 /**
58 * nsTableRowFrame is the frame that maps table rows
59 * (HTML tag TR). This class cannot be reused
60 * outside of an nsTableRowGroupFrame. It assumes that its parent is an nsTableRowGroupFrame,
61 * and its children are nsTableCellFrames.
63 * @see nsTableFrame
64 * @see nsTableRowGroupFrame
65 * @see nsTableCellFrame
67 class nsTableRowFrame : public nsHTMLContainerFrame
69 public:
70 virtual ~nsTableRowFrame();
72 NS_IMETHOD Init(nsIContent* aContent,
73 nsIFrame* aParent,
74 nsIFrame* aPrevInFlow);
75 /** @see nsIFrame::DidSetStyleContext */
76 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
78 NS_IMETHOD AppendFrames(nsIAtom* aListName,
79 nsIFrame* aFrameList);
80 NS_IMETHOD InsertFrames(nsIAtom* aListName,
81 nsIFrame* aPrevFrame,
82 nsIFrame* aFrameList);
83 NS_IMETHOD RemoveFrame(nsIAtom* aListName,
84 nsIFrame* aOldFrame);
86 /** instantiate a new instance of nsTableRowFrame.
87 * @param aPresShell the pres shell for this frame
89 * @return the frame that was created
91 friend nsIFrame* NS_NewTableRowFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
93 virtual nsMargin GetUsedMargin() const;
94 virtual nsMargin GetUsedBorder() const;
95 virtual nsMargin GetUsedPadding() const;
97 NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
98 const nsRect& aDirtyRect,
99 const nsDisplayListSet& aLists);
101 nsTableCellFrame* GetFirstCell() ;
103 /** calls Reflow for all of its child cells.
104 * Cells with rowspan=1 are all set to the same height and stacked horizontally.
105 * <P> Cells are not split unless absolutely necessary.
106 * <P> Cells are resized in nsTableFrame::BalanceColumnWidths
107 * and nsTableFrame::ShrinkWrapChildren
109 * @param aDesiredSize width set to width of the sum of the cells, height set to
110 * height of cells with rowspan=1.
112 * @see nsIFrame::Reflow
113 * @see nsTableFrame::BalanceColumnWidths
114 * @see nsTableFrame::ShrinkWrapChildren
116 NS_IMETHOD Reflow(nsPresContext* aPresContext,
117 nsHTMLReflowMetrics& aDesiredSize,
118 const nsHTMLReflowState& aReflowState,
119 nsReflowStatus& aStatus);
121 void DidResize();
123 virtual PRBool IsFrameOfType(PRUint32 aFlags) const
125 return nsHTMLContainerFrame::IsFrameOfType(aFlags &
126 ~nsIFrame::eExcludesIgnorableWhitespace);
130 * Get the "type" of the frame
132 * @see nsGkAtoms::tableRowFrame
134 virtual nsIAtom* GetType() const;
136 #ifdef DEBUG
137 NS_IMETHOD GetFrameName(nsAString& aResult) const;
138 #endif
140 void UpdateHeight(nscoord aHeight,
141 nscoord aAscent,
142 nscoord aDescent,
143 nsTableFrame* aTableFrame = nsnull,
144 nsTableCellFrame* aCellFrame = nsnull);
146 void ResetHeight(nscoord aRowStyleHeight);
148 // calculate the height, considering content height of the
149 // cells and the style height of the row and cells, excluding pct heights
150 nscoord CalcHeight(const nsHTMLReflowState& aReflowState);
152 // Support for cells with 'vertical-align: baseline'.
154 /**
155 * returns the max-ascent amongst all the cells that have
156 * 'vertical-align: baseline', *including* cells with rowspans.
157 * returns 0 if we don't have any cell with 'vertical-align: baseline'
159 nscoord GetMaxCellAscent() const;
161 /* return the row ascent
163 nscoord GetRowBaseline();
165 /** returns the ordinal position of this row in its table */
166 virtual PRInt32 GetRowIndex() const;
168 /** set this row's starting row index */
169 void SetRowIndex (int aRowIndex);
171 /** used by row group frame code */
172 nscoord ReflowCellFrame(nsPresContext* aPresContext,
173 const nsHTMLReflowState& aReflowState,
174 PRBool aIsTopOfPage,
175 nsTableCellFrame* aCellFrame,
176 nscoord aAvailableHeight,
177 nsReflowStatus& aStatus);
179 * Collapse the row if required, apply col and colgroup visibility: collapse
180 * info to the cells in the row.
181 * @return he amount to shift up all following rows
182 * @param aRowOffset - shift the row up by this amount
183 * @param aWidth - new width of the row
184 * @param aCollapseGroup - parent rowgroup is collapsed so this row needs
185 * to be collapsed
186 * @param aDidCollapse - the row has been collapsed
188 nscoord CollapseRowIfNecessary(nscoord aRowOffset,
189 nscoord aWidth,
190 PRBool aCollapseGroup,
191 PRBool& aDidCollapse);
193 void InsertCellFrame(nsTableCellFrame* aFrame,
194 nsTableCellFrame* aPrevSibling);
196 void InsertCellFrame(nsTableCellFrame* aFrame,
197 PRInt32 aColIndex);
199 void RemoveCellFrame(nsTableCellFrame* aFrame);
201 nsresult CalculateCellActualSize(nsIFrame* aRowFrame,
202 nscoord& aDesiredWidth,
203 nscoord& aDesiredHeight,
204 nscoord aAvailWidth);
206 PRBool IsFirstInserted() const;
207 void SetFirstInserted(PRBool aValue);
209 PRBool GetContentHeight() const;
210 void SetContentHeight(nscoord aTwipValue);
212 PRBool HasStyleHeight() const;
214 PRBool HasFixedHeight() const;
215 void SetHasFixedHeight(PRBool aValue);
217 PRBool HasPctHeight() const;
218 void SetHasPctHeight(PRBool aValue);
220 nscoord GetFixedHeight() const;
221 void SetFixedHeight(nscoord aValue);
223 float GetPctHeight() const;
224 void SetPctHeight(float aPctValue,
225 PRBool aForce = PR_FALSE);
227 nscoord GetHeight(nscoord aBasis = 0) const;
229 nsTableRowFrame* GetNextRow() const;
231 PRBool HasUnpaginatedHeight();
232 void SetHasUnpaginatedHeight(PRBool aValue);
233 nscoord GetUnpaginatedHeight(nsPresContext* aPresContext);
234 void SetUnpaginatedHeight(nsPresContext* aPresContext, nscoord aValue);
236 nscoord GetTopBCBorderWidth();
237 void SetTopBCBorderWidth(BCPixelSize aWidth);
238 nscoord GetBottomBCBorderWidth();
239 void SetBottomBCBorderWidth(BCPixelSize aWidth);
240 nsMargin* GetBCBorderWidth(nsMargin& aBorder);
243 * Gets inner border widths before collapsing with cell borders
244 * Caller must get bottom border from next row or from table
245 * GetContinuousBCBorderWidth will not overwrite aBorder.bottom
246 * see nsTablePainter about continuous borders
248 void GetContinuousBCBorderWidth(nsMargin& aBorder);
250 * @returns outer top bc border == prev row's bottom inner
252 nscoord GetOuterTopContBCBorderWidth();
254 * Sets full border widths before collapsing with cell borders
255 * @param aForSide - side to set; only accepts right, left, and top
257 void SetContinuousBCBorderWidth(PRUint8 aForSide,
258 BCPixelSize aPixelValue);
260 protected:
262 /** protected constructor.
263 * @see NewFrame
265 nsTableRowFrame(nsStyleContext *aContext);
267 void InitChildReflowState(nsPresContext& aPresContext,
268 const nsSize& aAvailSize,
269 PRBool aBorderCollapse,
270 nsTableCellReflowState& aReflowState);
272 /** implement abstract method on nsHTMLContainerFrame */
273 virtual PRIntn GetSkipSides() const;
275 // row-specific methods
277 nscoord ComputeCellXOffset(const nsHTMLReflowState& aState,
278 nsIFrame* aKidFrame,
279 const nsMargin& aKidMargin) const;
281 * Called for incremental/dirty and resize reflows. If aDirtyOnly is true then
282 * only reflow dirty cells.
284 NS_IMETHOD ReflowChildren(nsPresContext* aPresContext,
285 nsHTMLReflowMetrics& aDesiredSize,
286 const nsHTMLReflowState& aReflowState,
287 nsTableFrame& aTableFrame,
288 nsReflowStatus& aStatus);
290 private:
291 struct RowBits {
292 unsigned mRowIndex:29;
293 unsigned mHasFixedHeight:1; // set if the dominating style height on the row or any cell is pixel based
294 unsigned mHasPctHeight:1; // set if the dominating style height on the row or any cell is pct based
295 unsigned mFirstInserted:1; // if true, then it was the top most newly inserted row
296 } mBits;
298 // the desired height based on the content of the tallest cell in the row
299 nscoord mContentHeight;
300 // the height based on a style percentage height on either the row or any cell
301 // if mHasPctHeight is set
302 nscoord mStylePctHeight;
303 // the height based on a style pixel height on the row or any
304 // cell if mHasFixedHeight is set
305 nscoord mStyleFixedHeight;
307 // max-ascent and max-descent amongst all cells that have 'vertical-align: baseline'
308 nscoord mMaxCellAscent; // does include cells with rowspan > 1
309 nscoord mMaxCellDescent; // does *not* include cells with rowspan > 1
311 // border widths in pixels in the collapsing border model of the *inner*
312 // half of the border only
313 BCPixelSize mTopBorderWidth;
314 BCPixelSize mBottomBorderWidth;
315 BCPixelSize mRightContBorderWidth;
316 BCPixelSize mTopContBorderWidth;
317 BCPixelSize mLeftContBorderWidth;
320 * Sets the NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT bit to indicate whether
321 * this row has any cells that have non-auto-height. (Row-spanning
322 * cells are ignored.)
324 void InitHasCellWithStyleHeight(nsTableFrame* aTableFrame);
328 inline PRInt32 nsTableRowFrame::GetRowIndex() const
330 return PRInt32(mBits.mRowIndex);
333 inline void nsTableRowFrame::SetRowIndex (int aRowIndex)
335 mBits.mRowIndex = aRowIndex;
338 inline PRBool nsTableRowFrame::IsFirstInserted() const
340 return PRBool(mBits.mFirstInserted);
343 inline void nsTableRowFrame::SetFirstInserted(PRBool aValue)
345 mBits.mFirstInserted = aValue;
348 inline PRBool nsTableRowFrame::HasStyleHeight() const
350 return (PRBool)mBits.mHasFixedHeight || (PRBool)mBits.mHasPctHeight;
353 inline PRBool nsTableRowFrame::HasFixedHeight() const
355 return (PRBool)mBits.mHasFixedHeight;
358 inline void nsTableRowFrame::SetHasFixedHeight(PRBool aValue)
360 mBits.mHasFixedHeight = aValue;
363 inline PRBool nsTableRowFrame::HasPctHeight() const
365 return (PRBool)mBits.mHasPctHeight;
368 inline void nsTableRowFrame::SetHasPctHeight(PRBool aValue)
370 mBits.mHasPctHeight = aValue;
373 inline nscoord nsTableRowFrame::GetContentHeight() const
375 return mContentHeight;
378 inline void nsTableRowFrame::SetContentHeight(nscoord aValue)
380 mContentHeight = aValue;
383 inline nscoord nsTableRowFrame::GetFixedHeight() const
385 if (mBits.mHasFixedHeight)
386 return mStyleFixedHeight;
387 else
388 return 0;
391 inline float nsTableRowFrame::GetPctHeight() const
393 if (mBits.mHasPctHeight)
394 return (float)mStylePctHeight / 100.0f;
395 else
396 return 0.0f;
399 inline PRBool nsTableRowFrame::HasUnpaginatedHeight()
401 return (mState & NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT) ==
402 NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT;
405 inline void nsTableRowFrame::SetHasUnpaginatedHeight(PRBool aValue)
407 if (aValue) {
408 mState |= NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT;
409 } else {
410 mState &= ~NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT;
414 inline nscoord nsTableRowFrame::GetTopBCBorderWidth()
416 return mTopBorderWidth;
419 inline void nsTableRowFrame::SetTopBCBorderWidth(BCPixelSize aWidth)
421 mTopBorderWidth = aWidth;
424 inline nscoord nsTableRowFrame::GetBottomBCBorderWidth()
426 return mBottomBorderWidth;
429 inline void nsTableRowFrame::SetBottomBCBorderWidth(BCPixelSize aWidth)
431 mBottomBorderWidth = aWidth;
434 inline nsMargin* nsTableRowFrame::GetBCBorderWidth(nsMargin& aBorder)
436 aBorder.left = aBorder.right = 0;
438 aBorder.top = nsPresContext::CSSPixelsToAppUnits(mTopBorderWidth);
439 aBorder.bottom = nsPresContext::CSSPixelsToAppUnits(mBottomBorderWidth);
441 return &aBorder;
444 inline void
445 nsTableRowFrame::GetContinuousBCBorderWidth(nsMargin& aBorder)
447 PRInt32 aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel();
448 aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips,
449 mLeftContBorderWidth);
450 aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips,
451 mTopContBorderWidth);
452 aBorder.left = BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips,
453 mRightContBorderWidth);
456 inline nscoord nsTableRowFrame::GetOuterTopContBCBorderWidth()
458 PRInt32 aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel();
459 return BC_BORDER_TOP_HALF_COORD(aPixelsToTwips, mTopContBorderWidth);
462 #endif