layout/xul/nsSprocketLayout.h

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:8fcba2f5d807
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 nsSprocketLayout_h___
7 #define nsSprocketLayout_h___
8
9 #include "mozilla/Attributes.h"
10 #include "nsBoxLayout.h"
11 #include "nsCOMPtr.h"
12 #include "nsIFrame.h"
13
14 class nsBoxSize
15 {
16 public:
17
18 nsBoxSize();
19
20 nscoord pref;
21 nscoord min;
22 nscoord max;
23 nscoord flex;
24 nscoord left;
25 nscoord right;
26 bool collapsed;
27 bool bogus;
28
29 nsBoxSize* next;
30
31 void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
32 void operator delete(void* aPtr, size_t sz);
33 };
34
35 class nsComputedBoxSize
36 {
37 public:
38 nsComputedBoxSize();
39
40 nscoord size;
41 bool valid;
42 bool resized;
43 nsComputedBoxSize* next;
44
45 void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
46 void operator delete(void* aPtr, size_t sz);
47 };
48
49 #define GET_WIDTH(size, isHorizontal) (isHorizontal ? size.width : size.height)
50 #define GET_HEIGHT(size, isHorizontal) (isHorizontal ? size.height : size.width)
51 #define GET_X(size, isHorizontal) (isHorizontal ? size.x : size.y)
52 #define GET_Y(size, isHorizontal) (isHorizontal ? size.y : size.x)
53 #define GET_COORD(aX, aY, isHorizontal) (isHorizontal ? aX : aY)
54
55 #define SET_WIDTH(size, coord, isHorizontal) if (isHorizontal) { (size).width = (coord); } else { (size).height = (coord); }
56 #define SET_HEIGHT(size, coord, isHorizontal) if (isHorizontal) { (size).height = (coord); } else { (size).width = (coord); }
57 #define SET_X(size, coord, isHorizontal) if (isHorizontal) { (size).x = (coord); } else { (size).y = (coord); }
58 #define SET_Y(size, coord, isHorizontal) if (isHorizontal) { (size).y = (coord); } else { (size).x = (coord); }
59
60 #define SET_COORD(aX, aY, coord, isHorizontal) if (isHorizontal) { aX = (coord); } else { aY = (coord); }
61
62 nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsBoxLayout>& aNewLayout);
63
64 class nsSprocketLayout : public nsBoxLayout {
65
66 public:
67
68 friend nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsBoxLayout>& aNewLayout);
69 static void Shutdown();
70
71 NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState) MOZ_OVERRIDE;
72
73 virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
74 virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
75 virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
76 virtual nscoord GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
77
78 nsSprocketLayout();
79
80 static bool IsHorizontal(nsIFrame* aBox);
81
82 static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal);
83 static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal);
84
85 static void AddLargestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal);
86 static void AddSmallestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal);
87 static void AddCoord(nscoord& aCoord, nscoord aCoordToAdd);
88
89 protected:
90
91
92 void ComputeChildsNextPosition(nsIFrame* aBox,
93 const nscoord& aCurX,
94 const nscoord& aCurY,
95 nscoord& aNextX,
96 nscoord& aNextY,
97 const nsRect& aChildSize);
98
99 void ChildResized(nsIFrame* aBox,
100 nsBoxLayoutState& aState,
101 nsIFrame* aChild,
102 nsBoxSize* aChildBoxSize,
103 nsComputedBoxSize* aChildComputedBoxSize,
104 nsBoxSize* aBoxSizes,
105 nsComputedBoxSize* aComputedBoxSizes,
106 const nsRect& aChildLayoutRect,
107 nsRect& aChildActualRect,
108 nsRect& aContainingRect,
109 int32_t aFlexes,
110 bool& aFinished);
111
112 void AlignChildren(nsIFrame* aBox,
113 nsBoxLayoutState& aState);
114
115 virtual void ComputeChildSizes(nsIFrame* aBox,
116 nsBoxLayoutState& aState,
117 nscoord& aGivenSize,
118 nsBoxSize* aBoxSizes,
119 nsComputedBoxSize*& aComputedBoxSizes);
120
121
122 virtual void PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState,
123 nsBoxSize*& aBoxSizes, nscoord& aMinSize,
124 nscoord& aMaxSize, int32_t& aFlexes);
125
126 virtual void InvalidateComputedSizes(nsComputedBoxSize* aComputedBoxSizes);
127
128 virtual bool GetDefaultFlex(int32_t& aFlex);
129
130 virtual void GetFrameState(nsIFrame* aBox, nsFrameState& aState);
131
132 private:
133
134
135 // because the sprocket layout manager has no instance variables. We
136 // can make a static one and reuse it everywhere.
137 static nsBoxLayout* gInstance;
138
139 };
140
141 #endif
142

mercurial