layout/generic/nsFlexContainerFrame.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial