2012-06-26 22:12:13 +00: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 19:42:43 +00:00
|
|
|
/* rendering object for CSS "display: flex" */
|
2012-06-26 22:12:13 +00:00
|
|
|
|
|
|
|
#ifndef nsFlexContainerFrame_h___
|
|
|
|
#define nsFlexContainerFrame_h___
|
|
|
|
|
|
|
|
#include "nsContainerFrame.h"
|
2014-03-18 01:23:23 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
template <class T> class LinkedList;
|
|
|
|
}
|
2012-06-26 22:12:13 +00:00
|
|
|
|
2014-05-24 22:20:40 +00:00
|
|
|
nsContainerFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2012-06-26 22:12:13 +00:00
|
|
|
|
|
|
|
typedef nsContainerFrame nsFlexContainerFrameSuper;
|
|
|
|
|
|
|
|
class nsFlexContainerFrame : public nsFlexContainerFrameSuper {
|
2014-03-07 23:58:38 +00:00
|
|
|
public:
|
2012-06-26 22:12:13 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsFlexContainerFrame)
|
|
|
|
NS_DECL_QUERYFRAME
|
|
|
|
|
|
|
|
// Factory method:
|
2014-05-24 22:20:40 +00:00
|
|
|
friend nsContainerFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2012-06-26 22:12:13 +00:00
|
|
|
|
2014-01-21 22:51:58 +00:00
|
|
|
// Forward-decls of helper classes
|
2014-01-22 01:05:07 +00:00
|
|
|
class FlexItem;
|
|
|
|
class FlexLine;
|
|
|
|
class FlexboxAxisTracker;
|
2014-06-19 00:57:51 +00:00
|
|
|
struct StrutInfo;
|
2014-01-21 22:51:58 +00:00
|
|
|
|
2012-06-26 22:12:13 +00:00
|
|
|
// nsIFrame overrides
|
2013-02-14 11:12:27 +00:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2012-09-30 06:38:46 +00:00
|
|
|
|
2014-05-13 00:47:52 +00:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
2012-09-30 06:38:46 +00:00
|
|
|
|
|
|
|
virtual nscoord
|
2014-07-24 17:03:25 +00:00
|
|
|
GetMinISize(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
|
2012-09-30 06:38:46 +00:00
|
|
|
virtual nscoord
|
2014-07-24 17:03:25 +00:00
|
|
|
GetPrefISize(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
|
2012-09-30 06:38:46 +00:00
|
|
|
|
2012-06-26 22:12:13 +00:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
|
2014-01-05 23:31:14 +00:00
|
|
|
#endif
|
2012-09-30 06:38:46 +00:00
|
|
|
// Flexbox-specific public methods
|
|
|
|
bool IsHorizontal();
|
2012-06-26 22:12:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Protected constructor & destructor
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit nsFlexContainerFrame(nsStyleContext* aContext) :
|
2014-03-07 23:58:38 +00:00
|
|
|
nsFlexContainerFrameSuper(aContext)
|
2012-09-30 06:38:46 +00:00
|
|
|
{}
|
2012-06-26 22:12:13 +00:00
|
|
|
virtual ~nsFlexContainerFrame();
|
|
|
|
|
2014-01-21 22:51:57 +00: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 15:37:02 +00:00
|
|
|
void DoFlexLayout(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
nscoord aContentBoxMainSize,
|
|
|
|
nscoord aAvailableHeightForContent,
|
|
|
|
nsTArray<StrutInfo>& aStruts,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2014-01-21 22:51:57 +00:00
|
|
|
|
2012-12-26 20:17:52 +00: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-30 06:38:46 +00:00
|
|
|
// Protected flex-container-specific methods / member-vars
|
|
|
|
#ifdef DEBUG
|
|
|
|
void SanityCheckAnonymousFlexItems() const;
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2014-07-22 15:24:36 +00: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-18 01:23:23 +00:00
|
|
|
FlexItem* GenerateFlexItemForChild(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2013-11-01 02:39:02 +00:00
|
|
|
|
2014-07-22 15:24:36 +00: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 15:24:36 +00:00
|
|
|
nscoord MeasureFlexItemContentHeight(nsPresContext* aPresContext,
|
|
|
|
FlexItem& aFlexItem,
|
|
|
|
bool aForceVerticalResizeForMeasuringReflow,
|
|
|
|
const nsHTMLReflowState& aParentReflowState);
|
|
|
|
|
2014-07-22 15:24:36 +00:00
|
|
|
/**
|
|
|
|
* This method resolves an "auto" flex-basis and/or min-main-size value
|
|
|
|
* on aFlexItem, if needed.
|
|
|
|
* (Helper for GenerateFlexItemForChild().)
|
|
|
|
*/
|
2014-07-22 15:24:36 +00:00
|
|
|
void ResolveAutoFlexBasisAndMinSize(nsPresContext* aPresContext,
|
|
|
|
FlexItem& aFlexItem,
|
2014-07-22 15:24:37 +00:00
|
|
|
const nsHTMLReflowState& aItemReflowState,
|
2014-07-22 15:24:36 +00:00
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2012-09-30 06:38:46 +00:00
|
|
|
|
2014-03-18 01:23:23 +00: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 15:37:02 +00:00
|
|
|
void GenerateFlexLines(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord aContentBoxMainSize,
|
|
|
|
nscoord aAvailableHeightForContent,
|
|
|
|
const nsTArray<StrutInfo>& aStruts,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
mozilla::LinkedList<FlexLine>& aLines);
|
2012-09-30 06:38:46 +00:00
|
|
|
|
2013-12-05 18:57:51 +00:00
|
|
|
nscoord GetMainSizeFromReflowState(const nsHTMLReflowState& aReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2012-09-30 06:38:46 +00:00
|
|
|
|
2013-12-06 21:38:49 +00:00
|
|
|
nscoord ComputeCrossSize(const nsHTMLReflowState& aReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
2014-02-07 01:04:52 +00:00
|
|
|
nscoord aSumLineCrossSizes,
|
2013-12-06 21:38:49 +00:00
|
|
|
nscoord aAvailableHeightForContent,
|
|
|
|
bool* aIsDefinite,
|
|
|
|
nsReflowStatus& aStatus);
|
2013-11-21 18:20:01 +00:00
|
|
|
|
2014-06-13 15:37:02 +00:00
|
|
|
void SizeItemInCrossAxis(nsPresContext* aPresContext,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
nsHTMLReflowState& aChildReflowState,
|
|
|
|
FlexItem& aItem);
|
2012-09-30 06:38:46 +00:00
|
|
|
|
2013-11-13 02:50:39 +00:00
|
|
|
bool mChildrenHaveBeenReordered; // Have we ever had to reorder our kids
|
|
|
|
// to satisfy their 'order' values?
|
2012-06-26 22:12:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsFlexContainerFrame_h___ */
|