Back to index

lightning-sunbird  0.9+nobinonly
nsTableOuterFrame.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 nsTableOuterFrame_h__
00038 #define nsTableOuterFrame_h__
00039 
00040 #include "nscore.h"
00041 #include "nsHTMLContainerFrame.h"
00042 #include "nsBlockFrame.h"
00043 #include "nsITableLayout.h"
00044 
00045 #ifdef DEBUG_TABLE_REFLOW_TIMING
00046 class nsReflowTimer;
00047 #endif
00048 
00049 struct nsStyleTable;
00050 class nsTableFrame;
00051 
00052 class nsTableCaptionFrame : public nsBlockFrame
00053 {
00054 public:
00055   // nsISupports
00056   virtual nsIAtom* GetType() const;
00057   friend nsresult NS_NewTableCaptionFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
00058 
00059 protected:
00060   nsTableCaptionFrame();
00061   virtual ~nsTableCaptionFrame();
00062 };
00063 
00064 
00065 /* TODO
00066 1. decide if we'll allow subclassing.  If so, decide which methods really need to be virtual.
00067 */
00068 
00074 class nsTableOuterFrame : public nsHTMLContainerFrame, public nsITableLayout
00075 {
00076 public:
00077 
00078   // nsISupports
00079   NS_DECL_ISUPPORTS_INHERITED
00080 
00087   friend nsresult NS_NewTableOuterFrame(nsIPresShell* aPresShell, nsIFrame** aResult);
00088   
00089   // nsIFrame overrides - see there for a description
00090 
00091   NS_IMETHOD Init(nsPresContext*  aPresContext,
00092                   nsIContent*      aContent,
00093                   nsIFrame*        aParent,
00094                   nsStyleContext*  aContext,
00095                   nsIFrame*        aPrevInFlow);
00096 
00097   NS_IMETHOD Destroy(nsPresContext* aPresContext);
00098   
00099   virtual PRBool IsContainingBlock() const;
00100 
00101   NS_IMETHOD SetInitialChildList(nsPresContext* aPresContext,
00102                                  nsIAtom*        aListName,
00103                                  nsIFrame*       aChildList);
00104  
00105   virtual nsIFrame* GetFirstChild(nsIAtom* aListName) const;
00106 
00107   virtual nsIAtom* GetAdditionalChildListName(PRInt32 aIndex) const;
00108 
00109   NS_IMETHOD AppendFrames(nsIAtom*        aListName,
00110                           nsIFrame*       aFrameList);
00111 
00112   NS_IMETHOD InsertFrames(nsIAtom*        aListName,
00113                           nsIFrame*       aPrevFrame,
00114                           nsIFrame*       aFrameList);
00115 
00116   NS_IMETHOD RemoveFrame(nsIAtom*        aListName,
00117                          nsIFrame*       aOldFrame);
00118 
00119   virtual nsIFrame* GetContentInsertionFrame() {
00120     return GetFirstChild(nsnull)->GetContentInsertionFrame();
00121   }
00122 
00123 #ifdef ACCESSIBILITY
00124   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
00125 #endif
00126 
00128   NS_IMETHOD Paint(nsPresContext*      aPresContext,
00129                    nsIRenderingContext& aRenderingContext,
00130                    const nsRect&        aDirtyRect,
00131                    nsFramePaintLayer    aWhichLayer,
00132                    PRUint32             aFlags = 0);
00133 
00134   // the outer table does not paint its entire background if it has margins and/or captions
00135   virtual PRBool CanPaintBackground() { return PR_FALSE; }
00136 
00137   NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, 
00138                               nsFramePaintLayer aWhichLayer,
00139                               nsIFrame**     aFrame);
00140 
00144   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
00145                     nsHTMLReflowMetrics&     aDesiredSize,
00146                     const nsHTMLReflowState& aReflowState,
00147                     nsReflowStatus&          aStatus);
00148 
00154   virtual nsIAtom* GetType() const;
00155 
00156 #ifdef DEBUG
00157   NS_IMETHOD GetFrameName(nsAString& aResult) const;
00158 #endif
00159 
00162   NS_IMETHOD SetSelected(nsPresContext* aPresContext,
00163                          nsIDOMRange *aRange,
00164                          PRBool aSelected,
00165                          nsSpread aSpread);
00166 
00170   nscoord GetMinCaptionWidth();
00171 
00172   NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext,
00173                                         nsIFrame**      aProviderFrame,
00174                                         PRBool*         aIsChild);
00175 
00176   /*---------------- nsITableLayout methods ------------------------*/
00177 
00179   NS_IMETHOD GetCellDataAt(PRInt32 aRowIndex, PRInt32 aColIndex, 
00180                            nsIDOMElement* &aCell,   //out params
00181                            PRInt32& aStartRowIndex, PRInt32& aStartColIndex, 
00182                            PRInt32& aRowSpan, PRInt32& aColSpan,
00183                            PRInt32& aActualRowSpan, PRInt32& aActualColSpan,
00184                            PRBool& aIsSelected);
00185 
00187   NS_IMETHOD GetTableSize(PRInt32& aRowCount, PRInt32& aColCount);
00188 
00189   static void ZeroAutoMargin(nsHTMLReflowState& aReflowState,
00190                              nsMargin&          aMargin);
00191 
00192   PRBool IsNested(const nsHTMLReflowState& aReflowState) const;
00193 
00194   static PRBool IsAutoWidth(nsIFrame& aTableOrCaption,
00195                             PRBool*   aIsPctWidth = nsnull);
00196 
00197 protected:
00198 
00199 
00200   nsTableOuterFrame();
00201   virtual ~nsTableOuterFrame();
00202 
00203   void InitChildReflowState(nsPresContext&    aPresContext,                     
00204                             nsHTMLReflowState& aReflowState);
00205 
00209   virtual PRIntn GetSkipSides() const;
00210 
00214   NS_IMETHOD VerifyTree() const;
00215 
00229   virtual void DeleteChildsNextInFlow(nsPresContext* aPresContext, nsIFrame* aChild);
00230 
00231 // begin Incremental Reflow methods
00232 
00234   NS_IMETHOD IncrementalReflow(nsPresContext*          aPresContext,
00235                                nsHTMLReflowMetrics&     aDesiredSize,
00236                                const nsHTMLReflowState& aReflowState,
00237                                nsReflowStatus&          aStatus);
00238 
00240   NS_IMETHOD IR_TargetIsChild(nsPresContext*          aPresContext,
00241                               nsHTMLReflowMetrics&     aDesiredSize,
00242                               const nsHTMLReflowState& aReflowState,
00243                               nsReflowStatus&          aStatus,
00244                               nsIFrame *               aNextFrame);
00245 
00247   NS_IMETHOD IR_TargetIsInnerTableFrame(nsPresContext*          aPresContext,
00248                                         nsHTMLReflowMetrics&     aDesiredSize,
00249                                         const nsHTMLReflowState& aReflowState,
00250                                         nsReflowStatus&          aStatus);
00251 
00253   NS_IMETHOD IR_TargetIsCaptionFrame(nsPresContext*          aPresContext,
00254                                      nsHTMLReflowMetrics&     aDesiredSize,
00255                                      const nsHTMLReflowState& aReflowState,
00256                                      nsReflowStatus&          aStatus);
00257 
00263   NS_IMETHOD IR_TargetIsMe(nsPresContext*          aPresContext,
00264                            nsHTMLReflowMetrics&     aDesiredSize,
00265                            const nsHTMLReflowState& aReflowState,
00266                            nsReflowStatus&          aStatus);
00267 
00269   NS_IMETHOD IR_InnerTableReflow(nsPresContext*          aPresContext,
00270                                  nsHTMLReflowMetrics&     aDesiredSize,
00271                                  const nsHTMLReflowState& aReflowState,
00272                                  nsReflowStatus&          aStatus);
00273 
00275   NS_IMETHOD IR_CaptionInserted(nsPresContext*          aPresContext,
00276                                 nsHTMLReflowMetrics&     aDesiredSize,
00277                                 const nsHTMLReflowState& aReflowState,
00278                                 nsReflowStatus&          aStatus);
00279 
00281   NS_IMETHOD IR_ReflowDirty(nsPresContext*          aPresContext,
00282                             nsHTMLReflowMetrics&     aDesiredSize,
00283                             const nsHTMLReflowState& aReflowState,
00284                             nsReflowStatus&          aStatus);
00285 
00289   PRBool IR_CaptionChangedAxis(const nsStyleTable* aOldStyle, 
00290                                const nsStyleTable* aNewStyle) const;
00291 
00292   // end Incremental Reflow methods
00293 
00294   nscoord GetMaxElementWidth(PRUint8         aCaptionSide,
00295                              const nsMargin& aInnerMargin,
00296                              const nsMargin& aInnerPadding,
00297                              const nsMargin& aCaptionMargin);
00298 
00299   nscoord GetMaxWidth(PRUint8         aCaptionSide,
00300                       const nsMargin& aInnerMargin,
00301                       const nsMargin& aCaptionMargin);
00302 
00303   PRUint8 GetCaptionSide();
00304   
00305   PRUint8 GetCaptionVerticalAlign();
00306 
00307   void SetDesiredSize(PRUint8         aCaptionSide,
00308                       const nsMargin& aInnerMargin,
00309                       const nsMargin& aCaptionMargin,
00310                       nscoord         aAvailWidth,
00311                       nscoord&        aWidth,
00312                       nscoord&        aHeight);
00313 
00314   void PctAdjustMinCaptionWidth(nsPresContext*           aPresContext,
00315                                 const nsHTMLReflowState&  aOuterRS,
00316                                 PRUint8                   aCaptionSide,
00317                                 nscoord&                  capMin);
00318 
00319   void BalanceLeftRightCaption(PRUint8         aCaptionSide,
00320                                const nsMargin& aInnerMargin, 
00321                                const nsMargin& aCaptionMargin,
00322                                nscoord&        aInnerWidth,
00323                                nscoord&        aCaptionWidth);
00324 
00325   NS_IMETHOD GetCaptionOrigin(nsPresContext*  aPresContext,
00326                               PRUint32         aCaptionSide,
00327                               const nsSize&    aContainBlockSize,
00328                               const nsSize&    aInnerSize, 
00329                               const nsMargin&  aInnerMargin,
00330                               const nsSize&    aCaptionSize,
00331                               nsMargin&        aCaptionMargin,
00332                               nsPoint&         aOrigin);
00333 
00334   NS_IMETHOD GetInnerOrigin(nsPresContext*  aPresContext,
00335                             PRUint32         aCaptionSide,
00336                             const nsSize&    aContainBlockSize,
00337                             const nsSize&    aCaptionSize, 
00338                             const nsMargin&  aCaptionMargin,
00339                             const nsSize&    aInnerSize,
00340                             nsMargin&        aInnerMargin,
00341                             nsPoint&         aOrigin);
00342   // Get the available width for the caption, aInnerMarginNoAuto is aInnerMargin, but with 
00343   // auto margins set to 0
00344   nscoord GetCaptionAvailWidth(nsPresContext*          aPresContext,
00345                                nsIFrame*                aCaptionFrame,
00346                                const nsHTMLReflowState& aReflowState,
00347                                nsMargin&                aCaptionMargin,
00348                                nsMargin&                aCaptionPad,
00349                                nscoord*                 aInnerWidth        = nsnull,
00350                                const nsMargin*          aInnerMarginNoAuto = nsnull,
00351                                const nsMargin*          aInnerMargin       = nsnull);
00352 
00353   nscoord GetInnerTableAvailWidth(nsPresContext*          aPresContext,
00354                                   nsIFrame*                aInnerTable,
00355                                   const nsHTMLReflowState& aOuterRS,
00356                                   nscoord*                 aCaptionWidth,
00357                                   nsMargin&                aInnerMargin,
00358                                   nsMargin&                aInnerPadding);
00359   
00360   // reflow the child (caption or innertable frame),aMarginNoAuto is aMargin, 
00361   // but with auto margins set to 0 
00362   NS_IMETHOD OuterReflowChild(nsPresContext*           aPresContext,
00363                               nsIFrame*                 aChildFrame,
00364                               const nsHTMLReflowState&  aOuterRS,
00365                               nsHTMLReflowMetrics&      aMetrics,
00366                               nscoord                   aAvailWidth,
00367                               nsSize&                   aDesiredSize,
00368                               nsMargin&                 aMargin,
00369                               nsMargin&                 aMarginNoAuto,
00370                               nsMargin&                 aPadding,
00371                               nsReflowReason            aReflowReason,
00372                               nsReflowStatus&           aStatus,
00373                               PRBool*                   aNeedToReflowCaption = nsnull);
00374 
00375   // Set the reflow metrics,  aInnerMarginNoAuto is  aInnerMargin, but with 
00376   // auto margins set to 0
00377   // aCaptionMargionNoAuto is aCaptionMargin, but with auto margins set to 0
00378   void UpdateReflowMetrics(PRUint8              aCaptionSide,
00379                            nsHTMLReflowMetrics& aMet,
00380                            const nsMargin&      aInnerMargin,
00381                            const nsMargin&      aInnerMarginNoAuto,
00382                            const nsMargin&      aInnerPadding,
00383                            const nsMargin&      aCaptionMargin,
00384                            const nsMargin&      aCaptionMargionNoAuto,
00385                            const nscoord        aAvailWidth);
00386 
00387   void InvalidateDamage(PRUint8         aCaptionSide,
00388                         const nsSize&   aOuterSize,
00389                         PRBool          aInnerChanged,
00390                         PRBool          aCaptionChanged,
00391                         nsRect*         aOldOverflowArea);
00392   
00393   // Get the margin and padding, aMarginNoAuto is aMargin, but with auto 
00394   // margins set to 0
00395   void GetMarginPadding(nsPresContext*          aPresContext,                     
00396                         const nsHTMLReflowState& aOuterRS,
00397                         nsIFrame*                aChildFrame,
00398                         nscoord                  aAvailableWidth,
00399                         nsMargin&                aMargin,
00400                         nsMargin&                aMarginNoAuto,
00401                         nsMargin&                aPadding);
00402 
00403 private:
00404   // used to keep track of this frame's children. They are redundant with mFrames, but more convient
00405   nsTableFrame* mInnerTableFrame; 
00406   nsFrameList   mCaptionFrames;
00407   nsIFrame*     mCaptionFrame;
00408 
00409   // used to track caption max element size 
00410   PRInt32   mMinCaptionWidth;
00411   nscoord   mPriorAvailWidth;
00412 
00413 #ifdef DEBUG_TABLE_REFLOW_TIMING
00414 public:
00415   nsReflowTimer* mTimer;
00416 #endif
00417 };
00418 
00419 inline nscoord nsTableOuterFrame::GetMinCaptionWidth()
00420 { return mMinCaptionWidth; }
00421 
00422 inline PRIntn nsTableOuterFrame::GetSkipSides() const
00423 { return 0; }
00424 
00425 #endif
00426 
00427 
00428