michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsTablePainter_h__ michael@0: #define nsTablePainter_h__ michael@0: michael@0: #include "celldata.h" michael@0: michael@0: // flags for Paint, PaintChild, PaintChildren are currently only used by tables. michael@0: //Table-based paint call; not a direct call as with views michael@0: #define NS_PAINT_FLAG_TABLE_BG_PAINT 0x00000001 michael@0: //Cells should paint their backgrounds only, no children michael@0: #define NS_PAINT_FLAG_TABLE_CELL_BG_PASS 0x00000002 michael@0: michael@0: class nsIFrame; michael@0: class nsTableFrame; michael@0: class nsTableRowGroupFrame; michael@0: class nsTableRowFrame; michael@0: class nsTableCellFrame; michael@0: michael@0: class TableBackgroundPainter michael@0: { michael@0: /* michael@0: * Helper class for painting table backgrounds michael@0: * michael@0: */ michael@0: michael@0: public: michael@0: michael@0: enum Origin { eOrigin_Table, eOrigin_TableRowGroup, eOrigin_TableRow }; michael@0: michael@0: /** Public constructor michael@0: * @param aTableFrame - the table's table frame michael@0: * @param aOrigin - what type of table frame is creating this instance michael@0: * @param aPresContext - the presentation context michael@0: * @param aRenderingContext - the rendering context michael@0: * @param aDirtyRect - the area that needs to be painted, michael@0: * relative to aRenderingContext michael@0: * @param aPt - offset of the table frame relative to michael@0: * aRenderingContext michael@0: * @param aBGPaintFlags - Flags of the nsCSSRendering::PAINTBG_* variety michael@0: */ michael@0: TableBackgroundPainter(nsTableFrame* aTableFrame, michael@0: Origin aOrigin, michael@0: nsPresContext* aPresContext, michael@0: nsRenderingContext& aRenderingContext, michael@0: const nsRect& aDirtyRect, michael@0: const nsPoint& aPt, michael@0: uint32_t aBGPaintFlags); michael@0: michael@0: /** Destructor */ michael@0: ~TableBackgroundPainter(); michael@0: michael@0: /* ~*~ The Border Collapse Painting Issue ~*~ michael@0: michael@0: In border-collapse, the *table* paints the cells' borders, michael@0: so we need to make sure the backgrounds get painted first michael@0: (underneath) by doing a cell-background-only painting pass. michael@0: */ michael@0: michael@0: /* ~*~ Using nsTablePainter Background Painting ~*~ michael@0: michael@0: A call to PaintTable will normally paint all of the table's michael@0: elements (except for the table background, if aPaintTableBackground michael@0: is false). michael@0: Elements with views however, will be skipped and must create their michael@0: own painter to call the appropriate paint function in their ::Paint michael@0: method (e.g. painter.PaintRow in nsTableRow::Paint) michael@0: */ michael@0: michael@0: /** Paint background for the table frame (if requested) and its children michael@0: * down through cells. michael@0: * (Cells themselves will only be painted in border collapse) michael@0: * Table must do a flagged TABLE_BG_PAINT ::Paint call on its michael@0: * children afterwards michael@0: * @param aTableFrame - the table frame michael@0: * @param aDeflate - deflation needed to bring table's mRect michael@0: * to the outer grid lines in border-collapse michael@0: * @param aPaintTableBackground - if true, the table background michael@0: * is included, otherwise it isn't michael@0: */ michael@0: nsresult PaintTable(nsTableFrame* aTableFrame, const nsMargin& aDeflate, michael@0: bool aPaintTableBackground); michael@0: michael@0: /** Paint background for the row group and its children down through cells michael@0: * (Cells themselves will only be painted in border collapse) michael@0: * Standards mode only michael@0: * Table Row Group must do a flagged TABLE_BG_PAINT ::Paint call on its michael@0: * children afterwards michael@0: * @param aFrame - the table row group frame michael@0: */ michael@0: nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame) michael@0: { return PaintRowGroup(aFrame, false); } michael@0: michael@0: /** Paint background for the row and its children down through cells michael@0: * (Cells themselves will only be painted in border collapse) michael@0: * Standards mode only michael@0: * Table Row must do a flagged TABLE_BG_PAINT ::Paint call on its michael@0: * children afterwards michael@0: * @param aFrame - the table row frame michael@0: */ michael@0: nsresult PaintRow(nsTableRowFrame* aFrame) michael@0: { return PaintRow(aFrame, false); } michael@0: michael@0: private: michael@0: michael@0: /** Paint table frame's background michael@0: * @param aTableFrame - the table frame michael@0: * @param aFirstRowGroup - the first (in layout order) row group michael@0: * may be null michael@0: * @param aLastRowGroup - the last (in layout order) row group michael@0: * may be null michael@0: * @param aDeflate - adjustment to frame's rect (used for quirks BC) michael@0: * may be null michael@0: */ michael@0: nsresult PaintTableFrame(nsTableFrame* aTableFrame, michael@0: nsTableRowGroupFrame* aFirstRowGroup, michael@0: nsTableRowGroupFrame* aLastRowGroup, michael@0: const nsMargin& aDeflate); michael@0: michael@0: /* aPassThrough params indicate whether to paint the element or to just michael@0: * pass through and paint underlying layers only michael@0: * See Public versions for function descriptions michael@0: */ michael@0: nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame, michael@0: bool aPassThrough); michael@0: nsresult PaintRow(nsTableRowFrame* aFrame, michael@0: bool aPassThrough); michael@0: michael@0: /** Paint table background layers for this cell space michael@0: * Also paints cell's own background in border-collapse mode michael@0: * @param aFrame - the cell michael@0: * @param aPassSelf - pass this cell; i.e. paint only underlying layers michael@0: */ michael@0: nsresult PaintCell(nsTableCellFrame* aFrame, michael@0: bool aPassSelf); michael@0: michael@0: /** Translate mRenderingContext, mDirtyRect, and mCols' column and michael@0: * colgroup coords michael@0: * @param aDX - origin's x-coord change michael@0: * @param aDY - origin's y-coord change michael@0: */ michael@0: void TranslateContext(nscoord aDX, michael@0: nscoord aDY); michael@0: michael@0: struct TableBackgroundData; michael@0: friend struct TableBackgroundData; michael@0: struct TableBackgroundData { michael@0: nsIFrame* mFrame; michael@0: /** mRect is the rect of mFrame in the current coordinate system */ michael@0: nsRect mRect; michael@0: bool mVisible; michael@0: const nsStyleBorder* mBorder; michael@0: michael@0: /** Data is valid & frame is visible */ michael@0: bool IsVisible() const { return mVisible; } michael@0: michael@0: /** Constructor */ michael@0: TableBackgroundData(); michael@0: /** Destructor */ michael@0: ~TableBackgroundData(); michael@0: /** Destroys synthesized data. MUST be called before destructor michael@0: * @param aPresContext - the pres context michael@0: */ michael@0: void Destroy(nsPresContext* aPresContext); michael@0: michael@0: michael@0: /** Clear background data */ michael@0: void Clear(); michael@0: michael@0: /** Calculate and set all data values to represent aFrame */ michael@0: void SetFull(nsIFrame* aFrame); michael@0: michael@0: /** Set frame data (mFrame, mRect) but leave style data empty */ michael@0: void SetFrame(nsIFrame* aFrame); michael@0: michael@0: /** Calculate the style data for mFrame */ michael@0: void SetData(); michael@0: michael@0: /** True if need to set border-collapse border; must call SetFull beforehand */ michael@0: bool ShouldSetBCBorder(); michael@0: michael@0: /** Set border-collapse border with aBorderWidth as widths */ michael@0: nsresult SetBCBorder(nsMargin& aBorderWidth, michael@0: TableBackgroundPainter* aPainter); michael@0: michael@0: private: michael@0: nsStyleBorder* mSynthBorder; michael@0: }; michael@0: michael@0: struct ColData; michael@0: friend struct ColData; michael@0: struct ColData { michael@0: TableBackgroundData mCol; michael@0: TableBackgroundData* mColGroup; //link to col's parent colgroup's data (owned by painter) michael@0: ColData() { michael@0: mColGroup = nullptr; michael@0: } michael@0: }; michael@0: michael@0: nsPresContext* mPresContext; michael@0: nsRenderingContext& mRenderingContext; michael@0: nsPoint mRenderPt; michael@0: nsRect mDirtyRect; michael@0: #ifdef DEBUG michael@0: nsCompatibility mCompatMode; michael@0: #endif michael@0: bool mIsBorderCollapse; michael@0: Origin mOrigin; //user's table frame type michael@0: michael@0: ColData* mCols; //array of columns' ColData michael@0: uint32_t mNumCols; michael@0: TableBackgroundData mRowGroup; //current row group michael@0: TableBackgroundData mRow; //current row michael@0: nsRect mCellRect; //current cell's rect michael@0: michael@0: nsStyleBorder mZeroBorder; //cached zero-width border michael@0: uint32_t mBGPaintFlags; michael@0: }; michael@0: michael@0: #endif