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"
|
2012-09-29 23:38:46 -07:00
|
|
|
#include "nsTArray.h"
|
2012-06-26 15:12:13 -07:00
|
|
|
#include "mozilla/Types.h"
|
|
|
|
|
|
|
|
nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
|
|
|
|
|
|
|
typedef nsContainerFrame nsFlexContainerFrameSuper;
|
|
|
|
|
2012-09-29 23:38:46 -07:00
|
|
|
class FlexItem;
|
|
|
|
class FlexboxAxisTracker;
|
|
|
|
class MainAxisPositionTracker;
|
|
|
|
class SingleLineCrossAxisPositionTracker;
|
|
|
|
|
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:
|
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
|
|
|
|
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
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;
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
|
2012-09-29 23:38:46 -07:00
|
|
|
#endif // DEBUG
|
|
|
|
// 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),
|
|
|
|
mCachedContentBoxCrossSize(nscoord_MIN),
|
2012-12-26 12:17:52 -08:00
|
|
|
mCachedAscent(nscoord_MIN),
|
|
|
|
mChildrenHaveBeenReordered(false)
|
2012-09-29 23:38:46 -07:00
|
|
|
{}
|
2012-06-26 15:12:13 -07:00
|
|
|
virtual ~nsFlexContainerFrame();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
// Returns nsresult because we might have to reflow aChildFrame (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 AppendFlexItemForChild(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
nsTArray<FlexItem>& aFlexItems);
|
|
|
|
|
|
|
|
// Runs the "resolve the flexible lengths" algorithm, distributing
|
|
|
|
// |aFlexContainerMainSize| among the |aItems| and freezing them.
|
|
|
|
void ResolveFlexibleLengths(const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
nscoord aFlexContainerMainSize,
|
|
|
|
nsTArray<FlexItem>& aItems);
|
|
|
|
|
|
|
|
nsresult GenerateFlexItems(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
nsTArray<FlexItem>& aItems);
|
|
|
|
|
|
|
|
nscoord ComputeFlexContainerMainSize(const nsHTMLReflowState& aReflowState,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
const nsTArray<FlexItem>& aFlexItems);
|
|
|
|
|
|
|
|
void PositionItemInMainAxis(MainAxisPositionTracker& aMainAxisPosnTracker,
|
|
|
|
FlexItem& aItem);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void PositionItemInCrossAxis(
|
|
|
|
nscoord aLineStartPosition,
|
|
|
|
SingleLineCrossAxisPositionTracker& aLineCrossAxisPosnTracker,
|
|
|
|
FlexItem& aItem);
|
|
|
|
|
|
|
|
// Cached values from running flexbox layout algorithm, used in setting our
|
|
|
|
// reflow metrics w/out actually reflowing all of our children, in any
|
|
|
|
// reflows where we're not dirty:
|
2012-11-28 00:08:25 -08:00
|
|
|
nscoord mCachedContentBoxCrossSize; // Cross size of our content-box.
|
|
|
|
nscoord mCachedAscent; // Our ascent, in prev. reflow.
|
2012-12-26 12:17:52 -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___ */
|