Bumping manifests a=b2g-bump
[gecko.git] / layout / tables / nsTableCellFrame.h
blob3a593e83716360db0bf72a507b84953ffccdfe19
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"
9 #include "celldata.h"
10 #include "nsITableCellLayout.h"
11 #include "nscore.h"
12 #include "nsContainerFrame.h"
13 #include "nsStyleContext.h"
14 #include "nsIPercentHeightObserver.h"
15 #include "nsGkAtoms.h"
16 #include "nsLayoutUtils.h"
17 #include "nsTArray.h"
19 class nsTableFrame;
21 /**
22 * nsTableCellFrame
23 * data structure to maintain information about a single table cell's frame
25 * NOTE: frames are not ref counted. We expose addref and release here
26 * so we can change that decsion in the future. Users of nsITableCellLayout
27 * should refcount correctly as if this object is being ref counted, though
28 * no actual support is under the hood.
30 * @author sclark
32 class nsTableCellFrame : public nsContainerFrame,
33 public nsITableCellLayout,
34 public nsIPercentHeightObserver
36 public:
37 NS_DECL_QUERYFRAME_TARGET(nsTableCellFrame)
38 NS_DECL_QUERYFRAME
39 NS_DECL_FRAMEARENA_HELPERS
41 // default constructor supplied by the compiler
43 explicit nsTableCellFrame(nsStyleContext* aContext);
44 ~nsTableCellFrame();
46 virtual void Init(nsIContent* aContent,
47 nsContainerFrame* aParent,
48 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
50 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
52 #ifdef ACCESSIBILITY
53 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
54 #endif
56 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
57 nsIAtom* aAttribute,
58 int32_t aModType) MOZ_OVERRIDE;
60 /** @see nsIFrame::DidSetStyleContext */
61 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
63 #ifdef DEBUG
64 // Our anonymous block frame is the content insertion frame so these
65 // methods should never be called:
66 virtual void AppendFrames(ChildListID aListID,
67 nsFrameList& aFrameList) MOZ_OVERRIDE;
68 virtual void InsertFrames(ChildListID aListID,
69 nsIFrame* aPrevFrame,
70 nsFrameList& aFrameList) MOZ_OVERRIDE;
71 virtual void RemoveFrame(ChildListID aListID,
72 nsIFrame* aOldFrame) MOZ_OVERRIDE;
73 #endif
75 virtual nsContainerFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
76 return GetFirstPrincipalChild()->GetContentInsertionFrame();
79 virtual nsMargin GetUsedMargin() const MOZ_OVERRIDE;
81 virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
83 virtual bool NeedsToObserve(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
85 /** instantiate a new instance of nsTableRowFrame.
86 * @param aPresShell the pres shell for this frame
88 * @return the frame that was created
90 friend nsIFrame* NS_NewTableCellFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
92 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
93 const nsRect& aDirtyRect,
94 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
96 void PaintCellBackground(nsRenderingContext& aRenderingContext,
97 const nsRect& aDirtyRect, nsPoint aPt,
98 uint32_t aFlags);
101 virtual nsresult ProcessBorders(nsTableFrame* aFrame,
102 nsDisplayListBuilder* aBuilder,
103 const nsDisplayListSet& aLists);
105 virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
106 virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
107 virtual IntrinsicISizeOffsetData
108 IntrinsicISizeOffsets(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
110 virtual void Reflow(nsPresContext* aPresContext,
111 nsHTMLReflowMetrics& aDesiredSize,
112 const nsHTMLReflowState& aReflowState,
113 nsReflowStatus& aStatus) MOZ_OVERRIDE;
116 * Get the "type" of the frame
118 * @see nsLayoutAtoms::tableCellFrame
120 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
122 #ifdef DEBUG_FRAME_DUMP
123 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
124 #endif
126 void VerticallyAlignChild(nscoord aMaxAscent);
129 * Get the value of vertical-align adjusted for CSS 2's rules for a
130 * table cell, which means the result is always
131 * NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
133 virtual uint8_t GetVerticalAlign() const;
135 bool HasVerticalAlignBaseline() const {
136 return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE;
139 bool CellHasVisibleContent(nscoord height,
140 nsTableFrame* tableFrame,
141 nsIFrame* kidFrame);
144 * Get the first-line baseline of the cell relative to its top border
145 * edge, as if the cell were vertically aligned to the top of the row.
147 nscoord GetCellBaseline() const;
150 * return the cell's specified row span. this is what was specified in the
151 * content model or in the style info, and is always >= 1.
152 * to get the effective row span (the actual value that applies), use GetEffectiveRowSpan()
153 * @see nsTableFrame::GetEffectiveRowSpan()
155 virtual int32_t GetRowSpan();
157 // there is no set row index because row index depends on the cell's parent row only
159 /*---------------- nsITableCellLayout methods ------------------------*/
162 * return the cell's starting row index (starting at 0 for the first row).
163 * for continued cell frames the row index is that of the cell's first-in-flow
164 * and the column index (starting at 0 for the first column
166 NS_IMETHOD GetCellIndexes(int32_t &aRowIndex, int32_t &aColIndex) MOZ_OVERRIDE;
168 /** return the mapped cell's row index (starting at 0 for the first row) */
169 virtual nsresult GetRowIndex(int32_t &aRowIndex) const MOZ_OVERRIDE;
172 * return the cell's specified col span. this is what was specified in the
173 * content model or in the style info, and is always >= 1.
174 * to get the effective col span (the actual value that applies), use GetEffectiveColSpan()
175 * @see nsTableFrame::GetEffectiveColSpan()
177 virtual int32_t GetColSpan();
179 /** return the cell's column index (starting at 0 for the first column) */
180 virtual nsresult GetColIndex(int32_t &aColIndex) const MOZ_OVERRIDE;
181 void SetColIndex(int32_t aColIndex);
183 /** return the available width given to this frame during its last reflow */
184 inline nscoord GetPriorAvailWidth();
186 /** set the available width given to this frame during its last reflow */
187 inline void SetPriorAvailWidth(nscoord aPriorAvailWidth);
189 /** return the desired size returned by this frame during its last reflow */
190 inline mozilla::LogicalSize GetDesiredSize();
192 /** set the desired size returned by this frame during its last reflow */
193 inline void SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize);
195 bool GetContentEmpty();
196 void SetContentEmpty(bool aContentEmpty);
198 bool HasPctOverHeight();
199 void SetHasPctOverHeight(bool aValue);
201 nsTableCellFrame* GetNextCell() const;
203 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const;
205 virtual void PaintBackground(nsRenderingContext& aRenderingContext,
206 const nsRect& aDirtyRect,
207 nsPoint aPt,
208 uint32_t aFlags);
210 void DecorateForSelection(nsRenderingContext& aRenderingContext,
211 nsPoint aPt);
213 virtual bool UpdateOverflow() MOZ_OVERRIDE;
215 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
217 return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
220 virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
221 virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
222 virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE { InvalidateFrameSubtree(); }
224 protected:
225 virtual LogicalSides GetLogicalSkipSides(const nsHTMLReflowState* aReflowState= nullptr) const MOZ_OVERRIDE;
228 * GetBorderOverflow says how far the cell's own borders extend
229 * outside its own bounds. In the separated borders model this should
230 * just be zero (as it is for most frames), but in the collapsed
231 * borders model (for which nsBCTableCellFrame overrides this virtual
232 * method), it considers the extents of the collapsed border.
234 virtual nsMargin GetBorderOverflow();
236 friend class nsTableRowFrame;
238 uint32_t mColIndex; // the starting column for this cell
240 nscoord mPriorAvailWidth; // the avail width during the last reflow
241 mozilla::LogicalSize mDesiredSize; // the last desired inline and block size
244 inline nscoord nsTableCellFrame::GetPriorAvailWidth()
245 { return mPriorAvailWidth;}
247 inline void nsTableCellFrame::SetPriorAvailWidth(nscoord aPriorAvailWidth)
248 { mPriorAvailWidth = aPriorAvailWidth;}
250 inline mozilla::LogicalSize nsTableCellFrame::GetDesiredSize()
251 { return mDesiredSize; }
253 inline void nsTableCellFrame::SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize)
255 mozilla::WritingMode wm = aDesiredSize.GetWritingMode();
256 mDesiredSize = aDesiredSize.Size(wm).ConvertTo(GetWritingMode(), wm);
259 inline bool nsTableCellFrame::GetContentEmpty()
261 return (mState & NS_TABLE_CELL_CONTENT_EMPTY) ==
262 NS_TABLE_CELL_CONTENT_EMPTY;
265 inline void nsTableCellFrame::SetContentEmpty(bool aContentEmpty)
267 if (aContentEmpty) {
268 mState |= NS_TABLE_CELL_CONTENT_EMPTY;
269 } else {
270 mState &= ~NS_TABLE_CELL_CONTENT_EMPTY;
274 inline bool nsTableCellFrame::HasPctOverHeight()
276 return (mState & NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT) ==
277 NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
280 inline void nsTableCellFrame::SetHasPctOverHeight(bool aValue)
282 if (aValue) {
283 mState |= NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
284 } else {
285 mState &= ~NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
289 // nsBCTableCellFrame
290 class nsBCTableCellFrame MOZ_FINAL : public nsTableCellFrame
292 public:
293 NS_DECL_FRAMEARENA_HELPERS
295 explicit nsBCTableCellFrame(nsStyleContext* aContext);
297 ~nsBCTableCellFrame();
299 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
301 virtual nsMargin GetUsedBorder() const MOZ_OVERRIDE;
302 virtual bool GetBorderRadii(const nsSize& aFrameSize,
303 const nsSize& aBorderArea,
304 Sides aSkipSides,
305 nscoord aRadii[8]) const MOZ_OVERRIDE;
307 // Get the *inner half of the border only*, in twips.
308 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const MOZ_OVERRIDE;
310 // Get the *inner half of the border only*, in pixels.
311 BCPixelSize GetBorderWidth(mozilla::css::Side aSide) const;
313 // Set the full (both halves) width of the border
314 void SetBorderWidth(mozilla::css::Side aSide, BCPixelSize aPixelValue);
316 virtual nsMargin GetBorderOverflow() MOZ_OVERRIDE;
318 #ifdef DEBUG_FRAME_DUMP
319 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
320 #endif
322 virtual void PaintBackground(nsRenderingContext& aRenderingContext,
323 const nsRect& aDirtyRect,
324 nsPoint aPt,
325 uint32_t aFlags) MOZ_OVERRIDE;
327 private:
329 // These are the entire width of the border (the cell edge contains only
330 // the inner half, per the macros in nsTablePainter.h).
331 BCPixelSize mTopBorder;
332 BCPixelSize mRightBorder;
333 BCPixelSize mBottomBorder;
334 BCPixelSize mLeftBorder;
337 #endif