1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsSprocketLayout_h___
8 #define nsSprocketLayout_h___
10 #include "mozilla/Attributes.h"
11 #include "nsBoxLayout.h"
13 #include "nsFrameState.h"
33 void* operator new(size_t sz
, nsBoxLayoutState
& aState
) noexcept(true);
34 void operator delete(void* aPtr
, size_t sz
);
37 class nsComputedBoxSize
{
44 nsComputedBoxSize
* next
;
46 void* operator new(size_t sz
, nsBoxLayoutState
& aState
) noexcept(true);
47 void operator delete(void* aPtr
, size_t sz
);
50 #define GET_WIDTH(size, isHorizontal) (isHorizontal ? size.width : size.height)
51 #define GET_HEIGHT(size, isHorizontal) (isHorizontal ? size.height : size.width)
52 #define GET_X(size, isHorizontal) (isHorizontal ? size.x : size.y)
53 #define GET_Y(size, isHorizontal) (isHorizontal ? size.y : size.x)
54 #define GET_COORD(aX, aY, isHorizontal) (isHorizontal ? aX : aY)
56 #define SET_WIDTH(size, coord, isHorizontal) \
58 (size).width = (coord); \
60 (size).height = (coord); \
62 #define SET_HEIGHT(size, coord, isHorizontal) \
64 (size).height = (coord); \
66 (size).width = (coord); \
68 #define SET_X(size, coord, isHorizontal) \
74 #define SET_Y(size, coord, isHorizontal) \
81 #define SET_COORD(aX, aY, coord, isHorizontal) \
88 nsresult
NS_NewSprocketLayout(nsCOMPtr
<nsBoxLayout
>& aNewLayout
);
90 class nsSprocketLayout
: public nsBoxLayout
{
92 friend nsresult
NS_NewSprocketLayout(nsCOMPtr
<nsBoxLayout
>& aNewLayout
);
93 static void Shutdown();
95 NS_IMETHOD
XULLayout(nsIFrame
* aBox
, nsBoxLayoutState
& aState
) override
;
97 virtual nsSize
GetXULPrefSize(nsIFrame
* aBox
,
98 nsBoxLayoutState
& aBoxLayoutState
) override
;
99 virtual nsSize
GetXULMinSize(nsIFrame
* aBox
,
100 nsBoxLayoutState
& aBoxLayoutState
) override
;
101 virtual nsSize
GetXULMaxSize(nsIFrame
* aBox
,
102 nsBoxLayoutState
& aBoxLayoutState
) override
;
103 virtual nscoord
GetAscent(nsIFrame
* aBox
,
104 nsBoxLayoutState
& aBoxLayoutState
) override
;
108 static bool IsXULHorizontal(nsIFrame
* aBox
);
110 static void SetLargestSize(nsSize
& aSize1
, const nsSize
& aSize2
,
112 static void SetSmallestSize(nsSize
& aSize1
, const nsSize
& aSize2
,
115 static void AddLargestSize(nsSize
& aSize
, const nsSize
& aSizeToAdd
,
117 static void AddSmallestSize(nsSize
& aSize
, const nsSize
& aSizeToAdd
,
119 static void AddCoord(nscoord
& aCoord
, nscoord aCoordToAdd
);
122 void ComputeChildsNextPosition(nsIFrame
* aBox
, const nscoord
& aCurX
,
123 const nscoord
& aCurY
, nscoord
& aNextX
,
124 nscoord
& aNextY
, const nsRect
& aChildSize
);
126 void ChildResized(nsIFrame
* aBox
, nsBoxLayoutState
& aState
, nsIFrame
* aChild
,
127 nsBoxSize
* aChildBoxSize
,
128 nsComputedBoxSize
* aChildComputedBoxSize
,
129 nsBoxSize
* aBoxSizes
, nsComputedBoxSize
* aComputedBoxSizes
,
130 const nsRect
& aChildLayoutRect
, nsRect
& aChildActualRect
,
131 nsRect
& aContainingRect
, int32_t aFlexes
, bool& aFinished
);
133 void AlignChildren(nsIFrame
* aBox
, nsBoxLayoutState
& aState
);
135 virtual void ComputeChildSizes(nsIFrame
* aBox
, nsBoxLayoutState
& aState
,
136 nscoord
& aGivenSize
, nsBoxSize
* aBoxSizes
,
137 nsComputedBoxSize
*& aComputedBoxSizes
);
139 virtual void PopulateBoxSizes(nsIFrame
* aBox
,
140 nsBoxLayoutState
& aBoxLayoutState
,
141 nsBoxSize
*& aBoxSizes
, nscoord
& aMinSize
,
142 nscoord
& aMaxSize
, int32_t& aFlexes
);
144 virtual void InvalidateComputedSizes(nsComputedBoxSize
* aComputedBoxSizes
);
146 virtual bool GetDefaultFlex(int32_t& aFlex
);
148 virtual void GetFrameState(nsIFrame
* aBox
, nsFrameState
& aState
);
151 // because the sprocket layout manager has no instance variables. We
152 // can make a static one and reuse it everywhere.
153 static nsBoxLayout
* gInstance
;