Bug 1355595 - Simplify the default font size calculation; r=dbaron draft
authorEvelyn Hung <jj.evelyn@gmail.com>
Tue, 11 Apr 2017 18:13:31 -0400
changeset 561695 3014550ed122288b589c0c1a4d8dbf3815c8e310
parent 557282 facaf90aeaaf6d7cf5e2966f9f918319536bddea
child 624046 4742a4ad46e017783189119f384d65df4c974fd7
push id53807
push userbmo:ehung@mozilla.com
push dateThu, 13 Apr 2017 02:04:26 +0000
reviewersdbaron
bugs1355595, 1355600
milestone55.0a1
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
layout/generic/nsTextFrame.cpp
--- 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;
   }
 }