summaryrefslogtreecommitdiffstats
path: root/layout/generic/nsGridContainerFrame.h
diff options
context:
space:
mode:
Diffstat (limited to 'layout/generic/nsGridContainerFrame.h')
-rw-r--r--layout/generic/nsGridContainerFrame.h71
1 files changed, 33 insertions, 38 deletions
diff --git a/layout/generic/nsGridContainerFrame.h b/layout/generic/nsGridContainerFrame.h
index cf3a3b5776..1fa7bbe487 100644
--- a/layout/generic/nsGridContainerFrame.h
+++ b/layout/generic/nsGridContainerFrame.h
@@ -233,12 +233,12 @@ class nsGridContainerFrame final : public nsContainerFrame,
/** Return true if this frame is subgridded in its aAxis. */
bool IsSubgrid(LogicalAxis aAxis) const {
- return HasAnyStateBits(aAxis == mozilla::eLogicalAxisBlock
+ return HasAnyStateBits(aAxis == mozilla::LogicalAxis::Block
? NS_STATE_GRID_IS_ROW_SUBGRID
: NS_STATE_GRID_IS_COL_SUBGRID);
}
- bool IsColSubgrid() const { return IsSubgrid(mozilla::eLogicalAxisInline); }
- bool IsRowSubgrid() const { return IsSubgrid(mozilla::eLogicalAxisBlock); }
+ bool IsColSubgrid() const { return IsSubgrid(mozilla::LogicalAxis::Inline); }
+ bool IsRowSubgrid() const { return IsSubgrid(mozilla::LogicalAxis::Block); }
/** Return true if this frame is subgridded in any axis. */
bool IsSubgrid() const {
return HasAnyStateBits(NS_STATE_GRID_IS_ROW_SUBGRID |
@@ -247,7 +247,7 @@ class nsGridContainerFrame final : public nsContainerFrame,
/** Return true if this frame has an item that is subgridded in our aAxis. */
bool HasSubgridItems(LogicalAxis aAxis) const {
- return HasAnyStateBits(aAxis == mozilla::eLogicalAxisBlock
+ return HasAnyStateBits(aAxis == mozilla::LogicalAxis::Block
? NS_STATE_GRID_HAS_ROW_SUBGRID_ITEM
: NS_STATE_GRID_HAS_COL_SUBGRID_ITEM);
}
@@ -375,10 +375,10 @@ class nsGridContainerFrame final : public nsContainerFrame,
mozilla::IntrinsicISizeType aConstraint);
nscoord GetBBaseline(BaselineSharingGroup aBaselineGroup) const {
- return mBaseline[mozilla::eLogicalAxisBlock][aBaselineGroup];
+ return mBaseline[mozilla::LogicalAxis::Block][aBaselineGroup];
}
nscoord GetIBaseline(BaselineSharingGroup aBaselineGroup) const {
- return mBaseline[mozilla::eLogicalAxisInline][aBaselineGroup];
+ return mBaseline[mozilla::LogicalAxis::Inline][aBaselineGroup];
}
/**
@@ -566,12 +566,8 @@ class nsGridContainerFrame final : public nsContainerFrame,
if (aFrame->IsSubtreeDirty()) {
return false;
}
-
- if (!CanCacheMeasurement(aFrame, aCBSize)) {
- return false;
- }
-
- return mKey == Key(aFrame, aCBSize);
+ const mozilla::Maybe<Key> maybeKey = Key::TryHash(aFrame, aCBSize);
+ return maybeKey.isSome() && mKey == *maybeKey;
}
static bool CanCacheMeasurement(const nsIFrame* aFrame,
@@ -583,55 +579,54 @@ class nsGridContainerFrame final : public nsContainerFrame,
void Update(const nsIFrame* aFrame, const LogicalSize& aCBSize,
const nscoord aBSize) {
- MOZ_ASSERT(CanCacheMeasurement(aFrame, aCBSize));
- mKey.mHashKey = Key::GenerateHash(aFrame, aCBSize);
+ mKey.UpdateHash(aFrame, aCBSize);
mBSize = aBSize;
}
private:
- struct Key {
+ class 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;
+ explicit Key(uint32_t aHashKey) : mHashKey(aHashKey) {}
+
+ public:
Key() = default;
Key(const nsIFrame* aFrame, const LogicalSize& aCBSize) {
- MOZ_ASSERT(CanHash(aFrame, aCBSize));
- mHashKey = GenerateHash(aFrame, aCBSize);
+ UpdateHash(aFrame, aCBSize);
}
void UpdateHash(const nsIFrame* aFrame, const LogicalSize& aCBSize) {
- MOZ_ASSERT(CanHash(aFrame, aCBSize));
- mHashKey = GenerateHash(aFrame, aCBSize);
+ const mozilla::Maybe<Key> maybeKey = TryHash(aFrame, aCBSize);
+ MOZ_ASSERT(maybeKey.isSome());
+ mHashKey = maybeKey->mHashKey;
}
- static uint32_t GenerateHash(const nsIFrame* aFrame,
- const LogicalSize& aCBSize) {
- MOZ_ASSERT(CanHash(aFrame, aCBSize));
-
- nscoord gridAreaISize = aCBSize.ISize(aFrame->GetWritingMode());
- nscoord bBaselinePaddingProperty =
+ static mozilla::Maybe<Key> TryHash(const nsIFrame* aFrame,
+ const LogicalSize& aCBSize) {
+ const nscoord gridAreaISize = aCBSize.ISize(aFrame->GetWritingMode());
+ const nscoord bBaselinePaddingProperty =
abs(aFrame->GetProperty(nsIFrame::BBaselinePadProperty()));
- uint_fast8_t bitsNeededForISize = mozilla::FloorLog2(gridAreaISize) + 1;
-
- return (gridAreaISize << (32 - bitsNeededForISize)) |
- bBaselinePaddingProperty;
+ const uint_fast8_t bitsNeededForISize =
+ mozilla::FloorLog2(gridAreaISize) + 1;
+
+ const uint_fast8_t bitsNeededForBBaselinePadding =
+ mozilla::FloorLog2(bBaselinePaddingProperty) + 1;
+ if (bitsNeededForISize + bitsNeededForBBaselinePadding > 32) {
+ return mozilla::Nothing();
+ }
+ const uint32_t hashKey = (gridAreaISize << (32 - bitsNeededForISize)) |
+ bBaselinePaddingProperty;
+ return mozilla::Some(Key(hashKey));
}
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;
+ return TryHash(aFrame, aCBSize).isSome();
}
bool operator==(const Key& aOther) const {