Skip to content

Commit

Permalink
Bug 1869580 - Move devtools info bit to specific frame classes. r=tni…
Browse files Browse the repository at this point in the history
…kkel,layout-reviewers

No need for them to live in nsIFrame.

Differential Revision: https://phabricator.services.mozilla.com/D196198
  • Loading branch information
emilio committed Dec 13, 2023
1 parent de8a41c commit 119487c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 52 deletions.
61 changes: 30 additions & 31 deletions layout/generic/nsFlexContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4971,7 +4971,7 @@ void nsFlexContainerFrame::CalculatePackingSpace(

ComputedFlexContainerInfo*
nsFlexContainerFrame::CreateOrClearFlexContainerInfo() {
if (!ShouldGenerateComputedInfo()) {
if (!HasAnyStateBits(NS_STATE_FLEX_COMPUTED_INFO)) {
return nullptr;
}

Expand Down Expand Up @@ -5126,36 +5126,36 @@ nsFlexContainerFrame* nsFlexContainerFrame::GetFlexFrameWithComputedInfo(
};

nsFlexContainerFrame* flexFrame = GetFlexContainerFrame(aFrame);
if (flexFrame) {
// Generate the FlexContainerInfo data, if it's not already there.
bool reflowNeeded = !flexFrame->HasProperty(FlexContainerInfo());

if (reflowNeeded) {
// Trigger a reflow that generates additional flex property data.
// Hold onto aFrame while we do this, in case reflow destroys it.
AutoWeakFrame weakFrameRef(aFrame);

RefPtr<mozilla::PresShell> presShell = flexFrame->PresShell();
flexFrame->SetShouldGenerateComputedInfo(true);
presShell->FrameNeedsReflow(flexFrame, IntrinsicDirty::None,
NS_FRAME_IS_DIRTY);
presShell->FlushPendingNotifications(FlushType::Layout);

// Since the reflow may have side effects, get the flex frame
// again. But if the weakFrameRef is no longer valid, then we
// must bail out.
if (!weakFrameRef.IsAlive()) {
return nullptr;
}
if (!flexFrame) {
return nullptr;
}
// Generate the FlexContainerInfo data, if it's not already there.
if (flexFrame->HasProperty(FlexContainerInfo())) {
return flexFrame;
}
// Trigger a reflow that generates additional flex property data.
// Hold onto aFrame while we do this, in case reflow destroys it.
AutoWeakFrame weakFrameRef(aFrame);

flexFrame = GetFlexContainerFrame(weakFrameRef.GetFrame());
RefPtr<mozilla::PresShell> presShell = flexFrame->PresShell();
flexFrame->AddStateBits(NS_STATE_FLEX_COMPUTED_INFO);
presShell->FrameNeedsReflow(flexFrame, IntrinsicDirty::None,
NS_FRAME_IS_DIRTY);
presShell->FlushPendingNotifications(FlushType::Layout);

NS_WARNING_ASSERTION(
!flexFrame || flexFrame->HasProperty(FlexContainerInfo()),
"The state bit should've made our forced-reflow "
"generate a FlexContainerInfo object");
}
// Since the reflow may have side effects, get the flex frame
// again. But if the weakFrameRef is no longer valid, then we
// must bail out.
if (!weakFrameRef.IsAlive()) {
return nullptr;
}

flexFrame = GetFlexContainerFrame(weakFrameRef.GetFrame());

NS_WARNING_ASSERTION(
!flexFrame || flexFrame->HasProperty(FlexContainerInfo()),
"The state bit should've made our forced-reflow "
"generate a FlexContainerInfo object");
return flexFrame;
}

Expand Down Expand Up @@ -5233,9 +5233,8 @@ nsFlexContainerFrame::FlexLayoutResult nsFlexContainerFrame::DoFlexLayout(
// size adjustments). We'll later fix up the line properties,
// because the correct values aren't available yet.
if (aContainerInfo) {
MOZ_ASSERT(ShouldGenerateComputedInfo(),
"We should only have the info struct if "
"ShouldGenerateComputedInfo() is true!");
MOZ_ASSERT(HasAnyStateBits(NS_STATE_FLEX_COMPUTED_INFO),
"We should only have the info struct if we should generate it");

if (!aStruts.IsEmpty()) {
// We restarted DoFlexLayout, and may have stale mLines to clear:
Expand Down
8 changes: 8 additions & 0 deletions layout/generic/nsFrameStateBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ FRAME_STATE_BIT(FlexContainer, 23, NS_STATE_FLEX_DID_PUSH_ITEMS)
// We've merged some OverflowList children since last reflow.
FRAME_STATE_BIT(FlexContainer, 24, NS_STATE_FLEX_HAS_CHILD_NIFS)

// True if the next reflow of this frame should generate computed info metrics.
// These are used by devtools to reveal details of the layout process.
FRAME_STATE_BIT(FlexContainer, 25, NS_STATE_FLEX_COMPUTED_INFO)

// == Frame state bits that apply to grid container frames ====================

FRAME_STATE_GROUP(GridContainer, nsGridContainerFrame)
Expand Down Expand Up @@ -380,6 +384,10 @@ FRAME_STATE_BIT(GridContainer, 28, NS_STATE_GRID_IS_COL_MASONRY)
// (mutually exclusive with NS_STATE_GRID_IS_COL_MASONRY)
FRAME_STATE_BIT(GridContainer, 29, NS_STATE_GRID_IS_ROW_MASONRY)

// True if the next reflow of this frame should generate computed info metrics.
// These are used by devtools to reveal details of the layout process.
FRAME_STATE_BIT(GridContainer, 30, NS_STATE_GRID_COMPUTED_INFO)

// == Frame state bits that apply to SVG frames ===============================

FRAME_STATE_GROUP_NAME(SVG)
Expand Down
11 changes: 6 additions & 5 deletions layout/generic/nsGridContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2906,7 +2906,7 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::GridReflowInput {

// Copy in the computed grid info state bit
if (mSharedGridData->mGenerateComputedGridInfo) {
aGridContainerFrame->SetShouldGenerateComputedInfo(true);
aGridContainerFrame->AddStateBits(NS_STATE_GRID_COMPUTED_INFO);
}
}

Expand Down Expand Up @@ -5013,7 +5013,7 @@ void nsGridContainerFrame::Grid::PlaceGridItems(
}

// Update the line boundaries of the implicit grid areas, if needed.
if (mAreas && aState.mFrame->ShouldGenerateComputedInfo()) {
if (mAreas && aState.mFrame->HasAnyStateBits(NS_STATE_GRID_COMPUTED_INFO)) {
for (auto iter = mAreas->iter(); !iter.done(); iter.next()) {
auto& areaInfo = iter.get().value();

Expand Down Expand Up @@ -9018,7 +9018,7 @@ void nsGridContainerFrame::Reflow(nsPresContext* aPresContext,
bp.BStart(wm), bp.BEnd(wm), desiredSize.BSize(wm));
}

if (ShouldGenerateComputedInfo()) {
if (HasAnyStateBits(NS_STATE_GRID_COMPUTED_INFO)) {
// This state bit will never be cleared, since reflow can be called
// multiple times in fragmented grids, and it's challenging to scope
// the bit to only that sequence of calls. This is relatively harmless
Expand Down Expand Up @@ -9287,7 +9287,8 @@ void nsGridContainerFrame::Reflow(nsPresContext* aPresContext,
sharedGridData->mGridItems = std::move(gridReflowInput.mGridItems);
sharedGridData->mAbsPosItems = std::move(gridReflowInput.mAbsPosItems);

sharedGridData->mGenerateComputedGridInfo = ShouldGenerateComputedInfo();
sharedGridData->mGenerateComputedGridInfo =
HasAnyStateBits(NS_STATE_GRID_COMPUTED_INFO);
} else if (sharedGridData && !GetNextInFlow()) {
RemoveProperty(SharedGridData::Prop());
}
Expand Down Expand Up @@ -9983,7 +9984,7 @@ nsGridContainerFrame* nsGridContainerFrame::GetGridFrameWithComputedInfo(
AutoWeakFrame weakFrameRef(gridFrame);

RefPtr<mozilla::PresShell> presShell = gridFrame->PresShell();
gridFrame->SetShouldGenerateComputedInfo(true);
gridFrame->AddStateBits(NS_STATE_GRID_COMPUTED_INFO);
presShell->FrameNeedsReflow(gridFrame, IntrinsicDirty::None,
NS_FRAME_IS_DIRTY);
presShell->FlushPendingNotifications(FlushType::Layout);
Expand Down
17 changes: 1 addition & 16 deletions layout/generic/nsIFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,7 @@ class nsIFrame : public nsQueryFrame {
mHasPaddingChange(false),
mInScrollAnchorChain(false),
mHasColumnSpanSiblings(false),
mDescendantMayDependOnItsStaticPosition(false),
mShouldGenerateComputedInfo(false) {
mDescendantMayDependOnItsStaticPosition(false) {
MOZ_ASSERT(mComputedStyle);
MOZ_ASSERT(mPresContext);
mozilla::PodZero(&mOverflow);
Expand Down Expand Up @@ -4915,13 +4914,6 @@ class nsIFrame : public nsQueryFrame {
mDescendantMayDependOnItsStaticPosition = aValue;
}

bool ShouldGenerateComputedInfo() const {
return mShouldGenerateComputedInfo;
}
void SetShouldGenerateComputedInfo(bool aValue) {
mShouldGenerateComputedInfo = aValue;
}

/**
* Returns the hit test area of the frame.
*/
Expand Down Expand Up @@ -5200,13 +5192,6 @@ class nsIFrame : public nsQueryFrame {
*/
bool mDescendantMayDependOnItsStaticPosition : 1;

/**
* True if the next reflow of this frame should generate computed info
* metrics. These are used by devtools to reveal details of the layout
* process.
*/
bool mShouldGenerateComputedInfo : 1;

protected:
// Helpers
/**
Expand Down

0 comments on commit 119487c

Please sign in to comment.