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 nsTableOuterFrame_h__
6 #define nsTableOuterFrame_h__
8 #include "mozilla/Attributes.h"
10 #include "nsContainerFrame.h"
11 #include "nsCellMap.h"
12 #include "nsBlockFrame.h"
13 #include "nsTableFrame.h"
15 class nsTableCaptionFrame
: public nsBlockFrame
18 NS_DECL_FRAMEARENA_HELPERS
20 friend nsTableCaptionFrame
* NS_NewTableCaptionFrame(nsIPresShell
* aPresShell
,
21 nsStyleContext
* aContext
);
23 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
25 virtual mozilla::LogicalSize
26 ComputeAutoSize(nsRenderingContext
*aRenderingContext
,
27 mozilla::WritingMode aWritingMode
,
28 const mozilla::LogicalSize
& aCBSize
,
29 nscoord aAvailableISize
,
30 const mozilla::LogicalSize
& aMargin
,
31 const mozilla::LogicalSize
& aBorder
,
32 const mozilla::LogicalSize
& aPadding
,
33 bool aShrinkWrap
) MOZ_OVERRIDE
;
35 virtual nsIFrame
* GetParentStyleContextFrame() const MOZ_OVERRIDE
;
38 virtual mozilla::a11y::AccType
AccessibleType() MOZ_OVERRIDE
;
41 #ifdef DEBUG_FRAME_DUMP
42 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
46 explicit nsTableCaptionFrame(nsStyleContext
* aContext
);
47 virtual ~nsTableCaptionFrame();
52 * Primary frame for a table element,
53 * the nsTableOuterFrame contains 0 or one caption frame, and a nsTableFrame
54 * pseudo-frame (referred to as the "inner frame').
56 class nsTableOuterFrame
: public nsContainerFrame
60 NS_DECL_FRAMEARENA_HELPERS
62 NS_DECL_QUERYFRAME_TARGET(nsTableOuterFrame
)
64 /** instantiate a new instance of nsTableRowFrame.
65 * @param aPresShell the pres shell for this frame
67 * @return the frame that was created
69 friend nsTableOuterFrame
* NS_NewTableOuterFrame(nsIPresShell
* aPresShell
,
70 nsStyleContext
* aContext
);
72 // nsIFrame overrides - see there for a description
74 virtual void DestroyFrom(nsIFrame
* aDestructRoot
) MOZ_OVERRIDE
;
76 virtual const nsFrameList
& GetChildList(ChildListID aListID
) const MOZ_OVERRIDE
;
77 virtual void GetChildLists(nsTArray
<ChildList
>* aLists
) const MOZ_OVERRIDE
;
79 virtual void SetInitialChildList(ChildListID aListID
,
80 nsFrameList
& aChildList
) MOZ_OVERRIDE
;
81 virtual void AppendFrames(ChildListID aListID
,
82 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
83 virtual void InsertFrames(ChildListID aListID
,
85 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
86 virtual void RemoveFrame(ChildListID aListID
,
87 nsIFrame
* aOldFrame
) MOZ_OVERRIDE
;
89 virtual nsContainerFrame
* GetContentInsertionFrame() MOZ_OVERRIDE
{
90 return GetFirstPrincipalChild()->GetContentInsertionFrame();
94 virtual mozilla::a11y::AccType
AccessibleType() MOZ_OVERRIDE
;
97 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
98 const nsRect
& aDirtyRect
,
99 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
101 void BuildDisplayListForInnerTable(nsDisplayListBuilder
* aBuilder
,
102 const nsRect
& aDirtyRect
,
103 const nsDisplayListSet
& aLists
);
105 virtual nscoord
GetLogicalBaseline(mozilla::WritingMode aWritingMode
) const MOZ_OVERRIDE
;
107 virtual nscoord
GetMinISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
108 virtual nscoord
GetPrefISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
110 virtual mozilla::LogicalSize
111 ComputeAutoSize(nsRenderingContext
*aRenderingContext
,
112 mozilla::WritingMode aWritingMode
,
113 const mozilla::LogicalSize
& aCBSize
,
114 nscoord aAvailableISize
,
115 const mozilla::LogicalSize
& aMargin
,
116 const mozilla::LogicalSize
& aBorder
,
117 const mozilla::LogicalSize
& aPadding
,
118 bool aShrinkWrap
) MOZ_OVERRIDE
;
120 /** process a reflow command for the table.
121 * This involves reflowing the caption and the inner table.
122 * @see nsIFrame::Reflow */
123 virtual void Reflow(nsPresContext
* aPresContext
,
124 nsHTMLReflowMetrics
& aDesiredSize
,
125 const nsHTMLReflowState
& aReflowState
,
126 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
129 * Get the "type" of the frame
131 * @see nsGkAtoms::tableOuterFrame
133 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
135 #ifdef DEBUG_FRAME_DUMP
136 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
139 virtual nsIFrame
* GetParentStyleContextFrame() const MOZ_OVERRIDE
;
142 * Return the content for the cell at the given row and column.
144 nsIContent
* GetCellAt(uint32_t aRowIdx
, uint32_t aColIdx
) const;
147 * Return the number of rows in the table.
149 int32_t GetRowCount() const
151 return InnerTableFrame()->GetRowCount();
155 * Return the number of columns in the table.
157 int32_t GetColCount() const
159 return InnerTableFrame()->GetColCount();
163 * Return the index of the cell at the given row and column.
165 int32_t GetIndexByRowAndColumn(int32_t aRowIdx
, int32_t aColIdx
) const
167 nsTableCellMap
* cellMap
= InnerTableFrame()->GetCellMap();
171 return cellMap
->GetIndexByRowAndColumn(aRowIdx
, aColIdx
);
175 * Get the row and column indices for the cell at the given index.
177 void GetRowAndColumnByIndex(int32_t aCellIdx
, int32_t* aRowIdx
,
178 int32_t* aColIdx
) const
180 *aRowIdx
= *aColIdx
= 0;
181 nsTableCellMap
* cellMap
= InnerTableFrame()->GetCellMap();
183 cellMap
->GetRowAndColumnByIndex(aCellIdx
, aRowIdx
, aColIdx
);
188 * return the frame for the cell at the given row and column.
190 nsTableCellFrame
* GetCellFrameAt(uint32_t aRowIdx
, uint32_t aColIdx
) const
192 nsTableCellMap
* map
= InnerTableFrame()->GetCellMap();
197 return map
->GetCellInfoAt(aRowIdx
, aColIdx
);
201 * Return the col span of the cell at the given row and column indices.
203 uint32_t GetEffectiveColSpanAt(uint32_t aRowIdx
, uint32_t aColIdx
) const
205 nsTableCellMap
* map
= InnerTableFrame()->GetCellMap();
206 return map
->GetEffectiveColSpan(aRowIdx
, aColIdx
);
210 * Return the effective row span of the cell at the given row and column.
212 uint32_t GetEffectiveRowSpanAt(uint32_t aRowIdx
, uint32_t aColIdx
) const
214 nsTableCellMap
* map
= InnerTableFrame()->GetCellMap();
215 return map
->GetEffectiveRowSpan(aRowIdx
, aColIdx
);
221 explicit nsTableOuterFrame(nsStyleContext
* aContext
);
222 virtual ~nsTableOuterFrame();
224 void InitChildReflowState(nsPresContext
& aPresContext
,
225 nsHTMLReflowState
& aReflowState
);
227 uint8_t GetCaptionSide(); // NS_STYLE_CAPTION_SIDE_* or NO_SIDE
229 bool HasSideCaption() {
230 uint8_t captionSide
= GetCaptionSide();
231 return captionSide
== NS_STYLE_CAPTION_SIDE_LEFT
||
232 captionSide
== NS_STYLE_CAPTION_SIDE_RIGHT
;
235 uint8_t GetCaptionVerticalAlign();
237 void SetDesiredSize(uint8_t aCaptionSide
,
238 const nsMargin
& aInnerMargin
,
239 const nsMargin
& aCaptionMargin
,
243 nsresult
GetCaptionOrigin(uint32_t aCaptionSide
,
244 const nsSize
& aContainBlockSize
,
245 const nsSize
& aInnerSize
,
246 const nsMargin
& aInnerMargin
,
247 const nsSize
& aCaptionSize
,
248 nsMargin
& aCaptionMargin
,
251 nsresult
GetInnerOrigin(uint32_t aCaptionSide
,
252 const nsSize
& aContainBlockSize
,
253 const nsSize
& aCaptionSize
,
254 const nsMargin
& aCaptionMargin
,
255 const nsSize
& aInnerSize
,
256 nsMargin
& aInnerMargin
,
259 // reflow the child (caption or innertable frame)
260 void OuterBeginReflowChild(nsPresContext
* aPresContext
,
261 nsIFrame
* aChildFrame
,
262 const nsHTMLReflowState
& aOuterRS
,
264 nscoord aAvailISize
);
266 void OuterDoReflowChild(nsPresContext
* aPresContext
,
267 nsIFrame
* aChildFrame
,
268 const nsHTMLReflowState
& aChildRS
,
269 nsHTMLReflowMetrics
& aMetrics
,
270 nsReflowStatus
& aStatus
);
272 // Set the reflow metrics
273 void UpdateReflowMetrics(uint8_t aCaptionSide
,
274 nsHTMLReflowMetrics
& aMet
,
275 const nsMargin
& aInnerMargin
,
276 const nsMargin
& aCaptionMargin
);
278 // Get the margin. aMarginNoAuto is aMargin, but with auto
280 void GetChildMargin(nsPresContext
* aPresContext
,
281 const nsHTMLReflowState
& aOuterRS
,
282 nsIFrame
* aChildFrame
,
283 nscoord aAvailableWidth
,
284 mozilla::LogicalMargin
& aMargin
);
286 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
288 return nsContainerFrame::IsFrameOfType(aFlags
&
289 (~eCanContainOverflowContainers
));
292 nsTableFrame
* InnerTableFrame() const {
293 return static_cast<nsTableFrame
*>(mFrames
.FirstChild());
297 nsFrameList mCaptionFrames
;