Merge m-c to fx-team.
[gecko.git] / layout / generic / nsFlexContainerFrame.h
blob56b1134c1a221d2a19794973932af9bddaddcbe4
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"
15 nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
16 nsStyleContext* aContext);
18 typedef nsContainerFrame nsFlexContainerFrameSuper;
20 class FlexItem;
21 class FlexboxAxisTracker;
22 class MainAxisPositionTracker;
23 class SingleLineCrossAxisPositionTracker;
24 template <class T> class nsTArray;
26 class nsFlexContainerFrame : public nsFlexContainerFrameSuper {
27 NS_DECL_FRAMEARENA_HELPERS
28 NS_DECL_QUERYFRAME_TARGET(nsFlexContainerFrame)
29 NS_DECL_QUERYFRAME
31 // Factory method:
32 friend nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
33 nsStyleContext* aContext);
35 public:
36 // nsIFrame overrides
37 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
38 const nsRect& aDirtyRect,
39 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
41 NS_IMETHOD Reflow(nsPresContext* aPresContext,
42 nsHTMLReflowMetrics& aDesiredSize,
43 const nsHTMLReflowState& aReflowState,
44 nsReflowStatus& aStatus) MOZ_OVERRIDE;
46 virtual nscoord
47 GetMinWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
48 virtual nscoord
49 GetPrefWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
51 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
52 #ifdef DEBUG
53 NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
54 #endif // DEBUG
55 // Flexbox-specific public methods
56 bool IsHorizontal();
58 protected:
59 // Protected constructor & destructor
60 nsFlexContainerFrame(nsStyleContext* aContext) :
61 nsFlexContainerFrameSuper(aContext),
62 mChildrenHaveBeenReordered(false)
64 virtual ~nsFlexContainerFrame();
66 /**
67 * Checks whether our child-frame list "mFrames" is sorted, using the given
68 * IsLessThanOrEqual function, and sorts it if it's not already sorted.
70 * XXXdholbert Once we support pagination, we need to make this function
71 * check our continuations as well (or wrap it in a function that does).
73 * @return true if we had to sort mFrames, false if it was already sorted.
75 template<bool IsLessThanOrEqual(nsIFrame*, nsIFrame*)>
76 bool SortChildrenIfNeeded();
78 // Protected flex-container-specific methods / member-vars
79 #ifdef DEBUG
80 void SanityCheckAnonymousFlexItems() const;
81 #endif // DEBUG
83 FlexItem GenerateFlexItemForChild(nsPresContext* aPresContext,
84 nsIFrame* aChildFrame,
85 const nsHTMLReflowState& aParentReflowState,
86 const FlexboxAxisTracker& aAxisTracker);
88 // Returns nsresult because we might have to reflow aFlexItem.Frame() (to
89 // get its vertical intrinsic size in a vertical flexbox), and if that
90 // reflow fails (returns a failure nsresult), we want to bail out.
91 nsresult ResolveFlexItemMaxContentSizing(nsPresContext* aPresContext,
92 FlexItem& aFlexItem,
93 const nsHTMLReflowState& aParentReflowState,
94 const FlexboxAxisTracker& aAxisTracker);
96 // Runs the "resolve the flexible lengths" algorithm, distributing
97 // |aFlexContainerMainSize| among the |aItems| and freezing them.
98 void ResolveFlexibleLengths(const FlexboxAxisTracker& aAxisTracker,
99 nscoord aFlexContainerMainSize,
100 nsTArray<FlexItem>& aItems);
102 nsresult GenerateFlexItems(nsPresContext* aPresContext,
103 const nsHTMLReflowState& aReflowState,
104 const FlexboxAxisTracker& aAxisTracker,
105 nsTArray<FlexItem>& aItems);
107 nscoord ComputeFlexContainerMainSize(const nsHTMLReflowState& aReflowState,
108 const FlexboxAxisTracker& aAxisTracker,
109 const nsTArray<FlexItem>& aFlexItems);
111 void PositionItemInMainAxis(MainAxisPositionTracker& aMainAxisPosnTracker,
112 FlexItem& aItem);
114 nsresult SizeItemInCrossAxis(nsPresContext* aPresContext,
115 const FlexboxAxisTracker& aAxisTracker,
116 nsHTMLReflowState& aChildReflowState,
117 FlexItem& aItem);
119 void PositionItemInCrossAxis(
120 nscoord aLineStartPosition,
121 SingleLineCrossAxisPositionTracker& aLineCrossAxisPosnTracker,
122 FlexItem& aItem);
124 bool mChildrenHaveBeenReordered; // Have we ever had to reorder our kids
125 // to satisfy their 'order' values?
128 #endif /* nsFlexContainerFrame_h___ */