Bug 1869043 allow a device to be specified with MediaTrackGraph::NotifyWhenDeviceStar...
[gecko.git] / layout / tables / nsTableWrapperFrame.h
blob4e4c03e60792e889197b27527f00b819b6e31486
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 GetMinISize(gfxContext* aRenderingContext) override;
75 nscoord GetPrefISize(gfxContext* aRenderingContext) 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) return -1;
129 return cellMap->GetIndexByRowAndColumn(aRowIdx, aColIdx);
133 * Get the row and column indices for the cell at the given index.
135 void GetRowAndColumnByIndex(int32_t aCellIdx, int32_t* aRowIdx,
136 int32_t* aColIdx) const {
137 *aRowIdx = *aColIdx = 0;
138 nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
139 if (cellMap) {
140 cellMap->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
145 * return the frame for the cell at the given row and column.
147 nsTableCellFrame* GetCellFrameAt(uint32_t aRowIdx, uint32_t aColIdx) const {
148 nsTableCellMap* map = InnerTableFrame()->GetCellMap();
149 if (!map) {
150 return nullptr;
153 return map->GetCellInfoAt(aRowIdx, aColIdx);
157 * Return the col span of the cell at the given row and column indices.
159 uint32_t GetEffectiveColSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const {
160 nsTableCellMap* map = InnerTableFrame()->GetCellMap();
161 return map->GetEffectiveColSpan(aRowIdx, aColIdx);
165 * Return the effective row span of the cell at the given row and column.
167 uint32_t GetEffectiveRowSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const {
168 nsTableCellMap* map = InnerTableFrame()->GetCellMap();
169 return map->GetEffectiveRowSpan(aRowIdx, aColIdx);
172 protected:
173 explicit nsTableWrapperFrame(ComputedStyle* aStyle,
174 nsPresContext* aPresContext,
175 ClassID aID = kClassID);
176 virtual ~nsTableWrapperFrame();
178 using MaybeCaptionSide = Maybe<mozilla::StyleCaptionSide>;
180 // Get a StyleCaptionSide value, or Nothing if no caption is present.
182 // (Remember that caption-side values are interpreted logically, despite
183 // having "physical" names.)
184 MaybeCaptionSide GetCaptionSide() const;
186 mozilla::StyleVerticalAlignKeyword GetCaptionVerticalAlign() const;
188 nscoord ComputeFinalBSize(const mozilla::LogicalSize& aInnerSize,
189 const mozilla::LogicalSize& aCaptionSize,
190 const mozilla::LogicalMargin& aCaptionMargin,
191 const mozilla::WritingMode aWM) const;
193 void GetCaptionOrigin(mozilla::StyleCaptionSide,
194 const mozilla::LogicalSize& aInnerSize,
195 const mozilla::LogicalSize& aCaptionSize,
196 mozilla::LogicalMargin& aCaptionMargin,
197 mozilla::LogicalPoint& aOrigin,
198 mozilla::WritingMode aWM) const;
200 void GetInnerOrigin(const MaybeCaptionSide&,
201 const mozilla::LogicalSize& aCaptionSize,
202 const mozilla::LogicalMargin& aCaptionMargin,
203 const mozilla::LogicalSize& aInnerSize,
204 mozilla::LogicalPoint& aOrigin,
205 mozilla::WritingMode aWM) const;
207 // This is a helper for CreateReflowInputForInnerTable() and
208 // ComputeAutoSize(). It computes whether we need shrink-wrap behavior for
209 // children.
211 // Note: We don't need to call this in CreateReflowInputForCaption() because
212 // when we reflow the captions, we want them to stretch their inline-sizes to
213 // be at least as wide as the inner table frame.
214 mozilla::ComputeSizeFlags CreateComputeSizeFlagsForChild() const;
216 // Create and init the child reflow input, using passed-in aChildRI, so that
217 // caller can use it after we return.
219 // @param aBSizeOccupiedByCaption the block size occupied by the caption
220 // within our content box.
221 void CreateReflowInputForInnerTable(
222 nsPresContext* aPresContext, nsTableFrame* aTableFrame,
223 const ReflowInput& aOuterRI, Maybe<ReflowInput>& aChildRI,
224 const nscoord aAvailISize, nscoord aBSizeOccupiedByCaption = 0) const;
225 void CreateReflowInputForCaption(nsPresContext* aPresContext,
226 nsIFrame* aCaptionFrame,
227 const ReflowInput& aOuterRI,
228 Maybe<ReflowInput>& aChildRI,
229 const nscoord aAvailISize) const;
231 // Reflow the child (caption or inner table frame).
232 void ReflowChild(nsPresContext* aPresContext, nsIFrame* aChildFrame,
233 const ReflowInput& aChildRI, ReflowOutput& aMetrics,
234 nsReflowStatus& aStatus);
236 // Set the overflow areas in our reflow metrics
237 void UpdateOverflowAreas(ReflowOutput& aMet);
239 nsTableFrame* InnerTableFrame() const {
240 return static_cast<nsTableFrame*>(mFrames.FirstChild());
244 * Helper for ComputeAutoSize.
245 * Compute the margin-box inline size of the frame given the inputs.
247 * Note: CaptionShrinkWrapISize doesn't need StyleSizeOverrides parameter.
249 mozilla::LogicalSize InnerTableShrinkWrapSize(
250 gfxContext* aRenderingContext, nsTableFrame* aTableFrame,
251 mozilla::WritingMode aWM, const mozilla::LogicalSize& aCBSize,
252 nscoord aAvailableISize,
253 const mozilla::StyleSizeOverrides& aSizeOverrides,
254 mozilla::ComputeSizeFlags aFlag) const;
255 mozilla::LogicalSize CaptionShrinkWrapSize(
256 gfxContext* aRenderingContext, nsIFrame* aCaptionFrame,
257 mozilla::WritingMode aWM, const mozilla::LogicalSize& aCBSize,
258 nscoord aAvailableISize, mozilla::ComputeSizeFlags aFlag) const;
261 * Create a new StyleSize by reducing the size by aAmountToReduce.
263 * @param aStyleSize must be a Length.
265 mozilla::StyleSize ReduceStyleSizeBy(const mozilla::StyleSize& aStyleSize,
266 const nscoord aAmountToReduce) const;
269 * Compute StyleSizeOverrides for inner table frame given the overrides of the
270 * table wrapper frame.
272 mozilla::StyleSizeOverrides ComputeSizeOverridesForInnerTable(
273 const nsTableFrame* aTableFrame,
274 const mozilla::StyleSizeOverrides& aWrapperSizeOverrides,
275 const mozilla::LogicalSize& aBorderPadding,
276 nscoord aBSizeOccupiedByCaption) const;
278 private:
279 nsFrameList mCaptionFrames;
282 #endif