2017-10-27 17:33:53 +00: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 17:09:35 +00: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/. */
|
2014-02-27 07:45:29 +00:00
|
|
|
|
2014-05-12 21:16:05 +00:00
|
|
|
/* rendering object for CSS "display: grid | inline-grid" */
|
2014-02-27 07:45:29 +00:00
|
|
|
|
|
|
|
#ifndef nsGridContainerFrame_h___
|
|
|
|
#define nsGridContainerFrame_h___
|
|
|
|
|
2020-06-26 16:51:40 +00:00
|
|
|
#include "mozilla/CSSOrderAwareFrameIterator.h"
|
2021-09-20 19:52:45 +00:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2016-03-12 23:30:36 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2019-06-19 05:58:11 +00:00
|
|
|
#include "mozilla/HashTable.h"
|
2023-08-18 18:43:27 +00:00
|
|
|
#include "nsAtomHashKeys.h"
|
2014-02-27 07:45:29 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2022-10-02 07:49:46 +00:00
|
|
|
#include "nsILineIterator.h"
|
2014-02-27 07:45:29 +00:00
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
namespace mozilla {
|
|
|
|
class PresShell;
|
2023-02-23 01:07:34 +00:00
|
|
|
namespace dom {
|
|
|
|
class Grid;
|
|
|
|
}
|
2019-04-16 07:24:49 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-05-12 21:16:05 +00:00
|
|
|
/**
|
|
|
|
* Factory function.
|
|
|
|
* @return a newly allocated nsGridContainerFrame (infallible)
|
|
|
|
*/
|
2019-04-16 07:24:49 +00:00
|
|
|
nsContainerFrame* NS_NewGridContainerFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 18:20:41 +00:00
|
|
|
mozilla::ComputedStyle* aStyle);
|
2014-02-27 07:45:29 +00:00
|
|
|
|
2016-01-27 16:02:13 +00:00
|
|
|
namespace mozilla {
|
2017-04-06 02:31:47 +00:00
|
|
|
|
2016-01-27 16:02:13 +00:00
|
|
|
/**
|
|
|
|
* The number of implicit / explicit tracks and their sizes.
|
|
|
|
*/
|
|
|
|
struct ComputedGridTrackInfo {
|
|
|
|
ComputedGridTrackInfo(
|
|
|
|
uint32_t aNumLeadingImplicitTracks, uint32_t aNumExplicitTracks,
|
2016-07-06 18:45:18 +00:00
|
|
|
uint32_t aStartFragmentTrack, uint32_t aEndFragmentTrack,
|
|
|
|
nsTArray<nscoord>&& aPositions, nsTArray<nscoord>&& aSizes,
|
2016-09-21 18:49:29 +00:00
|
|
|
nsTArray<uint32_t>&& aStates, nsTArray<bool>&& aRemovedRepeatTracks,
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 11:27:19 +00:00
|
|
|
uint32_t aRepeatFirstTrack,
|
2019-10-12 17:16:02 +00:00
|
|
|
nsTArray<nsTArray<StyleCustomIdent>>&& aResolvedLineNames,
|
2020-04-28 01:18:47 +00:00
|
|
|
bool aIsSubgrid, bool aIsMasonry)
|
2016-01-27 16:02:13 +00:00
|
|
|
: mNumLeadingImplicitTracks(aNumLeadingImplicitTracks),
|
|
|
|
mNumExplicitTracks(aNumExplicitTracks),
|
2016-07-06 18:45:18 +00:00
|
|
|
mStartFragmentTrack(aStartFragmentTrack),
|
|
|
|
mEndFragmentTrack(aEndFragmentTrack),
|
2020-05-05 10:11:01 +00:00
|
|
|
mPositions(std::move(aPositions)),
|
|
|
|
mSizes(std::move(aSizes)),
|
|
|
|
mStates(std::move(aStates)),
|
|
|
|
mRemovedRepeatTracks(std::move(aRemovedRepeatTracks)),
|
2019-10-12 17:16:02 +00:00
|
|
|
mResolvedLineNames(std::move(aResolvedLineNames)),
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 11:27:19 +00:00
|
|
|
mRepeatFirstTrack(aRepeatFirstTrack),
|
2020-04-28 01:18:47 +00:00
|
|
|
mIsSubgrid(aIsSubgrid),
|
|
|
|
mIsMasonry(aIsMasonry) {}
|
2016-01-27 16:02:13 +00:00
|
|
|
uint32_t mNumLeadingImplicitTracks;
|
|
|
|
uint32_t mNumExplicitTracks;
|
2016-07-06 18:45:18 +00:00
|
|
|
uint32_t mStartFragmentTrack;
|
|
|
|
uint32_t mEndFragmentTrack;
|
|
|
|
nsTArray<nscoord> mPositions;
|
2016-01-27 16:02:13 +00:00
|
|
|
nsTArray<nscoord> mSizes;
|
2016-07-06 18:45:18 +00:00
|
|
|
nsTArray<uint32_t> mStates;
|
2020-01-28 16:58:06 +00:00
|
|
|
// Indicates if a track has been collapsed. This will be populated for each
|
|
|
|
// track in the repeat(auto-fit) and repeat(auto-fill), even if there are no
|
|
|
|
// collapsed tracks.
|
2016-09-08 15:40:06 +00:00
|
|
|
nsTArray<bool> mRemovedRepeatTracks;
|
2020-01-28 16:58:06 +00:00
|
|
|
// Contains lists of all line name lists, including the name lists inside
|
|
|
|
// repeats. When a repeat(auto) track exists, the internal track names will
|
|
|
|
// appear once each in this array.
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 11:27:19 +00:00
|
|
|
nsTArray<nsTArray<StyleCustomIdent>> mResolvedLineNames;
|
2019-10-12 17:16:02 +00:00
|
|
|
uint32_t mRepeatFirstTrack;
|
|
|
|
bool mIsSubgrid;
|
2020-04-28 01:18:47 +00:00
|
|
|
bool mIsMasonry;
|
2016-01-27 16:02:13 +00:00
|
|
|
};
|
2016-07-07 18:38:12 +00:00
|
|
|
|
|
|
|
struct ComputedGridLineInfo {
|
2019-06-19 05:58:11 +00:00
|
|
|
explicit ComputedGridLineInfo(
|
|
|
|
nsTArray<nsTArray<RefPtr<nsAtom>>>&& aNames,
|
|
|
|
const nsTArray<RefPtr<nsAtom>>& aNamesBefore,
|
|
|
|
const nsTArray<RefPtr<nsAtom>>& aNamesAfter,
|
|
|
|
nsTArray<RefPtr<nsAtom>>&& aNamesFollowingRepeat)
|
2020-05-05 10:11:01 +00:00
|
|
|
: mNames(std::move(aNames)),
|
|
|
|
mNamesBefore(aNamesBefore.Clone()),
|
|
|
|
mNamesAfter(aNamesAfter.Clone()),
|
|
|
|
mNamesFollowingRepeat(std::move(aNamesFollowingRepeat)) {}
|
2019-06-19 05:58:11 +00:00
|
|
|
nsTArray<nsTArray<RefPtr<nsAtom>>> mNames;
|
|
|
|
nsTArray<RefPtr<nsAtom>> mNamesBefore;
|
|
|
|
nsTArray<RefPtr<nsAtom>> mNamesAfter;
|
|
|
|
nsTArray<RefPtr<nsAtom>> mNamesFollowingRepeat;
|
2016-07-07 18:38:12 +00:00
|
|
|
};
|
2016-01-27 16:02:13 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2022-10-02 07:49:46 +00:00
|
|
|
class nsGridContainerFrame final : public nsContainerFrame,
|
|
|
|
public nsILineIterator {
|
2014-05-12 21:16:05 +00:00
|
|
|
public:
|
2017-05-26 10:11:11 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsGridContainerFrame)
|
2014-02-27 07:45:29 +00:00
|
|
|
NS_DECL_QUERYFRAME
|
2019-04-25 22:42:13 +00:00
|
|
|
using ComputedGridTrackInfo = mozilla::ComputedGridTrackInfo;
|
|
|
|
using ComputedGridLineInfo = mozilla::ComputedGridLineInfo;
|
|
|
|
using LogicalAxis = mozilla::LogicalAxis;
|
|
|
|
using BaselineSharingGroup = mozilla::BaselineSharingGroup;
|
2019-06-18 22:29:58 +00:00
|
|
|
using NamedArea = mozilla::StyleNamedArea;
|
2019-04-25 22:42:13 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2024-03-02 07:50:19 +00:00
|
|
|
using PerBaseline = mozilla::EnumeratedArray<BaselineSharingGroup, T, 2>;
|
2019-04-25 22:42:13 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2024-03-02 07:50:19 +00:00
|
|
|
using PerLogicalAxis = mozilla::EnumeratedArray<LogicalAxis, T, 2>;
|
2014-02-27 07:45:29 +00:00
|
|
|
|
|
|
|
// nsIFrame overrides
|
2014-05-13 00:47:54 +00:00
|
|
|
void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
|
2016-07-21 10:36:39 +00:00
|
|
|
const ReflowInput& aReflowInput,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsReflowStatus& aStatus) override;
|
2018-06-05 19:46:28 +00:00
|
|
|
void Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) override;
|
2019-05-01 21:53:47 +00:00
|
|
|
void DidSetComputedStyle(ComputedStyle* aOldStyle) override;
|
2017-06-09 19:14:53 +00:00
|
|
|
nscoord GetMinISize(gfxContext* aRenderingContext) override;
|
|
|
|
nscoord GetPrefISize(gfxContext* aRenderingContext) override;
|
2015-09-04 20:06:58 +00:00
|
|
|
void MarkIntrinsicISizesDirty() override;
|
2014-05-12 21:16:05 +00:00
|
|
|
|
2015-03-26 18:57:39 +00:00
|
|
|
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) override;
|
|
|
|
|
2023-02-23 14:53:27 +00:00
|
|
|
Maybe<nscoord> GetNaturalBaselineBOffset(
|
2023-05-17 12:56:54 +00:00
|
|
|
mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup,
|
|
|
|
BaselineExportContext) const override {
|
2021-08-06 18:46:22 +00:00
|
|
|
if (StyleDisplay()->IsContainLayout() ||
|
|
|
|
HasAnyStateBits(NS_STATE_GRID_SYNTHESIZE_BASELINE)) {
|
2023-02-23 14:53:27 +00:00
|
|
|
return Nothing{};
|
2016-12-20 22:56:35 +00:00
|
|
|
}
|
2023-02-23 14:53:27 +00:00
|
|
|
return mozilla::Some(GetBBaseline(aBaselineGroup));
|
2016-12-20 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 07:45:29 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2016-03-11 16:39:27 +00:00
|
|
|
nsresult GetFrameName(nsAString& aResult) const override;
|
2020-04-09 21:25:12 +00:00
|
|
|
void ExtraContainerFrameInfo(nsACString& aTo) const override;
|
2016-03-11 16:39:27 +00:00
|
|
|
#endif
|
2016-03-11 16:39:27 +00:00
|
|
|
|
|
|
|
// nsContainerFrame overrides
|
|
|
|
bool DrainSelfOverflowList() override;
|
2022-11-01 21:15:54 +00:00
|
|
|
void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
|
2016-03-11 16:39:27 +00:00
|
|
|
void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
2019-07-17 23:34:45 +00:00
|
|
|
const nsLineList::iterator* aPrevFrameLine,
|
2022-11-01 21:15:55 +00:00
|
|
|
nsFrameList&& aFrameList) override;
|
2023-09-08 15:11:17 +00:00
|
|
|
void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
|
2020-01-31 00:56:49 +00:00
|
|
|
mozilla::StyleAlignFlags CSSAlignmentForAbsPosChild(
|
|
|
|
const ReflowInput& aChildRI, LogicalAxis aLogicalAxis) const override;
|
2016-03-11 16:39:27 +00:00
|
|
|
|
2016-03-11 16:39:27 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void SetInitialChildList(ChildListID aListID,
|
2022-11-01 21:15:54 +00:00
|
|
|
nsFrameList&& aChildList) override;
|
2014-02-27 07:45:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-26 18:57:39 +00:00
|
|
|
/**
|
|
|
|
* Return the containing block for aChild which MUST be an abs.pos. child
|
2018-09-10 22:57:53 +00:00
|
|
|
* of a grid container and that container must have been reflowed.
|
2015-03-26 18:57:39 +00:00
|
|
|
*/
|
|
|
|
static const nsRect& GridItemCB(nsIFrame* aChild);
|
|
|
|
|
2016-01-28 03:23:59 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridItemContainingBlockRect, nsRect)
|
2015-03-26 18:57:39 +00:00
|
|
|
|
2016-07-07 18:38:12 +00:00
|
|
|
/**
|
|
|
|
* These properties are created by a call to
|
|
|
|
* nsGridContainerFrame::GetGridFrameWithComputedInfo, typically from
|
|
|
|
* Element::GetGridFragments.
|
|
|
|
*/
|
2016-01-28 03:23:59 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridColTrackInfo, ComputedGridTrackInfo)
|
2016-01-27 16:02:13 +00:00
|
|
|
const ComputedGridTrackInfo* GetComputedTemplateColumns() {
|
2017-05-27 11:36:00 +00:00
|
|
|
const ComputedGridTrackInfo* info = GetProperty(GridColTrackInfo());
|
2016-07-07 18:38:12 +00:00
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
2015-11-25 01:27:54 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 03:23:59 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridRowTrackInfo, ComputedGridTrackInfo)
|
2016-01-27 16:02:13 +00:00
|
|
|
const ComputedGridTrackInfo* GetComputedTemplateRows() {
|
2017-05-27 11:36:00 +00:00
|
|
|
const ComputedGridTrackInfo* info = GetProperty(GridRowTrackInfo());
|
2016-07-07 18:38:12 +00:00
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
2015-11-25 01:27:54 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 18:38:12 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridColumnLineInfo, ComputedGridLineInfo)
|
|
|
|
const ComputedGridLineInfo* GetComputedTemplateColumnLines() {
|
2017-05-27 11:36:00 +00:00
|
|
|
const ComputedGridLineInfo* info = GetProperty(GridColumnLineInfo());
|
2016-07-07 18:38:12 +00:00
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridRowLineInfo, ComputedGridLineInfo)
|
|
|
|
const ComputedGridLineInfo* GetComputedTemplateRowLines() {
|
2017-05-27 11:36:00 +00:00
|
|
|
const ComputedGridLineInfo* info = GetProperty(GridRowLineInfo());
|
2016-07-07 18:38:12 +00:00
|
|
|
MOZ_ASSERT(info, "Property generation wasn't requested.");
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-02-23 01:07:34 +00:00
|
|
|
/**
|
|
|
|
* This property is set by the creation of a dom::Grid object, and cleared
|
|
|
|
* during GC unlink. Since the Grid object manages the lifecycle, the property
|
|
|
|
* itself is set without a destructor. The property is also cleared whenever
|
|
|
|
* new grid computed info is generated during reflow, ensuring that we aren't
|
|
|
|
* holding a stale dom::Grid object.
|
|
|
|
*/
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(GridFragmentInfo, mozilla::dom::Grid)
|
|
|
|
mozilla::dom::Grid* GetGridFragmentInfo() {
|
|
|
|
return GetProperty(GridFragmentInfo());
|
|
|
|
}
|
|
|
|
|
2023-08-18 18:43:27 +00:00
|
|
|
using ImplicitNamedAreas =
|
|
|
|
mozilla::HashMap<mozilla::AtomHashKey, NamedArea, mozilla::AtomHashKey>;
|
2016-08-23 20:34:51 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ImplicitNamedAreasProperty,
|
|
|
|
ImplicitNamedAreas)
|
|
|
|
ImplicitNamedAreas* GetImplicitNamedAreas() const {
|
2017-05-27 11:36:00 +00:00
|
|
|
return GetProperty(ImplicitNamedAreasProperty());
|
2016-08-23 20:34:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 22:29:58 +00:00
|
|
|
using ExplicitNamedAreas = mozilla::StyleOwnedSlice<NamedArea>;
|
2016-08-23 20:34:51 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ExplicitNamedAreasProperty,
|
|
|
|
ExplicitNamedAreas)
|
|
|
|
ExplicitNamedAreas* GetExplicitNamedAreas() const {
|
2017-05-27 11:36:00 +00:00
|
|
|
return GetProperty(ExplicitNamedAreasProperty());
|
2016-08-23 20:34:51 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 01:18:47 +00:00
|
|
|
using nsContainerFrame::IsMasonry;
|
|
|
|
|
|
|
|
/** Return true if this frame has masonry layout in any axis. */
|
|
|
|
bool IsMasonry() const {
|
|
|
|
return HasAnyStateBits(NS_STATE_GRID_IS_ROW_MASONRY |
|
|
|
|
NS_STATE_GRID_IS_COL_MASONRY);
|
|
|
|
}
|
|
|
|
|
2018-06-05 19:46:28 +00:00
|
|
|
/** Return true if this frame is subgridded in its aAxis. */
|
2018-11-29 17:05:53 +00:00
|
|
|
bool IsSubgrid(LogicalAxis aAxis) const {
|
2024-03-30 16:20:37 +00:00
|
|
|
return HasAnyStateBits(aAxis == mozilla::LogicalAxis::Block
|
2018-06-05 19:46:28 +00:00
|
|
|
? NS_STATE_GRID_IS_ROW_SUBGRID
|
|
|
|
: NS_STATE_GRID_IS_COL_SUBGRID);
|
|
|
|
}
|
2024-03-30 16:20:37 +00:00
|
|
|
bool IsColSubgrid() const { return IsSubgrid(mozilla::LogicalAxis::Inline); }
|
|
|
|
bool IsRowSubgrid() const { return IsSubgrid(mozilla::LogicalAxis::Block); }
|
2018-06-05 19:46:28 +00:00
|
|
|
/** Return true if this frame is subgridded in any axis. */
|
|
|
|
bool IsSubgrid() const {
|
|
|
|
return HasAnyStateBits(NS_STATE_GRID_IS_ROW_SUBGRID |
|
|
|
|
NS_STATE_GRID_IS_COL_SUBGRID);
|
|
|
|
}
|
|
|
|
|
2018-06-05 19:46:28 +00:00
|
|
|
/** Return true if this frame has an item that is subgridded in our aAxis. */
|
2018-11-29 17:05:53 +00:00
|
|
|
bool HasSubgridItems(LogicalAxis aAxis) const {
|
2024-03-30 16:20:37 +00:00
|
|
|
return HasAnyStateBits(aAxis == mozilla::LogicalAxis::Block
|
2018-06-05 19:46:28 +00:00
|
|
|
? NS_STATE_GRID_HAS_ROW_SUBGRID_ITEM
|
|
|
|
: NS_STATE_GRID_HAS_COL_SUBGRID_ITEM);
|
|
|
|
}
|
|
|
|
/** Return true if this frame has any subgrid items. */
|
|
|
|
bool HasSubgridItems() const {
|
|
|
|
return HasAnyStateBits(NS_STATE_GRID_HAS_ROW_SUBGRID_ITEM |
|
|
|
|
NS_STATE_GRID_HAS_COL_SUBGRID_ITEM);
|
|
|
|
}
|
2023-12-18 22:12:43 +00:00
|
|
|
/**
|
|
|
|
* Return true if the grid item aChild should stretch in its aAxis (i.e. aAxis
|
|
|
|
* is in the aChild's writing-mode).
|
|
|
|
*
|
|
|
|
* Note: this method does *not* consider the grid item's aspect-ratio and
|
|
|
|
* natural size in the axis when the self-alignment value is 'normal' per
|
|
|
|
* https://drafts.csswg.org/css-grid/#grid-item-sizing
|
|
|
|
*/
|
|
|
|
bool GridItemShouldStretch(const nsIFrame* aChild, LogicalAxis aAxis) const;
|
2018-06-05 19:46:28 +00:00
|
|
|
|
2023-12-20 02:03:03 +00:00
|
|
|
/**
|
|
|
|
* Returns true if aFrame forms an independent formatting context and hence
|
|
|
|
* should be inhibited from being a subgrid (i.e. if the used value of
|
|
|
|
* 'grid-template-{rows,columns}:subgrid' should be 'none').
|
|
|
|
* https://drafts.csswg.org/css-grid-2/#subgrid-listing
|
|
|
|
*
|
|
|
|
* (Note this only makes sense to call if aFrame is itself either a grid
|
|
|
|
* container frame or a wrapper frame for a grid container frame, e.g. a
|
|
|
|
* scroll container frame for a scrollable grid. Having said that, this is
|
|
|
|
* technically safe to call on any non-null frame.)
|
|
|
|
*/
|
|
|
|
static bool ShouldInhibitSubgridDueToIFC(const nsIFrame* aFrame);
|
|
|
|
|
2016-07-07 18:38:12 +00:00
|
|
|
/**
|
2018-06-14 23:35:42 +00:00
|
|
|
* Return a container grid frame for the supplied frame, if available.
|
|
|
|
* @return nullptr if aFrame has no grid container.
|
|
|
|
*/
|
|
|
|
static nsGridContainerFrame* GetGridContainerFrame(nsIFrame* aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a container grid frame, and ensure it has computed grid info
|
2016-07-07 18:38:12 +00:00
|
|
|
* @return nullptr if aFrame has no grid container, or frame was destroyed
|
|
|
|
* @note this might destroy layout/style data since it may flush layout
|
|
|
|
*/
|
2019-04-13 12:43:57 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2016-07-07 18:38:12 +00:00
|
|
|
static nsGridContainerFrame* GetGridFrameWithComputedInfo(nsIFrame* aFrame);
|
|
|
|
|
2018-11-28 23:18:09 +00:00
|
|
|
struct Subgrid;
|
2018-11-29 17:05:53 +00:00
|
|
|
struct UsedTrackSizes;
|
2016-03-11 16:39:26 +00:00
|
|
|
struct TrackSize;
|
2016-06-02 15:46:58 +00:00
|
|
|
struct GridItemInfo;
|
2016-07-21 10:36:39 +00:00
|
|
|
struct GridReflowInput;
|
2016-10-01 00:26:39 +00:00
|
|
|
struct FindItemInGridOrderResult {
|
|
|
|
// The first(last) item in (reverse) grid order.
|
|
|
|
const GridItemInfo* mItem;
|
|
|
|
// Does the above item span the first(last) track?
|
|
|
|
bool mIsInEdgeTrack;
|
|
|
|
};
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-11-28 23:18:09 +00:00
|
|
|
/** Return our parent grid container; |this| MUST be a subgrid. */
|
|
|
|
nsGridContainerFrame* ParentGridContainerForSubgrid() const;
|
|
|
|
|
2020-04-28 01:18:47 +00:00
|
|
|
// https://drafts.csswg.org/css-sizing/#constraints
|
|
|
|
enum class SizingConstraint {
|
|
|
|
MinContent, // sizing under min-content constraint
|
|
|
|
MaxContent, // sizing under max-content constraint
|
|
|
|
NoConstraint // no constraint, used during Reflow
|
|
|
|
};
|
|
|
|
|
2014-02-27 07:45:29 +00:00
|
|
|
protected:
|
2015-03-26 18:57:39 +00:00
|
|
|
typedef mozilla::LogicalPoint LogicalPoint;
|
2015-03-18 09:02:32 +00:00
|
|
|
typedef mozilla::LogicalRect LogicalRect;
|
2015-09-10 10:24:34 +00:00
|
|
|
typedef mozilla::LogicalSize LogicalSize;
|
2015-03-18 09:02:32 +00:00
|
|
|
typedef mozilla::WritingMode WritingMode;
|
2016-03-11 16:39:25 +00:00
|
|
|
struct Grid;
|
2016-03-11 16:39:26 +00:00
|
|
|
struct GridArea;
|
2015-12-22 22:03:15 +00:00
|
|
|
class LineNameMap;
|
2016-03-11 16:39:26 +00:00
|
|
|
struct LineRange;
|
2016-03-11 16:39:26 +00:00
|
|
|
struct SharedGridData;
|
2018-11-29 17:05:53 +00:00
|
|
|
struct SubgridFallbackTrackSizingFunctions;
|
2016-03-11 16:39:26 +00:00
|
|
|
struct TrackSizingFunctions;
|
|
|
|
struct Tracks;
|
|
|
|
struct TranslatedLineRange;
|
2019-04-16 07:24:49 +00:00
|
|
|
friend nsContainerFrame* NS_NewGridContainerFrame(
|
|
|
|
mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
|
2019-02-05 16:45:54 +00:00
|
|
|
explicit nsGridContainerFrame(ComputedStyle* aStyle,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
: nsContainerFrame(aStyle, aPresContext, kClassID),
|
2019-05-03 17:34:36 +00:00
|
|
|
mCachedMinISize(NS_INTRINSIC_ISIZE_UNKNOWN),
|
|
|
|
mCachedPrefISize(NS_INTRINSIC_ISIZE_UNKNOWN) {
|
2019-04-25 22:42:13 +00:00
|
|
|
for (auto& perAxisBaseline : mBaseline) {
|
|
|
|
for (auto& baseline : perAxisBaseline) {
|
2019-05-03 17:34:36 +00:00
|
|
|
baseline = NS_INTRINSIC_ISIZE_UNKNOWN;
|
2019-04-25 22:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-01 00:26:39 +00:00
|
|
|
}
|
2014-05-19 23:57:00 +00:00
|
|
|
|
2015-01-14 21:59:59 +00: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);
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 11:27:19 +00:00
|
|
|
|
|
|
|
using LineNameList =
|
|
|
|
const mozilla::StyleOwnedSlice<mozilla::StyleCustomIdent>;
|
|
|
|
void AddImplicitNamedAreas(mozilla::Span<LineNameList>);
|
2023-11-08 21:44:36 +00:00
|
|
|
using StyleLineNameListValue =
|
|
|
|
const mozilla::StyleGenericLineNameListValue<mozilla::StyleInteger>;
|
|
|
|
void AddImplicitNamedAreas(mozilla::Span<StyleLineNameListValue>);
|
2015-03-26 18:57:39 +00:00
|
|
|
|
2015-03-18 09:02:32 +00:00
|
|
|
/**
|
|
|
|
* Reflow and place our children.
|
2016-03-11 16:39:27 +00:00
|
|
|
* @return the consumed size of all of this grid container's continuations
|
|
|
|
* so far including this frame
|
2015-03-18 09:02:32 +00:00
|
|
|
*/
|
2016-07-21 10:36:39 +00:00
|
|
|
nscoord ReflowChildren(GridReflowInput& aState,
|
2016-03-11 16:39:27 +00:00
|
|
|
const LogicalRect& aContentArea,
|
2020-04-28 01:18:47 +00:00
|
|
|
const nsSize& aContainerSize,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize, nsReflowStatus& aStatus);
|
2015-03-18 09:02:32 +00:00
|
|
|
|
2015-09-04 20:06:58 +00:00
|
|
|
/**
|
|
|
|
* Helper for GetMinISize / GetPrefISize.
|
|
|
|
*/
|
2017-06-09 19:14:53 +00:00
|
|
|
nscoord IntrinsicISize(gfxContext* aRenderingContext,
|
2020-09-26 18:19:14 +00:00
|
|
|
mozilla::IntrinsicISizeType aConstraint);
|
2015-09-04 20:06:58 +00:00
|
|
|
|
2023-02-23 14:53:27 +00:00
|
|
|
nscoord GetBBaseline(BaselineSharingGroup aBaselineGroup) const {
|
2024-03-30 16:20:37 +00:00
|
|
|
return mBaseline[mozilla::LogicalAxis::Block][aBaselineGroup];
|
2016-10-01 00:26:39 +00:00
|
|
|
}
|
2023-02-23 14:53:27 +00:00
|
|
|
nscoord GetIBaseline(BaselineSharingGroup aBaselineGroup) const {
|
2024-03-30 16:20:37 +00:00
|
|
|
return mBaseline[mozilla::LogicalAxis::Inline][aBaselineGroup];
|
2016-10-01 00:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate this grid container's baselines.
|
|
|
|
* @param aBaselineSet which baseline(s) to derive from a baseline-group or
|
|
|
|
* items; a baseline not included is synthesized from the border-box instead.
|
|
|
|
* @param aFragmentStartTrack is the first track in this fragment in the same
|
|
|
|
* axis as aMajor. Pass zero if that's not the axis we're fragmenting in.
|
|
|
|
* @param aFirstExcludedTrack should be the first track in the next fragment
|
|
|
|
* or one beyond the final track in the last fragment, in aMajor's axis.
|
|
|
|
* Pass the number of tracks if that's not the axis we're fragmenting in.
|
|
|
|
*/
|
|
|
|
enum BaselineSet : uint32_t {
|
|
|
|
eNone = 0x0,
|
|
|
|
eFirst = 0x1,
|
|
|
|
eLast = 0x2,
|
|
|
|
eBoth = eFirst | eLast,
|
|
|
|
};
|
|
|
|
void CalculateBaselines(BaselineSet aBaselineSet,
|
2020-06-26 16:51:40 +00:00
|
|
|
mozilla::CSSOrderAwareFrameIterator* aIter,
|
2016-10-01 00:26:39 +00:00
|
|
|
const nsTArray<GridItemInfo>* aGridItems,
|
|
|
|
const Tracks& aTracks, uint32_t aFragmentStartTrack,
|
|
|
|
uint32_t aFirstExcludedTrack, WritingMode aWM,
|
|
|
|
const nsSize& aCBPhysicalSize,
|
|
|
|
nscoord aCBBorderPaddingStart,
|
|
|
|
nscoord aCBBorderPaddingStartEnd, nscoord aCBSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synthesize a Grid container baseline for aGroup.
|
|
|
|
*/
|
2024-02-05 09:28:30 +00:00
|
|
|
nscoord SynthesizeBaseline(const FindItemInGridOrderResult& aGridOrderItem,
|
2018-11-29 17:05:53 +00:00
|
|
|
LogicalAxis aAxis, BaselineSharingGroup aGroup,
|
2016-10-01 00:26:39 +00:00
|
|
|
const nsSize& aCBPhysicalSize, nscoord aCBSize,
|
|
|
|
WritingMode aCBWM);
|
2016-10-01 00:26:39 +00:00
|
|
|
/**
|
|
|
|
* Find the first item in Grid Order in this fragment.
|
|
|
|
* https://drafts.csswg.org/css-grid/#grid-order
|
|
|
|
* @param aFragmentStartTrack is the first track in this fragment in the same
|
|
|
|
* axis as aMajor. Pass zero if that's not the axis we're fragmenting in.
|
|
|
|
*/
|
|
|
|
static FindItemInGridOrderResult FindFirstItemInGridOrder(
|
2020-06-26 16:51:40 +00:00
|
|
|
mozilla::CSSOrderAwareFrameIterator& aIter,
|
2016-10-01 00:26:39 +00:00
|
|
|
const nsTArray<GridItemInfo>& aGridItems, LineRange GridArea::*aMajor,
|
|
|
|
LineRange GridArea::*aMinor, uint32_t aFragmentStartTrack);
|
|
|
|
/**
|
|
|
|
* Find the last item in Grid Order in this fragment.
|
|
|
|
* @param aFragmentStartTrack is the first track in this fragment in the same
|
|
|
|
* axis as aMajor. Pass zero if that's not the axis we're fragmenting in.
|
|
|
|
* @param aFirstExcludedTrack should be the first track in the next fragment
|
|
|
|
* or one beyond the final track in the last fragment, in aMajor's axis.
|
|
|
|
* Pass the number of tracks if that's not the axis we're fragmenting in.
|
|
|
|
*/
|
|
|
|
static FindItemInGridOrderResult FindLastItemInGridOrder(
|
2020-06-26 16:51:40 +00:00
|
|
|
mozilla::ReverseCSSOrderAwareFrameIterator& aIter,
|
2016-10-01 00:26:39 +00:00
|
|
|
const nsTArray<GridItemInfo>& aGridItems, LineRange GridArea::*aMajor,
|
|
|
|
LineRange GridArea::*aMinor, uint32_t aFragmentStartTrack,
|
|
|
|
uint32_t aFirstExcludedTrack);
|
|
|
|
|
2019-05-01 21:53:47 +00:00
|
|
|
/**
|
|
|
|
* Update our NS_STATE_GRID_IS_COL/ROW_SUBGRID bits and related subgrid state
|
|
|
|
* on our entire continuation chain based on the current style.
|
|
|
|
* This is needed because grid-template-columns/rows style changes only
|
|
|
|
* trigger a reflow so we need to update this dynamically.
|
|
|
|
*/
|
|
|
|
void UpdateSubgridFrameState();
|
|
|
|
|
|
|
|
/**
|
2020-04-28 01:18:47 +00:00
|
|
|
* Return the NS_STATE_GRID_IS_COL/ROW_SUBGRID and
|
|
|
|
* NS_STATE_GRID_IS_ROW/COL_MASONRY bits we ought to have.
|
2019-05-01 21:53:47 +00:00
|
|
|
*/
|
2020-04-28 01:18:47 +00:00
|
|
|
nsFrameState ComputeSelfSubgridMasonryBits() const;
|
2020-01-25 02:45:31 +00:00
|
|
|
|
2015-03-18 09:02:32 +00:00
|
|
|
private:
|
2016-03-11 16:39:26 +00: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-12 23:30:36 +00:00
|
|
|
mozilla::Maybe<nsGridContainerFrame::Fragmentainer> GetNearestFragmentainer(
|
2016-07-21 10:36:39 +00:00
|
|
|
const GridReflowInput& aState) const;
|
2016-03-11 16:39:26 +00:00
|
|
|
|
2016-03-11 16:39:27 +00:00
|
|
|
// @return the consumed size of all continuations so far including this frame
|
2016-07-21 10:36:39 +00:00
|
|
|
nscoord ReflowInFragmentainer(GridReflowInput& aState,
|
2016-03-11 16:39:27 +00:00
|
|
|
const LogicalRect& aContentArea,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-03-11 16:39:27 +00: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 10:36:39 +00:00
|
|
|
nscoord ReflowRowsInFragmentainer(
|
2016-03-11 16:39:27 +00:00
|
|
|
GridReflowInput& aState, const LogicalRect& aContentArea,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize, nsReflowStatus& aStatus,
|
2016-03-11 16:39:27 +00:00
|
|
|
Fragmentainer& aFragmentainer, const nsSize& aContainerSize,
|
|
|
|
const nsTArray<const GridItemInfo*>& aItems, uint32_t aStartRow,
|
|
|
|
uint32_t aEndRow, nscoord aBSize, nscoord aAvailableSize);
|
|
|
|
|
2016-03-11 16:39:26 +00:00
|
|
|
// Helper for ReflowChildren / ReflowInFragmentainer
|
2016-05-18 11:49:33 +00:00
|
|
|
void ReflowInFlowChild(nsIFrame* aChild, const GridItemInfo* aGridItemInfo,
|
|
|
|
nsSize aContainerSize,
|
2017-02-13 17:07:40 +00:00
|
|
|
const mozilla::Maybe<nscoord>& aStretchBSize,
|
2016-05-18 11:49:33 +00:00
|
|
|
const Fragmentainer* aFragmentainer,
|
2016-07-21 10:36:39 +00:00
|
|
|
const GridReflowInput& aState,
|
2016-05-18 11:49:33 +00:00
|
|
|
const LogicalRect& aContentArea,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize, nsReflowStatus& aStatus);
|
2016-03-11 16:39:26 +00:00
|
|
|
|
2020-04-28 01:18:47 +00:00
|
|
|
/**
|
|
|
|
* Places and reflows items when we have masonry layout.
|
|
|
|
* It handles unconstrained reflow and also fragmentation when the row axis
|
|
|
|
* is the masonry axis. ReflowInFragmentainer handles the case when we're
|
|
|
|
* fragmenting and our row axis is a grid axis and it handles masonry layout
|
|
|
|
* in the column axis in that case.
|
|
|
|
* @return the intrinsic size in the masonry axis
|
|
|
|
*/
|
|
|
|
nscoord MasonryLayout(GridReflowInput& aState,
|
|
|
|
const LogicalRect& aContentArea,
|
|
|
|
SizingConstraint aConstraint,
|
|
|
|
ReflowOutput& aDesiredSize, nsReflowStatus& aStatus,
|
|
|
|
Fragmentainer* aFragmentainer,
|
|
|
|
const nsSize& aContainerSize);
|
|
|
|
|
2018-11-29 17:05:53 +00:00
|
|
|
// Return the stored UsedTrackSizes, if any.
|
|
|
|
UsedTrackSizes* GetUsedTrackSizes() const;
|
|
|
|
|
|
|
|
// Store the given TrackSizes in aAxis on a UsedTrackSizes frame property.
|
|
|
|
void StoreUsedTrackSizes(LogicalAxis aAxis,
|
|
|
|
const nsTArray<TrackSize>& aSizes);
|
|
|
|
|
2023-11-08 21:44:36 +00:00
|
|
|
// The internal implementation for AddImplicitNamedAreas().
|
|
|
|
void AddImplicitNamedAreasInternal(LineNameList& aNameList,
|
2023-12-04 12:08:47 +00:00
|
|
|
ImplicitNamedAreas*& aAreas);
|
2023-11-08 21:44:36 +00:00
|
|
|
|
2015-09-04 20:06:58 +00:00
|
|
|
/**
|
|
|
|
* Cached values to optimize GetMinISize/GetPrefISize.
|
|
|
|
*/
|
|
|
|
nscoord mCachedMinISize;
|
|
|
|
nscoord mCachedPrefISize;
|
2016-03-11 16:39:27 +00:00
|
|
|
|
2016-10-01 00:26:39 +00:00
|
|
|
// Our baselines, one per BaselineSharingGroup per axis.
|
2019-04-25 22:42:13 +00:00
|
|
|
PerLogicalAxis<PerBaseline<nscoord>> mBaseline;
|
2021-09-20 19:52:45 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// A cached result for a grid item's block-axis measuring reflow. This
|
|
|
|
// cache prevents us from doing exponential reflows in cases of deeply
|
|
|
|
// nested grid frames.
|
|
|
|
//
|
|
|
|
// We store the cached value in the grid item's frame property table.
|
|
|
|
//
|
|
|
|
// We cache the following as a "key"
|
|
|
|
// - The size of the grid area in the item's inline axis
|
|
|
|
// - The item's block axis baseline padding
|
|
|
|
// ...and we cache the following as the "value",
|
|
|
|
// - The item's border-box BSize
|
|
|
|
class CachedBAxisMeasurement {
|
|
|
|
public:
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(Prop, CachedBAxisMeasurement)
|
|
|
|
CachedBAxisMeasurement(const nsIFrame* aFrame, const LogicalSize& aCBSize,
|
|
|
|
const nscoord aBSize)
|
|
|
|
: mKey(aFrame, aCBSize), mBSize(aBSize) {}
|
|
|
|
|
|
|
|
CachedBAxisMeasurement() = default;
|
|
|
|
|
|
|
|
bool IsValidFor(const nsIFrame* aFrame, const LogicalSize& aCBSize) const {
|
2022-01-12 21:51:45 +00:00
|
|
|
if (aFrame->IsSubtreeDirty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-20 19:52:45 +00:00
|
|
|
if (!CanCacheMeasurement(aFrame, aCBSize)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mKey == Key(aFrame, aCBSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CanCacheMeasurement(const nsIFrame* aFrame,
|
|
|
|
const LogicalSize& aCBSize) {
|
|
|
|
return Key::CanHash(aFrame, aCBSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord BSize() const { return mBSize; }
|
|
|
|
|
|
|
|
void Update(const nsIFrame* aFrame, const LogicalSize& aCBSize,
|
|
|
|
const nscoord aBSize) {
|
|
|
|
MOZ_ASSERT(CanCacheMeasurement(aFrame, aCBSize));
|
|
|
|
mKey.mHashKey = Key::GenerateHash(aFrame, aCBSize);
|
|
|
|
mBSize = aBSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Key {
|
|
|
|
// mHashKey is generated by combining these 2 variables together
|
|
|
|
// 1. The containing block size in the item's inline axis used
|
|
|
|
// for measuring reflow
|
|
|
|
// 2. The item's baseline padding property
|
|
|
|
uint32_t mHashKey;
|
|
|
|
|
|
|
|
Key() = default;
|
|
|
|
|
|
|
|
Key(const nsIFrame* aFrame, const LogicalSize& aCBSize) {
|
|
|
|
MOZ_ASSERT(CanHash(aFrame, aCBSize));
|
|
|
|
mHashKey = GenerateHash(aFrame, aCBSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateHash(const nsIFrame* aFrame, const LogicalSize& aCBSize) {
|
|
|
|
MOZ_ASSERT(CanHash(aFrame, aCBSize));
|
|
|
|
mHashKey = GenerateHash(aFrame, aCBSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t GenerateHash(const nsIFrame* aFrame,
|
|
|
|
const LogicalSize& aCBSize) {
|
|
|
|
MOZ_ASSERT(CanHash(aFrame, aCBSize));
|
|
|
|
|
|
|
|
nscoord gridAreaISize = aCBSize.ISize(aFrame->GetWritingMode());
|
|
|
|
nscoord bBaselinePaddingProperty =
|
|
|
|
abs(aFrame->GetProperty(nsIFrame::BBaselinePadProperty()));
|
|
|
|
|
|
|
|
uint_fast8_t bitsNeededForISize = mozilla::FloorLog2(gridAreaISize) + 1;
|
|
|
|
|
|
|
|
return (gridAreaISize << (32 - bitsNeededForISize)) |
|
|
|
|
bBaselinePaddingProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CanHash(const nsIFrame* aFrame, const LogicalSize& aCBSize) {
|
|
|
|
uint_fast8_t bitsNeededForISize =
|
|
|
|
mozilla::FloorLog2(aCBSize.ISize(aFrame->GetWritingMode())) + 1;
|
|
|
|
|
|
|
|
uint_fast8_t bitsNeededForBBaselinePadding =
|
|
|
|
mozilla::FloorLog2(
|
|
|
|
abs(aFrame->GetProperty(nsIFrame::BBaselinePadProperty()))) +
|
|
|
|
1;
|
|
|
|
|
|
|
|
return bitsNeededForISize + bitsNeededForBBaselinePadding <= 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const Key& aOther) const {
|
|
|
|
return mHashKey == aOther.mHashKey;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Key mKey;
|
|
|
|
nscoord mBSize;
|
|
|
|
};
|
2022-10-02 07:49:46 +00:00
|
|
|
|
|
|
|
bool CanProvideLineIterator() const final { return true; }
|
|
|
|
nsILineIterator* GetLineIterator() final { return this; }
|
|
|
|
int32_t GetNumLines() const final;
|
2022-10-03 11:00:39 +00:00
|
|
|
bool IsLineIteratorFlowRTL() final;
|
2022-10-02 07:49:46 +00:00
|
|
|
mozilla::Result<LineInfo, nsresult> GetLine(int32_t aLineNumber) final;
|
|
|
|
int32_t FindLineContaining(nsIFrame* aFrame, int32_t aStartLine = 0) final;
|
|
|
|
NS_IMETHOD FindFrameAt(int32_t aLineNumber, nsPoint aPos,
|
|
|
|
nsIFrame** aFrameFound, bool* aPosIsBeforeFirstFrame,
|
|
|
|
bool* aPosIsAfterLastFrame) final;
|
|
|
|
NS_IMETHOD CheckLineOrder(int32_t aLine, bool* aIsReordered,
|
|
|
|
nsIFrame** aFirstVisual,
|
|
|
|
nsIFrame** aLastVisual) final;
|
2014-02-27 07:45:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsGridContainerFrame_h___ */
|