2014-02-27 11:45:29 +04: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/. */
|
|
|
|
|
2014-05-13 01:16:05 +04:00
|
|
|
/* rendering object for CSS "display: grid | inline-grid" */
|
2014-02-27 11:45:29 +04:00
|
|
|
|
|
|
|
#ifndef nsGridContainerFrame_h___
|
|
|
|
#define nsGridContainerFrame_h___
|
|
|
|
|
2016-03-13 02:30:36 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-09-04 23:06:57 +03:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2014-02-27 11:45:29 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2015-01-15 00:59:59 +03:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsTHashtable.h"
|
2014-02-27 11:45:29 +04:00
|
|
|
|
2014-05-13 01:16:05 +04:00
|
|
|
/**
|
|
|
|
* Factory function.
|
|
|
|
* @return a newly allocated nsGridContainerFrame (infallible)
|
|
|
|
*/
|
2014-05-25 02:20:40 +04:00
|
|
|
nsContainerFrame* NS_NewGridContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2014-02-27 11:45:29 +04:00
|
|
|
|
2016-01-27 19:02:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
/**
|
|
|
|
* The number of implicit / explicit tracks and their sizes.
|
|
|
|
*/
|
|
|
|
struct ComputedGridTrackInfo
|
|
|
|
{
|
|
|
|
ComputedGridTrackInfo(uint32_t aNumLeadingImplicitTracks,
|
|
|
|
uint32_t aNumExplicitTracks,
|
2016-07-06 21:45:18 +03:00
|
|
|
uint32_t aStartFragmentTrack,
|
|
|
|
uint32_t aEndFragmentTrack,
|
|
|
|
nsTArray<nscoord>&& aPositions,
|
|
|
|
nsTArray<nscoord>&& aSizes,
|
|
|
|
nsTArray<uint32_t>&& aStates)
|
2016-01-27 19:02:13 +03:00
|
|
|
: mNumLeadingImplicitTracks(aNumLeadingImplicitTracks)
|
|
|
|
, mNumExplicitTracks(aNumExplicitTracks)
|
2016-07-06 21:45:18 +03:00
|
|
|
, mStartFragmentTrack(aStartFragmentTrack)
|
|
|
|
, mEndFragmentTrack(aEndFragmentTrack)
|
|
|
|
, mPositions(aPositions)
|
2016-01-27 19:02:13 +03:00
|
|
|
, mSizes(aSizes)
|
2016-07-06 21:45:18 +03:00
|
|
|
, mStates(aStates)
|
2016-01-27 19:02:13 +03:00
|
|
|
{}
|
|
|
|
uint32_t mNumLeadingImplicitTracks;
|
|
|
|
uint32_t mNumExplicitTracks;
|
2016-07-06 21:45:18 +03:00
|
|
|
uint32_t mStartFragmentTrack;
|
|
|
|
uint32_t mEndFragmentTrack;
|
|
|
|
nsTArray<nscoord> mPositions;
|
2016-01-27 19:02:13 +03:00
|
|
|
nsTArray<nscoord> mSizes;
|
2016-07-06 21:45:18 +03:00
|
|
|
nsTArray<uint32_t> mStates;
|
2016-01-27 19:02:13 +03:00
|
|
|
};
|
2016-07-07 21:38:12 +03:00
|
|
|
|
|
|
|
struct ComputedGridLineInfo
|
|
|
|
{
|
|
|
|
explicit ComputedGridLineInfo(nsTArray<nsTArray<nsString>>&& aNames)
|
|
|
|
: mNames(aNames)
|
|
|
|
{}
|
|
|
|
nsTArray<nsTArray<nsString>> mNames;
|
|
|
|
};
|
2016-01-27 19:02:13 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsGridContainerFrame final : public nsContainerFrame
|
2014-05-13 01:16:05 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-02-27 11:45:29 +04:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsGridContainerFrame)
|
|
|
|
NS_DECL_QUERYFRAME
|
2016-03-13 02:30:36 +03:00
|
|
|
typedef mozilla::ComputedGridTrackInfo ComputedGridTrackInfo;
|
2016-07-07 21:38:12 +03:00
|
|
|
typedef mozilla::ComputedGridLineInfo ComputedGridLineInfo;
|
2014-02-27 11:45:29 +04:00
|
|
|
|
|
|
|
// nsIFrame overrides
|
2014-05-13 04:47:54 +04:00
|
|
|
void Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsReflowStatus& aStatus) override;
|
2015-09-04 23:06:58 +03:00
|
|
|
nscoord GetMinISize(nsRenderingContext* aRenderingContext) override;
|
|
|
|
nscoord GetPrefISize(nsRenderingContext* aRenderingContext) override;
|
|
|
|
void MarkIntrinsicISizesDirty() override;
|
2016-03-11 19:39:26 +03:00
|
|
|
nsIAtom* GetType() const override;
|
|
|
|
bool IsFrameOfType(uint32_t aFlags) const override
|
|
|
|
{
|
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
|
|
|
~nsIFrame::eCanContainOverflowContainers);
|
|
|
|
}
|
2014-05-13 01:16:05 +04:00
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) override;
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2016-03-11 19:39:27 +03:00
|
|
|
nsresult GetFrameName(nsAString& aResult) const override;
|
|
|
|
#endif
|
2016-03-11 19:39:27 +03:00
|
|
|
|
|
|
|
// nsContainerFrame overrides
|
|
|
|
bool DrainSelfOverflowList() override;
|
|
|
|
void AppendFrames(ChildListID aListID, nsFrameList& aFrameList) override;
|
|
|
|
void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList) override;
|
|
|
|
void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
|
|
|
|
|
2016-03-11 19:39:27 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList) override;
|
2014-02-27 11:45:29 +04:00
|
|
|
#endif
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
/**
|
|
|
|
* Return the containing block for aChild which MUST be an abs.pos. child
|
|
|
|
* of a grid container. This is just a helper method for
|
|
|
|
* nsAbsoluteContainingBlock::Reflow - it's not meant to be used elsewhere.
|
|
|
|
*/
|
|
|
|
static const nsRect& GridItemCB(nsIFrame* aChild);
|
|
|
|
|
2016-01-28 06:23:59 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridItemContainingBlockRect, nsRect)
|
2015-03-26 21:57:39 +03:00
|
|
|
|
2016-07-07 21:38:12 +03:00
|
|
|
/**
|
|
|
|
* These properties are created by a call to
|
|
|
|
* nsGridContainerFrame::GetGridFrameWithComputedInfo, typically from
|
|
|
|
* Element::GetGridFragments.
|
|
|
|
*/
|
2016-01-28 06:23:59 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridColTrackInfo, ComputedGridTrackInfo)
|
2016-01-27 19:02:13 +03:00
|
|
|
const ComputedGridTrackInfo* GetComputedTemplateColumns()
|
2015-11-25 04:27:54 +03:00
|
|
|
{
|
2016-07-07 21:38:12 +03:00
|
|
|
const ComputedGridTrackInfo* info = Properties().Get(GridColTrackInfo());
|
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
2015-11-25 04:27:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-28 06:23:59 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridRowTrackInfo, ComputedGridTrackInfo)
|
2016-01-27 19:02:13 +03:00
|
|
|
const ComputedGridTrackInfo* GetComputedTemplateRows()
|
2015-11-25 04:27:54 +03:00
|
|
|
{
|
2016-07-07 21:38:12 +03:00
|
|
|
const ComputedGridTrackInfo* info = Properties().Get(GridRowTrackInfo());
|
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
2015-11-25 04:27:54 +03:00
|
|
|
}
|
|
|
|
|
2016-07-07 21:38:12 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridColumnLineInfo, ComputedGridLineInfo)
|
|
|
|
const ComputedGridLineInfo* GetComputedTemplateColumnLines()
|
|
|
|
{
|
|
|
|
const ComputedGridLineInfo* info = Properties().Get(GridColumnLineInfo());
|
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridRowLineInfo, ComputedGridLineInfo)
|
|
|
|
const ComputedGridLineInfo* GetComputedTemplateRowLines()
|
|
|
|
{
|
|
|
|
const ComputedGridLineInfo* info = Properties().Get(GridRowLineInfo());
|
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:34:51 +03:00
|
|
|
typedef nsTHashtable<nsStringHashKey> ImplicitNamedAreas;
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ImplicitNamedAreasProperty,
|
|
|
|
ImplicitNamedAreas)
|
|
|
|
ImplicitNamedAreas* GetImplicitNamedAreas() const {
|
|
|
|
return Properties().Get(ImplicitNamedAreasProperty());
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef nsTArray<mozilla::css::GridNamedArea> ExplicitNamedAreas;
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ExplicitNamedAreasProperty,
|
|
|
|
ExplicitNamedAreas)
|
|
|
|
ExplicitNamedAreas* GetExplicitNamedAreas() const {
|
|
|
|
return Properties().Get(ExplicitNamedAreasProperty());
|
|
|
|
}
|
|
|
|
|
2016-07-07 21:38:12 +03:00
|
|
|
/**
|
|
|
|
* Return a containing grid frame, and ensure it has computed grid info
|
|
|
|
* @return nullptr if aFrame has no grid container, or frame was destroyed
|
|
|
|
* @note this might destroy layout/style data since it may flush layout
|
|
|
|
*/
|
|
|
|
static nsGridContainerFrame* GetGridFrameWithComputedInfo(nsIFrame* aFrame);
|
|
|
|
|
2016-03-11 19:39:26 +03:00
|
|
|
struct TrackSize;
|
2016-06-02 18:46:58 +03:00
|
|
|
struct GridItemInfo;
|
2016-07-21 13:36:39 +03:00
|
|
|
struct GridReflowInput;
|
2014-02-27 11:45:29 +04:00
|
|
|
protected:
|
2015-04-30 21:42:50 +03:00
|
|
|
static const uint32_t kAutoLine;
|
2015-04-30 21:42:50 +03:00
|
|
|
// The maximum line number, in the zero-based translated grid.
|
|
|
|
static const uint32_t kTranslatedMaxLine;
|
2015-03-26 21:57:39 +03:00
|
|
|
typedef mozilla::LogicalPoint LogicalPoint;
|
2015-03-18 12:02:32 +03:00
|
|
|
typedef mozilla::LogicalRect LogicalRect;
|
2015-09-10 13:24:34 +03:00
|
|
|
typedef mozilla::LogicalSize LogicalSize;
|
2015-03-18 12:02:32 +03:00
|
|
|
typedef mozilla::WritingMode WritingMode;
|
2015-03-18 12:02:32 +03:00
|
|
|
typedef mozilla::css::GridNamedArea GridNamedArea;
|
2016-03-13 16:12:00 +03:00
|
|
|
typedef mozilla::layout::AutoFrameListPtr AutoFrameListPtr;
|
2015-09-04 23:06:57 +03:00
|
|
|
typedef nsLayoutUtils::IntrinsicISizeType IntrinsicISizeType;
|
2016-03-11 19:39:25 +03:00
|
|
|
struct Grid;
|
2016-03-11 19:39:26 +03:00
|
|
|
struct GridArea;
|
|
|
|
class GridItemCSSOrderIterator;
|
2015-12-23 01:03:15 +03:00
|
|
|
class LineNameMap;
|
2016-03-11 19:39:26 +03:00
|
|
|
struct LineRange;
|
2016-03-11 19:39:26 +03:00
|
|
|
struct SharedGridData;
|
2016-03-11 19:39:26 +03:00
|
|
|
struct TrackSizingFunctions;
|
|
|
|
struct Tracks;
|
|
|
|
struct TranslatedLineRange;
|
2014-05-25 02:20:40 +04:00
|
|
|
friend nsContainerFrame* NS_NewGridContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2015-09-04 23:06:58 +03:00
|
|
|
explicit nsGridContainerFrame(nsStyleContext* aContext)
|
|
|
|
: nsContainerFrame(aContext)
|
|
|
|
, mCachedMinISize(NS_INTRINSIC_WIDTH_UNKNOWN)
|
|
|
|
, mCachedPrefISize(NS_INTRINSIC_WIDTH_UNKNOWN)
|
|
|
|
{}
|
2014-05-20 03:57:00 +04:00
|
|
|
|
2015-01-15 00:59:59 +03:00
|
|
|
/**
|
|
|
|
* XXX temporary - move the ImplicitNamedAreas stuff to the style system.
|
|
|
|
* The implicit area names that come from x-start .. x-end lines in
|
|
|
|
* grid-template-columns / grid-template-rows are stored in this frame
|
|
|
|
* property when needed, as a ImplicitNamedAreas* value.
|
|
|
|
*/
|
|
|
|
void InitImplicitNamedAreas(const nsStylePosition* aStyle);
|
|
|
|
void AddImplicitNamedAreas(const nsTArray<nsTArray<nsString>>& aLineNameLists);
|
2015-03-26 21:57:39 +03:00
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
/**
|
|
|
|
* Reflow and place our children.
|
2016-03-11 19:39:27 +03:00
|
|
|
* @return the consumed size of all of this grid container's continuations
|
|
|
|
* so far including this frame
|
2015-03-18 12:02:32 +03:00
|
|
|
*/
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord ReflowChildren(GridReflowInput& aState,
|
2016-03-11 19:39:27 +03:00
|
|
|
const LogicalRect& aContentArea,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-03-11 19:39:27 +03:00
|
|
|
nsReflowStatus& aStatus);
|
2015-03-18 12:02:32 +03:00
|
|
|
|
2015-09-04 23:06:58 +03:00
|
|
|
/**
|
|
|
|
* Helper for GetMinISize / GetPrefISize.
|
|
|
|
*/
|
|
|
|
nscoord IntrinsicISize(nsRenderingContext* aRenderingContext,
|
|
|
|
IntrinsicISizeType aConstraint);
|
|
|
|
|
2016-03-11 19:39:27 +03:00
|
|
|
// Helper for AppendFrames / InsertFrames.
|
|
|
|
void NoteNewChildren(ChildListID aListID, const nsFrameList& aFrameList);
|
|
|
|
|
2016-03-11 19:39:27 +03:00
|
|
|
// Helper to move child frames into the kOverflowList.
|
|
|
|
void MergeSortedOverflow(nsFrameList& aList);
|
|
|
|
// Helper to move child frames into the kExcessOverflowContainersList:.
|
|
|
|
void MergeSortedExcessOverflowContainers(nsFrameList& aList);
|
|
|
|
|
2014-05-20 03:57:00 +04:00
|
|
|
#ifdef DEBUG
|
2016-03-11 19:39:27 +03:00
|
|
|
void SanityCheckGridItemsBeforeReflow() const;
|
2014-05-20 03:57:00 +04:00
|
|
|
#endif // DEBUG
|
2015-03-18 12:02:32 +03:00
|
|
|
|
|
|
|
private:
|
2016-03-11 19:39:26 +03:00
|
|
|
// Helpers for ReflowChildren
|
|
|
|
struct Fragmentainer {
|
|
|
|
/**
|
|
|
|
* The distance from the first grid container fragment's block-axis content
|
|
|
|
* edge to the fragmentainer end.
|
|
|
|
*/
|
|
|
|
nscoord mToFragmentainerEnd;
|
|
|
|
/**
|
|
|
|
* True if the current fragment is at the start of the fragmentainer.
|
|
|
|
*/
|
|
|
|
bool mIsTopOfPage;
|
|
|
|
/**
|
|
|
|
* Is there a Class C break opportunity at the start content edge?
|
|
|
|
*/
|
|
|
|
bool mCanBreakAtStart;
|
|
|
|
/**
|
|
|
|
* Is there a Class C break opportunity at the end content edge?
|
|
|
|
*/
|
|
|
|
bool mCanBreakAtEnd;
|
|
|
|
/**
|
|
|
|
* Is the grid container's block-size unconstrained?
|
|
|
|
*/
|
|
|
|
bool mIsAutoBSize;
|
|
|
|
};
|
|
|
|
|
2016-03-13 02:30:36 +03:00
|
|
|
mozilla::Maybe<nsGridContainerFrame::Fragmentainer>
|
2016-07-21 13:36:39 +03:00
|
|
|
GetNearestFragmentainer(const GridReflowInput& aState) const;
|
2016-03-11 19:39:26 +03:00
|
|
|
|
2016-03-11 19:39:27 +03:00
|
|
|
// @return the consumed size of all continuations so far including this frame
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord ReflowInFragmentainer(GridReflowInput& aState,
|
2016-03-11 19:39:27 +03:00
|
|
|
const LogicalRect& aContentArea,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-03-11 19:39:27 +03:00
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
Fragmentainer& aFragmentainer,
|
|
|
|
const nsSize& aContainerSize);
|
|
|
|
|
|
|
|
// Helper for ReflowInFragmentainer
|
|
|
|
// @return the consumed size of all continuations so far including this frame
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord ReflowRowsInFragmentainer(GridReflowInput& aState,
|
2016-03-11 19:39:27 +03:00
|
|
|
const LogicalRect& aContentArea,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-03-11 19:39:27 +03:00
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
Fragmentainer& aFragmentainer,
|
|
|
|
const nsSize& aContainerSize,
|
|
|
|
const nsTArray<const GridItemInfo*>& aItems,
|
|
|
|
uint32_t aStartRow,
|
|
|
|
uint32_t aEndRow,
|
|
|
|
nscoord aBSize,
|
|
|
|
nscoord aAvailableSize);
|
|
|
|
|
2016-03-11 19:39:26 +03:00
|
|
|
// Helper for ReflowChildren / ReflowInFragmentainer
|
2016-05-18 14:49:33 +03:00
|
|
|
void ReflowInFlowChild(nsIFrame* aChild,
|
|
|
|
const GridItemInfo* aGridItemInfo,
|
|
|
|
nsSize aContainerSize,
|
|
|
|
mozilla::Maybe<nscoord> aStretchBSize,
|
|
|
|
const Fragmentainer* aFragmentainer,
|
2016-07-21 13:36:39 +03:00
|
|
|
const GridReflowInput& aState,
|
2016-05-18 14:49:33 +03:00
|
|
|
const LogicalRect& aContentArea,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-05-18 14:49:33 +03:00
|
|
|
nsReflowStatus& aStatus);
|
2016-03-11 19:39:26 +03:00
|
|
|
|
2015-09-04 23:06:58 +03:00
|
|
|
/**
|
|
|
|
* Cached values to optimize GetMinISize/GetPrefISize.
|
|
|
|
*/
|
|
|
|
nscoord mCachedMinISize;
|
|
|
|
nscoord mCachedPrefISize;
|
2016-03-11 19:39:27 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// If true, NS_STATE_GRID_DID_PUSH_ITEMS may be set even though all pushed
|
|
|
|
// frames may have been removed. This is used to suppress an assertion
|
|
|
|
// in case RemoveFrame removed all associated child frames.
|
|
|
|
bool mDidPushItemsBitMayLie;
|
|
|
|
#endif
|
2014-02-27 11:45:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsGridContainerFrame_h___ */
|