Bug 1349417 - Part 1: stylo: Factor out system font computation into nsRuleNode::ComputeSystemFont; r?xidorn
MozReview-Commit-ID: 5xytKh37B7l
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -3548,16 +3548,68 @@ static int8_t ClampTo8Bit(int32_t aValue
if (aValue < -128)
return -128;
if (aValue > 127)
return 127;
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,
const nsStyleFont* aParentFont,
nsStyleFont* aFont, bool aUsedStartStruct,
RuleNodeCacheConditions& aConditions)
{
bool atRoot = !aContext->GetParent();
@@ -3616,64 +3668,19 @@ nsRuleNode::SetFont(nsPresContext* aPres
NS_STYLE_FONT_LIST == LookAndFeel::eFont_List &&
NS_STYLE_FONT_FIELD == LookAndFeel::eFont_Field,
"LookAndFeel.h system-font constants out of sync with nsStyleConsts.h");
// Fall back to defaultVariableFont.
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
const nsCSSValue* familyValue = aRuleData->ValueForFontFamily();
NS_ASSERTION(eCSSUnit_Enumerated != familyValue->GetUnit(),
"system fonts should not be in mFamily anymore");
if (eCSSUnit_FontFamilyList == familyValue->GetUnit()) {
// set the correct font if we are using DocumentFonts OR we are overriding for XUL
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -11,16 +11,17 @@
#ifndef nsRuleNode_h___
#define nsRuleNode_h___
#include "mozilla/ArenaObjectID.h"
#include "mozilla/LinkedList.h"
#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"
class nsCSSPropertyIDSet;
class nsCSSValue;
class nsFontMetrics;
class nsIStyleRule;
@@ -1093,16 +1094,19 @@ private:
bool ContextHasCachedData(nsStyleContext* aContext, nsStyleStructID aSID);
#endif
// Store style struct on the style context and tell the style context
// that it doesn't own the data
static void StoreStyleOnContext(nsStyleContext* aContext,
nsStyleStructID aSID,
void* aStruct);
+ static void ComputeSystemFont(nsFont* aSystemFont,
+ mozilla::LookAndFeel::FontID aFontID,
+ const nsPresContext* aPresContext);
};
/**
* We allocate arrays of CSS values with alloca. (These arrays are a
* fixed size per style struct, but we don't want to waste the
* allocation and construction/destruction costs of the big structs when
* we're handling much smaller ones.) Since the lifetime of an alloca
* allocation is the life of the calling function, the caller must call