Back to index

lightning-sunbird  0.9+nobinonly
nsTableRowGroupFrame.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 nsTableRowGroupFrame_h__
00038 #define nsTableRowGroupFrame_h__
00039 
00040 #include "nscore.h"
00041 #include "nsHTMLContainerFrame.h"
00042 #include "nsIAtom.h"
00043 #include "nsILineIterator.h"
00044 #include "nsTablePainter.h"
00045 
00046 class nsTableFrame;
00047 class nsTableRowFrame;
00048 class nsTableCellFrame;
00049 #ifdef DEBUG_TABLE_REFLOW_TIMING
00050 class nsReflowTimer;
00051 #endif
00052 
00053 struct nsRowGroupReflowState {
00054   const nsHTMLReflowState& reflowState;  // Our reflow state
00055 
00056   nsTableFrame* tableFrame;
00057 
00058   nsReflowReason reason;
00059 
00060   // The available size (computed from the parent)
00061   nsSize availSize;
00062 
00063   // Running y-offset
00064   nscoord y;
00065 
00066   nsRowGroupReflowState(const nsHTMLReflowState& aReflowState,
00067                         nsTableFrame*            aTableFrame)
00068       :reflowState(aReflowState), tableFrame(aTableFrame)
00069   {
00070     availSize.width  = reflowState.availableWidth;
00071     availSize.height = reflowState.availableHeight;
00072     reason = reflowState.reason;
00073     y = 0;  
00074   }
00075 
00076   ~nsRowGroupReflowState() {}
00077 };
00078 
00079 #define NS_ITABLEROWGROUPFRAME_IID    \
00080 { 0xe940e7bc, 0xb534, 0x11d2,  \
00081   { 0x95, 0xa2, 0x0, 0x60, 0xb0, 0xc3, 0x44, 0x14 } }
00082 
00083 // use the following bits from nsFrame's frame state 
00084 
00085 // thead or tfoot should be repeated on every printed page
00086 #define NS_ROWGROUP_REPEATABLE           0x80000000
00087 #define NS_ROWGROUP_HAS_STYLE_HEIGHT     0x40000000
00088 // we need a 3rd pass reflow to deal with pct height nested tables 
00089 #define NS_ROWGROUP_NEED_SPECIAL_REFLOW  0x20000000
00090 // the next is also used on rows (see nsTableRowGroupFrame::InitRepeatedFrame)
00091 #define NS_REPEATED_ROW_OR_ROWGROUP      0x10000000
00092 
00101 class nsTableRowGroupFrame : public nsHTMLContainerFrame, public nsILineIteratorNavigator
00102 {
00103 public:
00104   // nsISupports
00105   NS_DECL_ISUPPORTS_INHERITED
00106 
00107   // default constructor supplied by the compiler
00108 
00116   friend nsresult 
00117   NS_NewTableRowGroupFrame(nsIPresShell* aPresShell, nsIFrame** aResult);
00118   virtual ~nsTableRowGroupFrame();
00119 
00120   NS_IMETHOD Init(nsPresContext*  aPresContext,
00121                   nsIContent*      aContent,
00122                   nsIFrame*        aParent,
00123                   nsStyleContext*  aContext,
00124                   nsIFrame*        aPrevInFlow);
00125 
00126   NS_IMETHOD AppendFrames(nsIAtom*        aListName,
00127                           nsIFrame*       aFrameList);
00128   
00129   NS_IMETHOD InsertFrames(nsIAtom*        aListName,
00130                           nsIFrame*       aPrevFrame,
00131                           nsIFrame*       aFrameList);
00132 
00133   NS_IMETHOD RemoveFrame(nsIAtom*        aListName,
00134                          nsIFrame*       aOldFrame);
00135 
00137   NS_IMETHOD Paint(nsPresContext*      aPresContext,
00138                    nsIRenderingContext& aRenderingContext,
00139                    const nsRect&        aDirtyRect,
00140                    nsFramePaintLayer    aWhichLayer,
00141                    PRUint32             aFlags = 0);
00142 
00143   // row groups don't paint their own background -- the cells do
00144   virtual PRBool CanPaintBackground() { return PR_FALSE; }
00145 
00151   NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, nsFramePaintLayer aWhichLayer, nsIFrame** aFrame);
00152 
00162   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
00163                     nsHTMLReflowMetrics&     aDesiredSize,
00164                     const nsHTMLReflowState& aReflowState,
00165                     nsReflowStatus&          aStatus);
00166 
00172   virtual nsIAtom* GetType() const;
00173 
00174   virtual PRBool IsContainingBlock() const;
00175 
00176   nsTableRowFrame* GetFirstRow();
00177 
00178 #ifdef DEBUG
00179   NS_IMETHOD GetFrameName(nsAString& aResult) const;
00180 #endif
00181 
00183   PRInt32 GetRowCount();
00184 
00188   PRInt32 GetStartRowIndex();
00189 
00194   void AdjustRowIndices(PRInt32   aRowIndex,
00195                         PRInt32   anAdjustment);
00196 
00206   nsresult  InitRepeatedFrame(nsPresContext*       aPresContext,
00207                               nsTableRowGroupFrame* aHeaderFooterFrame);
00208 
00209   
00213   nscoord GetHeightOfRows();
00214   nscoord GetHeightBasis(const nsHTMLReflowState& aReflowState);
00215   
00216   nsMargin* GetBCBorderWidth(float     aPixelsToTwips,
00217                              nsMargin& aBorder);
00218 
00225   void GetContinuousBCBorderWidth(float     aPixelsToTwips,
00226                                   nsMargin& aBorder);
00231   void SetContinuousBCBorderWidth(PRUint8     aForSide,
00232                                   BCPixelSize aPixelValue);
00233 
00234 // nsILineIterator methods
00235 public:
00236   NS_IMETHOD GetNumLines(PRInt32* aResult);
00237   NS_IMETHOD GetDirection(PRBool* aIsRightToLeft);
00238   
00239   NS_IMETHOD GetLine(PRInt32 aLineNumber,
00240                      nsIFrame** aFirstFrameOnLine,
00241                      PRInt32* aNumFramesOnLine,
00242                      nsRect& aLineBounds,
00243                      PRUint32* aLineFlags);
00244   
00245   NS_IMETHOD FindLineContaining(nsIFrame* aFrame, PRInt32* aLineNumberResult);
00246   NS_IMETHOD FindLineAt(nscoord aY, PRInt32* aLineNumberResult);
00247   
00248   NS_IMETHOD FindFrameAt(PRInt32 aLineNumber,
00249                          nscoord aX,
00250                          nsIFrame** aFrameFound,
00251                          PRBool* aXIsBeforeFirstFrame,
00252                          PRBool* aXIsAfterLastFrame);
00253 
00254 #ifdef IBMBIDI
00255   NS_IMETHOD CheckLineOrder(PRInt32                  aLine,
00256                             PRBool                   *aIsReordered,
00257                             nsIFrame                 **aFirstVisual,
00258                             nsIFrame                 **aLastVisual);
00259 #endif
00260   NS_IMETHOD GetNextSiblingOnLine(nsIFrame*& aFrame, PRInt32 aLineNumber);
00261 
00262 
00263 protected:
00264   nsTableRowGroupFrame();
00265 
00266   void InitChildReflowState(nsPresContext&    aPresContext, 
00267                             PRBool             aBorderCollapse,
00268                             float              aPixelsToTwips,
00269                             nsHTMLReflowState& aReflowState);
00270   
00272   virtual PRIntn GetSkipSides() const;
00273 
00274   void PlaceChild(nsPresContext*        aPresContext,
00275                   nsRowGroupReflowState& aReflowState,
00276                   nsIFrame*              aKidFrame,
00277                   nsHTMLReflowMetrics&   aDesiredSize);
00278 
00279   void CalculateRowHeights(nsPresContext*          aPresContext, 
00280                            nsHTMLReflowMetrics&     aDesiredSize,
00281                            const nsHTMLReflowState& aReflowState,
00282                            nsTableRowFrame*         aStartRowFrameIn = nsnull);
00283 
00284   void DidResizeRows(nsPresContext&          aPresContext,
00285                      const nsHTMLReflowState& aReflowState,
00286                      nsHTMLReflowMetrics&     aDesiredSize,
00287                      nsTableRowFrame*         aStartRowFrameIn = nsnull);
00288 
00296   NS_IMETHOD IncrementalReflow(nsPresContext*        aPresContext,
00297                                nsHTMLReflowMetrics&   aDesiredSize,
00298                                nsRowGroupReflowState& aReflowState,
00299                                nsReflowStatus&        aStatus);
00300 
00301   NS_IMETHOD IR_TargetIsChild(nsPresContext*        aPresContext,
00302                               nsHTMLReflowMetrics&   aDesiredSize,
00303                               nsRowGroupReflowState& aReflowState,
00304                               nsReflowStatus&        aStatus,
00305                               nsIFrame*              aNextFrame);
00306 
00307   NS_IMETHOD IR_TargetIsMe(nsPresContext*        aPresContext,
00308                            nsHTMLReflowMetrics&   aDesiredSize,
00309                            nsRowGroupReflowState& aReflowState,
00310                            nsReflowStatus&        aStatus);
00311 
00312   NS_IMETHOD IR_StyleChanged(nsPresContext*        aPresContext,
00313                              nsHTMLReflowMetrics&   aDesiredSize,
00314                              nsRowGroupReflowState& aReflowState,
00315                              nsReflowStatus&        aStatus);
00316 
00317   nsresult AdjustSiblingsAfterReflow(nsRowGroupReflowState& aReflowState,
00318                                      nsIFrame*              aKidFrame,
00319                                      nscoord                aDeltaY);
00320   
00321   nsresult RecoverState(nsRowGroupReflowState& aReflowState,
00322                         nsIFrame*              aKidFrame);
00323 
00332   NS_METHOD ReflowChildren(nsPresContext*        aPresContext,
00333                            nsHTMLReflowMetrics&   aDesiredSize,
00334                            nsRowGroupReflowState& aReflowState,
00335                            nsReflowStatus&        aStatus,
00336                            nsTableRowFrame*       aStartFrame,
00337                            PRBool                 aDirtyOnly,
00338                            nsTableRowFrame**      aFirstRowReflowed   = nsnull,
00339                            PRBool*                aPageBreakBeforeEnd = nsnull);
00340 
00341   nsresult SplitRowGroup(nsPresContext*          aPresContext,
00342                          nsHTMLReflowMetrics&     aDesiredSize,
00343                          const nsHTMLReflowState& aReflowState,
00344                          nsTableFrame*            aTableFrame,
00345                          nsReflowStatus&          aStatus);
00346 
00347   void SplitSpanningCells(nsPresContext&          aPresContext,
00348                           const nsHTMLReflowState& aReflowState,
00349                           nsTableFrame&            aTableFrame,
00350                           nsTableRowFrame&         aFirstRow, 
00351                           nsTableRowFrame&         aLastRow,  
00352                           PRBool                   aFirstRowIsTopOfPage,
00353                           nscoord                  aAvailHeight,
00354                           nsTableRowFrame*&        aContRowFrame,
00355                           nsTableRowFrame*&        aFirstTruncatedRow,
00356                           nscoord&                 aDesiredHeight);
00357 
00358   void CreateContinuingRowFrame(nsPresContext& aPresContext,
00359                                 nsIFrame&       aRowFrame,
00360                                 nsIFrame**      aContRowFrame);
00361 
00362   PRBool IsSimpleRowFrame(nsTableFrame* aTableFrame, 
00363                           nsIFrame*     aFrame);
00364 
00365   void GetNextRowSibling(nsIFrame** aRowFrame);
00366 
00367   void UndoContinuedRow(nsPresContext*  aPresContext,
00368                         nsTableRowFrame* aRow);
00369                         
00370 private:
00371   // border widths in pixels in the collapsing border model
00372   BCPixelSize mRightContBorderWidth;
00373   BCPixelSize mBottomContBorderWidth;
00374   BCPixelSize mLeftContBorderWidth;
00375 
00376 public:
00377   virtual nsIFrame* GetFirstFrame() { return mFrames.FirstChild(); };
00378   virtual nsIFrame* GetLastFrame() { return mFrames.LastChild(); };
00379   virtual void GetNextFrame(nsIFrame*  aFrame, 
00380                             nsIFrame** aResult) { *aResult = aFrame->GetNextSibling(); };
00381   PRBool IsRepeatable() const;
00382   void   SetRepeatable(PRBool aRepeatable);
00383   PRBool HasStyleHeight() const;
00384   void   SetHasStyleHeight(PRBool aValue);
00385   PRBool NeedSpecialReflow() const;
00386   void   SetNeedSpecialReflow(PRBool aValue);
00387 
00388 #ifdef DEBUG_TABLE_REFLOW_TIMING
00389 public:
00390   nsReflowTimer* mTimer;
00391 #endif
00392 };
00393 
00394 
00395 inline PRBool nsTableRowGroupFrame::IsRepeatable() const
00396 {
00397   return (mState & NS_ROWGROUP_REPEATABLE) == NS_ROWGROUP_REPEATABLE;
00398 }
00399 
00400 inline void nsTableRowGroupFrame::SetRepeatable(PRBool aRepeatable)
00401 {
00402   if (aRepeatable) {
00403     mState |= NS_ROWGROUP_REPEATABLE;
00404   } else {
00405     mState &= ~NS_ROWGROUP_REPEATABLE;
00406   }
00407 }
00408 
00409 inline PRBool nsTableRowGroupFrame::NeedSpecialReflow() const
00410 {
00411   return (mState & NS_ROWGROUP_NEED_SPECIAL_REFLOW) == NS_ROWGROUP_NEED_SPECIAL_REFLOW;
00412 }
00413 
00414 inline void nsTableRowGroupFrame::SetNeedSpecialReflow(PRBool aValue)
00415 {
00416   if (aValue) {
00417     mState |= NS_ROWGROUP_NEED_SPECIAL_REFLOW;
00418   } else {
00419     mState &= ~NS_ROWGROUP_NEED_SPECIAL_REFLOW;
00420   }
00421 }
00422 
00423 inline PRBool nsTableRowGroupFrame::HasStyleHeight() const
00424 {
00425   return (mState & NS_ROWGROUP_HAS_STYLE_HEIGHT) == NS_ROWGROUP_HAS_STYLE_HEIGHT;
00426 }
00427 
00428 inline void nsTableRowGroupFrame::SetHasStyleHeight(PRBool aValue)
00429 {
00430   if (aValue) {
00431     mState |= NS_ROWGROUP_HAS_STYLE_HEIGHT;
00432   } else {
00433     mState &= ~NS_ROWGROUP_HAS_STYLE_HEIGHT;
00434   }
00435 }
00436 
00437 inline void
00438 nsTableRowGroupFrame::GetContinuousBCBorderWidth(float     aPixelsToTwips,
00439                                                  nsMargin& aBorder)
00440 {
00441   aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips,
00442                                             mRightContBorderWidth);
00443   aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips,
00444                                             mBottomContBorderWidth);
00445   aBorder.left = BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips,
00446                                             mLeftContBorderWidth);
00447   return;
00448 }
00449 #endif