Bug 1730256 [wpt PR 30555] - Move getWindowSegments to visualViewport.segments, a...
[gecko.git] / layout / xul / nsSprocketLayout.h
blobe1e7fe377eb6ab16280290fceacf673b5ed8f51b
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"
12 #include "nsCOMPtr.h"
13 #include "nsFrameState.h"
15 class nsIFrame;
16 struct nsRect;
18 class nsBoxSize {
19 public:
20 nsBoxSize();
22 nscoord pref;
23 nscoord min;
24 nscoord max;
25 nscoord flex;
26 nscoord left;
27 nscoord right;
28 bool collapsed;
29 bool bogus;
31 nsBoxSize* next;
33 void* operator new(size_t sz, nsBoxLayoutState& aState) noexcept(true);
34 void operator delete(void* aPtr, size_t sz);
37 class nsComputedBoxSize {
38 public:
39 nsComputedBoxSize();
41 nscoord size;
42 bool valid;
43 bool resized;
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) \
57 if (isHorizontal) { \
58 (size).width = (coord); \
59 } else { \
60 (size).height = (coord); \
62 #define SET_HEIGHT(size, coord, isHorizontal) \
63 if (isHorizontal) { \
64 (size).height = (coord); \
65 } else { \
66 (size).width = (coord); \
68 #define SET_X(size, coord, isHorizontal) \
69 if (isHorizontal) { \
70 (size).x = (coord); \
71 } else { \
72 (size).y = (coord); \
74 #define SET_Y(size, coord, isHorizontal) \
75 if (isHorizontal) { \
76 (size).y = (coord); \
77 } else { \
78 (size).x = (coord); \
81 #define SET_COORD(aX, aY, coord, isHorizontal) \
82 if (isHorizontal) { \
83 aX = (coord); \
84 } else { \
85 aY = (coord); \
88 nsresult NS_NewSprocketLayout(nsCOMPtr<nsBoxLayout>& aNewLayout);
90 class nsSprocketLayout : public nsBoxLayout {
91 public:
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;
106 nsSprocketLayout();
108 static bool IsXULHorizontal(nsIFrame* aBox);
110 static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2,
111 bool aIsHorizontal);
112 static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2,
113 bool aIsHorizontal);
115 static void AddLargestSize(nsSize& aSize, const nsSize& aSizeToAdd,
116 bool aIsHorizontal);
117 static void AddSmallestSize(nsSize& aSize, const nsSize& aSizeToAdd,
118 bool aIsHorizontal);
119 static void AddCoord(nscoord& aCoord, nscoord aCoordToAdd);
121 protected:
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);
150 private:
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;
156 #endif