From 5487515bcab438ae29fa6342583b8b5c5bde6b92 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 23 Jul 2022 23:35:18 +0000 Subject: 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. --- layout/generic/BlockReflowInput.cpp | 3 +-- layout/generic/ReflowInput.cpp | 14 +++++++++----- layout/generic/ReflowInput.h | 18 +++++++++++------- layout/generic/nsBRFrame.cpp | 2 +- layout/generic/nsRubyBaseContainerFrame.cpp | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/layout/generic/BlockReflowInput.cpp b/layout/generic/BlockReflowInput.cpp index 86248ac141..e73ae6331c 100644 --- a/layout/generic/BlockReflowInput.cpp +++ b/layout/generic/BlockReflowInput.cpp @@ -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 diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index 0c3fef3825..f308ebcdf5 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -2798,15 +2798,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 diff --git a/layout/generic/ReflowInput.h b/layout/generic/ReflowInput.h index 1d2df6af68..d8e0518399 100644 --- a/layout/generic/ReflowInput.h +++ b/layout/generic/ReflowInput.h @@ -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 diff --git a/layout/generic/nsBRFrame.cpp b/layout/generic/nsBRFrame.cpp index 08c0fe3dda..e02711353a 100644 --- a/layout/generic/nsBRFrame.cpp +++ b/layout/generic/nsBRFrame.cpp @@ -125,7 +125,7 @@ BRFrame::Reflow(nsPresContext* aPresContext, RefPtr 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())); diff --git a/layout/generic/nsRubyBaseContainerFrame.cpp b/layout/generic/nsRubyBaseContainerFrame.cpp index 91bbf5de85..ed2a35b417 100644 --- a/layout/generic/nsRubyBaseContainerFrame.cpp +++ b/layout/generic/nsRubyBaseContainerFrame.cpp @@ -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. -- cgit v1.2.3