layout/tables/nsTablePainter.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial