Back to index

lightning-sunbird  0.9+nobinonly
nsTableColFrame.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 mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
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 of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 #ifndef nsTableColFrame_h__
00038 #define nsTableColFrame_h__
00039 
00040 #include "nscore.h"
00041 #include "nsContainerFrame.h"
00042 #include "nsTablePainter.h"
00043 
00044 class nsVoidArray;
00045 class nsTableCellFrame;
00046 
00047 // this is used to index arrays of widths in nsColFrame and to group important widths
00048 // for calculations. It is important that the order: min, desired, fixed be maintained
00049 // for each category (con, adj).
00050 #define WIDTH_NOT_SET   -1
00051 #define NUM_WIDTHS      10
00052 #define NUM_MAJOR_WIDTHS 3 // MIN, DES, FIX
00053 #define MIN_CON          0 // minimum width required of the content + padding
00054 #define DES_CON          1 // desired width of the content + padding
00055 #define FIX              2 // fixed width either from the content or cell, col, etc. + padding
00056 #define MIN_ADJ          3 // minimum width + padding due to col spans
00057 #define DES_ADJ          4 // desired width + padding due to col spans
00058 #define FIX_ADJ          5 // fixed width + padding due to col spans
00059 #define PCT              6 // percent width of cell or col 
00060 #define PCT_ADJ          7 // percent width of cell or col from percent colspan
00061 #define MIN_PRO          8 // desired width due to proportional <col>s or cols attribute
00062 #define FINAL            9 // width after the table has been balanced, considering all of the others
00063 
00064 enum nsColConstraint {
00065   eNoConstraint          = 0,
00066   ePixelConstraint       = 1,      // pixel width 
00067   ePercentConstraint     = 2,      // percent width
00068   eProportionConstraint  = 3,      // 1*, 2*, etc. cols attribute assigns 1*
00069   e0ProportionConstraint = 4       // 0*, means to force to min width
00070 };
00071 
00072 enum nsTableColType {
00073   eColContent            = 0, // there is real col content associated   
00074   eColAnonymousCol       = 1, // the result of a span on a col
00075   eColAnonymousColGroup  = 2, // the result of a span on a col group
00076   eColAnonymousCell      = 3  // the result of a cell alone
00077 };
00078 
00079 class nsTableColFrame : public nsFrame {
00080 public:
00081 
00082   enum {eWIDTH_SOURCE_NONE          =0,   // no cell has contributed to the width style
00083         eWIDTH_SOURCE_CELL          =1,   // a cell specified a width
00084         eWIDTH_SOURCE_CELL_WITH_SPAN=2    // a cell implicitly specified a width via colspan
00085   };
00086 
00087   nsTableColType GetColType() const;
00088   void SetColType(nsTableColType aType);
00089 
00097   friend nsresult 
00098   NS_NewTableColFrame(nsIPresShell* aPresShell, nsIFrame** aResult);
00099 
00100   nsStyleCoord GetStyleWidth() const;
00101 
00102   PRInt32 GetColIndex() const;
00103   
00104   void SetColIndex (PRInt32 aColIndex);
00105 
00106   nsTableColFrame* GetNextCol() const;
00107 
00108   NS_IMETHOD Init(nsPresContext*  aPresContext,
00109                   nsIContent*      aContent,
00110                   nsIFrame*        aParent,
00111                   nsStyleContext*  aContext,
00112                   nsIFrame*        aPrevInFlow);
00113 
00114   NS_IMETHOD Paint(nsPresContext*      aPresContext,
00115                    nsIRenderingContext& aRenderingContext,
00116                    const nsRect&        aDirtyRect,
00117                    nsFramePaintLayer    aWhichLayer,
00118                    PRUint32             aFlags = 0);
00119 
00120   // column groups don't paint their own background -- the cells do
00121   virtual PRBool CanPaintBackground() { return PR_FALSE; }
00122 
00123   NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, 
00124                               nsFramePaintLayer aWhichLayer,
00125                               nsIFrame**     aFrame);
00126 
00127   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
00128                     nsHTMLReflowMetrics&     aDesiredSize,
00129                     const nsHTMLReflowState& aReflowState,
00130                     nsReflowStatus&          aStatus);
00131 
00137   virtual nsIAtom* GetType() const;
00138   
00139 #ifdef DEBUG
00140   NS_IMETHOD GetFrameName(nsAString& aResult) const;
00141 #endif
00142 
00144   virtual PRInt32 GetSpan ();
00145 
00147   nsVoidArray * GetCells();
00148 
00149   nscoord GetWidth(PRUint32 aWidthType);
00150   void    SetWidth(PRUint32 aWidthType,
00151                    nscoord  aWidth);
00152   nscoord GetMinWidth();
00153   nscoord GetDesWidth();
00154   nscoord GetFixWidth();
00155   nscoord GetPctWidth();
00156 
00157   void            SetConstraint(nsColConstraint aConstraint);
00158   nsColConstraint GetConstraint() const;
00159 
00161   PRInt32 Count() const;
00162 
00163   void ResetSizingInfo();
00164 
00165   nscoord GetLeftBorderWidth(float* aPixelsToTwips = nsnull);
00166   void    SetLeftBorderWidth(BCPixelSize aWidth);
00167   nscoord GetRightBorderWidth(float* aPixelsToTwips = nsnull);
00168   void    SetRightBorderWidth(BCPixelSize aWidth);
00169 
00178   nscoord GetContinuousBCBorderWidth(float     aPixelsToTwips,
00179                                      nsMargin& aBorder);
00184   void SetContinuousBCBorderWidth(PRUint8     aForSide,
00185                                   BCPixelSize aPixelValue);
00186 #ifdef DEBUG
00187   void Dump(PRInt32 aIndent);
00188 #endif
00189 
00190 protected:
00191 
00192   nsTableColFrame();
00193   ~nsTableColFrame();
00194 
00195   // the index of the column with respect to the whole tabble (starting at 0) 
00196   // it should never be smaller then the start column index of the parent 
00197   // colgroup
00198   PRUint32 mColIndex:        16;
00199   
00200   // border width in pixels of the inner half of the border only
00201   BCPixelSize mLeftBorderWidth;
00202   BCPixelSize mRightBorderWidth;
00203   BCPixelSize mTopContBorderWidth;
00204   BCPixelSize mRightContBorderWidth;
00205   BCPixelSize mBottomContBorderWidth;
00206   // Widths including MIN_CON, DES_CON, FIX_CON, MIN_ADJ, DES_ADJ, FIX_ADJ, PCT, PCT_ADJ, MIN_PRO, FINAL
00207   // Widths including MIN_CON, DES_CON, FIX_CON, MIN_ADJ, DES_ADJ, FIX_ADJ, PCT, PCT_ADJ, MIN_PRO, FINAL
00208   // XXX these could be stored as pixels and converted to twips for a savings of 10 x 2 bytes.
00209   nscoord           mWidths[NUM_WIDTHS];
00210 };
00211 
00212 inline PRInt32 nsTableColFrame::GetColIndex() const
00213 {
00214   return mColIndex; 
00215 }
00216 
00217 inline void nsTableColFrame::SetColIndex (PRInt32 aColIndex)
00218 { 
00219   mColIndex = aColIndex; 
00220 }
00221 
00222 inline nscoord nsTableColFrame::GetLeftBorderWidth(float*  aPixelsToTwips)
00223 {
00224   nscoord width = (aPixelsToTwips) ? NSToCoordRound(*aPixelsToTwips * mLeftBorderWidth) : mLeftBorderWidth;
00225   return width;
00226 }
00227 
00228 inline void nsTableColFrame::SetLeftBorderWidth(BCPixelSize aWidth)
00229 {
00230   mLeftBorderWidth = aWidth;
00231 }
00232 
00233 inline nscoord nsTableColFrame::GetRightBorderWidth(float*  aPixelsToTwips)
00234 {
00235   nscoord width = (aPixelsToTwips) ? NSToCoordRound(*aPixelsToTwips * mRightBorderWidth) : mRightBorderWidth;
00236   return width;
00237 }
00238 
00239 inline void nsTableColFrame::SetRightBorderWidth(BCPixelSize aWidth)
00240 {
00241   mRightBorderWidth = aWidth;
00242 }
00243 
00244 inline nscoord
00245 nsTableColFrame::GetContinuousBCBorderWidth(float     aPixelsToTwips,
00246                                             nsMargin& aBorder)
00247 {
00248   aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips,
00249                                             mTopContBorderWidth);
00250   aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips,
00251                                             mRightContBorderWidth);
00252   aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips,
00253                                             mBottomContBorderWidth);
00254   return BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, mRightContBorderWidth);
00255 }
00256 
00257 #endif
00258