Back to index

lightning-sunbird  0.9+nobinonly
nsTableRowFrame.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 nsTableRowFrame_h__
00038 #define nsTableRowFrame_h__
00039 
00040 #include "nscore.h"
00041 #include "nsHTMLContainerFrame.h"
00042 #include "nsTablePainter.h"
00043 
00044 class  nsTableFrame;
00045 class  nsTableCellFrame;
00046 struct nsTableCellReflowState;
00047 
00048 #ifdef DEBUG_TABLE_REFLOW_TIMING
00049 class nsReflowTimer;
00050 #endif
00051 
00052 #define NS_ROW_NEED_SPECIAL_REFLOW          0x20000000
00053 #define NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT 0x40000000
00054 // This is also used on rows, from nsTableRowGroupFrame.h
00055 // #define NS_REPEATED_ROW_OR_ROWGROUP      0x10000000
00056 
00067 class nsTableRowFrame : public nsHTMLContainerFrame
00068 {
00069 public:
00070   virtual ~nsTableRowFrame();
00071 
00072   NS_IMETHOD Init(nsPresContext*  aPresContext,
00073                   nsIContent*      aContent,
00074                   nsIFrame*        aParent,
00075                   nsStyleContext*  aContext,
00076                   nsIFrame*        aPrevInFlow);
00077 
00078   NS_IMETHOD AppendFrames(nsIAtom*        aListName,
00079                           nsIFrame*       aFrameList);
00080   NS_IMETHOD InsertFrames(nsIAtom*        aListName,
00081                           nsIFrame*       aPrevFrame,
00082                           nsIFrame*       aFrameList);
00083   NS_IMETHOD RemoveFrame(nsIAtom*        aListName,
00084                          nsIFrame*       aOldFrame);
00085 
00093   friend nsresult 
00094   NS_NewTableRowFrame(nsIPresShell* aPresShell, nsIFrame** aResult);
00095 
00097   NS_IMETHOD Paint(nsPresContext*      aPresContext,
00098                    nsIRenderingContext& aRenderingContext,
00099                    const nsRect&        aDirtyRect,
00100                    nsFramePaintLayer    aWhichLayer,
00101                    PRUint32             aFlags = 0);
00102 
00103   // rows don't paint their own background -- the cells do
00104   virtual PRBool CanPaintBackground() { return PR_FALSE; }
00105 
00106   NS_IMETHOD GetFrameForPoint(const nsPoint&    aPoint, 
00107                               nsFramePaintLayer aWhichLayer,
00108                               nsIFrame**        aFrame);
00109 
00110   nsTableCellFrame* GetFirstCell() ;
00111 
00125   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
00126                     nsHTMLReflowMetrics&     aDesiredSize,
00127                     const nsHTMLReflowState& aReflowState,
00128                     nsReflowStatus&          aStatus);
00129 
00130   void DidResize(nsPresContext*          aPresContext,
00131                  const nsHTMLReflowState& aReflowState);
00132 
00138   virtual nsIAtom* GetType() const;
00139 
00140 #ifdef DEBUG
00141   NS_IMETHOD GetFrameName(nsAString& aResult) const;
00142 #endif
00143  
00144   void UpdateHeight(nscoord           aHeight,
00145                     nscoord           aAscent,
00146                     nscoord           aDescent,
00147                     nsTableFrame*     aTableFrame = nsnull,
00148                     nsTableCellFrame* aCellFrame  = nsnull);
00149 
00150   void ResetHeight(nscoord aRowStyleHeight);
00151 
00152   // calculate the height, considering content height of the 
00153   // cells and the style height of the row and cells, excluding pct heights
00154   nscoord CalcHeight(const nsHTMLReflowState& aReflowState);
00155 
00156   // Support for cells with 'vertical-align: baseline'.
00157 
00163   nscoord GetMaxCellAscent() const;
00164  
00166   virtual PRInt32 GetRowIndex() const;
00167 
00169   void SetRowIndex (int aRowIndex);
00170 
00172   nscoord ReflowCellFrame(nsPresContext*          aPresContext,
00173                           const nsHTMLReflowState& aReflowState,
00174                           nsTableCellFrame*        aCellFrame,
00175                           nscoord                  aAvailableHeight,
00176                           nsReflowStatus&          aStatus);
00177 
00178   void InsertCellFrame(nsTableCellFrame* aFrame, 
00179                        nsTableCellFrame* aPrevSibling);
00180 
00181   void InsertCellFrame(nsTableCellFrame* aFrame,
00182                        PRInt32           aColIndex);
00183 
00184   void RemoveCellFrame(nsTableCellFrame* aFrame);
00185 
00186   nsresult CalculateCellActualSize(nsIFrame*       aRowFrame,
00187                                    nscoord&        aDesiredWidth,
00188                                    nscoord&        aDesiredHeight,
00189                                    nscoord         aAvailWidth);
00190 
00191   PRBool IsFirstInserted() const;
00192   void   SetFirstInserted(PRBool aValue);
00193 
00194   PRBool NeedSpecialReflow() const;
00195   void   SetNeedSpecialReflow(PRBool aValue);
00196 
00197   PRBool GetContentHeight() const;
00198   void   SetContentHeight(nscoord aTwipValue);
00199 
00200   PRBool HasStyleHeight() const;
00201 
00202   PRBool HasFixedHeight() const;
00203   void   SetHasFixedHeight(PRBool aValue);
00204 
00205   PRBool HasPctHeight() const;
00206   void   SetHasPctHeight(PRBool aValue);
00207 
00208   nscoord GetFixedHeight() const;
00209   void    SetFixedHeight(nscoord aValue);
00210 
00211   float   GetPctHeight() const;
00212   void    SetPctHeight(float  aPctValue,
00213                        PRBool aForce = PR_FALSE);
00214 
00215   nscoord GetHeight(nscoord aBasis = 0) const;
00216 
00217   nsTableRowFrame* GetNextRow() const;
00218 
00219   PRBool  HasUnpaginatedHeight();
00220   void    SetHasUnpaginatedHeight(PRBool aValue);
00221   nscoord GetUnpaginatedHeight(nsPresContext* aPresContext);
00222   void    SetUnpaginatedHeight(nsPresContext* aPresContext, nscoord aValue);
00223 
00224   nscoord GetTopBCBorderWidth(float* aPixelsToTwips = nsnull);
00225   void    SetTopBCBorderWidth(BCPixelSize aWidth);
00226   nscoord GetBottomBCBorderWidth(float* aPixelsToTwips = nsnull);
00227   void    SetBottomBCBorderWidth(BCPixelSize aWidth);
00228   nsMargin* GetBCBorderWidth(float     aPixelsToTwips,
00229                              nsMargin& aBorder);
00230                              
00237   void GetContinuousBCBorderWidth(float     aPixelsToTwips,
00238                                   nsMargin& aBorder);
00242   nscoord GetOuterTopContBCBorderWidth(float aPixelsToTwips);
00247   void SetContinuousBCBorderWidth(PRUint8     aForSide,
00248                                   BCPixelSize aPixelValue);
00249 
00250 protected:
00251 
00255   nsTableRowFrame();
00256 
00257   void InitChildReflowState(nsPresContext&         aPresContext,
00258                             const nsSize&           aAvailSize,
00259                             PRBool                  aBorderCollapse,
00260                             float                   aPixelsToTwips,
00261                             nsTableCellReflowState& aReflowState,
00262                             PRBool                  aResetComputedWidth = PR_FALSE);
00263   
00265   virtual PRIntn GetSkipSides() const;
00266 
00274   NS_IMETHOD IncrementalReflow(nsPresContext*          aPresContext,
00275                                nsHTMLReflowMetrics&     aDesiredSize,
00276                                const nsHTMLReflowState& aReflowState,
00277                                nsTableFrame&            aTableFrame,
00278                                nsReflowStatus&          aStatus);
00279 
00280   NS_IMETHOD IR_TargetIsChild(nsPresContext*          aPresContext,
00281                               nsHTMLReflowMetrics&     aDesiredSize,
00282                               const nsHTMLReflowState& aReflowState,
00283                               nsTableFrame&            aTableFrame,
00284                               nsReflowStatus&          aStatus,
00285                               nsIFrame*                aNextFrame);
00286 
00287   NS_IMETHOD IR_TargetIsMe(nsPresContext*          aPresContext,
00288                            nsHTMLReflowMetrics&     aDesiredSize,
00289                            const nsHTMLReflowState& aReflowState,
00290                            nsTableFrame&            aTableFrame,
00291                            nsReflowStatus&          aStatus);
00292 
00293   NS_IMETHOD IR_StyleChanged(nsPresContext*          aPresContext,
00294                              nsHTMLReflowMetrics&     aDesiredSize,
00295                              const nsHTMLReflowState& aReflowState,
00296                              nsTableFrame&            aTableFrame,
00297                              nsReflowStatus&          aStatus);
00298 
00299   // row-specific methods
00300 
00301   nscoord ComputeCellXOffset(const nsHTMLReflowState& aState,
00302                              nsIFrame*                aKidFrame,
00303                              const nsMargin&          aKidMargin) const;
00308   NS_IMETHOD ReflowChildren(nsPresContext*          aPresContext,
00309                             nsHTMLReflowMetrics&     aDesiredSize,
00310                             const nsHTMLReflowState& aReflowState,
00311                             nsTableFrame&            aTableFrame,
00312                             nsReflowStatus&          aStatus,
00313                             PRBool                   aDirtyOnly = PR_FALSE);
00314 
00315 private:
00316   struct RowBits {
00317     unsigned mRowIndex:29;
00318     unsigned mHasFixedHeight:1; // set if the dominating style height on the row or any cell is pixel based
00319     unsigned mHasPctHeight:1;   // set if the dominating style height on the row or any cell is pct based
00320     unsigned mFirstInserted:1;  // if true, then it was the top most newly inserted row 
00321   } mBits;
00322 
00323   // the desired height based on the content of the tallest cell in the row
00324   nscoord mContentHeight;
00325   // the height based on a style percentage height on either the row or any cell
00326   // if mHasPctHeight is set
00327   nscoord mStylePctHeight;
00328   // the height based on a style pixel height on the row or any
00329   // cell if mHasFixedHeight is set
00330   nscoord mStyleFixedHeight;
00331 
00332   // max-ascent and max-descent amongst all cells that have 'vertical-align: baseline'
00333   nscoord mMaxCellAscent;  // does include cells with rowspan > 1
00334   nscoord mMaxCellDescent; // does *not* include cells with rowspan > 1
00335 
00336   // border widths in pixels in the collapsing border model of the *inner*
00337   // half of the border only
00338   BCPixelSize mTopBorderWidth;
00339   BCPixelSize mBottomBorderWidth;
00340   BCPixelSize mRightContBorderWidth;
00341   BCPixelSize mTopContBorderWidth;
00342   BCPixelSize mLeftContBorderWidth;
00343 
00344 #ifdef DEBUG_TABLE_REFLOW_TIMING
00345 public:
00346   nsReflowTimer* mTimer;
00347 #endif
00348 };
00349 
00350 inline PRInt32 nsTableRowFrame::GetRowIndex() const
00351 {
00352   return PRInt32(mBits.mRowIndex);
00353 }
00354 
00355 inline void nsTableRowFrame::SetRowIndex (int aRowIndex)
00356 {
00357   mBits.mRowIndex = aRowIndex;
00358 }
00359 
00360 inline PRBool nsTableRowFrame::IsFirstInserted() const
00361 {
00362   return PRBool(mBits.mFirstInserted);
00363 }
00364 
00365 inline void nsTableRowFrame::SetFirstInserted(PRBool aValue)
00366 {
00367   mBits.mFirstInserted = aValue;
00368 }
00369 
00370 inline PRBool nsTableRowFrame::HasStyleHeight() const
00371 {
00372   return (PRBool)mBits.mHasFixedHeight || (PRBool)mBits.mHasPctHeight;
00373 }
00374 
00375 inline PRBool nsTableRowFrame::HasFixedHeight() const
00376 {
00377   return (PRBool)mBits.mHasFixedHeight;
00378 }
00379 
00380 inline void nsTableRowFrame::SetHasFixedHeight(PRBool aValue)
00381 {
00382   mBits.mHasFixedHeight = aValue;
00383 }
00384 
00385 inline PRBool nsTableRowFrame::HasPctHeight() const
00386 {
00387   return (PRBool)mBits.mHasPctHeight;
00388 }
00389 
00390 inline void nsTableRowFrame::SetHasPctHeight(PRBool aValue)
00391 {
00392   mBits.mHasPctHeight = aValue;
00393 }
00394 
00395 inline nscoord nsTableRowFrame::GetContentHeight() const
00396 {
00397   return mContentHeight;
00398 }
00399 
00400 inline void nsTableRowFrame::SetContentHeight(nscoord aValue)
00401 {
00402   mContentHeight = aValue;
00403 }
00404 
00405 inline nscoord nsTableRowFrame::GetFixedHeight() const
00406 {
00407   if (mBits.mHasFixedHeight)
00408     return mStyleFixedHeight;
00409   else
00410     return 0;
00411 }
00412 
00413 inline float nsTableRowFrame::GetPctHeight() const
00414 {
00415   if (mBits.mHasPctHeight) 
00416     return (float)mStylePctHeight / 100.0f;
00417   else
00418     return 0.0f;
00419 }
00420 
00421 inline PRBool nsTableRowFrame::NeedSpecialReflow() const
00422 {
00423   return (mState & NS_ROW_NEED_SPECIAL_REFLOW) == NS_ROW_NEED_SPECIAL_REFLOW;
00424 }
00425 
00426 inline void nsTableRowFrame::SetNeedSpecialReflow(PRBool aValue)
00427 {
00428   if (aValue) {
00429     mState |= NS_ROW_NEED_SPECIAL_REFLOW;
00430   } else {
00431     mState &= ~NS_ROW_NEED_SPECIAL_REFLOW;
00432   }
00433 }
00434 
00435 inline PRBool nsTableRowFrame::HasUnpaginatedHeight()
00436 {
00437   return (mState & NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT) ==
00438          NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT;
00439 }
00440 
00441 inline void nsTableRowFrame::SetHasUnpaginatedHeight(PRBool aValue)
00442 {
00443   if (aValue) {
00444     mState |= NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT;
00445   } else {
00446     mState &= ~NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT;
00447   }
00448 }
00449 
00450 inline nscoord nsTableRowFrame::GetTopBCBorderWidth(float*  aPixelsToTwips)
00451 {
00452   nscoord width = (aPixelsToTwips) ? NSToCoordRound(*aPixelsToTwips * mTopBorderWidth) : mTopBorderWidth;
00453   return width;
00454 }
00455 
00456 inline void nsTableRowFrame::SetTopBCBorderWidth(BCPixelSize aWidth)
00457 {
00458   mTopBorderWidth = aWidth;
00459 }
00460 
00461 inline nscoord nsTableRowFrame::GetBottomBCBorderWidth(float*  aPixelsToTwips)
00462 {
00463   nscoord width = (aPixelsToTwips) ? NSToCoordRound(*aPixelsToTwips * mBottomBorderWidth) : mBottomBorderWidth;
00464   return width;
00465 }
00466 
00467 inline void nsTableRowFrame::SetBottomBCBorderWidth(BCPixelSize aWidth)
00468 {
00469   mBottomBorderWidth = aWidth;
00470 }
00471 
00472 inline nsMargin* nsTableRowFrame::GetBCBorderWidth(float     aPixelsToTwips,
00473                                                    nsMargin& aBorder)
00474 {
00475   aBorder.left = aBorder.right = 0;
00476 
00477   aBorder.top    = NSToCoordRound(aPixelsToTwips * mTopBorderWidth);
00478   aBorder.bottom = NSToCoordRound(aPixelsToTwips * mBottomBorderWidth);
00479 
00480   return &aBorder;
00481 }
00482 
00483 inline void
00484 nsTableRowFrame::GetContinuousBCBorderWidth(float     aPixelsToTwips,
00485                                             nsMargin& aBorder)
00486 {
00487   aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips,
00488                                             mLeftContBorderWidth);
00489   aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips,
00490                                             mTopContBorderWidth);
00491   aBorder.left = BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips,
00492                                             mRightContBorderWidth);
00493 }
00494 
00495 inline nscoord nsTableRowFrame::GetOuterTopContBCBorderWidth(float aPixelsToTwips)
00496 {
00497   return BC_BORDER_TOP_HALF_COORD(aPixelsToTwips, mTopContBorderWidth);
00498 }
00499 
00500 #endif