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"
|
|
|
|
|
|
|
|
nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
|
|
|
|
|
|
|
typedef nsContainerFrame nsFlexContainerFrameSuper;
|
|
|
|
|
2013-08-22 11:32:52 -07:00
|
|
|
template <class T> class nsTArray;
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2012-06-26 15:12:13 -07:00
|
|
|
class nsFlexContainerFrame : public nsFlexContainerFrameSuper {
|
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsFlexContainerFrame)
|
|
|
|
NS_DECL_QUERYFRAME
|
|
|
|
|
|
|
|
// Factory method:
|
|
|
|
friend nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
|
|
|
|
2012-09-29 23:38:46 -07:00
|
|
|
public:
|
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-01-21 14:51:58 -08:00
|
|
|
class StrutInfo;
|
|
|
|
|
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,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult Reflow(nsPresContext* aPresContext,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
2012-09-29 23:38:46 -07:00
|
|
|
|
|
|
|
virtual nscoord
|
|
|
|
GetMinWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
|
|
|
|
virtual nscoord
|
|
|
|
GetPrefWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
|
|
|
|
|
2012-06-26 15:12:13 -07:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_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
|
2012-09-29 23:38:46 -07:00
|
|
|
nsFlexContainerFrame(nsStyleContext* aContext) :
|
|
|
|
nsFlexContainerFrameSuper(aContext),
|
2012-12-26 12:17:52 -08:00
|
|
|
mChildrenHaveBeenReordered(false)
|
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.)
|
|
|
|
*/
|
|
|
|
nsresult DoFlexLayout(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
nscoord aContentBoxMainSize,
|
|
|
|
nscoord aAvailableHeightForContent,
|
2014-01-21 14:51:58 -08:00
|
|
|
nsTArray<StrutInfo>& aStruts,
|
2014-01-21 14:51:57 -08:00
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
|
|
|
|
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
|
|
|
|
|
2013-10-31 19:39:02 -07:00
|
|
|
FlexItem GenerateFlexItemForChild(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
|
|
|
|
|
|
|
// Returns nsresult because we might have to reflow aFlexItem.Frame() (to
|
|
|
|
// get its vertical intrinsic size in a vertical flexbox), and if that
|
|
|
|
// reflow fails (returns a failure nsresult), we want to bail out.
|
|
|
|
nsresult ResolveFlexItemMaxContentSizing(nsPresContext* aPresContext,
|
|
|
|
FlexItem& aFlexItem,
|
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2013-12-05 10:57:51 -08:00
|
|
|
nsresult GenerateFlexLines(nsPresContext* aPresContext,
|
2012-09-29 23:38:46 -07:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
2013-12-05 10:57:51 -08:00
|
|
|
nscoord aContentBoxMainSize,
|
|
|
|
nscoord aAvailableHeightForContent,
|
2014-01-21 14:52:27 -08:00
|
|
|
const nsTArray<StrutInfo>& aStruts,
|
2012-09-29 23:38:46 -07:00
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
2013-12-05 10:57:51 -08:00
|
|
|
nsTArray<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,
|
2013-12-06 13:38:49 -08:00
|
|
|
nscoord aAvailableHeightForContent,
|
|
|
|
bool* aIsDefinite,
|
|
|
|
nsReflowStatus& aStatus);
|
2013-11-21 10:20:01 -08:00
|
|
|
|
2012-09-29 23:38:46 -07:00
|
|
|
nsresult SizeItemInCrossAxis(nsPresContext* aPresContext,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
2013-02-15 14:01:48 -08:00
|
|
|
nsHTMLReflowState& aChildReflowState,
|
2012-09-29 23:38:46 -07:00
|
|
|
FlexItem& aItem);
|
|
|
|
|
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___ */
|