Issue #1970 - Part 6: Rename CalcLineHeight(), and cache used line height

To better distinguish the calculation of line height (still present with args)
and simply getting the line height without args, it's now called GetLineHeight()
This also introduces `mLineHeight` to cache specifically calculated line heights
that aren't "auto" (which is a magic value), and it opens up the possibility to
override it in Part 7.
This commit is contained in:
Moonchild 2022-07-23 23:35:18 +00:00 • committed by roytam1
commit 7203916733
5 changed files with 23 additions and 16 deletions

View file

@ -43,6 +43,7 @@ BlockReflowInput::BlockReflowInput(const ReflowInput& aReflowInput,
mOverflowTracker(nullptr),
mBorderPadding(mReflowInput.ComputedLogicalBorderPadding()),
mPrevBEndMargin(),
mMinLineHeight(aReflowInput.GetLineHeight()),
mLineNumber(0),
mFloatBreakType(StyleClear::None),
mConsumedBSize(aConsumedBSize)
@ -141,8 +142,6 @@ BlockReflowInput::BlockReflowInput(const ReflowInput& aReflowInput,
mPrevChild = nullptr;
mCurrentLine = aFrame->LinesEnd();
mMinLineHeight = aReflowInput.CalcLineHeight();
}
nscoord

View file

@ -2802,15 +2802,19 @@ ComputeLineHeight(nsStyleContext* aStyleContext,
return GetNormalLineHeight(fm);
}
nscoord
ReflowInput::CalcLineHeight() const
{
nscoord ReflowInput::GetLineHeight() const {
if (mLineHeight != NS_AUTOHEIGHT) {
return mLineHeight;
}
nscoord blockBSize =
nsLayoutUtils::IsNonWrapperBlock(mFrame) ? ComputedBSize() :
(mCBReflowInput ? mCBReflowInput->ComputedBSize() : NS_AUTOHEIGHT);
return CalcLineHeight(mFrame->GetContent(), mFrame->StyleContext(), blockBSize,
nsLayoutUtils::FontSizeInflationFor(mFrame));
mLineHeight = CalcLineHeight(mFrame->GetContent(),
mFrame->StyleContext(),
blockBSize,
nsLayoutUtils::FontSizeInflationFor(mFrame));
}
/* static */ nscoord

View file

@ -744,18 +744,19 @@ public:
nscoord GetContainingBlockContentISize(mozilla::WritingMode aWritingMode) const;
/**
* Calculate the used line-height property. The return value will be >= 0.
* Get the used line-height property. The return value will be >= 0.
*/
nscoord CalcLineHeight() const;
nscoord GetLineHeight() const;
/**
* Same as CalcLineHeight() above, but doesn't need a reflow state.
* Calculate the used line-height property without a reflow input instance.
* The return value will be >= 0.
*
* @param aBlockBSize The computed block size of the content rect of the block
* that the line should fill.
* Only used with line-height:-moz-block-height.
* NS_AUTOHEIGHT results in a normal line-height for
* line-height:-moz-block-height.
* that the line should fill.
* Only used with line-height:-moz-block-height.
* NS_AUTOHEIGHT results in a normal line-height for
* line-height:-moz-block-height.
* @param aFontSizeInflation The result of the appropriate
* nsLayoutUtils::FontSizeInflationFor call,
* or 1.0 if during intrinsic size
@ -1000,6 +1001,9 @@ protected:
nscoord* aOutsideBoxSizing) const;
void CalculateBlockSideMargins(nsIAtom* aFrameType);
// Cache the used line-height property.
mutable nscoord mLineHeight = NS_AUTOHEIGHT;
};
} // namespace mozilla

View file

@ -125,7 +125,7 @@ BRFrame::Reflow(nsPresContext* aPresContext,
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
if (fm) {
nscoord logicalHeight = aReflowInput.CalcLineHeight();
nscoord logicalHeight = aReflowInput.GetLineHeight();
finalSize.BSize(wm) = logicalHeight;
aMetrics.SetBlockStartAscent(nsLayoutUtils::GetCenteredFontBaseline(
fm, logicalHeight, wm.IsLineInverted()));

View file

@ -363,7 +363,7 @@ nsRubyBaseContainerFrame::Reflow(nsPresContext* aPresContext,
// Line number is useless for ruby text
// XXX nullptr here may cause problem, see comments for
// nsLineLayout::mBlockRI and nsLineLayout::AddFloat
lineLayout->Init(nullptr, reflowInput->CalcLineHeight(), -1);
lineLayout->Init(nullptr, reflowInput->GetLineHeight(), -1);
reflowInput->mLineLayout = lineLayout;
// Border and padding are suppressed on ruby text containers.