Bug 1355595 - Simplify the default font size calculation; r=dbaron
When calculating the thickness of the spellchecker underline, we can
directly use aPresContext to get default font size, instead of creating
a temporary nsStyleFont object. nsStyleFont does more work than default
font size calculation, and destructing its member mFont object is
expensive (see
bug 1355600), so it's better to avoid it on this hot path.
MozReview-Commit-ID: GSvnZHULtL5
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -5795,20 +5795,22 @@ nsTextFrame::ComputeSelectionUnderlineHe
return aFontMetrics.underlineSize;
case SelectionType::eSpellCheck: {
// The thickness of the spellchecker underline shouldn't honor the font
// metrics. It should be constant pixels value which is decided from the
// default font size. Note that if the actual font size is smaller than
// the default font size, we should use the actual font size because the
// computed value from the default font size can be too thick for the
// current font size.
- int32_t defaultFontSize =
- aPresContext->AppUnitsToDevPixels(nsStyleFont(aPresContext).mFont.size);
- gfxFloat fontSize = std::min(gfxFloat(defaultFontSize),
- aFontMetrics.emHeight);
+ nscoord defaultFontSize = aPresContext->GetDefaultFont(
+ kPresContext_DefaultVariableFont_ID, nullptr)->size;
+ int32_t zoomedFontSize = aPresContext->AppUnitsToDevPixels(
+ nsStyleFont::ZoomText(aPresContext, defaultFontSize));
+ gfxFloat fontSize = std::min(gfxFloat(zoomedFontSize),
+ aFontMetrics.emHeight);
fontSize = std::max(fontSize, 1.0);
return ceil(fontSize / 20);
}
default:
NS_WARNING("Requested underline style is not valid");
return aFontMetrics.underlineSize;
}
}