1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsTableCellFrame_h__
38 #define nsTableCellFrame_h__
40 #include "nsITableCellLayout.h"
42 #include "nsHTMLContainerFrame.h"
43 #include "nsTableRowFrame.h" // need to actually include this here to inline GetRowIndex
44 #include "nsStyleContext.h"
45 #include "nsIPercentHeightObserver.h"
46 #include "nsGkAtoms.h"
47 #include "nsLayoutUtils.h"
52 * Additional frame-state bits
54 #define NS_TABLE_CELL_CONTENT_EMPTY 0x80000000
55 #define NS_TABLE_CELL_HAD_SPECIAL_REFLOW 0x20000000
56 #define NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT 0x10000000
60 * data structure to maintain information about a single table cell's frame
62 * NOTE: frames are not ref counted. We expose addref and release here
63 * so we can change that decsion in the future. Users of nsITableCellLayout
64 * should refcount correctly as if this object is being ref counted, though
65 * no actual support is under the hood.
69 class nsTableCellFrame
: public nsHTMLContainerFrame
,
70 public nsITableCellLayout
,
71 public nsIPercentHeightObserver
76 NS_DECL_ISUPPORTS_INHERITED
78 // default constructor supplied by the compiler
80 nsTableCellFrame(nsStyleContext
* aContext
);
83 NS_IMETHOD
Init(nsIContent
* aContent
,
85 nsIFrame
* aPrevInFlow
);
88 NS_IMETHOD
GetAccessible(nsIAccessible
** aAccessible
);
91 NS_IMETHOD
AttributeChanged(PRInt32 aNameSpaceID
,
95 /** @see nsIFrame::DidSetStyleContext */
96 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
);
98 // table cells contain an area frame which does most of the work, and
99 // so these functions should never be called. They assert and return
100 // NS_ERROR_NOT_IMPLEMENTED
101 NS_IMETHOD
AppendFrames(nsIAtom
* aListName
,
102 nsIFrame
* aFrameList
);
103 NS_IMETHOD
InsertFrames(nsIAtom
* aListName
,
104 nsIFrame
* aPrevFrame
,
105 nsIFrame
* aFrameList
);
106 NS_IMETHOD
RemoveFrame(nsIAtom
* aListName
,
107 nsIFrame
* aOldFrame
);
109 virtual nsIFrame
* GetContentInsertionFrame() {
110 return GetFirstChild(nsnull
)->GetContentInsertionFrame();
113 virtual nsMargin
GetUsedMargin() const;
115 virtual void NotifyPercentHeight(const nsHTMLReflowState
& aReflowState
);
117 virtual PRBool
NeedsToObserve(const nsHTMLReflowState
& aReflowState
);
119 /** instantiate a new instance of nsTableRowFrame.
120 * @param aPresShell the pres shell for this frame
122 * @return the frame that was created
124 friend nsIFrame
* NS_NewTableCellFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
126 NS_IMETHOD
BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
127 const nsRect
& aDirtyRect
,
128 const nsDisplayListSet
& aLists
);
130 void PaintCellBackground(nsIRenderingContext
& aRenderingContext
,
131 const nsRect
& aDirtyRect
, nsPoint aPt
);
133 NS_IMETHOD
SetSelected(nsPresContext
* aPresContext
,
137 SelectionType aType
);
139 virtual nscoord
GetMinWidth(nsIRenderingContext
*aRenderingContext
);
140 virtual nscoord
GetPrefWidth(nsIRenderingContext
*aRenderingContext
);
141 virtual IntrinsicWidthOffsetData
142 IntrinsicWidthOffsets(nsIRenderingContext
* aRenderingContext
);
144 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
145 nsHTMLReflowMetrics
& aDesiredSize
,
146 const nsHTMLReflowState
& aReflowState
,
147 nsReflowStatus
& aStatus
);
150 * Get the "type" of the frame
152 * @see nsLayoutAtoms::tableCellFrame
154 virtual nsIAtom
* GetType() const;
156 virtual PRBool
IsContainingBlock() const;
159 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const;
162 void VerticallyAlignChild(nscoord aMaxAscent
);
164 PRBool
HasVerticalAlignBaseline();
166 PRBool
CellHasVisibleContent(nscoord height
,
167 nsTableFrame
* tableFrame
,
171 * Get the first-line baseline of the cell relative to its top border
172 * edge, as if the cell were vertically aligned to the top of the row.
174 nscoord
GetCellBaseline() const;
177 * return the cell's specified row span. this is what was specified in the
178 * content model or in the style info, and is always >= 1.
179 * to get the effective row span (the actual value that applies), use GetEffectiveRowSpan()
180 * @see nsTableFrame::GetEffectiveRowSpan()
182 virtual PRInt32
GetRowSpan();
184 // there is no set row index because row index depends on the cell's parent row only
186 /*---------------- nsITableCellLayout methods ------------------------*/
189 * return the cell's starting row index (starting at 0 for the first row).
190 * for continued cell frames the row index is that of the cell's first-in-flow
191 * and the column index (starting at 0 for the first column
193 NS_IMETHOD
GetCellIndexes(PRInt32
&aRowIndex
, PRInt32
&aColIndex
);
195 /** return the mapped cell's row index (starting at 0 for the first row) */
196 virtual nsresult
GetRowIndex(PRInt32
&aRowIndex
) const;
199 * return the cell's specified col span. this is what was specified in the
200 * content model or in the style info, and is always >= 1.
201 * to get the effective col span (the actual value that applies), use GetEffectiveColSpan()
202 * @see nsTableFrame::GetEffectiveColSpan()
204 virtual PRInt32
GetColSpan();
206 /** return the cell's column index (starting at 0 for the first column) */
207 virtual nsresult
GetColIndex(PRInt32
&aColIndex
) const;
208 void SetColIndex(PRInt32 aColIndex
);
210 /** return the available width given to this frame during its last reflow */
211 inline nscoord
GetPriorAvailWidth();
213 /** set the available width given to this frame during its last reflow */
214 inline void SetPriorAvailWidth(nscoord aPriorAvailWidth
);
216 /** return the desired size returned by this frame during its last reflow */
217 inline nsSize
GetDesiredSize();
219 /** set the desired size returned by this frame during its last reflow */
220 inline void SetDesiredSize(const nsHTMLReflowMetrics
& aDesiredSize
);
222 PRBool
GetContentEmpty();
223 void SetContentEmpty(PRBool aContentEmpty
);
225 PRBool
HasPctOverHeight();
226 void SetHasPctOverHeight(PRBool aValue
);
228 nsTableCellFrame
* GetNextCell() const;
230 virtual nsMargin
* GetBorderWidth(nsMargin
& aBorder
) const;
232 virtual void PaintBackground(nsIRenderingContext
& aRenderingContext
,
233 const nsRect
& aDirtyRect
,
236 void DecorateForSelection(nsIRenderingContext
& aRenderingContext
,
240 /** implement abstract method on nsHTMLContainerFrame */
241 virtual PRIntn
GetSkipSides() const;
243 virtual PRBool
ParentDisablesSelection() const; //override default behavior
246 * GetSelfOverflow says what effect the cell should have on its own
247 * overflow area. In the separated borders model this should just be
248 * the frame's size (as it is for most frames), but in the collapsed
249 * borders model (for which nsBCTableCellFrame overrides this virtual
250 * method), it considers the extents of the collapsed border so we
251 * handle invalidation correctly for dynamic border changes.
253 virtual void GetSelfOverflow(nsRect
& aOverflowArea
);
257 // All these methods are support methods for RecalcLayoutData
258 nsIFrame
* GetFrameAt(nsVoidArray
* aList
, PRInt32 aIndex
);
262 friend class nsTableRowFrame
;
264 PRUint32 mColIndex
; // the starting column for this cell
266 nscoord mPriorAvailWidth
; // the avail width during the last reflow
267 nsSize mDesiredSize
; // the last desired width & height
270 inline nscoord
nsTableCellFrame::GetPriorAvailWidth()
271 { return mPriorAvailWidth
;}
273 inline void nsTableCellFrame::SetPriorAvailWidth(nscoord aPriorAvailWidth
)
274 { mPriorAvailWidth
= aPriorAvailWidth
;}
276 inline nsSize
nsTableCellFrame::GetDesiredSize()
277 { return mDesiredSize
; }
279 inline void nsTableCellFrame::SetDesiredSize(const nsHTMLReflowMetrics
& aDesiredSize
)
281 mDesiredSize
.width
= aDesiredSize
.width
;
282 mDesiredSize
.height
= aDesiredSize
.height
;
285 inline PRBool
nsTableCellFrame::GetContentEmpty()
287 return (mState
& NS_TABLE_CELL_CONTENT_EMPTY
) ==
288 NS_TABLE_CELL_CONTENT_EMPTY
;
291 inline void nsTableCellFrame::SetContentEmpty(PRBool aContentEmpty
)
294 mState
|= NS_TABLE_CELL_CONTENT_EMPTY
;
296 mState
&= ~NS_TABLE_CELL_CONTENT_EMPTY
;
300 inline PRBool
nsTableCellFrame::HasPctOverHeight()
302 return (mState
& NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
) ==
303 NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
;
306 inline void nsTableCellFrame::SetHasPctOverHeight(PRBool aValue
)
309 mState
|= NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
;
311 mState
&= ~NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT
;
315 // nsBCTableCellFrame
316 class nsBCTableCellFrame
: public nsTableCellFrame
320 nsBCTableCellFrame(nsStyleContext
* aContext
);
322 ~nsBCTableCellFrame();
324 virtual nsIAtom
* GetType() const;
326 virtual nsMargin
GetUsedBorder() const;
328 // Get the *inner half of the border only*, in twips.
329 virtual nsMargin
* GetBorderWidth(nsMargin
& aBorder
) const;
331 // Get the *inner half of the border only*, in pixels.
332 BCPixelSize
GetBorderWidth(PRUint8 aSide
) const;
334 // Set the full (both halves) width of the border
335 void SetBorderWidth(PRUint8 aSide
, BCPixelSize aPixelValue
);
337 virtual void GetSelfOverflow(nsRect
& aOverflowArea
);
340 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const;
343 virtual void PaintBackground(nsIRenderingContext
& aRenderingContext
,
344 const nsRect
& aDirtyRect
,
349 // These are the entire width of the border (the cell edge contains only
350 // the inner half, per the macros in nsTablePainter.h).
351 BCPixelSize mTopBorder
;
352 BCPixelSize mRightBorder
;
353 BCPixelSize mBottomBorder
;
354 BCPixelSize mLeftBorder
;