Back to index

lightning-sunbird  0.9+nobinonly
nsBox.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 
00038 #ifndef nsBox_h___
00039 #define nsBox_h___
00040 
00041 #include "nsIFrame.h"
00042 
00043 class nsITheme;
00044 
00045 #define DEFAULT_ORDINAL_GROUP 1
00046 
00047 #define NS_STATE_IS_ROOT        0x01000000
00048 #define NS_STATE_SET_TO_DEBUG   0x04000000
00049 #define NS_STATE_DEBUG_WAS_SET  0x08000000
00050 #define NS_STATE_STYLE_CHANGE   0x20000000
00051 
00052 class nsBox : public nsIFrame {
00053 
00054 public:
00055 
00056   friend class nsIFrame;
00057 
00058   static void Shutdown();
00059 
00060   NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00061   NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00062   NS_IMETHOD GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00063   NS_IMETHOD GetFlex(nsBoxLayoutState& aBoxLayoutState, nscoord& aFlex);
00064   NS_IMETHOD GetAscent(nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent);
00065 
00066   virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState);
00067 
00068   NS_IMETHOD IsCollapsed(nsBoxLayoutState& aBoxLayoutState, PRBool& aCollapsed);
00069 
00070   NS_IMETHOD SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect,
00071                        PRBool aRemoveOverflowArea = PR_FALSE);
00072 
00073   NS_IMETHOD MarkDirty(nsBoxLayoutState& aState);
00074 
00075   NS_IMETHOD GetBorder(nsMargin& aBorderAndPadding);
00076   NS_IMETHOD GetPadding(nsMargin& aBorderAndPadding);
00077   NS_IMETHOD GetMargin(nsMargin& aMargin);
00078 
00079   NS_IMETHOD SetLayoutManager(nsIBoxLayout* aLayout);
00080   NS_IMETHOD GetLayoutManager(nsIBoxLayout** aLayout);
00081 
00082   NS_IMETHOD GetVAlign(Valignment& aAlign);
00083   NS_IMETHOD GetHAlign(Halignment& aAlign);
00084 
00085 
00086   NS_IMETHOD NeedsRecalc();
00087   NS_IMETHOD RelayoutDirtyChild(nsBoxLayoutState& aState, nsIBox* aChild);
00088   NS_IMETHOD RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIBox* aChild);
00089 
00090   NS_IMETHOD GetMouseThrough(PRBool& aMouseThrough);
00091 
00092   NS_IMETHOD MarkChildrenStyleChange();
00093   NS_IMETHOD MarkStyleChange(nsBoxLayoutState& aState);
00094 #ifdef DEBUG_LAYOUT
00095   NS_IMETHOD GetInset(nsMargin& aInset);
00096   NS_IMETHOD GetDebugBoxAt(const nsPoint& aPoint, nsIBox** aBox);
00097   NS_IMETHOD GetDebug(PRBool& aDebug);
00098   NS_IMETHOD SetDebug(nsBoxLayoutState& aState, PRBool aDebug);
00099 
00100   NS_IMETHOD DumpBox(FILE* out);
00101   NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState);
00102 #endif
00103   NS_IMETHOD ChildrenMustHaveWidgets(PRBool& aMust) const;
00104   NS_IMETHOD GetIndexOf(nsIBox* aChild, PRInt32* aIndex);
00105 
00106   nsBox();
00107   virtual ~nsBox();
00108 
00113   virtual PRBool DoesClipChildren();
00114   virtual PRBool ComputesOwnOverflowArea() = 0;
00115 
00116   NS_HIDDEN_(nsresult) SyncLayout(nsBoxLayoutState& aBoxLayoutState);
00117 
00118   PRBool DoesNeedRecalc(const nsSize& aSize);
00119   PRBool DoesNeedRecalc(nscoord aCoord);
00120   void SizeNeedsRecalc(nsSize& aSize);
00121   void CoordNeedsRecalc(nscoord& aCoord);
00122 
00123   void AddBorderAndPadding(nsSize& aSize);
00124   void AddInset(nsSize& aSize) { AddInset(this, aSize); }
00125   void AddMargin(nsSize& aSize);
00126 
00127   static void AddBorderAndPadding(nsIBox* aBox, nsSize& aSize);
00128 #ifdef DEBUG_LAYOUT
00129   static void AddInset(nsIBox* aBox, nsSize& aSize);
00130 #else
00131   static void AddInset(nsIBox* aBox, nsSize& aSize) {}
00132 #endif
00133   static void AddMargin(nsIBox* aChild, nsSize& aSize);
00134   static void AddMargin(nsSize& aSize, const nsMargin& aMargin);
00135 
00136   static void BoundsCheckMinMax(nsSize& aMinSize, nsSize& aMaxSize);
00137   static void BoundsCheck(nsSize& aMinSize, nsSize& aPrefSize, nsSize& aMaxSize);
00138   static void BoundsCheck(nscoord& aMinSize, nscoord& aPrefSize, nscoord& aMaxSize);
00139 
00140 protected:
00141 
00142 #ifdef DEBUG_LAYOUT
00143   virtual void AppendAttribute(const nsAutoString& aAttribute, const nsAutoString& aValue, nsAutoString& aResult);
00144 
00145   virtual void ListBox(nsAutoString& aResult);
00146 #endif
00147   
00148   virtual PRBool HasStyleChange();
00149   virtual void SetStyleChangeFlag(PRBool aDirty);
00150 
00151   virtual PRBool GetWasCollapsed(nsBoxLayoutState& aState);
00152   virtual void SetWasCollapsed(nsBoxLayoutState& aState, PRBool aWas);
00153   virtual PRBool GetDefaultFlex(PRInt32& aFlex);
00154   virtual void GetLayoutFlags(PRUint32& aFlags);
00155 
00156   NS_HIDDEN_(nsresult) BeginLayout(nsBoxLayoutState& aState);
00157   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
00158   NS_HIDDEN_(nsresult) EndLayout(nsBoxLayoutState& aState);
00159 
00160 #ifdef DEBUG_LAYOUT
00161   virtual void GetBoxName(nsAutoString& aName);
00162   NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState);
00163 #endif
00164 
00165   static PRBool gGotTheme;
00166   static nsITheme* gTheme;
00167 
00168   enum eMouseThrough {
00169     unset,
00170     never,
00171     always
00172   };
00173 
00174 private:
00175 
00176   //nscoord mX;
00177   //nscoord mY;
00178 };
00179 
00180 #ifdef DEBUG_LAYOUT
00181 #define NS_BOX_ASSERTION(box,expr,str) \
00182   if (!(expr)) { \
00183        box->DumpBox(stdout); \
00184        NSGlue_Assertion(str, #expr, __FILE__, __LINE__); \
00185   }
00186 #else
00187 #define NS_BOX_ASSERTION(box,expr,str) {}
00188 #endif
00189 
00190 #endif
00191