1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsBox_h___
39 : #define nsBox_h___
40 :
41 : #include "nsIFrame.h"
42 :
43 : class nsITheme;
44 :
45 : #define NS_STATE_IS_ROOT NS_FRAME_STATE_BIT(24)
46 : #define NS_STATE_SET_TO_DEBUG NS_FRAME_STATE_BIT(26)
47 : #define NS_STATE_DEBUG_WAS_SET NS_FRAME_STATE_BIT(27)
48 :
49 : class nsBox : public nsIFrame {
50 :
51 : public:
52 :
53 : friend class nsIFrame;
54 :
55 : static void Shutdown();
56 :
57 : virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState);
58 : virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState);
59 : virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState);
60 : virtual nscoord GetFlex(nsBoxLayoutState& aBoxLayoutState);
61 : virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState);
62 :
63 : virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState);
64 :
65 : virtual bool IsCollapsed();
66 :
67 : virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect,
68 : bool aRemoveOverflowAreas = false);
69 :
70 : NS_IMETHOD GetBorder(nsMargin& aBorderAndPadding);
71 : NS_IMETHOD GetPadding(nsMargin& aBorderAndPadding);
72 : NS_IMETHOD GetMargin(nsMargin& aMargin);
73 :
74 0 : virtual Valignment GetVAlign() const { return vAlign_Top; }
75 0 : virtual Halignment GetHAlign() const { return hAlign_Left; }
76 :
77 : NS_IMETHOD RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIBox* aChild);
78 :
79 : #ifdef DEBUG_LAYOUT
80 : NS_IMETHOD GetDebugBoxAt(const nsPoint& aPoint, nsIBox** aBox);
81 : NS_IMETHOD GetDebug(bool& aDebug);
82 : NS_IMETHOD SetDebug(nsBoxLayoutState& aState, bool aDebug);
83 :
84 : NS_IMETHOD DumpBox(FILE* out);
85 : NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState);
86 : #endif
87 :
88 : nsBox();
89 : virtual ~nsBox();
90 :
91 : /**
92 : * Returns true if this box clips its children, e.g., if this box is an sc
93 : rollbox.
94 : */
95 : virtual bool DoesClipChildren();
96 : virtual bool ComputesOwnOverflowArea() = 0;
97 :
98 : NS_HIDDEN_(nsresult) SyncLayout(nsBoxLayoutState& aBoxLayoutState);
99 :
100 : bool DoesNeedRecalc(const nsSize& aSize);
101 : bool DoesNeedRecalc(nscoord aCoord);
102 : void SizeNeedsRecalc(nsSize& aSize);
103 : void CoordNeedsRecalc(nscoord& aCoord);
104 :
105 : void AddBorderAndPadding(nsSize& aSize);
106 :
107 : static void AddBorderAndPadding(nsIBox* aBox, nsSize& aSize);
108 : static void AddMargin(nsIBox* aChild, nsSize& aSize);
109 : static void AddMargin(nsSize& aSize, const nsMargin& aMargin);
110 :
111 : static nsSize BoundsCheckMinMax(const nsSize& aMinSize, const nsSize& aMaxSize);
112 : static nsSize BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize);
113 : static nscoord BoundsCheck(nscoord aMinSize, nscoord aPrefSize, nscoord aMaxSize);
114 :
115 : protected:
116 :
117 : #ifdef DEBUG_LAYOUT
118 : virtual void AppendAttribute(const nsAutoString& aAttribute, const nsAutoString& aValue, nsAutoString& aResult);
119 :
120 : virtual void ListBox(nsAutoString& aResult);
121 : #endif
122 :
123 : virtual void GetLayoutFlags(PRUint32& aFlags);
124 :
125 : NS_HIDDEN_(nsresult) BeginLayout(nsBoxLayoutState& aState);
126 : NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
127 : NS_HIDDEN_(nsresult) EndLayout(nsBoxLayoutState& aState);
128 :
129 : #ifdef DEBUG_LAYOUT
130 : virtual void GetBoxName(nsAutoString& aName);
131 : NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState);
132 : #endif
133 :
134 : static bool gGotTheme;
135 : static nsITheme* gTheme;
136 :
137 : enum eMouseThrough {
138 : unset,
139 : never,
140 : always
141 : };
142 :
143 : private:
144 :
145 : //nscoord mX;
146 : //nscoord mY;
147 : };
148 :
149 : #ifdef DEBUG_LAYOUT
150 : #define NS_BOX_ASSERTION(box,expr,str) \
151 : if (!(expr)) { \
152 : box->DumpBox(stdout); \
153 : NS_DebugBreak(NSDebugAssertion, str, #expr, __FILE__, __LINE__); \
154 : }
155 : #else
156 : #define NS_BOX_ASSERTION(box,expr,str) {}
157 : #endif
158 :
159 : #endif
160 :
|