tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e866f02b75251ed4cc3d237cc70dc532ced8b0ec
parent a30eb75acd5d3973f671c68b91ff7bd1783caf85
Author: Jonathan Kew <jkew@mozilla.com>
Date:   Fri, 24 Oct 2025 22:15:17 +0000

Bug 1993939 followup - Do ComputeDecorationTrim()'s frame-geometry work in appUnits, before converting to device pixels for drawing. r=AlaskanEmily,layout-reviewers,emilio

Differential Revision: https://phabricator.services.mozilla.com/D269968

Diffstat:
Mlayout/base/nsPresContext.h | 8++++----
Mlayout/generic/nsTextFrame.cpp | 26+++++++++++++-------------
2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h @@ -639,20 +639,20 @@ class nsPresContext : public nsISupports, return NSAppUnitsToIntPixels(aAppUnits, float(AppUnitsPerDevPixel())); } - float AppUnitsToFloatDevPixels(nscoord aAppUnits) { + float AppUnitsToFloatDevPixels(nscoord aAppUnits) const { return aAppUnits / float(AppUnitsPerDevPixel()); } - int32_t CSSPixelsToDevPixels(int32_t aPixels) { + int32_t CSSPixelsToDevPixels(int32_t aPixels) const { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); } - float CSSPixelsToDevPixels(float aPixels) { + float CSSPixelsToDevPixels(float aPixels) const { return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels), float(AppUnitsPerDevPixel())); } - int32_t DevPixelsToIntCSSPixels(int32_t aPixels) { + int32_t DevPixelsToIntCSSPixels(int32_t aPixels) const { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); } diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp @@ -5789,7 +5789,6 @@ static bool ComputeDecorationTrim( nsTextFrame* aFrame, const nsPresContext* aPresCtx, const nsIFrame* aDecFrame, const gfxFont::Metrics& aMetrics, nsCSSRendering::DecorationRectParams& aParams) { - const gfxFloat app = aPresCtx->AppUnitsPerDevPixel(); const WritingMode wm = aDecFrame->GetWritingMode(); bool verticalDec = wm.IsVertical(); @@ -5799,16 +5798,17 @@ static bool ComputeDecorationTrim( // Find the trim values for this frame. const StyleTextDecorationTrim& cssTrim = aDecFrame->StyleTextReset()->mTextDecorationTrim; - gfxFloat trimLeft, trimRight; + nscoord trimLeft, trimRight; if (cssTrim.IsAuto()) { // Use a trim factor of 1/12.5, so we get 2px of trim (resulting in a 4px // gap between adjacent lines) at font-size 25px. constexpr gfxFloat kAutoTrimFactor = 1.0 / 12.5; // Use the EM size multiplied by kAutoTrimFactor, with a minimum of one // CSS pixel to ensure that at least some separation occurs. - const gfxFloat scale = aPresCtx->CSSToDevPixelScale().scale; const nscoord autoDecorationTrim = - std::max(aMetrics.emHeight * kAutoTrimFactor, scale); + std::max(aPresCtx->DevPixelsToAppUnits( + NS_round(aMetrics.emHeight * kAutoTrimFactor)), + nsPresContext::CSSPixelsToAppUnits(1)); trimLeft = autoDecorationTrim; trimRight = autoDecorationTrim; } else { @@ -5819,8 +5819,8 @@ static bool ComputeDecorationTrim( // walking up and back down the frame tree, and walking continuations. return true; } - trimLeft = NSAppUnitsToDoublePixels(length.start.ToAppUnits(), app); - trimRight = NSAppUnitsToDoublePixels(length.end.ToAppUnits(), app); + trimLeft = length.start.ToAppUnits(); + trimRight = length.end.ToAppUnits(); } if (wm.IsInlineReversed()) { @@ -5909,17 +5909,17 @@ static bool ComputeDecorationTrim( std::swap(applyLeft, applyRight); } if (applyLeft) { - trimLeft -= NSAppUnitsToDoublePixels(marginLeft, app); + trimLeft -= marginLeft; } else { trimLeft = 0; } if (applyRight) { - trimRight -= NSAppUnitsToDoublePixels(marginRight, app); + trimRight -= marginRight; } else { trimRight = 0; } - if (trimLeft >= NSAppUnitsToDoublePixels(frameSize, app) - trimRight) { + if (trimLeft + trimRight >= frameSize) { // This frame does not contain the decoration at all. return false; } @@ -5934,11 +5934,11 @@ static bool ComputeDecorationTrim( // I am unsure if it's possible that the first/last frame might be inset // for some reason, as well, in which case we will not draw the outset // decorations. - if (trimLeft > 0.0 || marginLeft == 0) { - aParams.trimLeft = trimLeft; + if (trimLeft > 0 || marginLeft == 0) { + aParams.trimLeft = aPresCtx->AppUnitsToFloatDevPixels(trimLeft); } - if (trimRight > 0.0 || marginRight == 0) { - aParams.trimRight = trimRight; + if (trimRight > 0 || marginRight == 0) { + aParams.trimRight = aPresCtx->AppUnitsToFloatDevPixels(trimRight); } return true; }