Backed out 2 changesets (bug 1932051) for causing bc failures @browser_passwords_upda...
[gecko.git] / layout / tables / nsTableWrapperFrame.h
blobbe7f1aee1c380f95537dc72fb82448faaccf0635
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 nsTableWrapperFrame_h__
6 #define nsTableWrapperFrame_h__
8 #include "LayoutConstants.h"
9 #include "mozilla/Attributes.h"
10 #include "mozilla/Maybe.h"
11 #include "nscore.h"
12 #include "nsContainerFrame.h"
13 #include "nsCellMap.h"
14 #include "nsTableFrame.h"
16 namespace mozilla {
17 class PresShell;
18 } // namespace mozilla
20 /**
21 * Primary frame for a table element,
22 * the nsTableWrapperFrame contains 0 or one caption frame, and a nsTableFrame
23 * pseudo-frame (referred to as the "inner frame').
25 class nsTableWrapperFrame : public nsContainerFrame {
26 public:
27 NS_DECL_QUERYFRAME
28 NS_DECL_FRAMEARENA_HELPERS(nsTableWrapperFrame)
30 /** instantiate a new instance of nsTableRowFrame.
31 * @param aPresShell the pres shell for this frame
33 * @return the frame that was created
35 friend nsTableWrapperFrame* NS_NewTableWrapperFrame(
36 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
38 // nsIFrame overrides - see there for a description
40 void Destroy(DestroyContext&) override;
42 const nsFrameList& GetChildList(ChildListID aListID) const override;
43 void GetChildLists(nsTArray<ChildList>* aLists) const override;
45 void SetInitialChildList(ChildListID aListID,
46 nsFrameList&& aChildList) override;
47 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
48 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
49 const nsLineList::iterator* aPrevFrameLine,
50 nsFrameList&& aFrameList) override;
51 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
53 nsContainerFrame* GetContentInsertionFrame() override {
54 return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
57 #ifdef ACCESSIBILITY
58 mozilla::a11y::AccType AccessibleType() override;
59 #endif
61 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
62 const nsDisplayListSet& aLists) override;
64 void BuildDisplayListForInnerTable(nsDisplayListBuilder* aBuilder,
65 const nsDisplayListSet& aLists);
67 nscoord SynthesizeFallbackBaseline(
68 mozilla::WritingMode aWM,
69 BaselineSharingGroup aBaselineGroup) const override;
70 Maybe<nscoord> GetNaturalBaselineBOffset(
71 mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup,
72 BaselineExportContext aExportContext) const override;
74 nscoord IntrinsicISize(const mozilla::IntrinsicSizeInput& aInput,
75 mozilla::IntrinsicISizeType aType) override;
77 SizeComputationResult ComputeSize(
78 gfxContext* aRenderingContext, mozilla::WritingMode aWM,
79 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
80 const mozilla::LogicalSize& aMargin,
81 const mozilla::LogicalSize& aBorderPadding,
82 const mozilla::StyleSizeOverrides& aSizeOverrides,
83 mozilla::ComputeSizeFlags aFlags) override;
85 mozilla::LogicalSize ComputeAutoSize(
86 gfxContext* aRenderingContext, mozilla::WritingMode aWM,
87 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
88 const mozilla::LogicalSize& aMargin,
89 const mozilla::LogicalSize& aBorderPadding,
90 const mozilla::StyleSizeOverrides& aSizeOverrides,
91 mozilla::ComputeSizeFlags aFlags) override;
93 /** process a reflow command for the table.
94 * This involves reflowing the caption and the inner table.
95 * @see nsIFrame::Reflow */
96 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
97 const ReflowInput& aReflowInput,
98 nsReflowStatus& aStatus) override;
100 #ifdef DEBUG_FRAME_DUMP
101 nsresult GetFrameName(nsAString& aResult) const override;
102 #endif
104 ComputedStyle* GetParentComputedStyle(
105 nsIFrame** aProviderFrame) const override;
108 * Return the content for the cell at the given row and column.
110 nsIContent* GetCellAt(uint32_t aRowIdx, uint32_t aColIdx) const;
113 * Return the number of rows in the table.
115 int32_t GetRowCount() const { return InnerTableFrame()->GetRowCount(); }
118 * Return the number of columns in the table.
120 int32_t GetColCount() const { return InnerTableFrame()->GetColCount(); }
123 * Return the index of the cell at the given row and column.
125 int32_t GetIndexByRowAndColumn(int32_t aRowIdx, int32_t aColIdx) const {
126 nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
127 if (!cellMap) {
128 return -1;
131 return cellMap->GetIndexByRowAndColumn(aRowIdx, aColIdx);
135 * Get the row and column indices for the cell at the given index.
137 void GetRowAndColumnByIndex(int32_t aCellIdx, int32_t* aRowIdx,
138 int32_t* aColIdx) const {
139 *aRowIdx = *aColIdx = 0;
140 nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
141 if (cellMap) {
142 cellMap->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
147 * return the frame for the cell at the given row and column.
149 nsTableCellFrame* GetCellFrameAt(uint32_t aRowIdx, uint32_t aColIdx) const {
150 nsTableCellMap* map = InnerTableFrame()->GetCellMap();
151 if (!map) {
152 return nullptr;
155 return map->GetCellInfoAt(aRowIdx, aColIdx);
159 * Return the col span of the cell at the given row and column indices.
161 uint32_t GetEffectiveColSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const {
162 nsTableCellMap* map = InnerTableFrame()->GetCellMap();
163 return map->GetEffectiveColSpan(aRowIdx, aColIdx);
167 * Return the effective row span of the cell at the given row and column.
169 uint32_t GetEffectiveRowSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const {
170 nsTableCellMap* map = InnerTableFrame()->GetCellMap();
171 return map->GetEffectiveRowSpan(aRowIdx, aColIdx);
174 protected:
175 explicit nsTableWrapperFrame(ComputedStyle* aStyle,
176 nsPresContext* aPresContext,
177 ClassID aID = kClassID);
178 virtual ~nsTableWrapperFrame();
180 using MaybeCaptionSide = Maybe<mozilla::StyleCaptionSide>;
182 // Get a StyleCaptionSide value, or Nothing if no caption is present.
184 // (Remember that caption-side values are interpreted logically, despite
185 // having "physical" names.)
186 MaybeCaptionSide GetCaptionSide() const;
188 mozilla::StyleVerticalAlignKeyword GetCaptionVerticalAlign() const;
190 nscoord ComputeFinalBSize(const mozilla::LogicalSize& aInnerSize,
191 const mozilla::LogicalSize& aCaptionSize,
192 const mozilla::LogicalMargin& aCaptionMargin,
193 const mozilla::WritingMode aWM) const;
195 void GetCaptionOrigin(mozilla::StyleCaptionSide,
196 const mozilla::LogicalSize& aInnerSize,
197 const mozilla::LogicalSize& aCaptionSize,
198 mozilla::LogicalMargin& aCaptionMargin,
199 mozilla::LogicalPoint& aOrigin,
200 mozilla::WritingMode aWM) const;
202 void GetInnerOrigin(const MaybeCaptionSide&,
203 const mozilla::LogicalSize& aCaptionSize,
204 const mozilla::LogicalMargin& aCaptionMargin,
205 const mozilla::LogicalSize& aInnerSize,
206 mozilla::LogicalPoint& aOrigin,
207 mozilla::WritingMode aWM) const;
209 // This is a helper for CreateReflowInputForInnerTable() and
210 // ComputeAutoSize(). It computes whether we need shrink-wrap behavior for
211 // children.
213 // Note: We don't need to call this in CreateReflowInputForCaption() because
214 // when we reflow the captions, we want them to stretch their inline-sizes to
215 // be at least as wide as the inner table frame.
216 mozilla::ComputeSizeFlags CreateComputeSizeFlagsForChild() const;
218 // Create and init the child reflow input, using passed-in aChildRI, so that
219 // caller can use it after we return.
221 // @param aBSizeOccupiedByCaption the block size occupied by the caption
222 // within our content box.
223 void CreateReflowInputForInnerTable(
224 nsPresContext* aPresContext, nsTableFrame* aTableFrame,
225 const ReflowInput& aOuterRI, Maybe<ReflowInput>& aChildRI,
226 const nscoord aAvailISize, nscoord aBSizeOccupiedByCaption = 0) const;
227 void CreateReflowInputForCaption(nsPresContext* aPresContext,
228 nsIFrame* aCaptionFrame,
229 const ReflowInput& aOuterRI,
230 Maybe<ReflowInput>& aChildRI,
231 const nscoord aAvailISize) const;
233 // Reflow the child (caption or inner table frame).
234 void ReflowChild(nsPresContext* aPresContext, nsIFrame* aChildFrame,
235 const ReflowInput& aChildRI, ReflowOutput& aMetrics,
236 nsReflowStatus& aStatus);
238 // Set the overflow areas in our reflow metrics
239 void UpdateOverflowAreas(ReflowOutput& aMet);
241 nsTableFrame* InnerTableFrame() const {
242 return static_cast<nsTableFrame*>(mFrames.FirstChild());
246 * Helper for ComputeAutoSize.
247 * Compute the margin-box inline size of the frame given the inputs.
249 * Note: CaptionShrinkWrapISize doesn't need StyleSizeOverrides parameter.
251 mozilla::LogicalSize InnerTableShrinkWrapSize(
252 gfxContext* aRenderingContext, nsTableFrame* aTableFrame,
253 mozilla::WritingMode aWM, const mozilla::LogicalSize& aCBSize,
254 nscoord aAvailableISize,
255 const mozilla::StyleSizeOverrides& aSizeOverrides,
256 mozilla::ComputeSizeFlags aFlag) const;
257 mozilla::LogicalSize CaptionShrinkWrapSize(
258 gfxContext* aRenderingContext, nsIFrame* aCaptionFrame,
259 mozilla::WritingMode aWM, const mozilla::LogicalSize& aCBSize,
260 nscoord aAvailableISize, mozilla::ComputeSizeFlags aFlag) const;
263 * Create a new StyleSize by reducing the size by aAmountToReduce.
265 * @param aStyleSize must be a Length.
267 mozilla::StyleSize ReduceStyleSizeBy(const mozilla::StyleSize& aStyleSize,
268 const nscoord aAmountToReduce) const;
271 * Compute StyleSizeOverrides for inner table frame given the overrides of the
272 * table wrapper frame.
274 mozilla::StyleSizeOverrides ComputeSizeOverridesForInnerTable(
275 const nsTableFrame* aTableFrame,
276 const mozilla::StyleSizeOverrides& aWrapperSizeOverrides,
277 const mozilla::LogicalSize& aBorderPadding,
278 nscoord aBSizeOccupiedByCaption) const;
280 private:
281 nsFrameList mCaptionFrames;
284 #endif