1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
4 /* This Source Code is subject to the terms of the Mozilla Public License
5 * version 2.0 (the "License"). You can obtain a copy of the License at
6 * http://mozilla.org/MPL/2.0/. */
8 /* rendering object for CSS "display: flex" */
10 #ifndef nsFlexContainerFrame_h___
11 #define nsFlexContainerFrame_h___
13 #include "nsContainerFrame.h"
16 template <class T
> class LinkedList
;
19 nsContainerFrame
* NS_NewFlexContainerFrame(nsIPresShell
* aPresShell
,
20 nsStyleContext
* aContext
);
22 typedef nsContainerFrame nsFlexContainerFrameSuper
;
24 class nsFlexContainerFrame
: public nsFlexContainerFrameSuper
{
26 NS_DECL_FRAMEARENA_HELPERS
27 NS_DECL_QUERYFRAME_TARGET(nsFlexContainerFrame
)
31 friend nsContainerFrame
* NS_NewFlexContainerFrame(nsIPresShell
* aPresShell
,
32 nsStyleContext
* aContext
);
34 // Forward-decls of helper classes
37 class FlexboxAxisTracker
;
41 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
42 const nsRect
& aDirtyRect
,
43 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
45 virtual void Reflow(nsPresContext
* aPresContext
,
46 nsHTMLReflowMetrics
& aDesiredSize
,
47 const nsHTMLReflowState
& aReflowState
,
48 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
51 GetMinISize(nsRenderingContext
* aRenderingContext
) MOZ_OVERRIDE
;
53 GetPrefISize(nsRenderingContext
* aRenderingContext
) MOZ_OVERRIDE
;
55 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
56 #ifdef DEBUG_FRAME_DUMP
57 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
59 // Flexbox-specific public methods
63 // Protected constructor & destructor
64 explicit nsFlexContainerFrame(nsStyleContext
* aContext
) :
65 nsFlexContainerFrameSuper(aContext
)
67 virtual ~nsFlexContainerFrame();
70 * This method does the bulk of the flex layout, implementing the algorithm
72 * http://dev.w3.org/csswg/css-flexbox/#layout-algorithm
73 * (with a few initialization pieces happening in the caller, Reflow().
75 * Since this is a helper for Reflow(), this takes all the same parameters
76 * as Reflow(), plus a few more parameters that Reflow() sets up for us.
78 * (The logic behind the division of work between Reflow and DoFlexLayout is
79 * as follows: DoFlexLayout() begins at the step that we have to jump back
80 * to, if we find any visibility:collapse children, and Reflow() does
81 * everything before that point.)
83 void DoFlexLayout(nsPresContext
* aPresContext
,
84 nsHTMLReflowMetrics
& aDesiredSize
,
85 const nsHTMLReflowState
& aReflowState
,
86 nsReflowStatus
& aStatus
,
87 nscoord aContentBoxMainSize
,
88 nscoord aAvailableHeightForContent
,
89 nsTArray
<StrutInfo
>& aStruts
,
90 const FlexboxAxisTracker
& aAxisTracker
);
93 * Checks whether our child-frame list "mFrames" is sorted, using the given
94 * IsLessThanOrEqual function, and sorts it if it's not already sorted.
96 * XXXdholbert Once we support pagination, we need to make this function
97 * check our continuations as well (or wrap it in a function that does).
99 * @return true if we had to sort mFrames, false if it was already sorted.
101 template<bool IsLessThanOrEqual(nsIFrame
*, nsIFrame
*)>
102 bool SortChildrenIfNeeded();
104 // Protected flex-container-specific methods / member-vars
106 void SanityCheckAnonymousFlexItems() const;
110 * Returns a new FlexItem for the given child frame, allocated on the heap.
111 * Guaranteed to return non-null. Caller is responsible for managing the
112 * FlexItem's lifetime.
114 * Before returning, this method also processes the FlexItem to resolve its
115 * flex basis (including e.g. auto-height) as well as to resolve
116 * "min-height:auto", via ResolveAutoFlexBasisAndMinSize(). (Basically, the
117 * returned FlexItem will be ready to participate in the "Resolve the
118 * Flexible Lengths" step of the Flex Layout Algorithm.)
120 FlexItem
* GenerateFlexItemForChild(nsPresContext
* aPresContext
,
121 nsIFrame
* aChildFrame
,
122 const nsHTMLReflowState
& aParentReflowState
,
123 const FlexboxAxisTracker
& aAxisTracker
);
126 * This method performs a "measuring" reflow to get the content height of
127 * aFlexItem.Frame() (treating it as if it had auto-height), & returns the
129 * (Helper for ResolveAutoFlexBasisAndMinSize().)
131 nscoord
MeasureFlexItemContentHeight(nsPresContext
* aPresContext
,
133 bool aForceVerticalResizeForMeasuringReflow
,
134 const nsHTMLReflowState
& aParentReflowState
);
137 * This method resolves an "auto" flex-basis and/or min-main-size value
138 * on aFlexItem, if needed.
139 * (Helper for GenerateFlexItemForChild().)
141 void ResolveAutoFlexBasisAndMinSize(nsPresContext
* aPresContext
,
143 const nsHTMLReflowState
& aItemReflowState
,
144 const FlexboxAxisTracker
& aAxisTracker
);
146 // Creates FlexItems for all of our child frames, arranged in a list of
147 // FlexLines. These are returned by reference in |aLines|. Our actual
148 // return value has to be |nsresult|, in case we have to reflow a child
149 // to establish its flex base size and that reflow fails.
150 void GenerateFlexLines(nsPresContext
* aPresContext
,
151 const nsHTMLReflowState
& aReflowState
,
152 nscoord aContentBoxMainSize
,
153 nscoord aAvailableHeightForContent
,
154 const nsTArray
<StrutInfo
>& aStruts
,
155 const FlexboxAxisTracker
& aAxisTracker
,
156 mozilla::LinkedList
<FlexLine
>& aLines
);
158 nscoord
GetMainSizeFromReflowState(const nsHTMLReflowState
& aReflowState
,
159 const FlexboxAxisTracker
& aAxisTracker
);
161 nscoord
ComputeCrossSize(const nsHTMLReflowState
& aReflowState
,
162 const FlexboxAxisTracker
& aAxisTracker
,
163 nscoord aSumLineCrossSizes
,
164 nscoord aAvailableHeightForContent
,
166 nsReflowStatus
& aStatus
);
168 void SizeItemInCrossAxis(nsPresContext
* aPresContext
,
169 const FlexboxAxisTracker
& aAxisTracker
,
170 nsHTMLReflowState
& aChildReflowState
,
173 bool mChildrenHaveBeenReordered
; // Have we ever had to reorder our kids
174 // to satisfy their 'order' values?
177 #endif /* nsFlexContainerFrame_h___ */