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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : *
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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 : #ifndef nsTableColFrame_h__
38 : #define nsTableColFrame_h__
39 :
40 : #include "nscore.h"
41 : #include "nsContainerFrame.h"
42 : #include "nsTablePainter.h"
43 : #include "nsTArray.h"
44 :
45 : class nsTableCellFrame;
46 :
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
52 : };
53 :
54 : class nsTableColFrame : public nsSplittableFrame {
55 : public:
56 : NS_DECL_FRAMEARENA_HELPERS
57 :
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
61 : };
62 :
63 : nsTableColType GetColType() const;
64 : void SetColType(nsTableColType aType);
65 :
66 : /** instantiate a new instance of nsTableRowFrame.
67 : * @param aPresShell the pres shell for this frame
68 : *
69 : * @return the frame that was created
70 : */
71 : friend nsTableColFrame* NS_NewTableColFrame(nsIPresShell* aPresShell,
72 : nsStyleContext* aContext);
73 : /** @see nsIFrame::DidSetStyleContext */
74 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
75 :
76 : PRInt32 GetColIndex() const;
77 :
78 : void SetColIndex (PRInt32 aColIndex);
79 :
80 : nsTableColFrame* GetNextCol() const;
81 :
82 : NS_IMETHOD Reflow(nsPresContext* aPresContext,
83 : nsHTMLReflowMetrics& aDesiredSize,
84 : const nsHTMLReflowState& aReflowState,
85 : nsReflowStatus& aStatus);
86 :
87 : /**
88 : * Table columns never paint anything, nor receive events.
89 : */
90 0 : NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
91 : const nsRect& aDirtyRect,
92 0 : const nsDisplayListSet& aLists) { return NS_OK; }
93 :
94 : /**
95 : * Get the "type" of the frame
96 : *
97 : * @see nsGkAtoms::tableColFrame
98 : */
99 : virtual nsIAtom* GetType() const;
100 :
101 : #ifdef DEBUG
102 : NS_IMETHOD GetFrameName(nsAString& aResult) const;
103 : #endif
104 :
105 : virtual nsSplittableType GetSplittableType() const;
106 :
107 : /** return the number of the columns the col represents. always >= 1 */
108 : PRInt32 GetSpan();
109 :
110 : /** convenience method, calls into cellmap */
111 : PRInt32 Count() const;
112 :
113 : nscoord GetLeftBorderWidth();
114 : void SetLeftBorderWidth(BCPixelSize aWidth);
115 : nscoord GetRightBorderWidth();
116 : void SetRightBorderWidth(BCPixelSize aWidth);
117 :
118 : /**
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
123 : *
124 : * @return outer right border width (left inner for next column)
125 : */
126 : nscoord GetContinuousBCBorderWidth(nsMargin& aBorder);
127 : /**
128 : * Set full border widths before collapsing with cell borders
129 : * @param aForSide - side to set; only valid for top, right, and bottom
130 : */
131 : void SetContinuousBCBorderWidth(PRUint8 aForSide,
132 : BCPixelSize aPixelValue);
133 : #ifdef DEBUG
134 : void Dump(PRInt32 aIndent);
135 : #endif
136 :
137 : /**
138 : * Restore the default values of the intrinsic widths, so that we can
139 : * re-accumulate intrinsic widths from the cells in the column.
140 : */
141 0 : void ResetIntrinsics() {
142 0 : mMinCoord = 0;
143 0 : mPrefCoord = 0;
144 0 : mPrefPercent = 0.0f;
145 0 : mHasSpecifiedCoord = false;
146 0 : }
147 :
148 : /**
149 : * Restore the default value of the preferred percentage width (the
150 : * only intrinsic width used by FixedTableLayoutStrategy.
151 : */
152 0 : void ResetPrefPercent() {
153 0 : mPrefPercent = 0.0f;
154 0 : }
155 :
156 : /**
157 : * Restore the default values of the temporary buffer for
158 : * spanning-cell intrinsic widths (as we process spanning cells).
159 : */
160 0 : void ResetSpanIntrinsics() {
161 0 : mSpanMinCoord = 0;
162 0 : mSpanPrefCoord = 0;
163 0 : mSpanPrefPercent = 0.0f;
164 0 : }
165 :
166 : /**
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.
175 : *
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.
185 : */
186 0 : void AddCoords(nscoord aMinCoord, nscoord aPrefCoord,
187 : bool aHasSpecifiedCoord) {
188 0 : NS_ASSERTION(aMinCoord <= aPrefCoord, "intrinsic widths out of order");
189 :
190 0 : if (aHasSpecifiedCoord && !mHasSpecifiedCoord) {
191 0 : mPrefCoord = mMinCoord;
192 0 : mHasSpecifiedCoord = true;
193 : }
194 0 : if (!aHasSpecifiedCoord && mHasSpecifiedCoord) {
195 0 : aPrefCoord = aMinCoord; // NOTE: modifying argument
196 : }
197 :
198 0 : if (aMinCoord > mMinCoord)
199 0 : mMinCoord = aMinCoord;
200 0 : if (aPrefCoord > mPrefCoord)
201 0 : mPrefCoord = aPrefCoord;
202 :
203 0 : NS_ASSERTION(mMinCoord <= mPrefCoord, "min larger than pref");
204 0 : }
205 :
206 : /**
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.
210 : */
211 0 : void AddPrefPercent(float aPrefPercent) {
212 0 : if (aPrefPercent > mPrefPercent)
213 0 : mPrefPercent = aPrefPercent;
214 0 : }
215 :
216 : /**
217 : * Get the largest minimum intrinsic width for this column.
218 : */
219 0 : nscoord GetMinCoord() const { return mMinCoord; }
220 : /**
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.
224 : */
225 0 : nscoord GetPrefCoord() const { return mPrefCoord; }
226 : /**
227 : * Get whether there were any specified widths contributing to this
228 : * column.
229 : */
230 0 : bool GetHasSpecifiedCoord() const { return mHasSpecifiedCoord; }
231 :
232 : /**
233 : * Get the largest specified percentage width contributing to this
234 : * column (returns 0 if there were none).
235 : */
236 0 : float GetPrefPercent() const { return mPrefPercent; }
237 :
238 : /**
239 : * Like AddCoords, but into a temporary buffer used for groups of
240 : * column-spanning cells.
241 : */
242 0 : void AddSpanCoords(nscoord aSpanMinCoord, nscoord aSpanPrefCoord,
243 : bool aSpanHasSpecifiedCoord) {
244 0 : NS_ASSERTION(aSpanMinCoord <= aSpanPrefCoord,
245 : "intrinsic widths out of order");
246 :
247 0 : if (!aSpanHasSpecifiedCoord && mHasSpecifiedCoord) {
248 0 : aSpanPrefCoord = aSpanMinCoord; // NOTE: modifying argument
249 : }
250 :
251 0 : if (aSpanMinCoord > mSpanMinCoord)
252 0 : mSpanMinCoord = aSpanMinCoord;
253 0 : if (aSpanPrefCoord > mSpanPrefCoord)
254 0 : mSpanPrefCoord = aSpanPrefCoord;
255 :
256 0 : NS_ASSERTION(mSpanMinCoord <= mSpanPrefCoord, "min larger than pref");
257 0 : }
258 :
259 : /*
260 : * Accumulate percentage widths on column spanning cells into
261 : * temporary variables.
262 : */
263 0 : void AddSpanPrefPercent(float aSpanPrefPercent) {
264 0 : if (aSpanPrefPercent > mSpanPrefPercent)
265 0 : mSpanPrefPercent = aSpanPrefPercent;
266 0 : }
267 :
268 : /*
269 : * Accumulate the temporary variables for column spanning cells into
270 : * the primary variables.
271 : */
272 0 : void AccumulateSpanIntrinsics() {
273 0 : AddCoords(mSpanMinCoord, mSpanPrefCoord, mHasSpecifiedCoord);
274 0 : AddPrefPercent(mSpanPrefPercent);
275 0 : }
276 :
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 0 : void AdjustPrefPercent(float *aTableTotalPercent) {
281 0 : float allowed = 1.0f - *aTableTotalPercent;
282 0 : if (mPrefPercent > allowed)
283 0 : mPrefPercent = allowed;
284 0 : *aTableTotalPercent += mPrefPercent;
285 0 : }
286 :
287 : // The final width of the column.
288 0 : void ResetFinalWidth() {
289 0 : mFinalWidth = nscoord_MIN; // so we detect that it changed
290 0 : }
291 0 : void SetFinalWidth(nscoord aFinalWidth) {
292 0 : mFinalWidth = aFinalWidth;
293 0 : }
294 0 : nscoord GetFinalWidth() {
295 0 : return mFinalWidth;
296 : }
297 :
298 : protected:
299 :
300 : nsTableColFrame(nsStyleContext* aContext);
301 : ~nsTableColFrame();
302 :
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;
314 :
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;
319 :
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;
326 :
327 : bool mHasSpecifiedCoord;
328 : };
329 :
330 0 : inline PRInt32 nsTableColFrame::GetColIndex() const
331 : {
332 0 : return mColIndex;
333 : }
334 :
335 0 : inline void nsTableColFrame::SetColIndex (PRInt32 aColIndex)
336 : {
337 0 : mColIndex = aColIndex;
338 0 : }
339 :
340 0 : inline nscoord nsTableColFrame::GetLeftBorderWidth()
341 : {
342 0 : return mLeftBorderWidth;
343 : }
344 :
345 0 : inline void nsTableColFrame::SetLeftBorderWidth(BCPixelSize aWidth)
346 : {
347 0 : mLeftBorderWidth = aWidth;
348 0 : }
349 :
350 0 : inline nscoord nsTableColFrame::GetRightBorderWidth()
351 : {
352 0 : return mRightBorderWidth;
353 : }
354 :
355 0 : inline void nsTableColFrame::SetRightBorderWidth(BCPixelSize aWidth)
356 : {
357 0 : mRightBorderWidth = aWidth;
358 0 : }
359 :
360 : inline nscoord
361 0 : nsTableColFrame::GetContinuousBCBorderWidth(nsMargin& aBorder)
362 : {
363 0 : PRInt32 aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel();
364 : aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips,
365 0 : mTopContBorderWidth);
366 : aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips,
367 0 : mRightContBorderWidth);
368 : aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips,
369 0 : mBottomContBorderWidth);
370 0 : return BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, mRightContBorderWidth);
371 : }
372 :
373 : #endif
374 :
|