Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / layout / tables / nsTableColFrame.h
blob02d63e66b49b0b08d97cc7c74842c736f1223214
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"
43 #include "nsTArray.h"
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:
56 NS_DECL_FRAMEARENA_HELPERS
58 enum {eWIDTH_SOURCE_NONE =0, // no cell has contributed to the width style
59 eWIDTH_SOURCE_CELL =1, // a cell specified a width
60 eWIDTH_SOURCE_CELL_WITH_SPAN=2 // a cell implicitly specified a width via colspan
63 nsTableColType GetColType() const;
64 void SetColType(nsTableColType aType);
66 /** instantiate a new instance of nsTableRowFrame.
67 * @param aPresShell the pres shell for this frame
69 * @return the frame that was created
71 friend nsTableColFrame* NS_NewTableColFrame(nsIPresShell* aPresShell,
72 nsStyleContext* aContext);
73 /** @see nsIFrame::DidSetStyleContext */
74 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
76 PRInt32 GetColIndex() const;
78 void SetColIndex (PRInt32 aColIndex);
80 nsTableColFrame* GetNextCol() const;
82 NS_IMETHOD Reflow(nsPresContext* aPresContext,
83 nsHTMLReflowMetrics& aDesiredSize,
84 const nsHTMLReflowState& aReflowState,
85 nsReflowStatus& aStatus);
87 /**
88 * Table columns never paint anything, nor receive events.
90 NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
91 const nsRect& aDirtyRect,
92 const nsDisplayListSet& aLists) { return NS_OK; }
94 /**
95 * Get the "type" of the frame
97 * @see nsGkAtoms::tableColFrame
99 virtual nsIAtom* GetType() const;
101 #ifdef DEBUG
102 NS_IMETHOD GetFrameName(nsAString& aResult) const;
103 #endif
105 virtual nsSplittableType GetSplittableType() const;
107 /** return the number of the columns the col represents. always >= 1 */
108 PRInt32 GetSpan();
110 /** convenience method, calls into cellmap */
111 PRInt32 Count() const;
113 nscoord GetLeftBorderWidth();
114 void SetLeftBorderWidth(BCPixelSize aWidth);
115 nscoord GetRightBorderWidth();
116 void SetRightBorderWidth(BCPixelSize aWidth);
119 * Gets inner border widths before collapsing with cell borders
120 * Caller must get left border from previous column or from table
121 * GetContinuousBCBorderWidth will not overwrite aBorder.left
122 * see nsTablePainter about continuous borders
124 * @return outer right border width (left inner for next column)
126 nscoord GetContinuousBCBorderWidth(nsMargin& aBorder);
128 * Set full border widths before collapsing with cell borders
129 * @param aForSide - side to set; only valid for top, right, and bottom
131 void SetContinuousBCBorderWidth(PRUint8 aForSide,
132 BCPixelSize aPixelValue);
133 #ifdef DEBUG
134 void Dump(PRInt32 aIndent);
135 #endif
138 * Restore the default values of the intrinsic widths, so that we can
139 * re-accumulate intrinsic widths from the cells in the column.
141 void ResetIntrinsics() {
142 mMinCoord = 0;
143 mPrefCoord = 0;
144 mPrefPercent = 0.0f;
145 mHasSpecifiedCoord = PR_FALSE;
149 * Restore the default value of the preferred percentage width (the
150 * only intrinsic width used by FixedTableLayoutStrategy.
152 void ResetPrefPercent() {
153 mPrefPercent = 0.0f;
157 * Restore the default values of the temporary buffer for
158 * spanning-cell intrinsic widths (as we process spanning cells).
160 void ResetSpanIntrinsics() {
161 mSpanMinCoord = 0;
162 mSpanPrefCoord = 0;
163 mSpanPrefPercent = 0.0f;
167 * Add the widths for a cell or column element, or the contribution of
168 * the widths from a column-spanning cell:
169 * @param aMinCoord The minimum intrinsic width
170 * @param aPrefCoord The preferred intrinsic width or, if there is a
171 * specified non-percentage width, max(specified width, minimum intrinsic
172 * width).
173 * @param aHasSpecifiedCoord Whether there is a specified
174 * non-percentage width.
176 * Note that the implementation of this functions is a bit tricky
177 * since mPrefCoord means different things depending on
178 * whether mHasSpecifiedCoord is true (and likewise for aPrefCoord and
179 * aHasSpecifiedCoord). If mHasSpecifiedCoord is false, then
180 * all widths added had aHasSpecifiedCoord false and mPrefCoord is the
181 * largest of the pref widths. But if mHasSpecifiedCoord is true,
182 * then mPrefCoord is the largest of (1) the pref widths for cells
183 * with aHasSpecifiedCoord true and (2) the min widths for cells with
184 * aHasSpecifiedCoord false.
186 void AddCoords(nscoord aMinCoord, nscoord aPrefCoord,
187 PRBool aHasSpecifiedCoord) {
188 NS_ASSERTION(aMinCoord <= aPrefCoord, "intrinsic widths out of order");
190 if (aHasSpecifiedCoord && !mHasSpecifiedCoord) {
191 mPrefCoord = mMinCoord;
192 mHasSpecifiedCoord = PR_TRUE;
194 if (!aHasSpecifiedCoord && mHasSpecifiedCoord) {
195 aPrefCoord = aMinCoord; // NOTE: modifying argument
198 if (aMinCoord > mMinCoord)
199 mMinCoord = aMinCoord;
200 if (aPrefCoord > mPrefCoord)
201 mPrefCoord = aPrefCoord;
203 NS_ASSERTION(mMinCoord <= mPrefCoord, "min larger than pref");
207 * Add a percentage width specified on a cell or column element or the
208 * contribution to this column of a percentage width specified on a
209 * column-spanning cell.
211 void AddPrefPercent(float aPrefPercent) {
212 if (aPrefPercent > mPrefPercent)
213 mPrefPercent = aPrefPercent;
217 * Get the largest minimum intrinsic width for this column.
219 nscoord GetMinCoord() const { return mMinCoord; }
221 * Get the largest preferred width for this column, or, if there were
222 * any specified non-percentage widths (see GetHasSpecifiedCoord), the
223 * largest minimum intrinsic width or specified width.
225 nscoord GetPrefCoord() const { return mPrefCoord; }
227 * Get whether there were any specified widths contributing to this
228 * column.
230 PRBool GetHasSpecifiedCoord() const { return mHasSpecifiedCoord; }
233 * Get the largest specified percentage width contributing to this
234 * column (returns 0 if there were none).
236 float GetPrefPercent() const { return mPrefPercent; }
239 * Like AddCoords, but into a temporary buffer used for groups of
240 * column-spanning cells.
242 void AddSpanCoords(nscoord aSpanMinCoord, nscoord aSpanPrefCoord,
243 PRBool aSpanHasSpecifiedCoord) {
244 NS_ASSERTION(aSpanMinCoord <= aSpanPrefCoord,
245 "intrinsic widths out of order");
247 if (!aSpanHasSpecifiedCoord && mHasSpecifiedCoord) {
248 aSpanPrefCoord = aSpanMinCoord; // NOTE: modifying argument
251 if (aSpanMinCoord > mSpanMinCoord)
252 mSpanMinCoord = aSpanMinCoord;
253 if (aSpanPrefCoord > mSpanPrefCoord)
254 mSpanPrefCoord = aSpanPrefCoord;
256 NS_ASSERTION(mSpanMinCoord <= mSpanPrefCoord, "min larger than pref");
260 * Accumulate percentage widths on column spanning cells into
261 * temporary variables.
263 void AddSpanPrefPercent(float aSpanPrefPercent) {
264 if (aSpanPrefPercent > mSpanPrefPercent)
265 mSpanPrefPercent = aSpanPrefPercent;
269 * Accumulate the temporary variables for column spanning cells into
270 * the primary variables.
272 void AccumulateSpanIntrinsics() {
273 AddCoords(mSpanMinCoord, mSpanPrefCoord, mHasSpecifiedCoord);
274 AddPrefPercent(mSpanPrefPercent);
277 // Used to adjust a column's pref percent so that the table's total
278 // never exceeeds 100% (by only allowing percentages to be used,
279 // starting at the first column, until they reach 100%).
280 void AdjustPrefPercent(float *aTableTotalPercent) {
281 float allowed = 1.0f - *aTableTotalPercent;
282 if (mPrefPercent > allowed)
283 mPrefPercent = allowed;
284 *aTableTotalPercent += mPrefPercent;
287 // The final width of the column.
288 void ResetFinalWidth() {
289 mFinalWidth = nscoord_MIN; // so we detect that it changed
291 void SetFinalWidth(nscoord aFinalWidth) {
292 mFinalWidth = aFinalWidth;
294 nscoord GetFinalWidth() {
295 return mFinalWidth;
298 protected:
300 nsTableColFrame(nsStyleContext* aContext);
301 ~nsTableColFrame();
303 nscoord mMinCoord;
304 nscoord mPrefCoord;
305 nscoord mSpanMinCoord; // XXX...
306 nscoord mSpanPrefCoord; // XXX...
307 float mPrefPercent;
308 float mSpanPrefPercent; // XXX...
309 // ...XXX the four members marked above could be allocated as part of
310 // a separate array allocated only during
311 // BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths (and only
312 // when colspans were present).
313 nscoord mFinalWidth;
315 // the index of the column with respect to the whole tabble (starting at 0)
316 // it should never be smaller then the start column index of the parent
317 // colgroup
318 PRUint32 mColIndex: 16;
320 // border width in pixels of the inner half of the border only
321 BCPixelSize mLeftBorderWidth;
322 BCPixelSize mRightBorderWidth;
323 BCPixelSize mTopContBorderWidth;
324 BCPixelSize mRightContBorderWidth;
325 BCPixelSize mBottomContBorderWidth;
327 PRPackedBool mHasSpecifiedCoord;
330 inline PRInt32 nsTableColFrame::GetColIndex() const
332 return mColIndex;
335 inline void nsTableColFrame::SetColIndex (PRInt32 aColIndex)
337 mColIndex = aColIndex;
340 inline nscoord nsTableColFrame::GetLeftBorderWidth()
342 return mLeftBorderWidth;
345 inline void nsTableColFrame::SetLeftBorderWidth(BCPixelSize aWidth)
347 mLeftBorderWidth = aWidth;
350 inline nscoord nsTableColFrame::GetRightBorderWidth()
352 return mRightBorderWidth;
355 inline void nsTableColFrame::SetRightBorderWidth(BCPixelSize aWidth)
357 mRightBorderWidth = aWidth;
360 inline nscoord
361 nsTableColFrame::GetContinuousBCBorderWidth(nsMargin& aBorder)
363 PRInt32 aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel();
364 aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips,
365 mTopContBorderWidth);
366 aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips,
367 mRightContBorderWidth);
368 aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips,
369 mBottomContBorderWidth);
370 return BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, mRightContBorderWidth);
373 #endif