2012-06-26 15:12:13 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
|
|
|
|
/* This Source Code is subject to the terms of the Mozilla Public License
|
|
|
|
* version 2.0 (the "License"). You can obtain a copy of the License at
|
|
|
|
* http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-10-15 12:42:43 -07:00
|
|
|
/* rendering object for CSS "display: flex" */
|
2012-06-26 15:12:13 -07:00
|
|
|
|
|
|
|
#ifndef nsFlexContainerFrame_h___
|
|
|
|
#define nsFlexContainerFrame_h___
|
|
|
|
|
|
|
|
#include "nsContainerFrame.h"
|
2014-03-17 18:23:23 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
template <class T> class LinkedList;
|
2015-01-23 10:25:58 -08:00
|
|
|
class LogicalPoint;
|
2014-03-17 18:23:23 -07:00
|
|
|
}
|
2012-06-26 15:12:13 -07:00
|
|
|
|
2014-05-24 15:20:40 -07:00
|
|
|
nsContainerFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2012-06-26 15:12:13 -07:00
|
|
|
|
|
|
|
typedef nsContainerFrame nsFlexContainerFrameSuper;
|
|
|
|
|
|
|
|
class nsFlexContainerFrame : public nsFlexContainerFrameSuper {
|
2014-03-07 15:58:38 -08:00
|
|
|
public:
|
2012-06-26 15:12:13 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsFlexContainerFrame)
|
|
|
|
NS_DECL_QUERYFRAME
|
|
|
|
|
|
|
|
// Factory method:
|
2014-05-24 15:20:40 -07:00
|
|
|
friend nsContainerFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2012-06-26 15:12:13 -07:00
|
|
|
|
2014-01-21 14:51:58 -08:00
|
|
|
// Forward-decls of helper classes
|
2014-01-21 17:05:07 -08:00
|
|
|
class FlexItem;
|
|
|
|
class FlexLine;
|
|
|
|
class FlexboxAxisTracker;
|
2014-06-18 17:57:51 -07:00
|
|
|
struct StrutInfo;
|
2014-01-21 14:51:58 -08:00
|
|
|
|
2012-06-26 15:12:13 -07:00
|
|
|
// nsIFrame overrides
|
2013-02-14 03:12:27 -08:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
2015-03-21 09:28:04 -07:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2015-03-21 09:28:04 -07:00
|
|
|
nsReflowStatus& aStatus) override;
|
2012-09-29 23:38:46 -07:00
|
|
|
|
|
|
|
virtual nscoord
|
2015-03-21 09:28:04 -07:00
|
|
|
GetMinISize(nsRenderingContext* aRenderingContext) override;
|
2012-09-29 23:38:46 -07:00
|
|
|
virtual nscoord
|
2015-03-21 09:28:04 -07:00
|
|
|
GetPrefISize(nsRenderingContext* aRenderingContext) override;
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetType() const override;
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override;
|
2014-01-05 15:31:14 -08:00
|
|
|
#endif
|
2012-09-29 23:38:46 -07:00
|
|
|
// Flexbox-specific public methods
|
|
|
|
bool IsHorizontal();
|
2012-06-26 15:12:13 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Protected constructor & destructor
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit nsFlexContainerFrame(nsStyleContext* aContext) :
|
2014-03-07 15:58:38 -08:00
|
|
|
nsFlexContainerFrameSuper(aContext)
|
2012-09-29 23:38:46 -07:00
|
|
|
{}
|
2012-06-26 15:12:13 -07:00
|
|
|
virtual ~nsFlexContainerFrame();
|
|
|
|
|
2014-01-21 14:51:57 -08:00
|
|
|
/*
|
|
|
|
* This method does the bulk of the flex layout, implementing the algorithm
|
|
|
|
* described at:
|
|
|
|
* http://dev.w3.org/csswg/css-flexbox/#layout-algorithm
|
|
|
|
* (with a few initialization pieces happening in the caller, Reflow().
|
|
|
|
*
|
|
|
|
* Since this is a helper for Reflow(), this takes all the same parameters
|
|
|
|
* as Reflow(), plus a few more parameters that Reflow() sets up for us.
|
|
|
|
*
|
|
|
|
* (The logic behind the division of work between Reflow and DoFlexLayout is
|
|
|
|
* as follows: DoFlexLayout() begins at the step that we have to jump back
|
|
|
|
* to, if we find any visibility:collapse children, and Reflow() does
|
|
|
|
* everything before that point.)
|
|
|
|
*/
|
2014-06-13 08:37:02 -07:00
|
|
|
void DoFlexLayout(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
nscoord aContentBoxMainSize,
|
2015-05-12 13:34:22 -07:00
|
|
|
nscoord aAvailableBSizeForContent,
|
2014-06-13 08:37:02 -07:00
|
|
|
nsTArray<StrutInfo>& aStruts,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2014-01-21 14:51:57 -08:00
|
|
|
|
2012-12-26 12:17:52 -08:00
|
|
|
/**
|
|
|
|
* Checks whether our child-frame list "mFrames" is sorted, using the given
|
|
|
|
* IsLessThanOrEqual function, and sorts it if it's not already sorted.
|
|
|
|
*
|
|
|
|
* XXXdholbert Once we support pagination, we need to make this function
|
|
|
|
* check our continuations as well (or wrap it in a function that does).
|
|
|
|
*
|
|
|
|
* @return true if we had to sort mFrames, false if it was already sorted.
|
|
|
|
*/
|
|
|
|
template<bool IsLessThanOrEqual(nsIFrame*, nsIFrame*)>
|
|
|
|
bool SortChildrenIfNeeded();
|
|
|
|
|
2012-09-29 23:38:46 -07:00
|
|
|
// Protected flex-container-specific methods / member-vars
|
|
|
|
#ifdef DEBUG
|
|
|
|
void SanityCheckAnonymousFlexItems() const;
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2014-07-22 08:24:36 -07:00
|
|
|
/*
|
|
|
|
* Returns a new FlexItem for the given child frame, allocated on the heap.
|
|
|
|
* Guaranteed to return non-null. Caller is responsible for managing the
|
|
|
|
* FlexItem's lifetime.
|
|
|
|
*
|
|
|
|
* Before returning, this method also processes the FlexItem to resolve its
|
|
|
|
* flex basis (including e.g. auto-height) as well as to resolve
|
|
|
|
* "min-height:auto", via ResolveAutoFlexBasisAndMinSize(). (Basically, the
|
|
|
|
* returned FlexItem will be ready to participate in the "Resolve the
|
|
|
|
* Flexible Lengths" step of the Flex Layout Algorithm.)
|
|
|
|
*/
|
2014-03-17 18:23:23 -07:00
|
|
|
FlexItem* GenerateFlexItemForChild(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2013-10-31 19:39:02 -07:00
|
|
|
|
2014-07-22 08:24:36 -07:00
|
|
|
/**
|
|
|
|
* This method performs a "measuring" reflow to get the content height of
|
|
|
|
* aFlexItem.Frame() (treating it as if it had auto-height), & returns the
|
|
|
|
* resulting height.
|
|
|
|
* (Helper for ResolveAutoFlexBasisAndMinSize().)
|
|
|
|
*/
|
2014-07-22 08:24:36 -07:00
|
|
|
nscoord MeasureFlexItemContentHeight(nsPresContext* aPresContext,
|
|
|
|
FlexItem& aFlexItem,
|
|
|
|
bool aForceVerticalResizeForMeasuringReflow,
|
|
|
|
const nsHTMLReflowState& aParentReflowState);
|
|
|
|
|
2014-07-22 08:24:36 -07:00
|
|
|
/**
|
|
|
|
* This method resolves an "auto" flex-basis and/or min-main-size value
|
|
|
|
* on aFlexItem, if needed.
|
|
|
|
* (Helper for GenerateFlexItemForChild().)
|
|
|
|
*/
|
2014-07-22 08:24:36 -07:00
|
|
|
void ResolveAutoFlexBasisAndMinSize(nsPresContext* aPresContext,
|
|
|
|
FlexItem& aFlexItem,
|
2014-07-22 08:24:37 -07:00
|
|
|
const nsHTMLReflowState& aItemReflowState,
|
2014-07-22 08:24:36 -07:00
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2014-03-17 18:23:23 -07:00
|
|
|
// Creates FlexItems for all of our child frames, arranged in a list of
|
|
|
|
// FlexLines. These are returned by reference in |aLines|. Our actual
|
|
|
|
// return value has to be |nsresult|, in case we have to reflow a child
|
|
|
|
// to establish its flex base size and that reflow fails.
|
2014-06-13 08:37:02 -07:00
|
|
|
void GenerateFlexLines(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord aContentBoxMainSize,
|
2015-05-12 13:34:22 -07:00
|
|
|
nscoord aAvailableBSizeForContent,
|
2014-06-13 08:37:02 -07:00
|
|
|
const nsTArray<StrutInfo>& aStruts,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
mozilla::LinkedList<FlexLine>& aLines);
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2013-12-05 10:57:51 -08:00
|
|
|
nscoord GetMainSizeFromReflowState(const nsHTMLReflowState& aReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2013-12-06 13:38:49 -08:00
|
|
|
nscoord ComputeCrossSize(const nsHTMLReflowState& aReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
2014-02-06 17:04:52 -08:00
|
|
|
nscoord aSumLineCrossSizes,
|
2015-05-12 13:34:22 -07:00
|
|
|
nscoord aAvailableBSizeForContent,
|
2013-12-06 13:38:49 -08:00
|
|
|
bool* aIsDefinite,
|
|
|
|
nsReflowStatus& aStatus);
|
2013-11-21 10:20:01 -08:00
|
|
|
|
2014-06-13 08:37:02 -07:00
|
|
|
void SizeItemInCrossAxis(nsPresContext* aPresContext,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
nsHTMLReflowState& aChildReflowState,
|
|
|
|
FlexItem& aItem);
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2015-01-23 14:15:11 -08:00
|
|
|
/**
|
|
|
|
* Moves the given flex item's frame to the given LogicalPosition (modulo any
|
|
|
|
* relative positioning).
|
|
|
|
*
|
|
|
|
* This can be used in cases where we've already done a "measuring reflow"
|
|
|
|
* for the flex item at the correct size, and hence can skip its final reflow
|
|
|
|
* (but still need to move it to the right final position).
|
|
|
|
*
|
|
|
|
* @param aReflowState The flex container's reflow state.
|
|
|
|
* @param aItem The flex item whose frame should be moved.
|
|
|
|
* @param aFramePos The position where the flex item's frame should
|
|
|
|
* be placed. (pre-relative positioning)
|
|
|
|
* @param aContainerWidth The flex container's width (required by some methods
|
|
|
|
* that we call, to interpret aFramePos correctly).
|
|
|
|
*/
|
|
|
|
void MoveFlexItemToFinalPosition(const nsHTMLReflowState& aReflowState,
|
|
|
|
const FlexItem& aItem,
|
|
|
|
mozilla::LogicalPoint& aFramePos,
|
|
|
|
nscoord aContainerWidth);
|
2015-01-23 10:25:58 -08:00
|
|
|
/**
|
|
|
|
* Helper-function to reflow a child frame, at its final position determined
|
|
|
|
* by flex layout.
|
|
|
|
*
|
|
|
|
* @param aPresContext The presentation context being used in reflow.
|
|
|
|
* @param aAxisTracker A FlexboxAxisTracker with the flex container's axes.
|
|
|
|
* @param aReflowState The flex container's reflow state.
|
|
|
|
* @param aItem The flex item to be reflowed.
|
|
|
|
* @param aFramePos The position where the flex item's frame should
|
|
|
|
* be placed. (pre-relative positioning)
|
|
|
|
* @param aContainerWidth The flex container's width (required by some methods
|
|
|
|
* that we call, to interpret aFramePos correctly).
|
|
|
|
*/
|
|
|
|
void ReflowFlexItem(nsPresContext* aPresContext,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2015-01-23 10:25:59 -08:00
|
|
|
const FlexItem& aItem,
|
2015-01-23 10:25:58 -08:00
|
|
|
mozilla::LogicalPoint& aFramePos,
|
|
|
|
nscoord aContainerWidth);
|
|
|
|
|
2013-11-12 18:50:39 -08:00
|
|
|
bool mChildrenHaveBeenReordered; // Have we ever had to reorder our kids
|
|
|
|
// to satisfy their 'order' values?
|
2012-06-26 15:12:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsFlexContainerFrame_h___ */
|