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 nsTableColFrame_h__
6 #define nsTableColFrame_h__
8 #include "mozilla/Attributes.h"
11 #include "nsContainerFrame.h"
13 #include "nsTableColGroupFrame.h"
14 #include "mozilla/WritingModes.h"
18 } // namespace mozilla
20 class nsTableColFrame final
: public nsSplittableFrame
{
22 NS_DECL_FRAMEARENA_HELPERS(nsTableColFrame
)
25 eWIDTH_SOURCE_NONE
= 0, // no cell has contributed to the width style
26 eWIDTH_SOURCE_CELL
= 1, // a cell specified a width
27 eWIDTH_SOURCE_CELL_WITH_SPAN
= 2 // a cell implicitly specified a width via
31 nsTableColType
GetColType() const;
32 void SetColType(nsTableColType aType
);
35 * instantiate a new instance of nsTableRowFrame.
37 * @param aPresShell the pres shell for this frame
39 * @return the frame that was created
41 friend nsTableColFrame
* NS_NewTableColFrame(mozilla::PresShell
* aPresShell
,
42 ComputedStyle
* aContext
);
45 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
46 nsIFrame
* aPrevInFlow
) override
{
47 nsSplittableFrame::Init(aContent
, aParent
, aPrevInFlow
);
49 mWritingMode
= GetTableFrame()->GetWritingMode();
53 /** @see nsIFrame::DidSetComputedStyle */
54 void DidSetComputedStyle(ComputedStyle
* aOldComputedStyle
) override
;
56 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
57 const ReflowInput
& aReflowInput
,
58 nsReflowStatus
& aStatus
) override
;
60 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
61 const nsDisplayListSet
& aLists
) override
;
63 #ifdef DEBUG_FRAME_DUMP
64 nsresult
GetFrameName(nsAString
& aResult
) const override
;
67 nsTableColGroupFrame
* GetTableColGroupFrame() const {
68 nsIFrame
* parent
= GetParent();
69 MOZ_ASSERT(parent
&& parent
->IsTableColGroupFrame());
70 return static_cast<nsTableColGroupFrame
*>(parent
);
73 nsTableFrame
* GetTableFrame() const {
74 return GetTableColGroupFrame()->GetTableFrame();
77 int32_t GetColIndex() const;
79 void SetColIndex(int32_t aColIndex
);
81 nsTableColFrame
* GetNextCol() const;
83 /** return the number of the columns the col represents. always >= 1 */
86 /** convenience method, calls into cellmap */
87 int32_t Count() const;
89 BCPixelSize
GetIStartBorderWidth() const { return mIStartBorderWidth
; }
90 BCPixelSize
GetIEndBorderWidth() const { return mIEndBorderWidth
; }
91 void SetIStartBorderWidth(BCPixelSize aWidth
) { mIStartBorderWidth
= aWidth
; }
92 void SetIEndBorderWidth(BCPixelSize aWidth
) { mIEndBorderWidth
= aWidth
; }
95 * Gets inner border widths before collapsing with cell borders
96 * Caller must get istart border from previous column or from table
97 * GetContinuousBCBorderWidth will not overwrite aBorder.IStart
98 * see nsTablePainter about continuous borders
100 * @return outer iend border width (istart inner for next column)
102 nscoord
GetContinuousBCBorderWidth(mozilla::WritingMode aWM
,
103 mozilla::LogicalMargin
& aBorder
);
105 * Set full border widths before collapsing with cell borders
106 * @param aForSide - side to set; only valid for bstart, iend, and bend
108 void SetContinuousBCBorderWidth(mozilla::LogicalSide aForSide
,
109 BCPixelSize aPixelValue
);
111 void Dump(int32_t aIndent
);
115 * Restore the default values of the intrinsic widths, so that we can
116 * re-accumulate intrinsic widths from the cells in the column.
118 void ResetIntrinsics() {
122 mHasSpecifiedCoord
= false;
126 * Restore the default value of the preferred percentage width (the
127 * only intrinsic width used by FixedTableLayoutStrategy.
129 void ResetPrefPercent() { mPrefPercent
= 0.0f
; }
132 * Restore the default values of the temporary buffer for
133 * spanning-cell intrinsic widths (as we process spanning cells).
135 void ResetSpanIntrinsics() {
138 mSpanPrefPercent
= 0.0f
;
142 * Add the widths for a cell or column element, or the contribution of
143 * the widths from a column-spanning cell:
144 * @param aMinCoord The minimum intrinsic width
145 * @param aPrefCoord The preferred intrinsic width or, if there is a
146 * specified non-percentage width, max(specified width, minimum intrinsic
148 * @param aHasSpecifiedCoord Whether there is a specified
149 * non-percentage width.
151 * Note that the implementation of this functions is a bit tricky
152 * since mPrefCoord means different things depending on
153 * whether mHasSpecifiedCoord is true (and likewise for aPrefCoord and
154 * aHasSpecifiedCoord). If mHasSpecifiedCoord is false, then
155 * all widths added had aHasSpecifiedCoord false and mPrefCoord is the
156 * largest of the pref widths. But if mHasSpecifiedCoord is true,
157 * then mPrefCoord is the largest of (1) the pref widths for cells
158 * with aHasSpecifiedCoord true and (2) the min widths for cells with
159 * aHasSpecifiedCoord false.
161 void AddCoords(nscoord aMinCoord
, nscoord aPrefCoord
,
162 bool aHasSpecifiedCoord
) {
163 NS_ASSERTION(aMinCoord
<= aPrefCoord
, "intrinsic widths out of order");
165 if (aHasSpecifiedCoord
&& !mHasSpecifiedCoord
) {
166 mPrefCoord
= mMinCoord
;
167 mHasSpecifiedCoord
= true;
169 if (!aHasSpecifiedCoord
&& mHasSpecifiedCoord
) {
170 aPrefCoord
= aMinCoord
; // NOTE: modifying argument
173 if (aMinCoord
> mMinCoord
) mMinCoord
= aMinCoord
;
174 if (aPrefCoord
> mPrefCoord
) mPrefCoord
= aPrefCoord
;
176 NS_ASSERTION(mMinCoord
<= mPrefCoord
, "min larger than pref");
180 * Add a percentage width specified on a cell or column element or the
181 * contribution to this column of a percentage width specified on a
182 * column-spanning cell.
184 void AddPrefPercent(float aPrefPercent
) {
185 if (aPrefPercent
> mPrefPercent
) mPrefPercent
= aPrefPercent
;
189 * Get the largest minimum intrinsic width for this column.
191 nscoord
GetMinCoord() const { return mMinCoord
; }
193 * Get the largest preferred width for this column, or, if there were
194 * any specified non-percentage widths (see GetHasSpecifiedCoord), the
195 * largest minimum intrinsic width or specified width.
197 nscoord
GetPrefCoord() const { return mPrefCoord
; }
199 * Get whether there were any specified widths contributing to this
202 bool GetHasSpecifiedCoord() const { return mHasSpecifiedCoord
; }
205 * Get the largest specified percentage width contributing to this
206 * column (returns 0 if there were none).
208 float GetPrefPercent() const { return mPrefPercent
; }
211 * Like AddCoords, but into a temporary buffer used for groups of
212 * column-spanning cells.
214 void AddSpanCoords(nscoord aSpanMinCoord
, nscoord aSpanPrefCoord
,
215 bool aSpanHasSpecifiedCoord
) {
216 NS_ASSERTION(aSpanMinCoord
<= aSpanPrefCoord
,
217 "intrinsic widths out of order");
219 if (!aSpanHasSpecifiedCoord
&& mHasSpecifiedCoord
) {
220 aSpanPrefCoord
= aSpanMinCoord
; // NOTE: modifying argument
223 if (aSpanMinCoord
> mSpanMinCoord
) mSpanMinCoord
= aSpanMinCoord
;
224 if (aSpanPrefCoord
> mSpanPrefCoord
) mSpanPrefCoord
= aSpanPrefCoord
;
226 NS_ASSERTION(mSpanMinCoord
<= mSpanPrefCoord
, "min larger than pref");
230 * Accumulate percentage widths on column spanning cells into
231 * temporary variables.
233 void AddSpanPrefPercent(float aSpanPrefPercent
) {
234 if (aSpanPrefPercent
> mSpanPrefPercent
)
235 mSpanPrefPercent
= aSpanPrefPercent
;
239 * Accumulate the temporary variables for column spanning cells into
240 * the primary variables.
242 void AccumulateSpanIntrinsics() {
243 AddCoords(mSpanMinCoord
, mSpanPrefCoord
, mHasSpecifiedCoord
);
244 AddPrefPercent(mSpanPrefPercent
);
247 // Used to adjust a column's pref percent so that the table's total
248 // never exceeeds 100% (by only allowing percentages to be used,
249 // starting at the first column, until they reach 100%).
250 void AdjustPrefPercent(float* aTableTotalPercent
) {
251 float allowed
= 1.0f
- *aTableTotalPercent
;
252 if (mPrefPercent
> allowed
) mPrefPercent
= allowed
;
253 *aTableTotalPercent
+= mPrefPercent
;
256 // The final width of the column.
257 void ResetFinalISize() {
258 mFinalISize
= nscoord_MIN
; // so we detect that it changed
260 void SetFinalISize(nscoord aFinalISize
) { mFinalISize
= aFinalISize
; }
261 nscoord
GetFinalISize() { return mFinalISize
; }
263 void InvalidateFrame(uint32_t aDisplayItemKey
= 0,
264 bool aRebuildDisplayItems
= true) override
;
265 void InvalidateFrameWithRect(const nsRect
& aRect
,
266 uint32_t aDisplayItemKey
= 0,
267 bool aRebuildDisplayItems
= true) override
;
268 void InvalidateFrameForRemoval() override
{ InvalidateFrameSubtree(); }
271 explicit nsTableColFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
);
276 nscoord mSpanMinCoord
; // XXX...
277 nscoord mSpanPrefCoord
; // XXX...
279 float mSpanPrefPercent
; // XXX...
280 // ...XXX the four members marked above could be allocated as part of
281 // a separate array allocated only during
282 // BasicTableLayoutStrategy::ComputeColumnIntrinsicISizes (and only
283 // when colspans were present).
286 // the index of the column with respect to the whole table (starting at 0)
287 // it should never be smaller then the start column index of the parent
291 // border width in pixels of the inner half of the border only
292 BCPixelSize mIStartBorderWidth
;
293 BCPixelSize mIEndBorderWidth
;
294 BCPixelSize mBStartContBorderWidth
;
295 BCPixelSize mIEndContBorderWidth
;
296 BCPixelSize mBEndContBorderWidth
;
298 bool mHasSpecifiedCoord
;
301 inline int32_t nsTableColFrame::GetColIndex() const { return mColIndex
; }
303 inline void nsTableColFrame::SetColIndex(int32_t aColIndex
) {
304 mColIndex
= aColIndex
;
307 inline nscoord
nsTableColFrame::GetContinuousBCBorderWidth(
308 mozilla::WritingMode aWM
, mozilla::LogicalMargin
& aBorder
) {
309 int32_t d2a
= PresContext()->AppUnitsPerDevPixel();
310 aBorder
.BStart(aWM
) = BC_BORDER_END_HALF_COORD(d2a
, mBStartContBorderWidth
);
311 aBorder
.IEnd(aWM
) = BC_BORDER_START_HALF_COORD(d2a
, mIEndContBorderWidth
);
312 aBorder
.BEnd(aWM
) = BC_BORDER_START_HALF_COORD(d2a
, mBEndContBorderWidth
);
313 return BC_BORDER_END_HALF_COORD(d2a
, mIEndContBorderWidth
);