2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-10-27 20:09:35 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-06-27 02:12:13 +04:00
|
|
|
|
2016-04-21 02:43:24 +03:00
|
|
|
/* rendering object for CSS "display: flex" and "display: -webkit-box" */
|
2012-06-27 02:12:13 +04:00
|
|
|
|
|
|
|
#ifndef nsFlexContainerFrame_h___
|
|
|
|
#define nsFlexContainerFrame_h___
|
|
|
|
|
2020-04-16 08:37:59 +03:00
|
|
|
#include <tuple>
|
|
|
|
|
2018-10-17 23:23:09 +03:00
|
|
|
#include "mozilla/dom/FlexBinding.h"
|
2020-02-28 03:37:49 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
#include "nsContainerFrame.h"
|
2014-03-18 05:23:23 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-01-23 21:25:58 +03:00
|
|
|
class LogicalPoint;
|
2019-04-16 10:24:49 +03:00
|
|
|
class PresShell;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2012-06-27 02:12:13 +04:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsContainerFrame* NS_NewFlexContainerFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
mozilla::ComputedStyle* aStyle);
|
2012-06-27 02:12:13 +04:00
|
|
|
|
2017-10-20 21:20:46 +03:00
|
|
|
/**
|
|
|
|
* These structures are used to capture data during reflow to be
|
|
|
|
* extracted by devtools via Chrome APIs. The structures are only
|
|
|
|
* created when requested in GetFlexFrameWithComputedInfo(), and
|
|
|
|
* the structures are attached to the nsFlexContainerFrame via the
|
|
|
|
* FlexContainerInfo property.
|
|
|
|
*/
|
|
|
|
struct ComputedFlexItemInfo {
|
|
|
|
nsCOMPtr<nsINode> mNode;
|
2018-11-17 03:56:51 +03:00
|
|
|
nsRect mFrameRect;
|
2017-10-20 21:20:46 +03:00
|
|
|
/**
|
|
|
|
* mMainBaseSize is a measure of the size of the item in the main
|
|
|
|
* axis before the flex sizing algorithm is applied. In the spec,
|
|
|
|
* this is called "flex base size", but we use this name to connect
|
|
|
|
* the value to the other main axis sizes.
|
|
|
|
*/
|
|
|
|
nscoord mMainBaseSize;
|
|
|
|
/**
|
2018-10-01 19:08:00 +03:00
|
|
|
* mMainDeltaSize is the amount that the flex sizing algorithm
|
|
|
|
* adds to the mMainBaseSize, before clamping to mMainMinSize and
|
|
|
|
* mMainMaxSize. This can be thought of as the amount by which the
|
|
|
|
* flex layout algorithm "wants" to shrink or grow the item, and
|
|
|
|
* would do, if it was unconstrained. Since the flex sizing
|
2017-10-20 21:20:46 +03:00
|
|
|
* algorithm proceeds linearly, the mMainDeltaSize for an item only
|
|
|
|
* respects the resolved size of items already frozen.
|
|
|
|
*/
|
|
|
|
nscoord mMainDeltaSize;
|
|
|
|
nscoord mMainMinSize;
|
|
|
|
nscoord mMainMaxSize;
|
|
|
|
nscoord mCrossMinSize;
|
|
|
|
nscoord mCrossMaxSize;
|
2018-10-25 02:47:23 +03:00
|
|
|
mozilla::dom::FlexItemClampState mClampState;
|
2017-10-20 21:20:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ComputedFlexLineInfo {
|
|
|
|
nsTArray<ComputedFlexItemInfo> mItems;
|
2017-12-02 00:02:35 +03:00
|
|
|
nscoord mCrossStart;
|
2017-10-20 21:20:46 +03:00
|
|
|
nscoord mCrossSize;
|
|
|
|
nscoord mFirstBaselineOffset;
|
|
|
|
nscoord mLastBaselineOffset;
|
2018-10-23 19:23:37 +03:00
|
|
|
mozilla::dom::FlexLineGrowthState mGrowthState;
|
2017-10-20 21:20:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ComputedFlexContainerInfo {
|
|
|
|
nsTArray<ComputedFlexLineInfo> mLines;
|
2018-10-17 23:23:09 +03:00
|
|
|
mozilla::dom::FlexPhysicalDirection mMainAxisDirection;
|
|
|
|
mozilla::dom::FlexPhysicalDirection mCrossAxisDirection;
|
2017-10-20 21:20:46 +03:00
|
|
|
};
|
2016-04-21 02:43:24 +03:00
|
|
|
|
2020-08-07 20:43:16 +03:00
|
|
|
/**
|
|
|
|
* Helper class to get the orientation of a flex container's axes.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS FlexboxAxisInfo final {
|
|
|
|
public:
|
|
|
|
explicit FlexboxAxisInfo(const nsIFrame* aFlexContainer);
|
|
|
|
|
|
|
|
// Is our main axis the inline axis? (Are we 'flex-direction:row[-reverse]'?)
|
|
|
|
bool mIsRowOriented = true;
|
|
|
|
|
|
|
|
// Is our main axis in the opposite direction as mWM's corresponding axis?
|
|
|
|
// (e.g. RTL vs LTR)
|
|
|
|
bool mIsMainAxisReversed = false;
|
|
|
|
|
|
|
|
// Is our cross axis in the opposite direction as mWM's corresponding axis?
|
|
|
|
// (e.g. BTT vs TTB)
|
|
|
|
bool mIsCrossAxisReversed = false;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Helpers for constructor which determine the orientation of our axes, based
|
|
|
|
// on legacy box properties (-webkit-box-orient, -webkit-box-direction) or
|
|
|
|
// modern flexbox properties (flex-direction, flex-wrap) depending on whether
|
|
|
|
// the flex container is a "legacy box" (as determined by IsLegacyBox).
|
|
|
|
void InitAxesFromLegacyProps(const nsIFrame* aFlexContainer);
|
|
|
|
void InitAxesFromModernProps(const nsIFrame* aFlexContainer);
|
|
|
|
};
|
|
|
|
|
2016-04-21 02:43:24 +03:00
|
|
|
/**
|
|
|
|
* This is the rendering object used for laying out elements with
|
|
|
|
* "display: flex" or "display: inline-flex".
|
|
|
|
*
|
|
|
|
* We also use this class for elements with "display: -webkit-box" or
|
|
|
|
* "display: -webkit-inline-box" (but not "-moz-box" / "-moz-inline-box" --
|
|
|
|
* those are rendered with old-school XUL frame classes).
|
|
|
|
*
|
|
|
|
* Note: we represent the -webkit-box family of properties (-webkit-box-orient,
|
|
|
|
* -webkit-box-flex, etc.) as aliases for their -moz equivalents. And for
|
|
|
|
* -webkit-{inline-}box containers, nsFlexContainerFrame will honor those
|
|
|
|
* "legacy" properties for alignment/flexibility/etc. *instead of* honoring the
|
|
|
|
* modern flexbox & alignment properties. For brevity, many comments in
|
|
|
|
* nsFlexContainerFrame.cpp simply refer to these properties using their
|
|
|
|
* "-webkit" versions, since we're mostly expecting to encounter them in that
|
|
|
|
* form. (Technically, the "-moz" versions of these properties *can* influence
|
|
|
|
* layout here as well (since that's what the -webkit versions are aliased to)
|
|
|
|
* -- but only inside of a "display:-webkit-{inline-}box" container.)
|
|
|
|
*/
|
2017-04-30 18:30:08 +03:00
|
|
|
class nsFlexContainerFrame final : public nsContainerFrame {
|
2014-03-08 03:58:38 +04:00
|
|
|
public:
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsFlexContainerFrame)
|
2012-06-27 02:12:13 +04:00
|
|
|
NS_DECL_QUERYFRAME
|
|
|
|
|
|
|
|
// Factory method:
|
2019-04-16 10:24:49 +03:00
|
|
|
friend nsContainerFrame* NS_NewFlexContainerFrame(
|
|
|
|
mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
|
2012-06-27 02:12:13 +04:00
|
|
|
|
2014-01-22 02:51:58 +04:00
|
|
|
// Forward-decls of helper classes
|
2014-01-22 05:05:07 +04:00
|
|
|
class FlexItem;
|
|
|
|
class FlexLine;
|
|
|
|
class FlexboxAxisTracker;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct StrutInfo;
|
2020-03-25 07:52:02 +03:00
|
|
|
class CachedBAxisMeasurement;
|
2020-03-25 08:02:35 +03:00
|
|
|
class CachedFlexItemData;
|
2020-04-16 08:37:57 +03:00
|
|
|
struct SharedFlexData;
|
2020-05-20 01:49:22 +03:00
|
|
|
class FlexItemIterator;
|
2014-01-22 02:51:58 +04:00
|
|
|
|
2012-06-27 02:12:13 +04:00
|
|
|
// nsIFrame overrides
|
2016-12-02 12:02:00 +03:00
|
|
|
void Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) override;
|
|
|
|
|
2020-05-12 19:55:00 +03:00
|
|
|
bool IsFrameOfType(uint32_t aFlags) const override {
|
|
|
|
return nsContainerFrame::IsFrameOfType(
|
|
|
|
aFlags & ~(nsIFrame::eCanContainOverflowContainers));
|
|
|
|
}
|
|
|
|
|
2017-01-18 03:27:03 +03:00
|
|
|
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) override;
|
2012-09-30 10:38:46 +04:00
|
|
|
|
2017-01-06 17:34:16 +03:00
|
|
|
void MarkIntrinsicISizesDirty() override;
|
|
|
|
|
2020-03-13 01:16:52 +03:00
|
|
|
void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput,
|
2017-01-18 03:27:03 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
|
|
|
nsReflowStatus& aStatus) override;
|
2012-09-30 10:38:46 +04:00
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
nscoord GetMinISize(gfxContext* aRenderingContext) override;
|
|
|
|
nscoord GetPrefISize(gfxContext* aRenderingContext) override;
|
2012-09-30 10:38:46 +04:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2017-01-18 03:27:03 +03:00
|
|
|
nsresult GetFrameName(nsAString& aResult) const override;
|
2014-01-06 03:31:14 +04:00
|
|
|
#endif
|
2016-10-11 22:54:00 +03:00
|
|
|
|
|
|
|
nscoord GetLogicalBaseline(mozilla::WritingMode aWM) const override;
|
|
|
|
|
2016-12-21 01:56:35 +03:00
|
|
|
bool GetVerticalAlignBaseline(mozilla::WritingMode aWM,
|
|
|
|
nscoord* aBaseline) const override {
|
2019-04-26 02:03:04 +03:00
|
|
|
return GetNaturalBaselineBOffset(aWM, BaselineSharingGroup::First,
|
2016-12-21 01:56:35 +03:00
|
|
|
aBaseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
|
|
|
|
BaselineSharingGroup aBaselineGroup,
|
|
|
|
nscoord* aBaseline) const override {
|
|
|
|
if (HasAnyStateBits(NS_STATE_FLEX_SYNTHESIZE_BASELINE)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-26 02:03:04 +03:00
|
|
|
*aBaseline = aBaselineGroup == BaselineSharingGroup::First
|
2016-12-21 01:56:35 +03:00
|
|
|
? mBaselineFromLastReflow
|
|
|
|
: mLastBaselineFromLastReflow;
|
2016-12-21 01:56:35 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-09 05:32:30 +03:00
|
|
|
/**
|
|
|
|
* Returns the effective value of -webkit-line-clamp for this flex container.
|
|
|
|
*
|
|
|
|
* This will be 0 if the property is 'none', or if the element is not
|
|
|
|
* display:-webkit-(inline-)box and -webkit-box-orient:vertical.
|
|
|
|
*/
|
|
|
|
uint32_t GetLineClampValue() const;
|
|
|
|
|
2016-10-31 18:59:40 +03:00
|
|
|
// nsContainerFrame overrides
|
2020-05-29 01:50:57 +03:00
|
|
|
bool DrainSelfOverflowList() override;
|
|
|
|
void AppendFrames(ChildListID aListID, nsFrameList& aFrameList) override;
|
|
|
|
void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
|
|
|
const nsLineList::iterator* aPrevFrameLine,
|
|
|
|
nsFrameList& aFrameList) override;
|
|
|
|
void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
|
2020-01-31 03:56:49 +03:00
|
|
|
mozilla::StyleAlignFlags CSSAlignmentForAbsPosChild(
|
2016-10-31 18:59:40 +03:00
|
|
|
const ReflowInput& aChildRI,
|
|
|
|
mozilla::LogicalAxis aLogicalAxis) const override;
|
|
|
|
|
2016-10-15 03:23:36 +03:00
|
|
|
/**
|
2017-10-20 21:20:46 +03:00
|
|
|
* Helper function to calculate packing space and initial offset of alignment
|
|
|
|
* subjects in MainAxisPositionTracker() and CrossAxisPositionTracker() for
|
|
|
|
* space-between, space-around, and space-evenly.
|
|
|
|
* * @param aNumThingsToPack Number of alignment subjects.
|
2020-01-31 03:56:49 +03:00
|
|
|
* @param aAlignVal Value for align-content or
|
|
|
|
* justify-content.
|
2017-10-20 21:20:46 +03:00
|
|
|
* @param aFirstSubjectOffset Outparam for first subject offset.
|
|
|
|
* @param aNumPackingSpacesRemaining Outparam for number of equal-sized
|
|
|
|
* packing spaces to apply between each
|
|
|
|
* alignment subject.
|
|
|
|
* @param aPackingSpaceRemaining Outparam for total amount of packing
|
|
|
|
* space to be divided up.
|
|
|
|
*/
|
2020-01-31 03:56:49 +03:00
|
|
|
static void CalculatePackingSpace(
|
|
|
|
uint32_t aNumThingsToPack,
|
|
|
|
const mozilla::StyleContentDistribution& aAlignVal,
|
|
|
|
nscoord* aFirstSubjectOffset, uint32_t* aNumPackingSpacesRemaining,
|
|
|
|
nscoord* aPackingSpaceRemaining);
|
2016-10-15 03:23:36 +03:00
|
|
|
|
2017-10-20 21:20:46 +03:00
|
|
|
/**
|
|
|
|
* This property is created by a call to
|
|
|
|
* nsFlexContainerFrame::GetFlexFrameWithComputedInfo.
|
|
|
|
*/
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(FlexContainerInfo,
|
|
|
|
ComputedFlexContainerInfo)
|
|
|
|
/**
|
|
|
|
* This function should only be called on a nsFlexContainerFrame
|
|
|
|
* that has just been returned by a call to
|
|
|
|
* GetFlexFrameWithComputedInfo.
|
|
|
|
*/
|
|
|
|
const ComputedFlexContainerInfo* GetFlexContainerInfo() {
|
|
|
|
const ComputedFlexContainerInfo* info = GetProperty(FlexContainerInfo());
|
2019-08-31 02:16:44 +03:00
|
|
|
NS_WARNING_ASSERTION(info,
|
|
|
|
"Property generation wasn't requested. "
|
|
|
|
"This is a known issue in Print Preview. "
|
|
|
|
"See Bug 1157012.");
|
2017-10-20 21:20:46 +03:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return aFrame as a flex frame after ensuring it has computed flex info.
|
|
|
|
* @return nullptr if aFrame is null or doesn't have a flex frame
|
|
|
|
* as its content insertion frame.
|
|
|
|
* @note this might destroy layout/style data since it may flush layout.
|
|
|
|
*/
|
2019-04-13 15:43:57 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2017-10-20 21:20:46 +03:00
|
|
|
static nsFlexContainerFrame* GetFlexFrameWithComputedInfo(nsIFrame* aFrame);
|
|
|
|
|
2018-03-30 00:49:28 +03:00
|
|
|
/**
|
|
|
|
* Given a frame for a flex item, this method returns true IFF that flex
|
|
|
|
* item's inline axis is the same as (i.e. not orthogonal to) its flex
|
|
|
|
* container's main axis.
|
|
|
|
*
|
|
|
|
* (This method is only intended to be used from external
|
|
|
|
* callers. Inside of flex reflow code, FlexItem::IsInlineAxisMainAxis() is
|
|
|
|
* equivalent & more optimal.)
|
|
|
|
*
|
|
|
|
* @param aFrame a flex item (must return true from IsFlexItem)
|
|
|
|
* @return true iff aFrame's inline axis is the same as (i.e. not orthogonal
|
|
|
|
* to) its flex container's main axis. Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool IsItemInlineAxisMainAxis(nsIFrame* aFrame);
|
|
|
|
|
2018-04-13 22:17:51 +03:00
|
|
|
/**
|
|
|
|
* Returns true iff the given computed 'flex-basis' & main-size property
|
|
|
|
* values collectively represent a used flex-basis of 'content'.
|
|
|
|
* See https://drafts.csswg.org/css-flexbox-1/#valdef-flex-basis-auto
|
|
|
|
*
|
|
|
|
* @param aFlexBasis the computed 'flex-basis' for a flex item.
|
|
|
|
* @param aMainSize the computed main-size property for a flex item.
|
|
|
|
*/
|
2019-02-10 15:55:16 +03:00
|
|
|
static bool IsUsedFlexBasisContent(const StyleFlexBasis& aFlexBasis,
|
|
|
|
const StyleSize& aMainSize);
|
2018-04-13 22:17:51 +03:00
|
|
|
|
2018-10-22 01:54:57 +03:00
|
|
|
/**
|
2020-07-07 01:29:42 +03:00
|
|
|
* Callback for nsIFrame::MarkIntrinsicISizesDirty() on a flex item.
|
2018-10-22 01:54:57 +03:00
|
|
|
*/
|
|
|
|
static void MarkCachedFlexMeasurementsDirty(nsIFrame* aItemFrame);
|
|
|
|
|
2012-06-27 02:12:13 +04:00
|
|
|
protected:
|
|
|
|
// Protected constructor & destructor
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit nsFlexContainerFrame(ComputedStyle* aStyle,
|
|
|
|
nsPresContext* aPresContext)
|
2019-12-16 03:39:55 +03:00
|
|
|
: nsContainerFrame(aStyle, aPresContext, kClassID) {}
|
2017-04-30 18:30:08 +03:00
|
|
|
|
2012-06-27 02:12:13 +04:00
|
|
|
virtual ~nsFlexContainerFrame();
|
|
|
|
|
2020-03-10 02:25:36 +03:00
|
|
|
// Protected flex-container-specific methods / member-vars
|
|
|
|
|
2014-01-22 02:51:57 +04: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().
|
|
|
|
*
|
|
|
|
* (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.)
|
2020-03-10 02:25:28 +03:00
|
|
|
*
|
|
|
|
* @param aContentBoxMainSize [in/out] initially, the "tentative" content-box
|
|
|
|
* main-size of the flex container; "tentative"
|
|
|
|
* because it may be unconstrained or may run off
|
|
|
|
* the page. In those cases, this method will
|
|
|
|
* resolve it to a final value before returning.
|
|
|
|
* @param aContentBoxCrossSize [out] the final content-box cross-size of the
|
|
|
|
* flex container.
|
|
|
|
* @param aFlexContainerAscent [out] the flex container's ascent, derived from
|
|
|
|
* any baseline-aligned flex items in the first
|
|
|
|
* flex line, if any such items exist. Otherwise,
|
|
|
|
* nscoord_MIN.
|
2014-01-22 02:51:57 +04:00
|
|
|
*/
|
2020-08-20 00:10:48 +03:00
|
|
|
void DoFlexLayout(const ReflowInput& aReflowInput,
|
2020-03-10 02:25:40 +03:00
|
|
|
nscoord& aContentBoxMainSize, nscoord& aContentBoxCrossSize,
|
2020-08-20 00:10:48 +03:00
|
|
|
nscoord& aFlexContainerAscent, nsTArray<FlexLine>& aLines,
|
|
|
|
nsTArray<StrutInfo>& aStruts,
|
2020-03-10 02:25:44 +03:00
|
|
|
nsTArray<nsIFrame*>& aPlaceholders,
|
2020-03-10 02:25:40 +03:00
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
nscoord aMainGapSize, nscoord aCrossGapSize,
|
|
|
|
bool aHasLineClampEllipsis,
|
|
|
|
ComputedFlexContainerInfo* const aContainerInfo);
|
2014-01-22 02:51:57 +04:00
|
|
|
|
2020-03-10 02:25:36 +03:00
|
|
|
/**
|
2020-03-10 02:25:38 +03:00
|
|
|
* If our devtools have requested a ComputedFlexContainerInfo for this flex
|
|
|
|
* container, this method ensures that we have one (and if one already exists,
|
|
|
|
* this method reinitializes it to look like a freshly-created one).
|
|
|
|
*
|
|
|
|
* @return the pointer to a freshly created or reinitialized
|
|
|
|
* ComputedFlexContainerInfo if our devtools have requested it;
|
|
|
|
* otherwise nullptr.
|
2020-03-10 02:25:36 +03:00
|
|
|
*/
|
2020-03-10 02:25:38 +03:00
|
|
|
ComputedFlexContainerInfo* CreateOrClearFlexContainerInfo();
|
2020-03-10 02:25:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helpers for DoFlexLayout to computed fields in ComputedFlexContainerInfo.
|
|
|
|
*/
|
|
|
|
static void CreateFlexLineAndFlexItemInfo(
|
|
|
|
ComputedFlexContainerInfo& aContainerInfo,
|
2020-03-23 10:24:43 +03:00
|
|
|
const nsTArray<FlexLine>& aLines);
|
2020-03-10 02:25:36 +03:00
|
|
|
|
|
|
|
static void ComputeFlexDirections(ComputedFlexContainerInfo& aContainerInfo,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
|
|
|
|
|
|
|
static void UpdateFlexLineAndItemInfo(
|
|
|
|
ComputedFlexContainerInfo& aContainerInfo,
|
2020-03-23 10:24:43 +03:00
|
|
|
const nsTArray<FlexLine>& aLines);
|
2020-03-10 02:25:36 +03:00
|
|
|
|
2012-09-30 10:38:46 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void SanityCheckAnonymousFlexItems() const;
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2020-03-23 20:48:02 +03:00
|
|
|
/**
|
|
|
|
* Returns a new FlexItem for the given child frame, directly constructed at
|
|
|
|
* the end of aLine. Guaranteed to return non-null.
|
2014-07-22 19:24:36 +04:00
|
|
|
*
|
|
|
|
* 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.)
|
2020-02-08 06:57:45 +03:00
|
|
|
* https://drafts.csswg.org/css-flexbox-1/#algo-flex
|
2020-03-23 20:48:02 +03:00
|
|
|
*
|
|
|
|
* Note that this method **does not** update aLine's main-size bookkeeping to
|
|
|
|
* account for the newly-constructed flex item. The caller is responsible for
|
|
|
|
* determining whether this line is a good fit for the new item. If so,
|
|
|
|
* updating aLine's bookkeeping (via FlexLine::AddLastItemToMainSizeTotals),
|
|
|
|
* or moving the new item to a new line otherwise.
|
2014-07-22 19:24:36 +04:00
|
|
|
*/
|
2020-03-23 20:48:02 +03:00
|
|
|
FlexItem* GenerateFlexItemForChild(FlexLine& aLine, nsIFrame* aChildFrame,
|
|
|
|
const ReflowInput& aParentReflowInput,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
bool aHasLineClampEllipsis);
|
2013-11-01 06:39:02 +04:00
|
|
|
|
2017-01-06 17:34:16 +03:00
|
|
|
/**
|
2020-03-25 07:52:02 +03:00
|
|
|
* This method looks up cached block-axis measurements for a flex item, or
|
|
|
|
* does a measuring reflow and caches those measurements.
|
2017-01-06 17:34:16 +03:00
|
|
|
*
|
2020-03-25 07:52:02 +03:00
|
|
|
* This avoids exponential reflows - see the comment above the
|
|
|
|
* CachedBAxisMeasurement struct.
|
2017-01-06 17:34:16 +03:00
|
|
|
*/
|
2020-03-25 07:52:02 +03:00
|
|
|
const CachedBAxisMeasurement& MeasureAscentAndBSizeForFlexItem(
|
2020-02-28 03:37:42 +03:00
|
|
|
FlexItem& aItem, ReflowInput& aChildReflowInput);
|
2017-01-06 17:34:16 +03:00
|
|
|
|
2014-07-22 19:24:36 +04:00
|
|
|
/**
|
2018-02-09 02:15:07 +03:00
|
|
|
* This method performs a "measuring" reflow to get the content BSize of
|
|
|
|
* aFlexItem.Frame() (treating it as if it had a computed BSize of "auto"),
|
|
|
|
* and returns the resulting BSize measurement.
|
2014-07-22 19:24:36 +04:00
|
|
|
* (Helper for ResolveAutoFlexBasisAndMinSize().)
|
|
|
|
*/
|
2020-02-28 03:37:42 +03:00
|
|
|
nscoord MeasureFlexItemContentBSize(FlexItem& aFlexItem,
|
2018-02-09 02:15:07 +03:00
|
|
|
bool aForceBResizeForMeasuringReflow,
|
2019-05-09 05:32:30 +03:00
|
|
|
bool aHasLineClampEllipsis,
|
2018-02-09 02:15:07 +03:00
|
|
|
const ReflowInput& aParentReflowInput);
|
2014-07-22 19:24:36 +04:00
|
|
|
|
2014-07-22 19:24:36 +04:00
|
|
|
/**
|
|
|
|
* This method resolves an "auto" flex-basis and/or min-main-size value
|
|
|
|
* on aFlexItem, if needed.
|
|
|
|
* (Helper for GenerateFlexItemForChild().)
|
|
|
|
*/
|
2020-02-28 03:37:42 +03:00
|
|
|
void ResolveAutoFlexBasisAndMinSize(FlexItem& aFlexItem,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aItemReflowInput,
|
2019-05-09 05:32:30 +03:00
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
bool aHasLineClampEllipsis);
|
2012-09-30 10:38:46 +04:00
|
|
|
|
2017-12-18 21:17:11 +03:00
|
|
|
/**
|
|
|
|
* Returns true if "this" is the nsFlexContainerFrame for a -moz-box or
|
|
|
|
* a -moz-inline-box -- these boxes have special behavior for flex items with
|
|
|
|
* "visibility:collapse".
|
|
|
|
*
|
|
|
|
* @param aFlexStyleDisp This frame's StyleDisplay(). (Just an optimization to
|
|
|
|
* avoid repeated lookup; some callers already have it.)
|
|
|
|
* @return true if "this" is the nsFlexContainerFrame for a -moz-{inline}box.
|
|
|
|
*/
|
|
|
|
bool ShouldUseMozBoxCollapseBehavior(const nsStyleDisplay* aFlexStyleDisp);
|
|
|
|
|
2016-10-31 18:58:17 +03:00
|
|
|
/**
|
|
|
|
* This method:
|
|
|
|
* - Creates FlexItems for all of our child frames (except placeholders).
|
|
|
|
* - Groups those FlexItems into FlexLines.
|
|
|
|
* - Returns those FlexLines in the outparam |aLines|.
|
|
|
|
*
|
2020-02-08 06:57:45 +03:00
|
|
|
* This corresponds to "Collect flex items into flex lines" step in the spec.
|
|
|
|
* https://drafts.csswg.org/css-flexbox-1/#algo-line-break
|
|
|
|
*
|
2016-10-31 18:58:17 +03:00
|
|
|
* For any child frames which are placeholders, this method will instead just
|
|
|
|
* append that child to the outparam |aPlaceholders| for separate handling.
|
|
|
|
* (Absolutely positioned children of a flex container are *not* flex items.)
|
|
|
|
*/
|
2020-02-28 03:37:42 +03:00
|
|
|
void GenerateFlexLines(const ReflowInput& aReflowInput,
|
2014-06-13 19:37:02 +04:00
|
|
|
nscoord aContentBoxMainSize,
|
|
|
|
const nsTArray<StrutInfo>& aStruts,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
2019-05-09 05:32:30 +03:00
|
|
|
nscoord aMainGapSize, bool aHasLineClampEllipsis,
|
2016-10-31 18:58:17 +03:00
|
|
|
nsTArray<nsIFrame*>& aPlaceholders,
|
2020-03-23 10:24:43 +03:00
|
|
|
nsTArray<FlexLine>& aLines);
|
2012-09-30 10:38:46 +04:00
|
|
|
|
2020-05-19 06:46:46 +03:00
|
|
|
/**
|
|
|
|
* This method creates FlexLines and FlexItems for children in flex
|
|
|
|
* container's next-in-flows by using the SharedFlexData stored in flex
|
|
|
|
* container's first-in-flow. Returns FlexLines in the outparam |aLines|.
|
|
|
|
*/
|
|
|
|
void GenerateFlexLines(const SharedFlexData& aData,
|
|
|
|
nsTArray<FlexLine>& aLines);
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord GetMainSizeFromReflowInput(const ReflowInput& aReflowInput,
|
2013-12-05 22:57:51 +04:00
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2012-09-30 10:38:46 +04:00
|
|
|
|
2020-03-10 02:25:23 +03:00
|
|
|
/**
|
|
|
|
* Resolves the content-box main-size of a flex container frame,
|
|
|
|
* primarily based on:
|
|
|
|
* - the "tentative" main size, taken from the reflow input ("tentative"
|
2020-08-20 00:10:48 +03:00
|
|
|
* because it may be unconstrained or may run off the page).
|
2020-03-10 02:25:23 +03:00
|
|
|
* - the sizes of our lines of flex items.
|
|
|
|
*
|
2020-08-20 00:10:48 +03:00
|
|
|
* We assume the available block-size is always *unconstrained* because this
|
|
|
|
* is called only in flex algorithm to measure the flex container's size
|
|
|
|
* without regards to pagination.
|
|
|
|
*
|
2020-03-10 02:25:23 +03:00
|
|
|
* Guaranteed to return a definite length, i.e. not NS_UNCONSTRAINEDSIZE,
|
|
|
|
* aside from cases with huge lengths which happen to compute to that value.
|
|
|
|
*
|
|
|
|
* This corresponds to "Determine the main size of the flex container" step in
|
|
|
|
* the spec. https://drafts.csswg.org/css-flexbox-1/#algo-main-container
|
|
|
|
*
|
|
|
|
* (Note: This function should be structurally similar to
|
|
|
|
* 'ComputeCrossSize()', except that here, the caller has already grabbed the
|
|
|
|
* tentative size from the reflow input.)
|
|
|
|
*/
|
|
|
|
nscoord ComputeMainSize(const ReflowInput& aReflowInput,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
nscoord aTentativeMainSize,
|
2020-08-20 00:10:48 +03:00
|
|
|
nsTArray<FlexLine>& aLines) const;
|
2020-03-10 02:25:23 +03:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord ComputeCrossSize(const ReflowInput& aReflowInput,
|
2013-12-07 01:38:49 +04:00
|
|
|
const FlexboxAxisTracker& aAxisTracker,
|
2020-08-20 00:10:48 +03:00
|
|
|
nscoord aSumLineCrossSizes, bool* aIsDefinite) const;
|
2013-11-21 22:20:01 +04:00
|
|
|
|
2020-04-16 08:37:47 +03:00
|
|
|
/**
|
|
|
|
* Compute the size of the available space that we'll give to our children to
|
|
|
|
* reflow into. In particular, compute the available size that we would give
|
|
|
|
* to a hypothetical child placed at the IStart/BStart corner of this flex
|
|
|
|
* container's content-box.
|
|
|
|
*
|
|
|
|
* @param aReflowInput the flex container's reflow input.
|
|
|
|
* @param aBorderPadding the border and padding of this frame with the
|
|
|
|
* assumption that this is the last fragment.
|
|
|
|
*
|
|
|
|
* @return the size of the available space for our children to reflow into.
|
|
|
|
*/
|
|
|
|
mozilla::LogicalSize ComputeAvailableSizeForItems(
|
|
|
|
const ReflowInput& aReflowInput,
|
|
|
|
const mozilla::LogicalMargin& aBorderPadding) const;
|
|
|
|
|
2020-02-28 03:37:42 +03:00
|
|
|
void SizeItemInCrossAxis(ReflowInput& aChildReflowInput, FlexItem& aItem);
|
2012-09-30 10:38:46 +04:00
|
|
|
|
2020-03-10 02:25:40 +03:00
|
|
|
/**
|
2020-04-16 22:10:32 +03:00
|
|
|
* This method computes the metrics to be reported via the flex container's
|
2020-04-20 23:43:29 +03:00
|
|
|
* ReflowOutput & nsReflowStatus output parameters in Reflow().
|
2020-03-10 02:25:40 +03:00
|
|
|
*
|
2020-04-16 22:10:32 +03:00
|
|
|
* @param aContentBoxSize the final content-box size for the flex container as
|
|
|
|
* a whole, converted from the flex container's
|
|
|
|
* main/cross sizes. The main/cross sizes are computed
|
|
|
|
* by DoFlexLayout() if this frame is the
|
|
|
|
* first-in-flow, or are the stored ones in
|
|
|
|
* SharedFlexData if this frame is a not the
|
|
|
|
* first-in-flow.
|
|
|
|
* @param aBorderPadding the border and padding for this frame (possibly with
|
|
|
|
* some sides skipped as-appropriate, if we're in a
|
|
|
|
* continuation chain).
|
|
|
|
* @param aConsumedBSize the sum of our content-box block-size consumed by our
|
|
|
|
* prev-in-flows.
|
|
|
|
* @param aMayNeedNextInFlow true if we may need a next-in-flow because our
|
|
|
|
* effective content-box block-size exceeds the
|
|
|
|
* available block-size.
|
|
|
|
* @param aMaxBlockEndEdgeOfChildren the maximum block-end edge of the
|
|
|
|
* children of this fragment in this frame's
|
|
|
|
* coordinate space (as returned by
|
|
|
|
* ReflowChildren()).
|
2020-05-12 20:20:12 +03:00
|
|
|
* @param aAnyChildIncomplete true if any child being reflowed is incomplete;
|
|
|
|
* false otherwise (as returned by
|
|
|
|
* ReflowChildren()).
|
2020-03-10 02:25:40 +03:00
|
|
|
* @param aFlexContainerAscent the flex container's ascent, if one has been
|
|
|
|
* determined from its children. (If there are no
|
|
|
|
* children, pass nscoord_MIN to synthesize a
|
|
|
|
* value from the flex container itself).
|
|
|
|
*/
|
2020-04-20 23:43:29 +03:00
|
|
|
void PopulateReflowOutput(
|
2020-03-23 10:24:43 +03:00
|
|
|
ReflowOutput& aReflowOutput, const ReflowInput& aReflowInput,
|
2020-04-16 22:10:32 +03:00
|
|
|
nsReflowStatus& aStatus, const mozilla::LogicalSize& aContentBoxSize,
|
|
|
|
const mozilla::LogicalMargin& aBorderPadding,
|
|
|
|
const nscoord aConsumedBSize, const bool aMayNeedNextInFlow,
|
2020-05-12 20:20:12 +03:00
|
|
|
const nscoord aMaxBlockEndEdgeOfChildren, const bool aAnyChildIncomplete,
|
2020-04-16 22:10:32 +03:00
|
|
|
nscoord aFlexContainerAscent, nsTArray<FlexLine>& aLines,
|
|
|
|
const FlexboxAxisTracker& aAxisTracker);
|
2020-03-10 02:25:40 +03:00
|
|
|
|
2020-03-10 02:25:44 +03:00
|
|
|
/**
|
|
|
|
* Perform a final Reflow for our child frames.
|
|
|
|
*
|
|
|
|
* @param aContentBoxMainSize the final content-box main-size of the flex
|
|
|
|
* container.
|
|
|
|
* @param aContentBoxCrossSize the final content-box cross-size of the flex
|
|
|
|
* container.
|
2020-04-16 08:37:47 +03:00
|
|
|
* @param aAvailableSizeForItems the size of the available space for our
|
|
|
|
* children to reflow into.
|
|
|
|
* @param aBorderPadding the border and padding for this frame (possibly with
|
|
|
|
* some sides skipped as-appropriate, if we're in a
|
|
|
|
* continuation chain).
|
2020-05-12 19:55:00 +03:00
|
|
|
* @param aSumOfPrevInFlowsChildrenBlockSize See the comment for
|
|
|
|
* SumOfChildrenBlockSizeProperty.
|
2020-03-10 02:25:44 +03:00
|
|
|
* @param aFlexContainerAscent [in/out] initially, the "tentative" flex
|
|
|
|
* container ascent computed in DoFlexLayout; or,
|
|
|
|
* nscoord_MIN if the ascent hasn't been
|
|
|
|
* established yet. If the latter, this will be
|
|
|
|
* updated with an ascent derived from the first
|
|
|
|
* flex item (if there are any flex items).
|
2020-04-16 08:37:59 +03:00
|
|
|
* @return nscoord the maximum block-end edge of children of this fragment in
|
|
|
|
* flex container's coordinate space.
|
2020-05-12 20:20:12 +03:00
|
|
|
* @return bool true if any child being reflowed is incomplete; false
|
|
|
|
* otherwise.
|
2020-03-10 02:25:44 +03:00
|
|
|
*/
|
2020-04-16 08:37:59 +03:00
|
|
|
std::tuple<nscoord, bool> ReflowChildren(
|
|
|
|
const ReflowInput& aReflowInput, const nscoord aContentBoxMainSize,
|
|
|
|
const nscoord aContentBoxCrossSize,
|
|
|
|
const mozilla::LogicalSize& aAvailableSizeForItems,
|
|
|
|
const mozilla::LogicalMargin& aBorderPadding,
|
2020-05-12 19:55:00 +03:00
|
|
|
const nscoord aSumOfPrevInFlowsChildrenBlockSize,
|
|
|
|
nscoord& aFlexContainerAscent, nsTArray<FlexLine>& aLines,
|
|
|
|
nsTArray<nsIFrame*>& aPlaceholders,
|
2020-04-16 08:37:59 +03:00
|
|
|
const FlexboxAxisTracker& aAxisTracker, bool aHasLineClampEllipsis);
|
2020-03-10 02:25:44 +03:00
|
|
|
|
2015-01-24 01:15:11 +03: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).
|
|
|
|
*
|
2019-04-11 23:27:37 +03:00
|
|
|
* @param aReflowInput The flex container's reflow input.
|
2015-01-24 01:15:11 +03:00
|
|
|
* @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)
|
2015-07-16 12:07:57 +03:00
|
|
|
* @param aContainerSize The flex container's size (required by some methods
|
2015-01-24 01:15:11 +03:00
|
|
|
* that we call, to interpret aFramePos correctly).
|
|
|
|
*/
|
2016-07-21 13:36:39 +03:00
|
|
|
void MoveFlexItemToFinalPosition(const ReflowInput& aReflowInput,
|
2015-01-24 01:15:11 +03:00
|
|
|
const FlexItem& aItem,
|
|
|
|
mozilla::LogicalPoint& aFramePos,
|
2015-07-16 12:07:57 +03:00
|
|
|
const nsSize& aContainerSize);
|
2015-01-23 21:25:58 +03:00
|
|
|
/**
|
|
|
|
* Helper-function to reflow a child frame, at its final position determined
|
|
|
|
* by flex layout.
|
|
|
|
*
|
|
|
|
* @param aAxisTracker A FlexboxAxisTracker with the flex container's axes.
|
2019-04-11 23:27:37 +03:00
|
|
|
* @param aReflowInput The flex container's reflow input.
|
2015-01-23 21:25:58 +03:00
|
|
|
* @param aItem The flex item to be reflowed.
|
|
|
|
* @param aFramePos The position where the flex item's frame should
|
|
|
|
* be placed. (pre-relative positioning)
|
2020-04-16 08:37:45 +03:00
|
|
|
* @param aAvailableSize The available size to reflow the child frame (in the
|
|
|
|
* child frame's writing-mode).
|
2015-07-16 12:07:57 +03:00
|
|
|
* @param aContainerSize The flex container's size (required by some methods
|
2015-01-23 21:25:58 +03:00
|
|
|
* that we call, to interpret aFramePos correctly).
|
2020-04-16 08:37:45 +03:00
|
|
|
* @return the child frame's reflow status.
|
2015-01-23 21:25:58 +03:00
|
|
|
*/
|
2020-04-16 08:37:45 +03:00
|
|
|
nsReflowStatus ReflowFlexItem(const FlexboxAxisTracker& aAxisTracker,
|
|
|
|
const ReflowInput& aReflowInput,
|
|
|
|
const FlexItem& aItem,
|
|
|
|
mozilla::LogicalPoint& aFramePos,
|
|
|
|
const mozilla::LogicalSize& aAvailableSize,
|
|
|
|
const nsSize& aContainerSize,
|
|
|
|
bool aHasLineClampEllipsis);
|
2015-01-23 21:25:58 +03:00
|
|
|
|
2016-10-31 18:58:17 +03:00
|
|
|
/**
|
|
|
|
* Helper-function to perform a "dummy reflow" on all our nsPlaceholderFrame
|
|
|
|
* children, at the container's content-box origin.
|
|
|
|
*
|
|
|
|
* This doesn't actually represent the static position of the placeholders'
|
|
|
|
* out-of-flow (OOF) frames -- we can't compute that until we've reflowed the
|
|
|
|
* OOF, because (depending on the CSS Align properties) the static position
|
|
|
|
* may be influenced by the OOF's size. So for now, we just co-opt the
|
|
|
|
* placeholder to store the flex container's logical content-box origin, and
|
|
|
|
* we defer to nsAbsoluteContainingBlock to determine the OOF's actual static
|
|
|
|
* position (using this origin, the OOF's size, and the CSS Align
|
|
|
|
* properties).
|
|
|
|
*
|
|
|
|
* @param aReflowInput The flex container's reflow input.
|
|
|
|
* @param aPlaceholders An array of all the flex container's
|
|
|
|
* nsPlaceholderFrame children.
|
|
|
|
* @param aContentBoxOrigin The flex container's logical content-box
|
|
|
|
* origin (in its own coordinate space).
|
|
|
|
* @param aContainerSize The flex container's size (required by some
|
|
|
|
* reflow methods to interpret positions correctly).
|
|
|
|
*/
|
2020-02-28 03:37:42 +03:00
|
|
|
void ReflowPlaceholders(const ReflowInput& aReflowInput,
|
2016-10-31 18:58:17 +03:00
|
|
|
nsTArray<nsIFrame*>& aPlaceholders,
|
|
|
|
const mozilla::LogicalPoint& aContentBoxOrigin,
|
|
|
|
const nsSize& aContainerSize);
|
|
|
|
|
2018-04-18 03:06:23 +03:00
|
|
|
/**
|
|
|
|
* Helper for GetMinISize / GetPrefISize.
|
|
|
|
*/
|
|
|
|
nscoord IntrinsicISize(gfxContext* aRenderingContext,
|
|
|
|
nsLayoutUtils::IntrinsicISizeType aType);
|
|
|
|
|
2018-04-18 03:06:26 +03:00
|
|
|
/**
|
|
|
|
* Cached values to optimize GetMinISize/GetPrefISize.
|
|
|
|
*/
|
2019-12-16 03:39:55 +03:00
|
|
|
nscoord mCachedMinISize = NS_INTRINSIC_ISIZE_UNKNOWN;
|
|
|
|
nscoord mCachedPrefISize = NS_INTRINSIC_ISIZE_UNKNOWN;
|
2018-04-18 03:06:26 +03:00
|
|
|
|
2019-12-16 03:39:55 +03:00
|
|
|
nscoord mBaselineFromLastReflow = NS_INTRINSIC_ISIZE_UNKNOWN;
|
2016-12-21 01:56:35 +03:00
|
|
|
// Note: the last baseline is a distance from our border-box end edge.
|
2019-12-16 03:39:55 +03:00
|
|
|
nscoord mLastBaselineFromLastReflow = NS_INTRINSIC_ISIZE_UNKNOWN;
|
2012-06-27 02:12:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsFlexContainerFrame_h___ */
|