From ff8c1a3788068606d7da052a9a1f7ac4b8594422 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 21 Mar 2017 20:38:12 -0700 Subject: [PATCH] Bug 1349417 - Part 1: stylo: Factor out system font computation into nsRuleNode::ComputeSystemFont; r=xidorn MozReview-Commit-ID: KfzzCodvLXd --- layout/style/nsRuleNode.cpp | 99 ++++++++++++++++++++----------------- layout/style/nsRuleNode.h | 4 ++ 2 files changed, 57 insertions(+), 46 deletions(-) diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 69c045807e3c..f88a645c9a4f 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -3566,6 +3566,58 @@ static int8_t ClampTo8Bit(int32_t aValue) { return int8_t(aValue); } +/* static */ void +nsRuleNode::ComputeSystemFont(nsFont* aSystemFont, LookAndFeel::FontID aFontID, + const nsPresContext* aPresContext) +{ + gfxFontStyle fontStyle; + float devPerCSS = + (float)nsPresContext::AppUnitsPerCSSPixel() / + aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom(); + nsAutoString systemFontName; + if (LookAndFeel::GetFont(aFontID, systemFontName, fontStyle, devPerCSS)) { + systemFontName.Trim("\"'"); + aSystemFont->fontlist = FontFamilyList(systemFontName, eUnquotedName); + aSystemFont->fontlist.SetDefaultFontType(eFamily_none); + aSystemFont->style = fontStyle.style; + aSystemFont->systemFont = fontStyle.systemFont; + aSystemFont->weight = fontStyle.weight; + aSystemFont->stretch = fontStyle.stretch; + aSystemFont->size = + NSFloatPixelsToAppUnits(fontStyle.size, + aPresContext->DeviceContext()-> + AppUnitsPerDevPixelAtUnitFullZoom()); + //aSystemFont->langGroup = fontStyle.langGroup; + aSystemFont->sizeAdjust = fontStyle.sizeAdjust; + +#ifdef XP_WIN + // XXXldb This platform-specific stuff should be in the + // LookAndFeel implementation, not here. + // XXXzw Should we even still *have* this code? It looks to be making + // old, probably obsolete assumptions. + + if (aFontID == LookAndFeel::eFont_Field || + aFontID == LookAndFeel::eFont_Button || + aFontID == LookAndFeel::eFont_List) { + // As far as I can tell the system default fonts and sizes + // on MS-Windows for Buttons, Listboxes/Comboxes and Text Fields are + // all pre-determined and cannot be changed by either the control panel + // or programmatically. + // Fields (text fields) + // Button and Selects (listboxes/comboboxes) + // We use whatever font is defined by the system. Which it appears + // (and the assumption is) it is always a proportional font. Then we + // always use 2 points smaller than what the browser has defined as + // the default proportional font. + // Assumption: system defined font is proportional + aSystemFont->size = + std::max(defaultVariableFont->size - + nsPresContext::CSSPointsToAppUnits(2), 0); + } +#endif + } +} + /* static */ void nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext, uint8_t aGenericFontID, const nsRuleData* aRuleData, @@ -3635,54 +3687,9 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext, nsFont systemFont = *defaultVariableFont; const nsCSSValue* systemFontValue = aRuleData->ValueForSystemFont(); if (eCSSUnit_Enumerated == systemFontValue->GetUnit()) { - gfxFontStyle fontStyle; LookAndFeel::FontID fontID = (LookAndFeel::FontID)systemFontValue->GetIntValue(); - float devPerCSS = - (float)nsPresContext::AppUnitsPerCSSPixel() / - aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom(); - nsAutoString systemFontName; - if (LookAndFeel::GetFont(fontID, systemFontName, fontStyle, devPerCSS)) { - systemFontName.Trim("\"'"); - systemFont.fontlist = FontFamilyList(systemFontName, eUnquotedName); - systemFont.fontlist.SetDefaultFontType(eFamily_none); - systemFont.style = fontStyle.style; - systemFont.systemFont = fontStyle.systemFont; - systemFont.weight = fontStyle.weight; - systemFont.stretch = fontStyle.stretch; - systemFont.size = - NSFloatPixelsToAppUnits(fontStyle.size, - aPresContext->DeviceContext()-> - AppUnitsPerDevPixelAtUnitFullZoom()); - //systemFont.langGroup = fontStyle.langGroup; - systemFont.sizeAdjust = fontStyle.sizeAdjust; - -#ifdef XP_WIN - // XXXldb This platform-specific stuff should be in the - // LookAndFeel implementation, not here. - // XXXzw Should we even still *have* this code? It looks to be making - // old, probably obsolete assumptions. - - if (fontID == LookAndFeel::eFont_Field || - fontID == LookAndFeel::eFont_Button || - fontID == LookAndFeel::eFont_List) { - // As far as I can tell the system default fonts and sizes - // on MS-Windows for Buttons, Listboxes/Comboxes and Text Fields are - // all pre-determined and cannot be changed by either the control panel - // or programmatically. - // Fields (text fields) - // Button and Selects (listboxes/comboboxes) - // We use whatever font is defined by the system. Which it appears - // (and the assumption is) it is always a proportional font. Then we - // always use 2 points smaller than what the browser has defined as - // the default proportional font. - // Assumption: system defined font is proportional - systemFont.size = - std::max(defaultVariableFont->size - - nsPresContext::CSSPointsToAppUnits(2), 0); - } -#endif - } + ComputeSystemFont(&systemFont, fontID, aPresContext); } // font-family: font family list, enum, inherit diff --git a/layout/style/nsRuleNode.h b/layout/style/nsRuleNode.h index 56faf5d62560..6502b35575fd 100644 --- a/layout/style/nsRuleNode.h +++ b/layout/style/nsRuleNode.h @@ -16,6 +16,7 @@ #include "mozilla/PodOperations.h" #include "mozilla/RangedArray.h" #include "mozilla/RuleNodeCacheConditions.h" +#include "mozilla/LookAndFeel.h" #include "mozilla/SheetType.h" #include "nsPresContext.h" #include "nsStyleStruct.h" @@ -1098,6 +1099,9 @@ private: static void StoreStyleOnContext(nsStyleContext* aContext, nsStyleStructID aSID, void* aStruct); + static void ComputeSystemFont(nsFont* aSystemFont, + mozilla::LookAndFeel::FontID aFontID, + const nsPresContext* aPresContext); }; /**