layout/generic/nsFlexContainerFrame.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:6cb13b9c520f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3
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/. */
7
8 /* rendering object for CSS "display: flex" */
9
10 #ifndef nsFlexContainerFrame_h___
11 #define nsFlexContainerFrame_h___
12
13 #include "nsContainerFrame.h"
14
15 namespace mozilla {
16 template <class T> class LinkedList;
17 }
18
19 nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
20 nsStyleContext* aContext);
21
22 typedef nsContainerFrame nsFlexContainerFrameSuper;
23
24 class nsFlexContainerFrame : public nsFlexContainerFrameSuper {
25 public:
26 NS_DECL_FRAMEARENA_HELPERS
27 NS_DECL_QUERYFRAME_TARGET(nsFlexContainerFrame)
28 NS_DECL_QUERYFRAME
29
30 // Factory method:
31 friend nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
32 nsStyleContext* aContext);
33
34 // Forward-decls of helper classes
35 class FlexItem;
36 class FlexLine;
37 class FlexboxAxisTracker;
38 class StrutInfo;
39
40 // nsIFrame overrides
41 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
42 const nsRect& aDirtyRect,
43 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
44
45 virtual nsresult Reflow(nsPresContext* aPresContext,
46 nsHTMLReflowMetrics& aDesiredSize,
47 const nsHTMLReflowState& aReflowState,
48 nsReflowStatus& aStatus) MOZ_OVERRIDE;
49
50 virtual nscoord
51 GetMinWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
52 virtual nscoord
53 GetPrefWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
54
55 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
56 #ifdef DEBUG_FRAME_DUMP
57 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
58 #endif
59 // Flexbox-specific public methods
60 bool IsHorizontal();
61
62 protected:
63 // Protected constructor & destructor
64 nsFlexContainerFrame(nsStyleContext* aContext) :
65 nsFlexContainerFrameSuper(aContext)
66 {}
67 virtual ~nsFlexContainerFrame();
68
69 /*
70 * This method does the bulk of the flex layout, implementing the algorithm
71 * described at:
72 * http://dev.w3.org/csswg/css-flexbox/#layout-algorithm
73 * (with a few initialization pieces happening in the caller, Reflow().
74 *
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.
77 *
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.)
82 */
83 nsresult 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);
91
92 /**
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.
95 *
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).
98 *
99 * @return true if we had to sort mFrames, false if it was already sorted.
100 */
101 template<bool IsLessThanOrEqual(nsIFrame*, nsIFrame*)>
102 bool SortChildrenIfNeeded();
103
104 // Protected flex-container-specific methods / member-vars
105 #ifdef DEBUG
106 void SanityCheckAnonymousFlexItems() const;
107 #endif // DEBUG
108
109 // Returns a new FlexItem for the given child frame, allocated on the heap.
110 // Caller is responsible for managing the FlexItem's lifetime.
111 FlexItem* GenerateFlexItemForChild(nsPresContext* aPresContext,
112 nsIFrame* aChildFrame,
113 const nsHTMLReflowState& aParentReflowState,
114 const FlexboxAxisTracker& aAxisTracker);
115
116 // Returns nsresult because we might have to reflow aFlexItem.Frame() (to
117 // get its vertical intrinsic size in a vertical flexbox), and if that
118 // reflow fails (returns a failure nsresult), we want to bail out.
119 nsresult ResolveFlexItemMaxContentSizing(nsPresContext* aPresContext,
120 FlexItem& aFlexItem,
121 const nsHTMLReflowState& aParentReflowState,
122 const FlexboxAxisTracker& aAxisTracker);
123
124 // Creates FlexItems for all of our child frames, arranged in a list of
125 // FlexLines. These are returned by reference in |aLines|. Our actual
126 // return value has to be |nsresult|, in case we have to reflow a child
127 // to establish its flex base size and that reflow fails.
128 nsresult GenerateFlexLines(nsPresContext* aPresContext,
129 const nsHTMLReflowState& aReflowState,
130 nscoord aContentBoxMainSize,
131 nscoord aAvailableHeightForContent,
132 const nsTArray<StrutInfo>& aStruts,
133 const FlexboxAxisTracker& aAxisTracker,
134 mozilla::LinkedList<FlexLine>& aLines);
135
136 nscoord GetMainSizeFromReflowState(const nsHTMLReflowState& aReflowState,
137 const FlexboxAxisTracker& aAxisTracker);
138
139 nscoord ComputeCrossSize(const nsHTMLReflowState& aReflowState,
140 const FlexboxAxisTracker& aAxisTracker,
141 nscoord aSumLineCrossSizes,
142 nscoord aAvailableHeightForContent,
143 bool* aIsDefinite,
144 nsReflowStatus& aStatus);
145
146 nsresult SizeItemInCrossAxis(nsPresContext* aPresContext,
147 const FlexboxAxisTracker& aAxisTracker,
148 nsHTMLReflowState& aChildReflowState,
149 FlexItem& aItem);
150
151 bool mChildrenHaveBeenReordered; // Have we ever had to reorder our kids
152 // to satisfy their 'order' values?
153 };
154
155 #endif /* nsFlexContainerFrame_h___ */

mercurial