Back to index

lightning-sunbird  0.9+nobinonly
nsBoxFrame.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 Communicator client 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 
00046 #ifndef nsBoxFrame_h___
00047 #define nsBoxFrame_h___
00048 
00049 #include "nsCOMPtr.h"
00050 #include "nsContainerFrame.h"
00051 class nsBoxLayoutState;
00052 
00053 class nsHTMLReflowCommand;
00054 class nsHTMLInfo;
00055 
00056 // flags for box info
00057 #define NS_FRAME_BOX_SIZE_VALID    0x0001
00058 #define NS_FRAME_BOX_IS_COLLAPSED  0x0002
00059 #define NS_FRAME_BOX_NEEDS_RECALC  0x0004
00060 
00061 
00062 // flags from box
00063 #define NS_STATE_BOX_CHILD_RESERVED      0x00100000
00064 #define NS_STATE_STACK_NOT_POSITIONED    0x00200000
00065 //#define NS_STATE_IS_HORIZONTAL           0x00400000  moved to nsIFrame.h
00066 #define NS_STATE_AUTO_STRETCH            0x00800000
00067 //#define NS_STATE_IS_ROOT                 0x01000000  moved to nsIFrame.h
00068 #define NS_STATE_CURRENTLY_IN_DEBUG      0x02000000
00069 //#define NS_STATE_SET_TO_DEBUG            0x04000000  moved to nsIFrame.h
00070 //#define NS_STATE_DEBUG_WAS_SET           0x08000000  moved to nsIFrame.h
00071 #define NS_STATE_IS_COLLAPSED            0x10000000
00072 //#define NS_STATE_STYLE_CHANGE            0x20000000  moved to nsIFrame.h
00073 #define NS_STATE_EQUAL_SIZE              0x40000000
00074 //#define NS_STATE_IS_DIRECTION_NORMAL     0x80000000  moved to nsIFrame.h
00075 
00076 nsresult NS_NewBoxFrame(nsIPresShell* aPresShell, 
00077                         nsIFrame** aNewFrame, 
00078                         PRBool aIsRoot = PR_FALSE,
00079                         nsIBoxLayout* aLayoutManager = nsnull);
00080 
00081 class nsBoxFrame : public nsContainerFrame
00082 {
00083 public:
00084 
00085   friend nsresult NS_NewBoxFrame(nsIPresShell* aPresShell, 
00086                                  nsIFrame** aNewFrame, 
00087                                  PRBool aIsRoot,
00088                                  nsIBoxLayout* aLayoutManager);
00089 
00090   // gets the rect inside our border and debug border. If you wish to paint inside a box
00091   // call this method to get the rect so you don't draw on the debug border or outer border.
00092 
00093   // ------ nsISupports --------
00094 
00095   NS_DECL_ISUPPORTS_INHERITED
00096 
00097   // ------ nsIBox -------------
00098   NS_IMETHOD SetLayoutManager(nsIBoxLayout* aLayout);
00099   NS_IMETHOD GetLayoutManager(nsIBoxLayout** aLayout);
00100   NS_IMETHOD RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIBox* aChild);
00101   NS_IMETHOD GetIndexOf(nsIBox* aChild, PRInt32* aIndex);
00102 
00103   NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00104   NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00105   NS_IMETHOD GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00106   NS_IMETHOD GetFlex(nsBoxLayoutState& aBoxLayoutState, nscoord& aFlex);
00107   NS_IMETHOD GetAscent(nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent);
00108 #ifdef DEBUG_LAYOUT
00109   NS_IMETHOD SetDebug(nsBoxLayoutState& aBoxLayoutState, PRBool aDebug);
00110   NS_IMETHOD GetDebug(PRBool& aDebug);
00111 
00112   NS_IMETHOD GetInset(nsMargin& aInset);
00113 #endif
00114   NS_IMETHOD GetVAlign(Valignment& aAlign);
00115   NS_IMETHOD GetHAlign(Halignment& aAlign);
00116   NS_IMETHOD NeedsRecalc();
00117   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
00118 
00119   NS_IMETHOD GetMouseThrough(PRBool& aMouseThrough);
00120   virtual PRBool ComputesOwnOverflowArea() { return PR_FALSE; }
00121 
00122   // ----- child and sibling operations ---
00123 
00124   // ----- public methods -------
00125   
00126   NS_IMETHOD GetFrameForPoint(const nsPoint&    aPoint,
00127                               nsFramePaintLayer aWhichLayer,    
00128                               nsIFrame**        aFrame);
00129 
00130   NS_IMETHOD GetCursor(const nsPoint&    aPoint,
00131                        nsIFrame::Cursor& aCursor);
00132 
00133 
00134   NS_IMETHOD ReflowDirtyChild(nsIPresShell* aPresShell, nsIFrame* aChild);
00135 
00136   NS_IMETHOD  Init(nsPresContext*  aPresContext,
00137                    nsIContent*      aContent,
00138                    nsIFrame*        aParent,
00139                    nsStyleContext*  aContext,
00140                    nsIFrame*        asPrevInFlow);
00141 
00142  
00143   NS_IMETHOD AttributeChanged(nsIContent*     aChild,
00144                               PRInt32         aNameSpaceID,
00145                               nsIAtom*        aAttribute,
00146                               PRInt32         aModType);
00147 
00148 
00149   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
00150                     nsHTMLReflowMetrics&     aDesiredSize,
00151                     const nsHTMLReflowState& aReflowState,
00152                     nsReflowStatus&          aStatus);
00153 
00154   NS_IMETHOD  AppendFrames(nsIAtom*        aListName,
00155                            nsIFrame*       aFrameList);
00156 
00157   NS_IMETHOD  InsertFrames(nsIAtom*        aListName,
00158                            nsIFrame*       aPrevFrame,
00159                            nsIFrame*       aFrameList);
00160 
00161   NS_IMETHOD  RemoveFrame(nsIAtom*        aListName,
00162                           nsIFrame*       aOldFrame);
00163 
00164   NS_IMETHOD  SetInitialChildList(nsPresContext* aPresContext,
00165                                   nsIAtom*        aListName,
00166                                   nsIFrame*       aChildList);
00167 
00168   virtual nsIAtom* GetType() const;
00169 #ifdef DEBUG
00170   NS_IMETHOD GetFrameName(nsAString& aResult) const;
00171 #endif
00172 
00173   NS_IMETHOD DidReflow(nsPresContext*           aPresContext,
00174                        const nsHTMLReflowState*  aReflowState,
00175                        nsDidReflowStatus         aStatus);
00176 
00177   virtual ~nsBoxFrame();
00178 
00179   virtual nsresult GetContentOf(nsIContent** aContent);
00180   
00181   nsBoxFrame(nsIPresShell* aPresShell, PRBool aIsRoot = nsnull, nsIBoxLayout* aLayoutManager = nsnull);
00182  
00183   static nsresult CreateViewForFrame(nsPresContext* aPresContext,
00184                                      nsIFrame* aChild,
00185                                      nsStyleContext* aStyleContext,
00186                                      PRBool aForce);
00187 
00188   NS_IMETHOD  Paint(nsPresContext*      aPresContext,
00189                     nsIRenderingContext& aRenderingContext,
00190                     const nsRect&        aDirtyRect,
00191                     nsFramePaintLayer    aWhichLayer,
00192                     PRUint32             aFlags = 0);
00193 
00194 
00195   // returns true if it is an Initial Reflow and doing Print Preview
00196   static PRBool IsInitialReflowForPrintPreview(nsBoxLayoutState& aState, PRBool& aIsChrome);
00197 
00198   nsIBox* GetBoxAt(PRInt32 aIndex) { return mFrames.FrameAt(aIndex); }
00199   PRInt32 GetChildCount() { return mFrames.GetLength(); }
00200   
00201 #ifdef DEBUG_LAYOUT
00202     virtual void SetDebugOnChildList(nsBoxLayoutState& aState, nsIBox* aChild, PRBool aDebug);
00203 #endif
00204 
00205   static nsresult LayoutChildAt(nsBoxLayoutState& aState, nsIBox* aBox, const nsRect& aRect);
00206 
00207    // Fire DOM event. If no aContent argument use frame's mContent.
00208   void FireDOMEventSynch(const nsAString& aDOMEventName, nsIContent *aContent = nsnull);
00209  
00210 protected:
00211 #ifdef DEBUG_LAYOUT
00212     virtual void GetBoxName(nsAutoString& aName);
00213 #endif
00214 
00215     virtual PRBool HasStyleChange();
00216     virtual void SetStyleChangeFlag(PRBool aDirty);
00217 
00218     virtual PRBool GetWasCollapsed(nsBoxLayoutState& aState);
00219     virtual void SetWasCollapsed(nsBoxLayoutState& aState, PRBool aWas);
00220 
00221 
00222     // Paint one child frame
00223     virtual void PaintChild(nsPresContext*      aPresContext,
00224                             nsIRenderingContext& aRenderingContext,
00225                             const nsRect&        aDirtyRect,
00226                             nsIFrame*            aFrame,
00227                             nsFramePaintLayer    aWhichLayer,
00228                             PRUint32             aFlags = 0);
00229 
00230     virtual void PaintChildren(nsPresContext*      aPresContext,
00231                                nsIRenderingContext& aRenderingContext,
00232                                const nsRect&        aDirtyRect,
00233                                nsFramePaintLayer    aWhichLayer,
00234                                PRUint32             aFlags = 0);
00235 
00236     virtual PRBool GetInitialEqualSize(PRBool& aEqualSize); 
00237     virtual void GetInitialOrientation(PRBool& aIsHorizontal);
00238     virtual void GetInitialDirection(PRBool& aIsNormal);
00239     virtual PRBool GetInitialHAlignment(Halignment& aHalign); 
00240     virtual PRBool GetInitialVAlignment(Valignment& aValign); 
00241     virtual PRBool GetInitialAutoStretch(PRBool& aStretch); 
00242   
00243     NS_IMETHOD  Destroy(nsPresContext* aPresContext);
00244 
00245     nsSize mPrefSize;
00246     nsSize mMinSize;
00247     nsSize mMaxSize;
00248     nscoord mFlex;
00249     nscoord mAscent;
00250 
00251     nsCOMPtr<nsIBoxLayout> mLayoutManager;
00252 
00253 protected:
00254     nsresult RegUnregAccessKey(nsPresContext* aPresContext,
00255                                PRBool aDoReg);
00256     virtual nsresult GetFrameForPointChild(const nsPoint&    aPoint,
00257                                            nsFramePaintLayer aWhichLayer,    
00258                                            nsIFrame*         aChild,
00259                                            PRBool            aCheckMouseThrough,
00260                                            nsIFrame**        aFrame);
00261 
00262   NS_HIDDEN_(void) CheckBoxOrder(nsBoxLayoutState& aState);
00263 
00264 private: 
00265 
00266     // helper methods
00267     void TranslateEventCoords(const nsPoint& aPoint,
00268                                     nsPoint& aResult);
00269 
00270     static PRBool AdjustTargetToScope(nsIFrame* aParent, nsIFrame*& aTargetFrame);
00271 
00272 
00273 
00274 
00275 #ifdef DEBUG_LAYOUT
00276     nsresult SetDebug(nsPresContext* aPresContext, PRBool aDebug);
00277     PRBool GetInitialDebug(PRBool& aDebug);
00278     void GetDebugPref(nsPresContext* aPresContext);
00279 
00280     nsresult DisplayDebugInfoFor(nsIBox*         aBox, 
00281                                  nsPresContext* aPresContext,
00282                                  nsPoint&        aPoint,
00283                                  PRInt32&        aCursor);
00284 
00285     void GetDebugBorder(nsMargin& aInset);
00286     void GetDebugPadding(nsMargin& aInset);
00287     void GetDebugMargin(nsMargin& aInset);
00288 
00289 #endif
00290 
00291     nsresult GetFrameSizeWithMargin(nsIBox* aBox, nsSize& aSize);
00292 
00293     void PixelMarginToTwips(nsPresContext* aPresContext, nsMargin& aMarginPixels);
00294 
00295 #ifdef DEBUG_LAYOUT
00296     void GetValue(nsPresContext* aPresContext, const nsSize& a, const nsSize& b, char* value);
00297     void GetValue(nsPresContext* aPresContext, PRInt32 a, PRInt32 b, char* value);
00298 #endif
00299     void DrawSpacer(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext, PRBool aHorizontal, PRInt32 flex, nscoord x, nscoord y, nscoord size, nscoord spacerSize);
00300     void DrawLine(nsIRenderingContext& aRenderingContext,  PRBool aHorizontal, nscoord x1, nscoord y1, nscoord x2, nscoord y2);
00301     void FillRect(nsIRenderingContext& aRenderingContext,  PRBool aHorizontal, nscoord x, nscoord y, nscoord width, nscoord height);
00302     void UpdateMouseThrough();
00303 
00304     void CacheAttributes();
00305 
00306     nsIBox* GetBoxForFrame(nsIFrame* aFrame, PRBool& aIsAdaptor);
00307 
00308     // instance variables.
00309     Halignment mHalign;
00310     Valignment mValign;
00311 
00312     eMouseThrough mMouseThrough;
00313 
00314     nsPresContext* mPresContext;
00315 
00316 #ifdef DEBUG_LAYOUT
00317     static PRBool gDebug;
00318     static nsIBox* mDebugChild;
00319 #endif
00320 
00321 }; // class nsBoxFrame
00322 
00323 #endif
00324