Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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/. */
6 #ifndef nsTablePainter_h__
7 #define nsTablePainter_h__
9 #include "celldata.h"
11 // flags for Paint, PaintChild, PaintChildren are currently only used by tables.
12 //Table-based paint call; not a direct call as with views
13 #define NS_PAINT_FLAG_TABLE_BG_PAINT 0x00000001
14 //Cells should paint their backgrounds only, no children
15 #define NS_PAINT_FLAG_TABLE_CELL_BG_PASS 0x00000002
17 class nsIFrame;
18 class nsTableFrame;
19 class nsTableRowGroupFrame;
20 class nsTableRowFrame;
21 class nsTableCellFrame;
23 class TableBackgroundPainter
24 {
25 /*
26 * Helper class for painting table backgrounds
27 *
28 */
30 public:
32 enum Origin { eOrigin_Table, eOrigin_TableRowGroup, eOrigin_TableRow };
34 /** Public constructor
35 * @param aTableFrame - the table's table frame
36 * @param aOrigin - what type of table frame is creating this instance
37 * @param aPresContext - the presentation context
38 * @param aRenderingContext - the rendering context
39 * @param aDirtyRect - the area that needs to be painted,
40 * relative to aRenderingContext
41 * @param aPt - offset of the table frame relative to
42 * aRenderingContext
43 * @param aBGPaintFlags - Flags of the nsCSSRendering::PAINTBG_* variety
44 */
45 TableBackgroundPainter(nsTableFrame* aTableFrame,
46 Origin aOrigin,
47 nsPresContext* aPresContext,
48 nsRenderingContext& aRenderingContext,
49 const nsRect& aDirtyRect,
50 const nsPoint& aPt,
51 uint32_t aBGPaintFlags);
53 /** Destructor */
54 ~TableBackgroundPainter();
56 /* ~*~ The Border Collapse Painting Issue ~*~
58 In border-collapse, the *table* paints the cells' borders,
59 so we need to make sure the backgrounds get painted first
60 (underneath) by doing a cell-background-only painting pass.
61 */
63 /* ~*~ Using nsTablePainter Background Painting ~*~
65 A call to PaintTable will normally paint all of the table's
66 elements (except for the table background, if aPaintTableBackground
67 is false).
68 Elements with views however, will be skipped and must create their
69 own painter to call the appropriate paint function in their ::Paint
70 method (e.g. painter.PaintRow in nsTableRow::Paint)
71 */
73 /** Paint background for the table frame (if requested) and its children
74 * down through cells.
75 * (Cells themselves will only be painted in border collapse)
76 * Table must do a flagged TABLE_BG_PAINT ::Paint call on its
77 * children afterwards
78 * @param aTableFrame - the table frame
79 * @param aDeflate - deflation needed to bring table's mRect
80 * to the outer grid lines in border-collapse
81 * @param aPaintTableBackground - if true, the table background
82 * is included, otherwise it isn't
83 */
84 nsresult PaintTable(nsTableFrame* aTableFrame, const nsMargin& aDeflate,
85 bool aPaintTableBackground);
87 /** Paint background for the row group and its children down through cells
88 * (Cells themselves will only be painted in border collapse)
89 * Standards mode only
90 * Table Row Group must do a flagged TABLE_BG_PAINT ::Paint call on its
91 * children afterwards
92 * @param aFrame - the table row group frame
93 */
94 nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame)
95 { return PaintRowGroup(aFrame, false); }
97 /** Paint background for the row and its children down through cells
98 * (Cells themselves will only be painted in border collapse)
99 * Standards mode only
100 * Table Row must do a flagged TABLE_BG_PAINT ::Paint call on its
101 * children afterwards
102 * @param aFrame - the table row frame
103 */
104 nsresult PaintRow(nsTableRowFrame* aFrame)
105 { return PaintRow(aFrame, false); }
107 private:
109 /** Paint table frame's background
110 * @param aTableFrame - the table frame
111 * @param aFirstRowGroup - the first (in layout order) row group
112 * may be null
113 * @param aLastRowGroup - the last (in layout order) row group
114 * may be null
115 * @param aDeflate - adjustment to frame's rect (used for quirks BC)
116 * may be null
117 */
118 nsresult PaintTableFrame(nsTableFrame* aTableFrame,
119 nsTableRowGroupFrame* aFirstRowGroup,
120 nsTableRowGroupFrame* aLastRowGroup,
121 const nsMargin& aDeflate);
123 /* aPassThrough params indicate whether to paint the element or to just
124 * pass through and paint underlying layers only
125 * See Public versions for function descriptions
126 */
127 nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame,
128 bool aPassThrough);
129 nsresult PaintRow(nsTableRowFrame* aFrame,
130 bool aPassThrough);
132 /** Paint table background layers for this cell space
133 * Also paints cell's own background in border-collapse mode
134 * @param aFrame - the cell
135 * @param aPassSelf - pass this cell; i.e. paint only underlying layers
136 */
137 nsresult PaintCell(nsTableCellFrame* aFrame,
138 bool aPassSelf);
140 /** Translate mRenderingContext, mDirtyRect, and mCols' column and
141 * colgroup coords
142 * @param aDX - origin's x-coord change
143 * @param aDY - origin's y-coord change
144 */
145 void TranslateContext(nscoord aDX,
146 nscoord aDY);
148 struct TableBackgroundData;
149 friend struct TableBackgroundData;
150 struct TableBackgroundData {
151 nsIFrame* mFrame;
152 /** mRect is the rect of mFrame in the current coordinate system */
153 nsRect mRect;
154 bool mVisible;
155 const nsStyleBorder* mBorder;
157 /** Data is valid & frame is visible */
158 bool IsVisible() const { return mVisible; }
160 /** Constructor */
161 TableBackgroundData();
162 /** Destructor */
163 ~TableBackgroundData();
164 /** Destroys synthesized data. MUST be called before destructor
165 * @param aPresContext - the pres context
166 */
167 void Destroy(nsPresContext* aPresContext);
170 /** Clear background data */
171 void Clear();
173 /** Calculate and set all data values to represent aFrame */
174 void SetFull(nsIFrame* aFrame);
176 /** Set frame data (mFrame, mRect) but leave style data empty */
177 void SetFrame(nsIFrame* aFrame);
179 /** Calculate the style data for mFrame */
180 void SetData();
182 /** True if need to set border-collapse border; must call SetFull beforehand */
183 bool ShouldSetBCBorder();
185 /** Set border-collapse border with aBorderWidth as widths */
186 nsresult SetBCBorder(nsMargin& aBorderWidth,
187 TableBackgroundPainter* aPainter);
189 private:
190 nsStyleBorder* mSynthBorder;
191 };
193 struct ColData;
194 friend struct ColData;
195 struct ColData {
196 TableBackgroundData mCol;
197 TableBackgroundData* mColGroup; //link to col's parent colgroup's data (owned by painter)
198 ColData() {
199 mColGroup = nullptr;
200 }
201 };
203 nsPresContext* mPresContext;
204 nsRenderingContext& mRenderingContext;
205 nsPoint mRenderPt;
206 nsRect mDirtyRect;
207 #ifdef DEBUG
208 nsCompatibility mCompatMode;
209 #endif
210 bool mIsBorderCollapse;
211 Origin mOrigin; //user's table frame type
213 ColData* mCols; //array of columns' ColData
214 uint32_t mNumCols;
215 TableBackgroundData mRowGroup; //current row group
216 TableBackgroundData mRow; //current row
217 nsRect mCellRect; //current cell's rect
219 nsStyleBorder mZeroBorder; //cached zero-width border
220 uint32_t mBGPaintFlags;
221 };
223 #endif