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 nsTableCellFrame_h__
6 #define nsTableCellFrame_h__
8 #include "mozilla/Attributes.h"
10 #include "nsITableCellLayout.h"
12 #include "nsContainerFrame.h"
13 #include "nsStyleContext.h"
14 #include "nsIPercentHeightObserver.h"
15 #include "nsGkAtoms.h"
16 #include "nsLayoutUtils.h"
22 * Additional frame-state bits
24 #define NS_TABLE_CELL_CONTENT_EMPTY NS_FRAME_STATE_BIT(31)
25 #define NS_TABLE_CELL_HAD_SPECIAL_REFLOW NS_FRAME_STATE_BIT(29)
26 #define NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT NS_FRAME_STATE_BIT(28)
30 * data structure to maintain information about a single table cell's frame
32 * NOTE: frames are not ref counted. We expose addref and release here
33 * so we can change that decsion in the future. Users of nsITableCellLayout
34 * should refcount correctly as if this object is being ref counted, though
35 * no actual support is under the hood.
39 class nsTableCellFrame
: public nsContainerFrame
,
40 public nsITableCellLayout
,
41 public nsIPercentHeightObserver
44 NS_DECL_QUERYFRAME_TARGET(nsTableCellFrame
)
46 NS_DECL_FRAMEARENA_HELPERS
48 // default constructor supplied by the compiler
50 nsTableCellFrame(nsStyleContext
* aContext
);
53 virtual void Init(nsIContent
* aContent
,
55 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
58 virtual mozilla::a11y::AccType
AccessibleType() MOZ_OVERRIDE
;
61 NS_IMETHOD
AttributeChanged(int32_t aNameSpaceID
,
63 int32_t aModType
) MOZ_OVERRIDE
;
65 /** @see nsIFrame::DidSetStyleContext */
66 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
) MOZ_OVERRIDE
;
68 // table cells contain a block frame which does most of the work, and
69 // so these functions should never be called. They assert and return
70 // NS_ERROR_NOT_IMPLEMENTED
71 NS_IMETHOD
AppendFrames(ChildListID aListID
,
72 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
73 NS_IMETHOD
InsertFrames(ChildListID aListID
,
75 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
76 NS_IMETHOD
RemoveFrame(ChildListID aListID
,
77 nsIFrame
* aOldFrame
) MOZ_OVERRIDE
;
79 virtual nsIFrame
* GetContentInsertionFrame() MOZ_OVERRIDE
{
80 return GetFirstPrincipalChild()->GetContentInsertionFrame();
83 virtual nsMargin
GetUsedMargin() const MOZ_OVERRIDE
;
85 virtual void NotifyPercentHeight(const nsHTMLReflowState
& aReflowState
) MOZ_OVERRIDE
;
87 virtual bool NeedsToObserve(const nsHTMLReflowState
& aReflowState
) MOZ_OVERRIDE
;
89 /** instantiate a new instance of nsTableRowFrame.
90 * @param aPresShell the pres shell for this frame
92 * @return the frame that was created
94 friend nsIFrame
* NS_NewTableCellFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
96 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
97 const nsRect
& aDirtyRect
,
98 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
100 void PaintCellBackground(nsRenderingContext
& aRenderingContext
,
101 const nsRect
& aDirtyRect
, nsPoint aPt
,
105 virtual nsresult
ProcessBorders(nsTableFrame
* aFrame
,
106 nsDisplayListBuilder
* aBuilder
,
107 const nsDisplayListSet
& aLists
);
109 virtual nscoord
GetMinWidth(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
110 virtual nscoord
GetPrefWidth(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
111 virtual IntrinsicWidthOffsetData
112 IntrinsicWidthOffsets(nsRenderingContext
* aRenderingContext
) MOZ_OVERRIDE
;
114 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
115 nsHTMLReflowMetrics
& aDesiredSize
,
116 const nsHTMLReflowState
& aReflowState
,
117 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
120 * Get the "type" of the frame
122 * @see nsLayoutAtoms::tableCellFrame
124 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
126 #ifdef DEBUG_FRAME_DUMP
127 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
130 void VerticallyAlignChild(nscoord aMaxAscent
);
133 * Get the value of vertical-align adjusted for CSS 2's rules for a
134 * table cell, which means the result is always
135 * NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
137 virtual uint8_t GetVerticalAlign() const;
139 bool HasVerticalAlignBaseline() const {
140 return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE
;
143 bool CellHasVisibleContent(nscoord height
,
144 nsTableFrame
* tableFrame
,
148 * Get the first-line baseline of the cell relative to its top border
149 * edge, as if the cell were vertically aligned to the top of the row.
151 nscoord
GetCellBaseline() const;
154 * return the cell's specified row span. this is what was specified in the
155 * content model or in the style info, and is always >= 1.
156 * to get the effective row span (the actual value that applies), use GetEffectiveRowSpan()
157 * @see nsTableFrame::GetEffectiveRowSpan()
159 virtual int32_t GetRowSpan();
161 // there is no set row index because row index depends on the cell's parent row only
163 /*---------------- nsITableCellLayout methods ------------------------*/
166 * return the cell's starting row index (starting at 0 for the first row).
167 * for continued cell frames the row index is that of the cell's first-in-flow
168 * and the column index (starting at 0 for the first column
170 NS_IMETHOD
GetCellIndexes(int32_t &aRowIndex
, int32_t &aColIndex
) MOZ_OVERRIDE
;
172 /** return the mapped cell's row index (starting at 0 for the first row) */
173 virtual nsresult
GetRowIndex(int32_t &aRowIndex
) const MOZ_OVERRIDE
;
176 * return the cell's specified col span. this is what was specified in the
177 * content model or in the style info, and is always >= 1.
178 * to get the effective col span (the actual value that applies), use GetEffectiveColSpan()
179 * @see nsTableFrame::GetEffectiveColSpan()
181 virtual int32_t GetColSpan();
183 /** return the cell's column index (starting at 0 for the first column) */
184 virtual nsresult
GetColIndex(int32_t &aColIndex
) const MOZ_OVERRIDE
;
185 void SetColIndex(int32_t aColIndex
);
187 /** return the available width given to this frame during its last reflow */
188 inline nscoord
GetPriorAvailWidth();
190 /** set the available width given to this frame during its last reflow */
191 inline void SetPriorAvailWidth(nscoord aPriorAvailWidth
);
193 /** return the desired size returned by this frame during its last reflow */
194 inline nsSize
GetDesiredSize();
196 /** set the desired size returned by this frame during its last reflow */
197 inline void SetDesiredSize(const nsHTMLReflowMetrics
& aDesiredSize
);
199 bool GetContentEmpty();
200 void SetContentEmpty(bool aContentEmpty
);
202 bool HasPctOverHeight();
203 void SetHasPctOverHeight(bool aValue
);
205 nsTableCellFrame
* GetNextCell() const;
207 virtual nsMargin
* GetBorderWidth(nsMargin
& aBorder
) const;
209 virtual void PaintBackground(nsRenderingContext
& aRenderingContext
,
210 const nsRect
& aDirtyRect
,
214 void DecorateForSelection(nsRenderingContext
& aRenderingContext
,
217 virtual bool UpdateOverflow() MOZ_OVERRIDE
;
219 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
221 return nsContainerFrame::IsFrameOfType(aFlags
& ~(nsIFrame::eTablePart
));
224 virtual void InvalidateFrame(uint32_t aDisplayItemKey
= 0) MOZ_OVERRIDE
;
225 virtual void InvalidateFrameWithRect(const nsRect
& aRect
, uint32_t aDisplayItemKey
= 0) MOZ_OVERRIDE
;
226 virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE
{ InvalidateFrameSubtree(); }
229 virtual int GetSkipSides(const nsHTMLReflowState
* aReflowState
= nullptr) const MOZ_OVERRIDE
;
232 * GetBorderOverflow says how far the cell's own borders extend
233 * outside its own bounds. In the separated borders model this should
234 * just be zero (as it is for most frames), but in the collapsed
235 * borders model (for which nsBCTableCellFrame overrides this virtual
236 * method), it considers the extents of the collapsed border.
238 virtual nsMargin
GetBorderOverflow();
240 friend class nsTableRowFrame
;
242 uint32_t mColIndex
; // the starting column for this cell
244 nscoord mPriorAvailWidth
; // the avail width during the last reflow
245 nsSize mDesiredSize
; // the last desired width & height
248 inline nscoord
nsTableCellFrame::GetPriorAvailWidth()
249 { return mPriorAvailWidth
;}
251 inline void nsTableCellFrame::SetPriorAvailWidth(nscoord aPriorAvailWidth
)
252 { mPriorAvailWidth
= aPriorAvailWidth
;}
254 inline nsSize
nsTableCellFrame::GetDesiredSize()
255 { return mDesiredSize
; }
257 inline void nsTableCellFrame::SetDesiredSize(const nsHTMLReflowMetrics
& aDesiredSize
)
259 mDesiredSize
.width
= aDesiredSize
.Width();
260 mDesiredSize
.height
= aDesiredSize
.Height();
263 inline bool nsTableCellFrame::GetContentEmpty()
265 return (mState
& NS_TABLE_CELL_CONTENT_EMPTY
) ==
266 NS_TABLE_CELL_CONTENT_EMPTY
;
269 inline void nsTableCellFrame::SetContentEmpty(bool aContentEmpty
)
272 mState
|= NS_TABLE_CELL_CONTENT_EMPTY
;
274 mState
&= ~NS_TABLE_CELL_CONTENT_EMPTY
;
278 inline bool nsTableCellFrame::HasPctOverHeight()
280 return (mState
& NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
) ==
281 NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
;
284 inline void nsTableCellFrame::SetHasPctOverHeight(bool aValue
)
287 mState
|= NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
;
289 mState
&= ~NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
;
293 // nsBCTableCellFrame
294 class nsBCTableCellFrame
: public nsTableCellFrame
297 NS_DECL_FRAMEARENA_HELPERS
299 nsBCTableCellFrame(nsStyleContext
* aContext
);
301 ~nsBCTableCellFrame();
303 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
305 virtual nsMargin
GetUsedBorder() const MOZ_OVERRIDE
;
306 virtual bool GetBorderRadii(nscoord aRadii
[8]) const MOZ_OVERRIDE
;
308 // Get the *inner half of the border only*, in twips.
309 virtual nsMargin
* GetBorderWidth(nsMargin
& aBorder
) const MOZ_OVERRIDE
;
311 // Get the *inner half of the border only*, in pixels.
312 BCPixelSize
GetBorderWidth(mozilla::css::Side aSide
) const;
314 // Set the full (both halves) width of the border
315 void SetBorderWidth(mozilla::css::Side aSide
, BCPixelSize aPixelValue
);
317 virtual nsMargin
GetBorderOverflow() MOZ_OVERRIDE
;
319 #ifdef DEBUG_FRAME_DUMP
320 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
323 virtual void PaintBackground(nsRenderingContext
& aRenderingContext
,
324 const nsRect
& aDirtyRect
,
326 uint32_t aFlags
) MOZ_OVERRIDE
;
330 // These are the entire width of the border (the cell edge contains only
331 // the inner half, per the macros in nsTablePainter.h).
332 BCPixelSize mTopBorder
;
333 BCPixelSize mRightBorder
;
334 BCPixelSize mBottomBorder
;
335 BCPixelSize mLeftBorder
;