Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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
24 *
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.
29 *
30 * @author sclark
31 */
32 class nsTableCellFrame : public nsContainerFrame,
33 public nsITableCellLayout,
34 public nsIPercentHeightObserver
35 {
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 nsTableCellFrame(nsStyleContext* aContext);
44 ~nsTableCellFrame();
46 virtual void Init(nsIContent* aContent,
47 nsIFrame* 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 // table cells contain a block frame which does most of the work, and
64 // so these functions should never be called. They assert and return
65 // NS_ERROR_NOT_IMPLEMENTED
66 virtual nsresult AppendFrames(ChildListID aListID,
67 nsFrameList& aFrameList) MOZ_OVERRIDE;
68 virtual nsresult InsertFrames(ChildListID aListID,
69 nsIFrame* aPrevFrame,
70 nsFrameList& aFrameList) MOZ_OVERRIDE;
71 virtual nsresult RemoveFrame(ChildListID aListID,
72 nsIFrame* aOldFrame) MOZ_OVERRIDE;
74 virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
75 return GetFirstPrincipalChild()->GetContentInsertionFrame();
76 }
78 virtual nsMargin GetUsedMargin() const MOZ_OVERRIDE;
80 virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
82 virtual bool NeedsToObserve(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
84 /** instantiate a new instance of nsTableRowFrame.
85 * @param aPresShell the pres shell for this frame
86 *
87 * @return the frame that was created
88 */
89 friend nsIFrame* NS_NewTableCellFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
91 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
92 const nsRect& aDirtyRect,
93 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
95 void PaintCellBackground(nsRenderingContext& aRenderingContext,
96 const nsRect& aDirtyRect, nsPoint aPt,
97 uint32_t aFlags);
100 virtual nsresult ProcessBorders(nsTableFrame* aFrame,
101 nsDisplayListBuilder* aBuilder,
102 const nsDisplayListSet& aLists);
104 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
105 virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
106 virtual IntrinsicWidthOffsetData
107 IntrinsicWidthOffsets(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
109 virtual nsresult Reflow(nsPresContext* aPresContext,
110 nsHTMLReflowMetrics& aDesiredSize,
111 const nsHTMLReflowState& aReflowState,
112 nsReflowStatus& aStatus) MOZ_OVERRIDE;
114 /**
115 * Get the "type" of the frame
116 *
117 * @see nsLayoutAtoms::tableCellFrame
118 */
119 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
121 #ifdef DEBUG_FRAME_DUMP
122 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
123 #endif
125 void VerticallyAlignChild(nscoord aMaxAscent);
127 /*
128 * Get the value of vertical-align adjusted for CSS 2's rules for a
129 * table cell, which means the result is always
130 * NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
131 */
132 virtual uint8_t GetVerticalAlign() const;
134 bool HasVerticalAlignBaseline() const {
135 return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE;
136 }
138 bool CellHasVisibleContent(nscoord height,
139 nsTableFrame* tableFrame,
140 nsIFrame* kidFrame);
142 /**
143 * Get the first-line baseline of the cell relative to its top border
144 * edge, as if the cell were vertically aligned to the top of the row.
145 */
146 nscoord GetCellBaseline() const;
148 /**
149 * return the cell's specified row span. this is what was specified in the
150 * content model or in the style info, and is always >= 1.
151 * to get the effective row span (the actual value that applies), use GetEffectiveRowSpan()
152 * @see nsTableFrame::GetEffectiveRowSpan()
153 */
154 virtual int32_t GetRowSpan();
156 // there is no set row index because row index depends on the cell's parent row only
158 /*---------------- nsITableCellLayout methods ------------------------*/
160 /**
161 * return the cell's starting row index (starting at 0 for the first row).
162 * for continued cell frames the row index is that of the cell's first-in-flow
163 * and the column index (starting at 0 for the first column
164 */
165 NS_IMETHOD GetCellIndexes(int32_t &aRowIndex, int32_t &aColIndex) MOZ_OVERRIDE;
167 /** return the mapped cell's row index (starting at 0 for the first row) */
168 virtual nsresult GetRowIndex(int32_t &aRowIndex) const MOZ_OVERRIDE;
170 /**
171 * return the cell's specified col span. this is what was specified in the
172 * content model or in the style info, and is always >= 1.
173 * to get the effective col span (the actual value that applies), use GetEffectiveColSpan()
174 * @see nsTableFrame::GetEffectiveColSpan()
175 */
176 virtual int32_t GetColSpan();
178 /** return the cell's column index (starting at 0 for the first column) */
179 virtual nsresult GetColIndex(int32_t &aColIndex) const MOZ_OVERRIDE;
180 void SetColIndex(int32_t aColIndex);
182 /** return the available width given to this frame during its last reflow */
183 inline nscoord GetPriorAvailWidth();
185 /** set the available width given to this frame during its last reflow */
186 inline void SetPriorAvailWidth(nscoord aPriorAvailWidth);
188 /** return the desired size returned by this frame during its last reflow */
189 inline nsSize GetDesiredSize();
191 /** set the desired size returned by this frame during its last reflow */
192 inline void SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize);
194 bool GetContentEmpty();
195 void SetContentEmpty(bool aContentEmpty);
197 bool HasPctOverHeight();
198 void SetHasPctOverHeight(bool aValue);
200 nsTableCellFrame* GetNextCell() const;
202 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const;
204 virtual void PaintBackground(nsRenderingContext& aRenderingContext,
205 const nsRect& aDirtyRect,
206 nsPoint aPt,
207 uint32_t aFlags);
209 void DecorateForSelection(nsRenderingContext& aRenderingContext,
210 nsPoint aPt);
212 virtual bool UpdateOverflow() MOZ_OVERRIDE;
214 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
215 {
216 return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
217 }
219 virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
220 virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
221 virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE { InvalidateFrameSubtree(); }
223 protected:
224 virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState= nullptr) const MOZ_OVERRIDE;
226 /**
227 * GetBorderOverflow says how far the cell's own borders extend
228 * outside its own bounds. In the separated borders model this should
229 * just be zero (as it is for most frames), but in the collapsed
230 * borders model (for which nsBCTableCellFrame overrides this virtual
231 * method), it considers the extents of the collapsed border.
232 */
233 virtual nsMargin GetBorderOverflow();
235 friend class nsTableRowFrame;
237 uint32_t mColIndex; // the starting column for this cell
239 nscoord mPriorAvailWidth; // the avail width during the last reflow
240 nsSize mDesiredSize; // the last desired width & height
241 };
243 inline nscoord nsTableCellFrame::GetPriorAvailWidth()
244 { return mPriorAvailWidth;}
246 inline void nsTableCellFrame::SetPriorAvailWidth(nscoord aPriorAvailWidth)
247 { mPriorAvailWidth = aPriorAvailWidth;}
249 inline nsSize nsTableCellFrame::GetDesiredSize()
250 { return mDesiredSize; }
252 inline void nsTableCellFrame::SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize)
253 {
254 mDesiredSize.width = aDesiredSize.Width();
255 mDesiredSize.height = aDesiredSize.Height();
256 }
258 inline bool nsTableCellFrame::GetContentEmpty()
259 {
260 return (mState & NS_TABLE_CELL_CONTENT_EMPTY) ==
261 NS_TABLE_CELL_CONTENT_EMPTY;
262 }
264 inline void nsTableCellFrame::SetContentEmpty(bool aContentEmpty)
265 {
266 if (aContentEmpty) {
267 mState |= NS_TABLE_CELL_CONTENT_EMPTY;
268 } else {
269 mState &= ~NS_TABLE_CELL_CONTENT_EMPTY;
270 }
271 }
273 inline bool nsTableCellFrame::HasPctOverHeight()
274 {
275 return (mState & NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT) ==
276 NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
277 }
279 inline void nsTableCellFrame::SetHasPctOverHeight(bool aValue)
280 {
281 if (aValue) {
282 mState |= NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
283 } else {
284 mState &= ~NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
285 }
286 }
288 // nsBCTableCellFrame
289 class nsBCTableCellFrame : public nsTableCellFrame
290 {
291 public:
292 NS_DECL_FRAMEARENA_HELPERS
294 nsBCTableCellFrame(nsStyleContext* aContext);
296 ~nsBCTableCellFrame();
298 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
300 virtual nsMargin GetUsedBorder() const MOZ_OVERRIDE;
301 virtual bool GetBorderRadii(nscoord aRadii[8]) const MOZ_OVERRIDE;
303 // Get the *inner half of the border only*, in twips.
304 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const MOZ_OVERRIDE;
306 // Get the *inner half of the border only*, in pixels.
307 BCPixelSize GetBorderWidth(mozilla::css::Side aSide) const;
309 // Set the full (both halves) width of the border
310 void SetBorderWidth(mozilla::css::Side aSide, BCPixelSize aPixelValue);
312 virtual nsMargin GetBorderOverflow() MOZ_OVERRIDE;
314 #ifdef DEBUG_FRAME_DUMP
315 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
316 #endif
318 virtual void PaintBackground(nsRenderingContext& aRenderingContext,
319 const nsRect& aDirtyRect,
320 nsPoint aPt,
321 uint32_t aFlags) MOZ_OVERRIDE;
323 private:
325 // These are the entire width of the border (the cell edge contains only
326 // the inner half, per the macros in nsTablePainter.h).
327 BCPixelSize mTopBorder;
328 BCPixelSize mRightBorder;
329 BCPixelSize mBottomBorder;
330 BCPixelSize mLeftBorder;
331 };
333 #endif