|
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__ |
|
7 |
|
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" |
|
18 |
|
19 class nsTableFrame; |
|
20 |
|
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 |
|
40 |
|
41 // default constructor supplied by the compiler |
|
42 |
|
43 nsTableCellFrame(nsStyleContext* aContext); |
|
44 ~nsTableCellFrame(); |
|
45 |
|
46 virtual void Init(nsIContent* aContent, |
|
47 nsIFrame* aParent, |
|
48 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
49 |
|
50 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
|
51 |
|
52 #ifdef ACCESSIBILITY |
|
53 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; |
|
54 #endif |
|
55 |
|
56 virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
|
57 nsIAtom* aAttribute, |
|
58 int32_t aModType) MOZ_OVERRIDE; |
|
59 |
|
60 /** @see nsIFrame::DidSetStyleContext */ |
|
61 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; |
|
62 |
|
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; |
|
73 |
|
74 virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE { |
|
75 return GetFirstPrincipalChild()->GetContentInsertionFrame(); |
|
76 } |
|
77 |
|
78 virtual nsMargin GetUsedMargin() const MOZ_OVERRIDE; |
|
79 |
|
80 virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE; |
|
81 |
|
82 virtual bool NeedsToObserve(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE; |
|
83 |
|
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); |
|
90 |
|
91 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
92 const nsRect& aDirtyRect, |
|
93 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
94 |
|
95 void PaintCellBackground(nsRenderingContext& aRenderingContext, |
|
96 const nsRect& aDirtyRect, nsPoint aPt, |
|
97 uint32_t aFlags); |
|
98 |
|
99 |
|
100 virtual nsresult ProcessBorders(nsTableFrame* aFrame, |
|
101 nsDisplayListBuilder* aBuilder, |
|
102 const nsDisplayListSet& aLists); |
|
103 |
|
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; |
|
108 |
|
109 virtual nsresult Reflow(nsPresContext* aPresContext, |
|
110 nsHTMLReflowMetrics& aDesiredSize, |
|
111 const nsHTMLReflowState& aReflowState, |
|
112 nsReflowStatus& aStatus) MOZ_OVERRIDE; |
|
113 |
|
114 /** |
|
115 * Get the "type" of the frame |
|
116 * |
|
117 * @see nsLayoutAtoms::tableCellFrame |
|
118 */ |
|
119 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
120 |
|
121 #ifdef DEBUG_FRAME_DUMP |
|
122 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
|
123 #endif |
|
124 |
|
125 void VerticallyAlignChild(nscoord aMaxAscent); |
|
126 |
|
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; |
|
133 |
|
134 bool HasVerticalAlignBaseline() const { |
|
135 return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE; |
|
136 } |
|
137 |
|
138 bool CellHasVisibleContent(nscoord height, |
|
139 nsTableFrame* tableFrame, |
|
140 nsIFrame* kidFrame); |
|
141 |
|
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; |
|
147 |
|
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(); |
|
155 |
|
156 // there is no set row index because row index depends on the cell's parent row only |
|
157 |
|
158 /*---------------- nsITableCellLayout methods ------------------------*/ |
|
159 |
|
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; |
|
166 |
|
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; |
|
169 |
|
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(); |
|
177 |
|
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); |
|
181 |
|
182 /** return the available width given to this frame during its last reflow */ |
|
183 inline nscoord GetPriorAvailWidth(); |
|
184 |
|
185 /** set the available width given to this frame during its last reflow */ |
|
186 inline void SetPriorAvailWidth(nscoord aPriorAvailWidth); |
|
187 |
|
188 /** return the desired size returned by this frame during its last reflow */ |
|
189 inline nsSize GetDesiredSize(); |
|
190 |
|
191 /** set the desired size returned by this frame during its last reflow */ |
|
192 inline void SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize); |
|
193 |
|
194 bool GetContentEmpty(); |
|
195 void SetContentEmpty(bool aContentEmpty); |
|
196 |
|
197 bool HasPctOverHeight(); |
|
198 void SetHasPctOverHeight(bool aValue); |
|
199 |
|
200 nsTableCellFrame* GetNextCell() const; |
|
201 |
|
202 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const; |
|
203 |
|
204 virtual void PaintBackground(nsRenderingContext& aRenderingContext, |
|
205 const nsRect& aDirtyRect, |
|
206 nsPoint aPt, |
|
207 uint32_t aFlags); |
|
208 |
|
209 void DecorateForSelection(nsRenderingContext& aRenderingContext, |
|
210 nsPoint aPt); |
|
211 |
|
212 virtual bool UpdateOverflow() MOZ_OVERRIDE; |
|
213 |
|
214 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
215 { |
|
216 return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart)); |
|
217 } |
|
218 |
|
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(); } |
|
222 |
|
223 protected: |
|
224 virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState= nullptr) const MOZ_OVERRIDE; |
|
225 |
|
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(); |
|
234 |
|
235 friend class nsTableRowFrame; |
|
236 |
|
237 uint32_t mColIndex; // the starting column for this cell |
|
238 |
|
239 nscoord mPriorAvailWidth; // the avail width during the last reflow |
|
240 nsSize mDesiredSize; // the last desired width & height |
|
241 }; |
|
242 |
|
243 inline nscoord nsTableCellFrame::GetPriorAvailWidth() |
|
244 { return mPriorAvailWidth;} |
|
245 |
|
246 inline void nsTableCellFrame::SetPriorAvailWidth(nscoord aPriorAvailWidth) |
|
247 { mPriorAvailWidth = aPriorAvailWidth;} |
|
248 |
|
249 inline nsSize nsTableCellFrame::GetDesiredSize() |
|
250 { return mDesiredSize; } |
|
251 |
|
252 inline void nsTableCellFrame::SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize) |
|
253 { |
|
254 mDesiredSize.width = aDesiredSize.Width(); |
|
255 mDesiredSize.height = aDesiredSize.Height(); |
|
256 } |
|
257 |
|
258 inline bool nsTableCellFrame::GetContentEmpty() |
|
259 { |
|
260 return (mState & NS_TABLE_CELL_CONTENT_EMPTY) == |
|
261 NS_TABLE_CELL_CONTENT_EMPTY; |
|
262 } |
|
263 |
|
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 } |
|
272 |
|
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 } |
|
278 |
|
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 } |
|
287 |
|
288 // nsBCTableCellFrame |
|
289 class nsBCTableCellFrame : public nsTableCellFrame |
|
290 { |
|
291 public: |
|
292 NS_DECL_FRAMEARENA_HELPERS |
|
293 |
|
294 nsBCTableCellFrame(nsStyleContext* aContext); |
|
295 |
|
296 ~nsBCTableCellFrame(); |
|
297 |
|
298 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
299 |
|
300 virtual nsMargin GetUsedBorder() const MOZ_OVERRIDE; |
|
301 virtual bool GetBorderRadii(nscoord aRadii[8]) const MOZ_OVERRIDE; |
|
302 |
|
303 // Get the *inner half of the border only*, in twips. |
|
304 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const MOZ_OVERRIDE; |
|
305 |
|
306 // Get the *inner half of the border only*, in pixels. |
|
307 BCPixelSize GetBorderWidth(mozilla::css::Side aSide) const; |
|
308 |
|
309 // Set the full (both halves) width of the border |
|
310 void SetBorderWidth(mozilla::css::Side aSide, BCPixelSize aPixelValue); |
|
311 |
|
312 virtual nsMargin GetBorderOverflow() MOZ_OVERRIDE; |
|
313 |
|
314 #ifdef DEBUG_FRAME_DUMP |
|
315 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
|
316 #endif |
|
317 |
|
318 virtual void PaintBackground(nsRenderingContext& aRenderingContext, |
|
319 const nsRect& aDirtyRect, |
|
320 nsPoint aPt, |
|
321 uint32_t aFlags) MOZ_OVERRIDE; |
|
322 |
|
323 private: |
|
324 |
|
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 }; |
|
332 |
|
333 #endif |