Bug 1885580 - Add a MenuGroup component for the menu redesign r=android-reviewers,007
[gecko.git] / layout / tables / nsTableColFrame.h
blob638347aeeb1220ad8bb8f92b0cb4d0d072d69c47
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"
9 #include "celldata.h"
10 #include "nscore.h"
11 #include "nsContainerFrame.h"
12 #include "nsTArray.h"
13 #include "nsTableColGroupFrame.h"
14 #include "mozilla/WritingModes.h"
16 namespace mozilla {
17 class PresShell;
18 } // namespace mozilla
20 class nsTableColFrame final : public nsSplittableFrame {
21 public:
22 NS_DECL_FRAMEARENA_HELPERS(nsTableColFrame)
24 enum {
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
28 // colspan
31 nsTableColType GetColType() const;
32 void SetColType(nsTableColType aType);
34 /**
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);
44 // nsIFrame overrides
45 void Init(nsIContent* aContent, nsContainerFrame* aParent,
46 nsIFrame* aPrevInFlow) override {
47 nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
48 if (!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;
65 #endif
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 */
84 int32_t GetSpan();
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; }
94 #ifdef DEBUG
95 void Dump(int32_t aIndent);
96 #endif
98 /**
99 * Restore the default values of the intrinsic widths, so that we can
100 * re-accumulate intrinsic widths from the cells in the column.
102 void ResetIntrinsics() {
103 mMinCoord = 0;
104 mPrefCoord = 0;
105 mPrefPercent = 0.0f;
106 mHasSpecifiedCoord = false;
110 * Restore the default value of the preferred percentage width (the
111 * only intrinsic width used by FixedTableLayoutStrategy.
113 void ResetPrefPercent() { mPrefPercent = 0.0f; }
116 * Restore the default values of the temporary buffer for
117 * spanning-cell intrinsic widths (as we process spanning cells).
119 void ResetSpanIntrinsics() {
120 mSpanMinCoord = 0;
121 mSpanPrefCoord = 0;
122 mSpanPrefPercent = 0.0f;
126 * Add the widths for a cell or column element, or the contribution of
127 * the widths from a column-spanning cell:
128 * @param aMinCoord The minimum intrinsic width
129 * @param aPrefCoord The preferred intrinsic width or, if there is a
130 * specified non-percentage width, max(specified width, minimum intrinsic
131 * width).
132 * @param aHasSpecifiedCoord Whether there is a specified
133 * non-percentage width.
135 * Note that the implementation of this functions is a bit tricky
136 * since mPrefCoord means different things depending on
137 * whether mHasSpecifiedCoord is true (and likewise for aPrefCoord and
138 * aHasSpecifiedCoord). If mHasSpecifiedCoord is false, then
139 * all widths added had aHasSpecifiedCoord false and mPrefCoord is the
140 * largest of the pref widths. But if mHasSpecifiedCoord is true,
141 * then mPrefCoord is the largest of (1) the pref widths for cells
142 * with aHasSpecifiedCoord true and (2) the min widths for cells with
143 * aHasSpecifiedCoord false.
145 void AddCoords(nscoord aMinCoord, nscoord aPrefCoord,
146 bool aHasSpecifiedCoord) {
147 NS_ASSERTION(aMinCoord <= aPrefCoord, "intrinsic widths out of order");
149 if (aHasSpecifiedCoord && !mHasSpecifiedCoord) {
150 mPrefCoord = mMinCoord;
151 mHasSpecifiedCoord = true;
153 if (!aHasSpecifiedCoord && mHasSpecifiedCoord) {
154 aPrefCoord = aMinCoord; // NOTE: modifying argument
157 if (aMinCoord > mMinCoord) mMinCoord = aMinCoord;
158 if (aPrefCoord > mPrefCoord) mPrefCoord = aPrefCoord;
160 NS_ASSERTION(mMinCoord <= mPrefCoord, "min larger than pref");
164 * Add a percentage width specified on a cell or column element or the
165 * contribution to this column of a percentage width specified on a
166 * column-spanning cell.
168 void AddPrefPercent(float aPrefPercent) {
169 if (aPrefPercent > mPrefPercent) mPrefPercent = aPrefPercent;
173 * Get the largest minimum intrinsic width for this column.
175 nscoord GetMinCoord() const { return mMinCoord; }
177 * Get the largest preferred width for this column, or, if there were
178 * any specified non-percentage widths (see GetHasSpecifiedCoord), the
179 * largest minimum intrinsic width or specified width.
181 nscoord GetPrefCoord() const { return mPrefCoord; }
183 * Get whether there were any specified widths contributing to this
184 * column.
186 bool GetHasSpecifiedCoord() const { return mHasSpecifiedCoord; }
189 * Get the largest specified percentage width contributing to this
190 * column (returns 0 if there were none).
192 float GetPrefPercent() const { return mPrefPercent; }
195 * Like AddCoords, but into a temporary buffer used for groups of
196 * column-spanning cells.
198 void AddSpanCoords(nscoord aSpanMinCoord, nscoord aSpanPrefCoord,
199 bool aSpanHasSpecifiedCoord) {
200 NS_ASSERTION(aSpanMinCoord <= aSpanPrefCoord,
201 "intrinsic widths out of order");
203 if (!aSpanHasSpecifiedCoord && mHasSpecifiedCoord) {
204 aSpanPrefCoord = aSpanMinCoord; // NOTE: modifying argument
207 if (aSpanMinCoord > mSpanMinCoord) mSpanMinCoord = aSpanMinCoord;
208 if (aSpanPrefCoord > mSpanPrefCoord) mSpanPrefCoord = aSpanPrefCoord;
210 NS_ASSERTION(mSpanMinCoord <= mSpanPrefCoord, "min larger than pref");
214 * Accumulate percentage widths on column spanning cells into
215 * temporary variables.
217 void AddSpanPrefPercent(float aSpanPrefPercent) {
218 if (aSpanPrefPercent > mSpanPrefPercent)
219 mSpanPrefPercent = aSpanPrefPercent;
223 * Accumulate the temporary variables for column spanning cells into
224 * the primary variables.
226 void AccumulateSpanIntrinsics() {
227 AddCoords(mSpanMinCoord, mSpanPrefCoord, mHasSpecifiedCoord);
228 AddPrefPercent(mSpanPrefPercent);
231 // Used to adjust a column's pref percent so that the table's total
232 // never exceeeds 100% (by only allowing percentages to be used,
233 // starting at the first column, until they reach 100%).
234 void AdjustPrefPercent(float* aTableTotalPercent) {
235 float allowed = 1.0f - *aTableTotalPercent;
236 if (mPrefPercent > allowed) mPrefPercent = allowed;
237 *aTableTotalPercent += mPrefPercent;
240 // The final width of the column.
241 void ResetFinalISize() {
242 mFinalISize = nscoord_MIN; // so we detect that it changed
244 void SetFinalISize(nscoord aFinalISize) { mFinalISize = aFinalISize; }
245 nscoord GetFinalISize() { return mFinalISize; }
247 void InvalidateFrame(uint32_t aDisplayItemKey = 0,
248 bool aRebuildDisplayItems = true) override;
249 void InvalidateFrameWithRect(const nsRect& aRect,
250 uint32_t aDisplayItemKey = 0,
251 bool aRebuildDisplayItems = true) override;
252 void InvalidateFrameForRemoval() override { InvalidateFrameSubtree(); }
254 protected:
255 explicit nsTableColFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
256 ~nsTableColFrame();
258 nscoord mMinCoord;
259 nscoord mPrefCoord;
260 nscoord mSpanMinCoord; // XXX...
261 nscoord mSpanPrefCoord; // XXX...
262 float mPrefPercent;
263 float mSpanPrefPercent; // XXX...
264 // ...XXX the four members marked above could be allocated as part of
265 // a separate array allocated only during
266 // BasicTableLayoutStrategy::ComputeColumnIntrinsicISizes (and only
267 // when colspans were present).
268 nscoord mFinalISize;
270 // the index of the column with respect to the whole table (starting at 0)
271 // it should never be smaller then the start column index of the parent
272 // colgroup
273 uint32_t mColIndex;
275 // border width in pixels of the inner half of the border only
276 BCPixelSize mIStartBorderWidth;
277 BCPixelSize mIEndBorderWidth;
279 bool mHasSpecifiedCoord;
282 inline int32_t nsTableColFrame::GetColIndex() const { return mColIndex; }
284 inline void nsTableColFrame::SetColIndex(int32_t aColIndex) {
285 mColIndex = aColIndex;
288 #endif