Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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/. */
6 #ifndef nsSprocketLayout_h___
7 #define nsSprocketLayout_h___
9 #include "mozilla/Attributes.h"
10 #include "nsBoxLayout.h"
11 #include "nsCOMPtr.h"
12 #include "nsIFrame.h"
14 class nsBoxSize
15 {
16 public:
18 nsBoxSize();
20 nscoord pref;
21 nscoord min;
22 nscoord max;
23 nscoord flex;
24 nscoord left;
25 nscoord right;
26 bool collapsed;
27 bool bogus;
29 nsBoxSize* next;
31 void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
32 void operator delete(void* aPtr, size_t sz);
33 };
35 class nsComputedBoxSize
36 {
37 public:
38 nsComputedBoxSize();
40 nscoord size;
41 bool valid;
42 bool resized;
43 nsComputedBoxSize* next;
45 void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
46 void operator delete(void* aPtr, size_t sz);
47 };
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)
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); }
60 #define SET_COORD(aX, aY, coord, isHorizontal) if (isHorizontal) { aX = (coord); } else { aY = (coord); }
62 nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsBoxLayout>& aNewLayout);
64 class nsSprocketLayout : public nsBoxLayout {
66 public:
68 friend nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsBoxLayout>& aNewLayout);
69 static void Shutdown();
71 NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState) MOZ_OVERRIDE;
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;
78 nsSprocketLayout();
80 static bool IsHorizontal(nsIFrame* aBox);
82 static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal);
83 static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal);
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);
89 protected:
92 void ComputeChildsNextPosition(nsIFrame* aBox,
93 const nscoord& aCurX,
94 const nscoord& aCurY,
95 nscoord& aNextX,
96 nscoord& aNextY,
97 const nsRect& aChildSize);
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);
112 void AlignChildren(nsIFrame* aBox,
113 nsBoxLayoutState& aState);
115 virtual void ComputeChildSizes(nsIFrame* aBox,
116 nsBoxLayoutState& aState,
117 nscoord& aGivenSize,
118 nsBoxSize* aBoxSizes,
119 nsComputedBoxSize*& aComputedBoxSizes);
122 virtual void PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState,
123 nsBoxSize*& aBoxSizes, nscoord& aMinSize,
124 nscoord& aMaxSize, int32_t& aFlexes);
126 virtual void InvalidateComputedSizes(nsComputedBoxSize* aComputedBoxSizes);
128 virtual bool GetDefaultFlex(int32_t& aFlex);
130 virtual void GetFrameState(nsIFrame* aBox, nsFrameState& aState);
132 private:
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;
139 };
141 #endif