Back to index

lightning-sunbird  0.9+nobinonly
nsTablePainter.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is TableBackgroundPainter interface.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Elika J. Etemad ("fantasai") <fantasai@inkedblade.net>.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsTablePainter_h__
00039 #define nsTablePainter_h__
00040 
00041 #include "celldata.h"
00042 
00043 // flags for Paint, PaintChild, PaintChildren are currently only used by tables.
00044 //Table-based paint call; not a direct call as with views
00045 #define NS_PAINT_FLAG_TABLE_BG_PAINT      0x00000001
00046 //Cells should paint their backgrounds only, no children
00047 #define NS_PAINT_FLAG_TABLE_CELL_BG_PASS  0x00000002
00048 
00049 #include "nsIFrame.h"
00050 class nsTableFrame;
00051 class nsTableRowGroupFrame;
00052 class nsTableRowFrame;
00053 class nsTableCellFrame;
00054 
00055 class TableBackgroundPainter
00056 {
00057   /*
00058    * Helper class for painting table backgrounds
00059    *
00060    */
00061 
00062   public:
00063 
00064     enum Origin { eOrigin_Table, eOrigin_TableRowGroup, eOrigin_TableRow };
00065 
00073     TableBackgroundPainter(nsTableFrame*        aTableFrame,
00074                            Origin               aOrigin,
00075                            nsPresContext*      aPresContext,
00076                            nsIRenderingContext& aRenderingContext,
00077                            const nsRect&        aDirtyRect);
00078 
00080     ~TableBackgroundPainter();
00081 
00082     /* ~*~ The Border Collapse Painting Issue ~*~
00083 
00084        In border-collapse, the *table* paints the cells' borders,
00085        so we need to make sure the backgrounds get painted first
00086        (underneath) by doing a cell-background-only painting pass.
00087        The table must then do a no-cell-background pass that
00088        continues as a normal background paint call in the cell
00089        descendants.) This method doesn't handle views very well,
00090        but then, nothing about BC table painting really does.
00091     */
00092 
00093     /* ~*~ Using nsTablePainter Background Painting ~*~
00094 
00095        A call to PaintTable will normally paint all of the table's
00096        elements (except the cells in non-BC). Elements with views
00097        however, will be skipped and must create their own painter
00098        to call the appropriate paint function in their ::Paint
00099        method (e.g. painter.PaintRow in nsTableRow::Paint)
00100     */
00101 
00110     nsresult PaintTable(nsTableFrame* aTableFrame, nsMargin* aDeflate);
00111 
00119     nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame)
00120     { return PaintRowGroup(aFrame, PR_FALSE); }
00121 
00129     nsresult PaintRow(nsTableRowFrame* aFrame)
00130     { return PaintRow(aFrame, PR_FALSE); }
00131 
00132   private:
00133 
00143     nsresult PaintTableFrame(nsTableFrame*         aTableFrame,
00144                              nsTableRowGroupFrame* aFirstRowGroup,
00145                              nsTableRowGroupFrame* aLastRowGroup,
00146                              nsMargin*             aDeflate = nsnull);
00147 
00148     /* aPassThrough params indicate whether to paint the element or to just
00149      * pass through and paint underlying layers only
00150      * See Public versions for function descriptions
00151      */
00152     nsresult PaintRowGroup(nsTableRowGroupFrame* aFrame,
00153                            PRBool                aPassThrough);
00154     nsresult PaintRow(nsTableRowFrame* aFrame,
00155                       PRBool           aPassThrough);
00156 
00162     nsresult PaintCell(nsTableCellFrame* aFrame,
00163                        PRBool            aPassSelf);
00164 
00170     void TranslateContext(nscoord aDX,
00171                           nscoord aDY);
00172 
00173     struct TableBackgroundData;
00174     friend struct TableBackgroundData;
00175     MOZ_DECL_CTOR_COUNTER(TableBackgroundData)
00176     struct TableBackgroundData {
00177       nsIFrame*                 mFrame;
00179       nsRect                    mRect;
00180       const nsStyleBackground*  mBackground;
00181       const nsStyleBorder*      mBorder;
00182 
00184       PRBool IsVisible() const { return mBackground != nsnull; }
00185 
00187       TableBackgroundData();
00189       ~TableBackgroundData();
00193       void Destroy(nsPresContext* aPresContext);
00194 
00195 
00197       void Clear();
00198 
00200       void SetFull(nsPresContext*      aPresContext,
00201                    nsIRenderingContext& aRenderingContext,
00202                    nsIFrame*            aFrame);
00203 
00205       void SetFrame(nsIFrame* aFrame);
00206 
00208       void SetData(nsPresContext*      aPresContext,
00209                    nsIRenderingContext& aRenderingContext);
00210 
00212       PRBool ShouldSetBCBorder();
00213 
00215       nsresult SetBCBorder(nsMargin&               aBorderWidth,
00216                            TableBackgroundPainter* aPainter);
00217 
00218       private:
00219       nsStyleBorder* mSynthBorder;
00220     };
00221 
00222     struct ColData;
00223     friend struct ColData;
00224     struct ColData {
00225       TableBackgroundData  mCol;
00226       TableBackgroundData* mColGroup; //link to col's parent colgroup's data (owned by painter)
00227       ColData() {
00228         mColGroup = nsnull;
00229       }
00230     };
00231 
00232     nsPresContext*      mPresContext;
00233     nsIRenderingContext& mRenderingContext;
00234     nsRect               mDirtyRect;
00235 #ifdef DEBUG
00236     nsCompatibility      mCompatMode;
00237 #endif
00238     PRBool               mIsBorderCollapse;
00239     Origin               mOrigin; //user's table frame type
00240 
00241     ColData*             mCols;  //array of columns' ColData
00242     PRUint32             mNumCols;
00243     TableBackgroundData  mRowGroup; //current row group
00244     TableBackgroundData  mRow;      //current row
00245     nsRect               mCellRect; //current cell's rect
00246 
00247 
00248     nsStyleBorder        mZeroBorder;  //cached zero-width border
00249     nsStylePadding       mZeroPadding; //cached zero-width padding
00250     float                mP2t;         //pixels to twips
00251 
00252 };
00253 MOZ_DECL_CTOR_COUNTER(TableBackgroundPainter)
00254 
00255 #endif