layout/tables/nsTablePainter.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tables/nsTablePainter.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,223 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsTablePainter_h__
    1.10 +#define nsTablePainter_h__
    1.11 +
    1.12 +#include "celldata.h"
    1.13 +
    1.14 +// flags for Paint, PaintChild, PaintChildren are currently only used by tables.
    1.15 +//Table-based paint call; not a direct call as with views
    1.16 +#define NS_PAINT_FLAG_TABLE_BG_PAINT      0x00000001
    1.17 +//Cells should paint their backgrounds only, no children
    1.18 +#define NS_PAINT_FLAG_TABLE_CELL_BG_PASS  0x00000002
    1.19 +
    1.20 +class nsIFrame;
    1.21 +class nsTableFrame;
    1.22 +class nsTableRowGroupFrame;
    1.23 +class nsTableRowFrame;
    1.24 +class nsTableCellFrame;
    1.25 +
    1.26 +class TableBackgroundPainter
    1.27 +{
    1.28 +  /*
    1.29 +   * Helper class for painting table backgrounds
    1.30 +   *
    1.31 +   */
    1.32 +
    1.33 +  public:
    1.34 +
    1.35 +    enum Origin { eOrigin_Table, eOrigin_TableRowGroup, eOrigin_TableRow };
    1.36 +
    1.37 +    /** Public constructor
    1.38 +      * @param aTableFrame       - the table's table frame
    1.39 +      * @param aOrigin           - what type of table frame is creating this instance
    1.40 +      * @param aPresContext      - the presentation context
    1.41 +      * @param aRenderingContext - the rendering context
    1.42 +      * @param aDirtyRect        - the area that needs to be painted,
    1.43 +      * relative to aRenderingContext
    1.44 +      * @param aPt               - offset of the table frame relative to
    1.45 +      * aRenderingContext
    1.46 +      * @param aBGPaintFlags - Flags of the nsCSSRendering::PAINTBG_* variety
    1.47 +      */
    1.48 +    TableBackgroundPainter(nsTableFrame*        aTableFrame,
    1.49 +                           Origin               aOrigin,
    1.50 +                           nsPresContext*       aPresContext,
    1.51 +                           nsRenderingContext& aRenderingContext,
    1.52 +                           const nsRect&        aDirtyRect,
    1.53 +                           const nsPoint&       aPt,
    1.54 +                           uint32_t             aBGPaintFlags);
    1.55 +
    1.56 +    /** Destructor */
    1.57 +    ~TableBackgroundPainter();
    1.58 +
    1.59 +    /* ~*~ The Border Collapse Painting Issue ~*~
    1.60 +
    1.61 +       In border-collapse, the *table* paints the cells' borders,
    1.62 +       so we need to make sure the backgrounds get painted first
    1.63 +       (underneath) by doing a cell-background-only painting pass.
    1.64 +    */
    1.65 +
    1.66 +    /* ~*~ Using nsTablePainter Background Painting ~*~
    1.67 +
    1.68 +       A call to PaintTable will normally paint all of the table's
    1.69 +       elements (except for the table background, if aPaintTableBackground
    1.70 +       is false).
    1.71 +       Elements with views however, will be skipped and must create their
    1.72 +       own painter to call the appropriate paint function in their ::Paint
    1.73 +       method (e.g. painter.PaintRow in nsTableRow::Paint)
    1.74 +    */
    1.75 +
    1.76 +    /** Paint background for the table frame (if requested) and its children
    1.77 +      * down through cells.
    1.78 +      * (Cells themselves will only be painted in border collapse)
    1.79 +      * Table must do a flagged TABLE_BG_PAINT ::Paint call on its
    1.80 +      * children afterwards
    1.81 +      * @param aTableFrame - the table frame
    1.82 +      * @param aDeflate    - deflation needed to bring table's mRect
    1.83 +      *                      to the outer grid lines in border-collapse
    1.84 +      * @param aPaintTableBackground - if true, the table background
    1.85 +      * is included, otherwise it isn't
    1.86 +      */
    1.87 +    nsresult PaintTable(nsTableFrame* aTableFrame, const nsMargin& aDeflate,
    1.88 +                        bool aPaintTableBackground);
    1.89 +
    1.90 +    /** Paint background for the row group and its children down through cells
    1.91 +      * (Cells themselves will only be painted in border collapse)
    1.92 +      * Standards mode only
    1.93 +      * Table Row Group must do a flagged TABLE_BG_PAINT ::Paint call on its
    1.94 +      * children afterwards
    1.95 +      * @param aFrame - the table row group frame
    1.96 +      */
    1.97 +    nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame)
    1.98 +    { return PaintRowGroup(aFrame, false); }
    1.99 +
   1.100 +    /** Paint background for the row and its children down through cells
   1.101 +      * (Cells themselves will only be painted in border collapse)
   1.102 +      * Standards mode only
   1.103 +      * Table Row must do a flagged TABLE_BG_PAINT ::Paint call on its
   1.104 +      * children afterwards
   1.105 +      * @param aFrame - the table row frame
   1.106 +      */
   1.107 +    nsresult PaintRow(nsTableRowFrame* aFrame)
   1.108 +    { return PaintRow(aFrame, false); }
   1.109 +
   1.110 +  private:
   1.111 +
   1.112 +    /** Paint table frame's background
   1.113 +      * @param aTableFrame     - the table frame
   1.114 +      * @param aFirstRowGroup  - the first (in layout order) row group
   1.115 +      *                          may be null
   1.116 +      * @param aLastRowGroup   - the last (in layout order) row group
   1.117 +      *                          may be null
   1.118 +      * @param aDeflate        - adjustment to frame's rect (used for quirks BC)
   1.119 +      *                          may be null
   1.120 +      */
   1.121 +    nsresult PaintTableFrame(nsTableFrame*         aTableFrame,
   1.122 +                             nsTableRowGroupFrame* aFirstRowGroup,
   1.123 +                             nsTableRowGroupFrame* aLastRowGroup,
   1.124 +                             const nsMargin&       aDeflate);
   1.125 +
   1.126 +    /* aPassThrough params indicate whether to paint the element or to just
   1.127 +     * pass through and paint underlying layers only
   1.128 +     * See Public versions for function descriptions
   1.129 +     */
   1.130 +    nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame,
   1.131 +                           bool                  aPassThrough);
   1.132 +    nsresult PaintRow(nsTableRowFrame* aFrame,
   1.133 +                      bool             aPassThrough);
   1.134 +
   1.135 +    /** Paint table background layers for this cell space
   1.136 +      * Also paints cell's own background in border-collapse mode
   1.137 +      * @param aFrame      - the cell
   1.138 +      * @param aPassSelf   - pass this cell; i.e. paint only underlying layers
   1.139 +      */
   1.140 +    nsresult PaintCell(nsTableCellFrame* aFrame,
   1.141 +                       bool              aPassSelf);
   1.142 +
   1.143 +    /** Translate mRenderingContext, mDirtyRect, and mCols' column and
   1.144 +      * colgroup coords
   1.145 +      * @param aDX - origin's x-coord change
   1.146 +      * @param aDY - origin's y-coord change
   1.147 +      */
   1.148 +    void TranslateContext(nscoord aDX,
   1.149 +                          nscoord aDY);
   1.150 +
   1.151 +    struct TableBackgroundData;
   1.152 +    friend struct TableBackgroundData;
   1.153 +    struct TableBackgroundData {
   1.154 +      nsIFrame*                 mFrame;
   1.155 +      /** mRect is the rect of mFrame in the current coordinate system */
   1.156 +      nsRect                    mRect;
   1.157 +      bool                      mVisible;
   1.158 +      const nsStyleBorder*      mBorder;
   1.159 +
   1.160 +      /** Data is valid & frame is visible */
   1.161 +      bool IsVisible() const { return mVisible; }
   1.162 +
   1.163 +      /** Constructor */
   1.164 +      TableBackgroundData();
   1.165 +      /** Destructor */
   1.166 +      ~TableBackgroundData();
   1.167 +      /** Destroys synthesized data. MUST be called before destructor
   1.168 +       *  @param aPresContext - the pres context
   1.169 +       */
   1.170 +      void Destroy(nsPresContext* aPresContext);
   1.171 +
   1.172 +
   1.173 +      /** Clear background data */
   1.174 +      void Clear();
   1.175 +
   1.176 +      /** Calculate and set all data values to represent aFrame */
   1.177 +      void SetFull(nsIFrame* aFrame);
   1.178 +
   1.179 +      /** Set frame data (mFrame, mRect) but leave style data empty */
   1.180 +      void SetFrame(nsIFrame* aFrame);
   1.181 +
   1.182 +      /** Calculate the style data for mFrame */
   1.183 +      void SetData();
   1.184 +
   1.185 +      /** True if need to set border-collapse border; must call SetFull beforehand */
   1.186 +      bool ShouldSetBCBorder();
   1.187 +
   1.188 +      /** Set border-collapse border with aBorderWidth as widths */
   1.189 +      nsresult SetBCBorder(nsMargin&               aBorderWidth,
   1.190 +                           TableBackgroundPainter* aPainter);
   1.191 +
   1.192 +      private:
   1.193 +      nsStyleBorder* mSynthBorder;
   1.194 +    };
   1.195 +
   1.196 +    struct ColData;
   1.197 +    friend struct ColData;
   1.198 +    struct ColData {
   1.199 +      TableBackgroundData  mCol;
   1.200 +      TableBackgroundData* mColGroup; //link to col's parent colgroup's data (owned by painter)
   1.201 +      ColData() {
   1.202 +        mColGroup = nullptr;
   1.203 +      }
   1.204 +    };
   1.205 +
   1.206 +    nsPresContext*      mPresContext;
   1.207 +    nsRenderingContext& mRenderingContext;
   1.208 +    nsPoint              mRenderPt;
   1.209 +    nsRect               mDirtyRect;
   1.210 +#ifdef DEBUG
   1.211 +    nsCompatibility      mCompatMode;
   1.212 +#endif
   1.213 +    bool                 mIsBorderCollapse;
   1.214 +    Origin               mOrigin; //user's table frame type
   1.215 +
   1.216 +    ColData*             mCols;  //array of columns' ColData
   1.217 +    uint32_t             mNumCols;
   1.218 +    TableBackgroundData  mRowGroup; //current row group
   1.219 +    TableBackgroundData  mRow;      //current row
   1.220 +    nsRect               mCellRect; //current cell's rect
   1.221 +
   1.222 +    nsStyleBorder        mZeroBorder;  //cached zero-width border
   1.223 +    uint32_t             mBGPaintFlags;
   1.224 +};
   1.225 +
   1.226 +#endif

mercurial