Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / tables / nsTableColFrame.h
blobdf6656d86a06cd6d2b085b85e736d4317245330e
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 nsTableColFrame_h__
38 #define nsTableColFrame_h__
40 #include "nscore.h"
41 #include "nsContainerFrame.h"
42 #include "nsTablePainter.h"
44 class nsVoidArray;
45 class nsTableCellFrame;
47 enum nsTableColType {
48 eColContent = 0, // there is real col content associated
49 eColAnonymousCol = 1, // the result of a span on a col
50 eColAnonymousColGroup = 2, // the result of a span on a col group
51 eColAnonymousCell = 3 // the result of a cell alone
54 class nsTableColFrame : public nsSplittableFrame {
55 public:
57 enum {eWIDTH_SOURCE_NONE =0, // no cell has contributed to the width style
58 eWIDTH_SOURCE_CELL =1, // a cell specified a width
59 eWIDTH_SOURCE_CELL_WITH_SPAN=2 // a cell implicitly specified a width via colspan
62 nsTableColType GetColType() const;
63 void SetColType(nsTableColType aType);
65 /** instantiate a new instance of nsTableRowFrame.
66 * @param aPresShell the pres shell for this frame
68 * @return the frame that was created
70 friend nsTableColFrame* NS_NewTableColFrame(nsIPresShell* aPresShell,
71 nsStyleContext* aContext);
72 /** @see nsIFrame::DidSetStyleContext */
73 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
75 PRInt32 GetColIndex() const;
77 void SetColIndex (PRInt32 aColIndex);
79 nsTableColFrame* GetNextCol() const;
81 NS_IMETHOD Reflow(nsPresContext* aPresContext,
82 nsHTMLReflowMetrics& aDesiredSize,
83 const nsHTMLReflowState& aReflowState,
84 nsReflowStatus& aStatus);
86 /**
87 * Table columns never paint anything, nor receive events.
89 NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
90 const nsRect& aDirtyRect,
91 const nsDisplayListSet& aLists) { return NS_OK; }
93 virtual PRBool IsFrameOfType(PRUint32 aFlags) const
95 return nsSplittableFrame::IsFrameOfType(aFlags &
96 ~(nsIFrame::eExcludesIgnorableWhitespace));
99 /**
100 * Get the "type" of the frame
102 * @see nsGkAtoms::tableColFrame
104 virtual nsIAtom* GetType() const;
106 #ifdef DEBUG
107 NS_IMETHOD GetFrameName(nsAString& aResult) const;
108 #endif
110 virtual nsSplittableType GetSplittableType() const;
112 /** return the number of the columns the col represents. always >= 1 */
113 PRInt32 GetSpan();
115 /** convenience method, calls into cellmap */
116 nsVoidArray * GetCells();
118 /** convenience method, calls into cellmap */
119 PRInt32 Count() const;
121 nscoord GetLeftBorderWidth();
122 void SetLeftBorderWidth(BCPixelSize aWidth);
123 nscoord GetRightBorderWidth();
124 void SetRightBorderWidth(BCPixelSize aWidth);
127 * Gets inner border widths before collapsing with cell borders
128 * Caller must get left border from previous column or from table
129 * GetContinuousBCBorderWidth will not overwrite aBorder.left
130 * see nsTablePainter about continuous borders
132 * @return outer right border width (left inner for next column)
134 nscoord GetContinuousBCBorderWidth(nsMargin& aBorder);
136 * Set full border widths before collapsing with cell borders
137 * @param aForSide - side to set; only valid for top, right, and bottom
139 void SetContinuousBCBorderWidth(PRUint8 aForSide,
140 BCPixelSize aPixelValue);
141 #ifdef DEBUG
142 void Dump(PRInt32 aIndent);
143 #endif
146 * Restore the default values of the intrinsic widths, so that we can
147 * re-accumulate intrinsic widths from the cells in the column.
149 void ResetIntrinsics() {
150 mMinCoord = 0;
151 mPrefCoord = 0;
152 mPrefPercent = 0.0f;
153 mHasSpecifiedCoord = PR_FALSE;
157 * Restore the default value of the preferred percentage width (the
158 * only intrinsic width used by FixedTableLayoutStrategy.
160 void ResetPrefPercent() {
161 mPrefPercent = 0.0f;
165 * Restore the default values of the temporary buffer for
166 * spanning-cell intrinsic widths (as we process spanning cells).
168 void ResetSpanIntrinsics() {
169 mSpanMinCoord = 0;
170 mSpanPrefCoord = 0;
171 mSpanPrefPercent = 0.0f;
175 * Add the widths for a cell or column element, or the contribution of
176 * the widths from a column-spanning cell:
177 * @param aMinCoord The minimum intrinsic width
178 * @param aPrefCoord The preferred intrinsic width or, if there is a
179 * specified non-percentage width, max(specified width, minimum intrinsic
180 * width).
181 * @param aHasSpecifiedCoord Whether there is a specified
182 * non-percentage width.
184 * Note that the implementation of this functions is a bit tricky
185 * since mPrefCoord means different things depending on
186 * whether mHasSpecifiedCoord is true (and likewise for aPrefCoord and
187 * aHasSpecifiedCoord). If mHasSpecifiedCoord is false, then
188 * all widths added had aHasSpecifiedCoord false and mPrefCoord is the
189 * largest of the pref widths. But if mHasSpecifiedCoord is true,
190 * then mPrefCoord is the largest of (1) the pref widths for cells
191 * with aHasSpecifiedCoord true and (2) the min widths for cells with
192 * aHasSpecifiedCoord false.
194 void AddCoords(nscoord aMinCoord, nscoord aPrefCoord,
195 PRBool aHasSpecifiedCoord) {
196 NS_ASSERTION(aMinCoord <= aPrefCoord, "intrinsic widths out of order");
198 if (aHasSpecifiedCoord && !mHasSpecifiedCoord) {
199 mPrefCoord = mMinCoord;
200 mHasSpecifiedCoord = PR_TRUE;
202 if (!aHasSpecifiedCoord && mHasSpecifiedCoord) {
203 aPrefCoord = aMinCoord; // NOTE: modifying argument
206 if (aMinCoord > mMinCoord)
207 mMinCoord = aMinCoord;
208 if (aPrefCoord > mPrefCoord)
209 mPrefCoord = aPrefCoord;
211 NS_ASSERTION(mMinCoord <= mPrefCoord, "min larger than pref");
215 * Add a percentage width specified on a cell or column element or the
216 * contribution to this column of a percentage width specified on a
217 * column-spanning cell.
219 void AddPrefPercent(float aPrefPercent) {
220 if (aPrefPercent > mPrefPercent)
221 mPrefPercent = aPrefPercent;
225 * Get the largest minimum intrinsic width for this column.
227 nscoord GetMinCoord() const { return mMinCoord; }
229 * Get the largest preferred width for this column, or, if there were
230 * any specified non-percentage widths (see GetHasSpecifiedCoord), the
231 * largest minimum intrinsic width or specified width.
233 nscoord GetPrefCoord() const { return mPrefCoord; }
235 * Get whether there were any specified widths contributing to this
236 * column.
238 PRBool GetHasSpecifiedCoord() const { return mHasSpecifiedCoord; }
241 * Get the largest specified percentage width contributing to this
242 * column (returns 0 if there were none).
244 float GetPrefPercent() const { return mPrefPercent; }
247 * Like AddCoords, but into a temporary buffer used for groups of
248 * column-spanning cells.
250 void AddSpanCoords(nscoord aSpanMinCoord, nscoord aSpanPrefCoord,
251 PRBool aSpanHasSpecifiedCoord) {
252 NS_ASSERTION(aSpanMinCoord <= aSpanPrefCoord,
253 "intrinsic widths out of order");
255 if (!aSpanHasSpecifiedCoord && mHasSpecifiedCoord) {
256 aSpanPrefCoord = aSpanMinCoord; // NOTE: modifying argument
259 if (aSpanMinCoord > mSpanMinCoord)
260 mSpanMinCoord = aSpanMinCoord;
261 if (aSpanPrefCoord > mSpanPrefCoord)
262 mSpanPrefCoord = aSpanPrefCoord;
264 NS_ASSERTION(mSpanMinCoord <= mSpanPrefCoord, "min larger than pref");
268 * Accumulate percentage widths on column spanning cells into
269 * temporary variables.
271 void AddSpanPrefPercent(float aSpanPrefPercent) {
272 if (aSpanPrefPercent > mSpanPrefPercent)
273 mSpanPrefPercent = aSpanPrefPercent;
277 * Accumulate the temporary variables for column spanning cells into
278 * the primary variables.
280 void AccumulateSpanIntrinsics() {
281 AddCoords(mSpanMinCoord, mSpanPrefCoord, mHasSpecifiedCoord);
282 AddPrefPercent(mSpanPrefPercent);
285 // Used to adjust a column's pref percent so that the table's total
286 // never exceeeds 100% (by only allowing percentages to be used,
287 // starting at the first column, until they reach 100%).
288 void AdjustPrefPercent(float *aTableTotalPercent) {
289 float allowed = 1.0f - *aTableTotalPercent;
290 if (mPrefPercent > allowed)
291 mPrefPercent = allowed;
292 *aTableTotalPercent += mPrefPercent;
295 // The final width of the column.
296 void ResetFinalWidth() {
297 mFinalWidth = nscoord_MIN; // so we detect that it changed
299 void SetFinalWidth(nscoord aFinalWidth) {
300 mFinalWidth = aFinalWidth;
302 nscoord GetFinalWidth() {
303 return mFinalWidth;
306 protected:
308 nsTableColFrame(nsStyleContext* aContext);
309 ~nsTableColFrame();
311 // the index of the column with respect to the whole tabble (starting at 0)
312 // it should never be smaller then the start column index of the parent
313 // colgroup
314 PRUint32 mColIndex: 16;
316 // border width in pixels of the inner half of the border only
317 BCPixelSize mLeftBorderWidth;
318 BCPixelSize mRightBorderWidth;
319 BCPixelSize mTopContBorderWidth;
320 BCPixelSize mRightContBorderWidth;
321 BCPixelSize mBottomContBorderWidth;
323 PRPackedBool mHasSpecifiedCoord;
324 nscoord mMinCoord;
325 nscoord mPrefCoord;
326 nscoord mSpanMinCoord; // XXX...
327 nscoord mSpanPrefCoord; // XXX...
328 float mPrefPercent;
329 float mSpanPrefPercent; // XXX...
330 // ...XXX the four members marked above could be allocated as part of
331 // a separate array allocated only during
332 // BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths (and only
333 // when colspans were present).
334 nscoord mFinalWidth;
337 inline PRInt32 nsTableColFrame::GetColIndex() const
339 return mColIndex;
342 inline void nsTableColFrame::SetColIndex (PRInt32 aColIndex)
344 mColIndex = aColIndex;
347 inline nscoord nsTableColFrame::GetLeftBorderWidth()
349 return mLeftBorderWidth;
352 inline void nsTableColFrame::SetLeftBorderWidth(BCPixelSize aWidth)
354 mLeftBorderWidth = aWidth;
357 inline nscoord nsTableColFrame::GetRightBorderWidth()
359 return mRightBorderWidth;
362 inline void nsTableColFrame::SetRightBorderWidth(BCPixelSize aWidth)
364 mRightBorderWidth = aWidth;
367 inline nscoord
368 nsTableColFrame::GetContinuousBCBorderWidth(nsMargin& aBorder)
370 PRInt32 aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel();
371 aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips,
372 mTopContBorderWidth);
373 aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips,
374 mRightContBorderWidth);
375 aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips,
376 mBottomContBorderWidth);
377 return BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, mRightContBorderWidth);
380 #endif