Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / tables / nsTablePainter.h
blob10b0337d2b0ae58a217d0eb7809f991f64f9d676
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
13 * License.
15 * The Original Code is TableBackgroundPainter interface.
17 * The Initial Developer of the Original Code is
18 * Elika J. Etemad ("fantasai") <fantasai@inkedblade.net>.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * 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 ***** */
38 #ifndef nsTablePainter_h__
39 #define nsTablePainter_h__
41 #include "celldata.h"
43 // flags for Paint, PaintChild, PaintChildren are currently only used by tables.
44 //Table-based paint call; not a direct call as with views
45 #define NS_PAINT_FLAG_TABLE_BG_PAINT 0x00000001
46 //Cells should paint their backgrounds only, no children
47 #define NS_PAINT_FLAG_TABLE_CELL_BG_PASS 0x00000002
49 #include "nsIFrame.h"
50 class nsTableFrame;
51 class nsTableRowGroupFrame;
52 class nsTableRowFrame;
53 class nsTableCellFrame;
55 class TableBackgroundPainter
58 * Helper class for painting table backgrounds
62 public:
64 enum Origin { eOrigin_Table, eOrigin_TableRowGroup, eOrigin_TableRow };
66 /** Public constructor
67 * @param aTableFrame - the table's table frame
68 * @param aOrigin - what type of table frame is creating this instance
69 * @param aPresContext - the presentation context
70 * @param aRenderingContext - the rendering context
71 * @param aDirtyRect - the area that needs to be painted,
72 * relative to aRenderingContext
73 * @param aPt - offset of the table frame relative to
74 * aRenderingContext
76 TableBackgroundPainter(nsTableFrame* aTableFrame,
77 Origin aOrigin,
78 nsPresContext* aPresContext,
79 nsIRenderingContext& aRenderingContext,
80 const nsRect& aDirtyRect,
81 const nsPoint& aPt);
83 /** Destructor */
84 ~TableBackgroundPainter();
86 /* ~*~ The Border Collapse Painting Issue ~*~
88 In border-collapse, the *table* paints the cells' borders,
89 so we need to make sure the backgrounds get painted first
90 (underneath) by doing a cell-background-only painting pass.
93 /* ~*~ Using nsTablePainter Background Painting ~*~
95 A call to PaintTable will normally paint all of the table's
96 elements (except the cells in non-BC). Elements with views
97 however, will be skipped and must create their own painter
98 to call the appropriate paint function in their ::Paint
99 method (e.g. painter.PaintRow in nsTableRow::Paint)
102 /** Paint background for the table frame and its children down through cells
103 * (Cells themselves will only be painted in border collapse)
104 * Table must do a flagged TABLE_BG_PAINT ::Paint call on its
105 * children afterwards
106 * @param aTableFrame - the table frame
107 * @param aDeflate - deflation needed to bring table's mRect
108 * to the outer grid lines in border-collapse
110 nsresult PaintTable(nsTableFrame* aTableFrame, nsMargin* aDeflate);
112 /** Paint background for the row group and its children down through cells
113 * (Cells themselves will only be painted in border collapse)
114 * Standards mode only
115 * Table Row Group must do a flagged TABLE_BG_PAINT ::Paint call on its
116 * children afterwards
117 * @param aFrame - the table row group frame
119 nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame)
120 { return PaintRowGroup(aFrame, PR_FALSE); }
122 /** Paint background for the row and its children down through cells
123 * (Cells themselves will only be painted in border collapse)
124 * Standards mode only
125 * Table Row must do a flagged TABLE_BG_PAINT ::Paint call on its
126 * children afterwards
127 * @param aFrame - the table row frame
129 nsresult PaintRow(nsTableRowFrame* aFrame)
130 { return PaintRow(aFrame, PR_FALSE); }
132 private:
134 /** Paint table frame's background
135 * @param aTableFrame - the table frame
136 * @param aFirstRowGroup - the first (in layout order) row group
137 * may be null
138 * @param aLastRowGroup - the last (in layout order) row group
139 * may be null
140 * @param aDeflate - adjustment to frame's rect (used for quirks BC)
141 * may be null
143 nsresult PaintTableFrame(nsTableFrame* aTableFrame,
144 nsTableRowGroupFrame* aFirstRowGroup,
145 nsTableRowGroupFrame* aLastRowGroup,
146 nsMargin* aDeflate = nsnull);
148 /* aPassThrough params indicate whether to paint the element or to just
149 * pass through and paint underlying layers only
150 * See Public versions for function descriptions
152 nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame,
153 PRBool aPassThrough);
154 nsresult PaintRow(nsTableRowFrame* aFrame,
155 PRBool aPassThrough);
157 /** Paint table background layers for this cell space
158 * Also paints cell's own background in border-collapse mode
159 * @param aFrame - the cell
160 * @param aPassSelf - pass this cell; i.e. paint only underlying layers
162 nsresult PaintCell(nsTableCellFrame* aFrame,
163 PRBool aPassSelf);
165 /** Translate mRenderingContext, mDirtyRect, and mCols' column and
166 * colgroup coords
167 * @param aDX - origin's x-coord change
168 * @param aDY - origin's y-coord change
170 void TranslateContext(nscoord aDX,
171 nscoord aDY);
173 struct TableBackgroundData;
174 friend struct TableBackgroundData;
175 struct TableBackgroundData {
176 nsIFrame* mFrame;
177 /** mRect is the rect of mFrame in the current coordinate system */
178 nsRect mRect;
179 const nsStyleBackground* mBackground;
180 const nsStyleBorder* mBorder;
182 /** Data is valid & frame is visible */
183 PRBool IsVisible() const { return mBackground != nsnull; }
185 /** Constructor */
186 TableBackgroundData();
187 /** Destructor */
188 ~TableBackgroundData();
189 /** Destroys synthesized data. MUST be called before destructor
190 * @param aPresContext - the pres context
192 void Destroy(nsPresContext* aPresContext);
195 /** Clear background data */
196 void Clear();
198 /** Calculate and set all data values to represent aFrame */
199 void SetFull(nsIFrame* aFrame);
201 /** Set frame data (mFrame, mRect) but leave style data empty */
202 void SetFrame(nsIFrame* aFrame);
204 /** Calculate the style data for mFrame */
205 void SetData();
207 /** True if need to set border-collapse border; must call SetFull beforehand */
208 PRBool ShouldSetBCBorder();
210 /** Set border-collapse border with aBorderWidth as widths */
211 nsresult SetBCBorder(nsMargin& aBorderWidth,
212 TableBackgroundPainter* aPainter);
214 private:
215 nsStyleBorder* mSynthBorder;
218 struct ColData;
219 friend struct ColData;
220 struct ColData {
221 TableBackgroundData mCol;
222 TableBackgroundData* mColGroup; //link to col's parent colgroup's data (owned by painter)
223 ColData() {
224 mColGroup = nsnull;
228 nsPresContext* mPresContext;
229 nsIRenderingContext& mRenderingContext;
230 nsPoint mRenderPt;
231 nsRect mDirtyRect;
232 #ifdef DEBUG
233 nsCompatibility mCompatMode;
234 #endif
235 PRBool mIsBorderCollapse;
236 Origin mOrigin; //user's table frame type
238 ColData* mCols; //array of columns' ColData
239 PRUint32 mNumCols;
240 TableBackgroundData mRowGroup; //current row group
241 TableBackgroundData mRow; //current row
242 nsRect mCellRect; //current cell's rect
244 nsStyleBorder mZeroBorder; //cached zero-width border
247 #endif