Bug 1349417 - Part 1: stylo: Factor out system font computation into nsRuleNode::ComputeSystemFont; r=xidorn

MozReview-Commit-ID: KfzzCodvLXd
This commit is contained in:
Manish Goregaokar 2017-03-21 20:38:12 -07:00
Родитель 690efb0293
Коммит ff8c1a3788
2 изменённых файлов: 57 добавлений и 46 удалений

Просмотреть файл

@ -3566,6 +3566,58 @@ static int8_t ClampTo8Bit(int32_t aValue) {
return int8_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 /* static */ void
nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext, nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
uint8_t aGenericFontID, const nsRuleData* aRuleData, uint8_t aGenericFontID, const nsRuleData* aRuleData,
@ -3635,54 +3687,9 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
nsFont systemFont = *defaultVariableFont; nsFont systemFont = *defaultVariableFont;
const nsCSSValue* systemFontValue = aRuleData->ValueForSystemFont(); const nsCSSValue* systemFontValue = aRuleData->ValueForSystemFont();
if (eCSSUnit_Enumerated == systemFontValue->GetUnit()) { if (eCSSUnit_Enumerated == systemFontValue->GetUnit()) {
gfxFontStyle fontStyle;
LookAndFeel::FontID fontID = LookAndFeel::FontID fontID =
(LookAndFeel::FontID)systemFontValue->GetIntValue(); (LookAndFeel::FontID)systemFontValue->GetIntValue();
float devPerCSS = ComputeSystemFont(&systemFont, fontID, aPresContext);
(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
}
} }
// font-family: font family list, enum, inherit // font-family: font family list, enum, inherit

Просмотреть файл

@ -16,6 +16,7 @@
#include "mozilla/PodOperations.h" #include "mozilla/PodOperations.h"
#include "mozilla/RangedArray.h" #include "mozilla/RangedArray.h"
#include "mozilla/RuleNodeCacheConditions.h" #include "mozilla/RuleNodeCacheConditions.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/SheetType.h" #include "mozilla/SheetType.h"
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsStyleStruct.h" #include "nsStyleStruct.h"
@ -1098,6 +1099,9 @@ private:
static void StoreStyleOnContext(nsStyleContext* aContext, static void StoreStyleOnContext(nsStyleContext* aContext,
nsStyleStructID aSID, nsStyleStructID aSID,
void* aStruct); void* aStruct);
static void ComputeSystemFont(nsFont* aSystemFont,
mozilla::LookAndFeel::FontID aFontID,
const nsPresContext* aPresContext);
}; };
/** /**