|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsBox_h___ |
|
7 #define nsBox_h___ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsIFrame.h" |
|
11 |
|
12 class nsITheme; |
|
13 |
|
14 class nsBox : public nsIFrame { |
|
15 |
|
16 public: |
|
17 |
|
18 friend class nsIFrame; |
|
19 |
|
20 static void Shutdown(); |
|
21 |
|
22 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
23 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
24 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
25 virtual nscoord GetFlex(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
26 virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
27 |
|
28 virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
29 |
|
30 virtual bool IsCollapsed() MOZ_OVERRIDE; |
|
31 |
|
32 virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, |
|
33 bool aRemoveOverflowAreas = false) MOZ_OVERRIDE; |
|
34 |
|
35 virtual nsresult GetBorder(nsMargin& aBorderAndPadding) MOZ_OVERRIDE; |
|
36 virtual nsresult GetPadding(nsMargin& aBorderAndPadding) MOZ_OVERRIDE; |
|
37 virtual nsresult GetMargin(nsMargin& aMargin) MOZ_OVERRIDE; |
|
38 |
|
39 virtual Valignment GetVAlign() const MOZ_OVERRIDE { return vAlign_Top; } |
|
40 virtual Halignment GetHAlign() const MOZ_OVERRIDE { return hAlign_Left; } |
|
41 |
|
42 virtual nsresult RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIFrame* aChild) MOZ_OVERRIDE; |
|
43 |
|
44 #ifdef DEBUG_LAYOUT |
|
45 NS_IMETHOD GetDebugBoxAt(const nsPoint& aPoint, nsIFrame** aBox); |
|
46 virtual nsresult GetDebug(bool& aDebug) MOZ_OVERRIDE; |
|
47 virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug) MOZ_OVERRIDE; |
|
48 |
|
49 virtual nsresult DumpBox(FILE* out) MOZ_OVERRIDE; |
|
50 NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState); |
|
51 #endif |
|
52 |
|
53 nsBox(); |
|
54 virtual ~nsBox(); |
|
55 |
|
56 /** |
|
57 * Returns true if this box clips its children, e.g., if this box is an sc |
|
58 rollbox. |
|
59 */ |
|
60 virtual bool DoesClipChildren(); |
|
61 virtual bool ComputesOwnOverflowArea() = 0; |
|
62 |
|
63 NS_HIDDEN_(nsresult) SyncLayout(nsBoxLayoutState& aBoxLayoutState); |
|
64 |
|
65 bool DoesNeedRecalc(const nsSize& aSize); |
|
66 bool DoesNeedRecalc(nscoord aCoord); |
|
67 void SizeNeedsRecalc(nsSize& aSize); |
|
68 void CoordNeedsRecalc(nscoord& aCoord); |
|
69 |
|
70 void AddBorderAndPadding(nsSize& aSize); |
|
71 |
|
72 static void AddBorderAndPadding(nsIFrame* aBox, nsSize& aSize); |
|
73 static void AddMargin(nsIFrame* aChild, nsSize& aSize); |
|
74 static void AddMargin(nsSize& aSize, const nsMargin& aMargin); |
|
75 |
|
76 static nsSize BoundsCheckMinMax(const nsSize& aMinSize, const nsSize& aMaxSize); |
|
77 static nsSize BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize); |
|
78 static nscoord BoundsCheck(nscoord aMinSize, nscoord aPrefSize, nscoord aMaxSize); |
|
79 |
|
80 protected: |
|
81 |
|
82 #ifdef DEBUG_LAYOUT |
|
83 virtual void AppendAttribute(const nsAutoString& aAttribute, const nsAutoString& aValue, nsAutoString& aResult); |
|
84 |
|
85 virtual void ListBox(nsAutoString& aResult); |
|
86 #endif |
|
87 |
|
88 virtual void GetLayoutFlags(uint32_t& aFlags); |
|
89 |
|
90 NS_HIDDEN_(nsresult) BeginLayout(nsBoxLayoutState& aState); |
|
91 NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState); |
|
92 NS_HIDDEN_(nsresult) EndLayout(nsBoxLayoutState& aState); |
|
93 |
|
94 #ifdef DEBUG_LAYOUT |
|
95 virtual void GetBoxName(nsAutoString& aName); |
|
96 NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState); |
|
97 #endif |
|
98 |
|
99 static bool gGotTheme; |
|
100 static nsITheme* gTheme; |
|
101 |
|
102 enum eMouseThrough { |
|
103 unset, |
|
104 never, |
|
105 always |
|
106 }; |
|
107 |
|
108 private: |
|
109 |
|
110 //nscoord mX; |
|
111 //nscoord mY; |
|
112 }; |
|
113 |
|
114 #ifdef DEBUG_LAYOUT |
|
115 #define NS_BOX_ASSERTION(box,expr,str) \ |
|
116 if (!(expr)) { \ |
|
117 box->DumpBox(stdout); \ |
|
118 NS_DebugBreak(NSDebugAssertion, str, #expr, __FILE__, __LINE__); \ |
|
119 } |
|
120 #else |
|
121 #define NS_BOX_ASSERTION(box,expr,str) {} |
|
122 #endif |
|
123 |
|
124 #endif |
|
125 |