Bug 1418899 - Part 2: Move some font-related static methods out of nsRuleNode. r=TYLin

MozReview-Commit-ID: 3l9L6bHr0PJ

--HG--
extra : rebase_source : 4d60e21f70a0e8b7a54b009ca6f5d6c2c90a80bd
This commit is contained in:
Cameron McCormack 2017-11-20 12:43:21 +08:00
Родитель d8a0eb82de
Коммит 3991f1ba0d
7 изменённых файлов: 302 добавлений и 298 удалений

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

@ -10095,3 +10095,229 @@ nsLayoutUtils::ControlCharVisibilityDefault()
? NS_STYLE_CONTROL_CHARACTER_VISIBILITY_VISIBLE
: NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN;
}
/* static */
already_AddRefed<nsFontMetrics>
nsLayoutUtils::GetMetricsFor(nsPresContext* aPresContext,
bool aIsVertical,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
bool aUseUserFontSet,
FlushUserFontSet aFlushUserFontSet)
{
nsFont font = aStyleFont->mFont;
font.size = aFontSize;
gfxFont::Orientation orientation
= aIsVertical ? gfxFont::eVertical : gfxFont::eHorizontal;
nsFontMetrics::Params params;
params.language = aStyleFont->mLanguage;
params.explicitLanguage = aStyleFont->mExplicitLanguage;
params.orientation = orientation;
params.userFontSet = aUseUserFontSet
? aPresContext->GetUserFontSet(aFlushUserFontSet == FlushUserFontSet::Yes)
: nullptr;
params.textPerf = aPresContext->GetTextPerfMetrics();
return aPresContext->DeviceContext()->GetMetricsFor(font, params);
}
/* static */ void
nsLayoutUtils::FixupNoneGeneric(nsFont* aFont,
const nsPresContext* aPresContext,
uint8_t aGenericFontID,
const nsFont* aDefaultVariableFont)
{
bool useDocumentFonts =
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts);
if (aGenericFontID == kGenericFont_NONE ||
(!useDocumentFonts && (aGenericFontID == kGenericFont_cursive ||
aGenericFontID == kGenericFont_fantasy))) {
FontFamilyType defaultGeneric =
aDefaultVariableFont->fontlist.GetDefaultFontType();
MOZ_ASSERT(aDefaultVariableFont->fontlist.IsEmpty() &&
(defaultGeneric == eFamily_serif ||
defaultGeneric == eFamily_sans_serif));
if (defaultGeneric != eFamily_none) {
if (useDocumentFonts) {
aFont->fontlist.SetDefaultFontType(defaultGeneric);
} else {
// Either prioritize the first generic in the list,
// or (if there isn't one) prepend the default variable font.
if (!aFont->fontlist.PrioritizeFirstGeneric()) {
aFont->fontlist.PrependGeneric(defaultGeneric);
}
}
}
} else {
aFont->fontlist.SetDefaultFontType(eFamily_none);
}
}
/* static */ void
nsLayoutUtils::ApplyMinFontSize(nsStyleFont* aFont,
const nsPresContext* aPresContext,
nscoord aMinFontSize)
{
nscoord fontSize = aFont->mSize;
// enforce the user' specified minimum font-size on the value that we expose
// (but don't change font-size:0, since that would unhide hidden text)
if (fontSize > 0) {
if (aMinFontSize < 0) {
aMinFontSize = 0;
} else {
aMinFontSize = (aMinFontSize * aFont->mMinFontSizeRatio) / 100;
}
if (fontSize < aMinFontSize && !aPresContext->IsChrome()) {
// override the minimum font-size constraint
fontSize = aMinFontSize;
}
}
aFont->mFont.size = fontSize;
}
/* static */ void
nsLayoutUtils::ComputeSystemFont(nsFont* aSystemFont, LookAndFeel::FontID aFontID,
const nsPresContext* aPresContext,
const nsFont* aDefaultVariableFont)
{
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(aDefaultVariableFont->size -
nsPresContext::CSSPointsToAppUnits(2), 0);
}
#endif
}
}
static inline void
AssertValidFontTag(const nsString& aString)
{
// To be valid as a font feature tag, a string MUST be:
MOZ_ASSERT(aString.Length() == 4 && // (1) exactly 4 chars long
NS_IsAscii(aString.BeginReading()) && // (2) entirely ASCII
isprint(aString[0]) && // (3) all printable chars
isprint(aString[1]) &&
isprint(aString[2]) &&
isprint(aString[3]));
}
/* static */ void
nsLayoutUtils::ComputeFontFeatures(const nsCSSValuePairList *aFeaturesList,
nsTArray<gfxFontFeature>& aFeatureSettings)
{
aFeatureSettings.Clear();
for (const nsCSSValuePairList* p = aFeaturesList; p; p = p->mNext) {
gfxFontFeature feat;
MOZ_ASSERT(aFeaturesList->mXValue.GetUnit() == eCSSUnit_String,
"unexpected value unit");
// tag is a 4-byte ASCII sequence
nsAutoString tag;
p->mXValue.GetStringValue(tag);
AssertValidFontTag(tag);
if (tag.Length() != 4) {
continue;
}
// parsing validates that these are ASCII chars
// tags are always big-endian
feat.mTag = (tag[0] << 24) | (tag[1] << 16) | (tag[2] << 8) | tag[3];
// value
NS_ASSERTION(p->mYValue.GetUnit() == eCSSUnit_Integer,
"should have found an integer unit");
feat.mValue = p->mYValue.GetIntValue();
aFeatureSettings.AppendElement(feat);
}
}
/* static */ void
nsLayoutUtils::ComputeFontVariations(const nsCSSValuePairList* aVariationsList,
nsTArray<gfxFontVariation>& aVariationSettings)
{
aVariationSettings.Clear();
for (const nsCSSValuePairList* p = aVariationsList; p; p = p->mNext) {
gfxFontVariation var;
MOZ_ASSERT(aVariationsList->mXValue.GetUnit() == eCSSUnit_String,
"unexpected value unit");
// tag is a 4-byte ASCII sequence
nsAutoString tag;
p->mXValue.GetStringValue(tag);
AssertValidFontTag(tag);
if (tag.Length() != 4) {
continue;
}
// parsing validates that these are ASCII chars
// tags are always big-endian
var.mTag = (tag[0] << 24) | (tag[1] << 16) | (tag[2] << 8) | tag[3];
// value
NS_ASSERTION(p->mYValue.GetUnit() == eCSSUnit_Number,
"should have found a number unit");
var.mValue = p->mYValue.GetFloatValue();
aVariationSettings.AppendElement(var);
}
}
/* static */ uint32_t
nsLayoutUtils::ParseFontLanguageOverride(const nsAString& aLangTag)
{
if (!aLangTag.Length() || aLangTag.Length() > 4) {
return NO_FONT_LANGUAGE_OVERRIDE;
}
uint32_t index, result = 0;
for (index = 0; index < aLangTag.Length(); ++index) {
char16_t ch = aLangTag[index];
if (!nsCRT::IsAscii(ch)) { // valid tags are pure ASCII
return NO_FONT_LANGUAGE_OVERRIDE;
}
result = (result << 8) + ch;
}
while (index++ < 4) {
result = (result << 8) + 0x20;
}
return result;
}

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

@ -3054,6 +3054,48 @@ public:
// from preferences.
static uint8_t ControlCharVisibilityDefault();
enum class FlushUserFontSet {
Yes,
No,
};
static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
bool aIsVertical,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
bool aUseUserFontSet,
FlushUserFontSet aFlushUserFontSet);
/**
* Appropriately add the correct font if we are using DocumentFonts or
* overriding for XUL
*/
static void FixupNoneGeneric(nsFont* aFont,
const nsPresContext* aPresContext,
uint8_t aGenericFontID,
const nsFont* aDefaultVariableFont);
/**
* For an nsStyleFont with mSize set, apply minimum font size constraints
* from preferences, as well as -moz-min-font-size-ratio.
*/
static void ApplyMinFontSize(nsStyleFont* aFont,
const nsPresContext* aPresContext,
nscoord aMinFontSize);
static void ComputeSystemFont(nsFont* aSystemFont,
mozilla::LookAndFeel::FontID aFontID,
const nsPresContext* aPresContext,
const nsFont* aDefaultVariableFont);
static void ComputeFontFeatures(const nsCSSValuePairList* aFeaturesList,
nsTArray<gfxFontFeature>& aFeatureSettings);
static void ComputeFontVariations(const nsCSSValuePairList* aVariationsList,
nsTArray<gfxFontVariation>& aVariationSettings);
static uint32_t ParseFontLanguageOverride(const nsAString& aLangTag);
private:
static uint32_t sFontSizeInflationEmPerLine;
static uint32_t sFontSizeInflationMinTwips;

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

@ -43,6 +43,7 @@
#include "nsNetUtil.h"
#include "nsIProtocolHandler.h"
#include "nsIInputStream.h"
#include "nsLayoutUtils.h"
#include "nsPresContext.h"
#include "nsPrintfCString.h"
#include "nsStyleSet.h"
@ -1067,7 +1068,7 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
if (unit == eCSSUnit_Normal) {
// empty list of features
} else if (unit == eCSSUnit_PairList || unit == eCSSUnit_PairListDep) {
nsRuleNode::ComputeFontFeatures(val.GetPairListValue(), featureSettings);
nsLayoutUtils::ComputeFontFeatures(val.GetPairListValue(), featureSettings);
} else {
NS_ASSERTION(unit == eCSSUnit_Null,
"@font-face font-feature-settings has unexpected unit");
@ -1081,7 +1082,7 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
} else if (unit == eCSSUnit_String) {
nsString stringValue;
val.GetStringValue(stringValue);
languageOverride = nsRuleNode::ParseFontLanguageOverride(stringValue);
languageOverride = nsLayoutUtils::ParseFontLanguageOverride(stringValue);
} else {
NS_ASSERTION(unit == eCSSUnit_Null,
"@font-face font-language-override has unexpected unit");

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

@ -1340,7 +1340,8 @@ Gecko_nsFont_InitSystem(nsFont* aDest, int32_t aFontId,
LookAndFeel::FontID fontID = static_cast<LookAndFeel::FontID>(aFontId);
AutoWriteLock guard(*sServoFFILock);
nsRuleNode::ComputeSystemFont(aDest, fontID, aPresContext, defaultVariableFont);
nsLayoutUtils::ComputeSystemFont(aDest, fontID, aPresContext,
defaultVariableFont);
}
void
@ -2357,10 +2358,11 @@ void
Gecko_nsStyleFont_FixupNoneGeneric(nsStyleFont* aFont,
RawGeckoPresContextBorrowed aPresContext)
{
const nsFont* defaultVariableFont = ThreadSafeGetDefaultFontHelper(aPresContext, aFont->mLanguage,
kPresContext_DefaultVariableFont_ID);
nsRuleNode::FixupNoneGeneric(&aFont->mFont, aPresContext,
aFont->mGenericID, defaultVariableFont);
const nsFont* defaultVariableFont =
ThreadSafeGetDefaultFontHelper(aPresContext, aFont->mLanguage,
kPresContext_DefaultVariableFont_ID);
nsLayoutUtils::FixupNoneGeneric(&aFont->mFont, aPresContext,
aFont->mGenericID, defaultVariableFont);
}
void
@ -2397,7 +2399,7 @@ Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* aFont,
minFontSize = aPresContext->MinFontSize(aFont->mLanguage, nullptr);
}
nsRuleNode::ApplyMinFontSize(aFont, aPresContext, minFontSize);
nsLayoutUtils::ApplyMinFontSize(aFont, aPresContext, minFontSize);
}
void
@ -2513,9 +2515,9 @@ Gecko_GetFontMetrics(RawGeckoPresContextBorrowed aPresContext,
nsPresContext* presContext = const_cast<nsPresContext*>(aPresContext);
presContext->SetUsesExChUnits(true);
RefPtr<nsFontMetrics> fm = nsRuleNode::GetMetricsFor(
RefPtr<nsFontMetrics> fm = nsLayoutUtils::GetMetricsFor(
presContext, aIsVertical, aFont, aFontSize, aUseUserFontSet,
nsRuleNode::FlushUserFontSet::No);
nsLayoutUtils::FlushUserFontSet::No);
ret.mXSize = fm->XHeight();
gfxFloat zeroWidth = fm->GetThebesFontGroup()->GetFirstValidFont()->

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

@ -371,30 +371,6 @@ static inline nscoord ScaleViewportCoordTrunc(const nsCSSValue& aValue,
aViewportSize / 100.0f);
}
/* static */
already_AddRefed<nsFontMetrics>
nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
bool aIsVertical,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
bool aUseUserFontSet,
FlushUserFontSet aFlushUserFontSet)
{
nsFont font = aStyleFont->mFont;
font.size = aFontSize;
gfxFont::Orientation orientation
= aIsVertical ? gfxFont::eVertical : gfxFont::eHorizontal;
nsFontMetrics::Params params;
params.language = aStyleFont->mLanguage;
params.explicitLanguage = aStyleFont->mExplicitLanguage;
params.orientation = orientation;
params.userFontSet = aUseUserFontSet
? aPresContext->GetUserFontSet(aFlushUserFontSet == FlushUserFontSet::Yes)
: nullptr;
params.textPerf = aPresContext->GetTextPerfMetrics();
return aPresContext->DeviceContext()->GetMetricsFor(font, params);
}
/* static */
already_AddRefed<nsFontMetrics>
nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
@ -410,66 +386,9 @@ nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
isVertical = true;
}
}
return nsRuleNode::GetMetricsFor(
return nsLayoutUtils::GetMetricsFor(
aPresContext, isVertical, aStyleFont, aFontSize, aUseUserFontSet,
FlushUserFontSet::Yes);
}
/* static */
void
nsRuleNode::FixupNoneGeneric(nsFont* aFont,
const nsPresContext* aPresContext,
uint8_t aGenericFontID,
const nsFont* aDefaultVariableFont)
{
bool useDocumentFonts =
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts);
if (aGenericFontID == kGenericFont_NONE ||
(!useDocumentFonts && (aGenericFontID == kGenericFont_cursive ||
aGenericFontID == kGenericFont_fantasy))) {
FontFamilyType defaultGeneric =
aDefaultVariableFont->fontlist.GetDefaultFontType();
MOZ_ASSERT(aDefaultVariableFont->fontlist.IsEmpty() &&
(defaultGeneric == eFamily_serif ||
defaultGeneric == eFamily_sans_serif));
if (defaultGeneric != eFamily_none) {
if (useDocumentFonts) {
aFont->fontlist.SetDefaultFontType(defaultGeneric);
} else {
// Either prioritize the first generic in the list,
// or (if there isn't one) prepend the default variable font.
if (!aFont->fontlist.PrioritizeFirstGeneric()) {
aFont->fontlist.PrependGeneric(defaultGeneric);
}
}
}
} else {
aFont->fontlist.SetDefaultFontType(eFamily_none);
}
}
/* static */
void
nsRuleNode::ApplyMinFontSize(nsStyleFont* aFont,
const nsPresContext* aPresContext,
nscoord aMinFontSize)
{
nscoord fontSize = aFont->mSize;
// enforce the user' specified minimum font-size on the value that we expose
// (but don't change font-size:0, since that would unhide hidden text)
if (fontSize > 0) {
if (aMinFontSize < 0) {
aMinFontSize = 0;
} else {
aMinFontSize = (aMinFontSize * aFont->mMinFontSizeRatio) / 100;
}
if (fontSize < aMinFontSize && !aPresContext->IsChrome()) {
// override the minimum font-size constraint
fontSize = aMinFontSize;
}
}
aFont->mFont.size = fontSize;
nsLayoutUtils::FlushUserFontSet::Yes);
}
static nsSize CalcViewportUnitsScale(nsPresContext* aPresContext)
@ -3537,59 +3456,6 @@ static int8_t ClampTo8Bit(int32_t aValue) {
return int8_t(aValue);
}
/* static */ void
nsRuleNode::ComputeSystemFont(nsFont* aSystemFont, LookAndFeel::FontID aFontID,
const nsPresContext* aPresContext,
const nsFont* aDefaultVariableFont)
{
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(aDefaultVariableFont->size -
nsPresContext::CSSPointsToAppUnits(2), 0);
}
#endif
}
}
/* static */ void
nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
uint8_t aGenericFontID, const nsRuleData* aRuleData,
@ -3658,8 +3524,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
lazySystemFont.emplace(*defaultVariableFont);
LookAndFeel::FontID fontID =
(LookAndFeel::FontID)systemFontValue->GetIntValue();
ComputeSystemFont(lazySystemFont.ptr(), fontID, aPresContext,
defaultVariableFont);
nsLayoutUtils::ComputeSystemFont(lazySystemFont.ptr(), fontID, aPresContext,
defaultVariableFont);
}
const nsFont& systemFont = lazySystemFont.refOr(*defaultVariableFont);
@ -3668,8 +3534,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
case eCSSUnit_FontFamilyList:
// set the correct font if we are using DocumentFonts OR we are overriding
// for XUL - MJA: bug 31816
nsRuleNode::FixupNoneGeneric(&aFont->mFont, aPresContext,
aGenericFontID, defaultVariableFont);
nsLayoutUtils::FixupNoneGeneric(&aFont->mFont, aPresContext,
aGenericFontID, defaultVariableFont);
aFont->mFont.systemFont = false;
// Technically this is redundant with the code below, but it's good
@ -3696,8 +3562,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
// with the default generic from defaultVariableFont, which is computed
// using aFont->mLanguage above.
if (aRuleData->ValueForLang()->GetUnit() != eCSSUnit_Null) {
FixupNoneGeneric(&aFont->mFont, aPresContext, aGenericFontID,
defaultVariableFont);
nsLayoutUtils::FixupNoneGeneric(&aFont->mFont, aPresContext,
aGenericFontID, defaultVariableFont);
}
break;
case eCSSUnit_Initial:
@ -3999,8 +3865,9 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
case eCSSUnit_PairList:
case eCSSUnit_PairListDep:
ComputeFontFeatures(featureSettingsValue->GetPairListValue(),
aFont->mFont.fontFeatureSettings);
nsLayoutUtils::ComputeFontFeatures(
featureSettingsValue->GetPairListValue(),
aFont->mFont.fontFeatureSettings);
break;
default:
@ -4034,8 +3901,9 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
case eCSSUnit_PairList:
case eCSSUnit_PairListDep:
ComputeFontVariations(variationSettingsValue->GetPairListValue(),
aFont->mFont.fontVariationSettings);
nsLayoutUtils::ComputeFontVariations(
variationSettingsValue->GetPairListValue(),
aFont->mFont.fontVariationSettings);
break;
default:
@ -4058,7 +3926,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
} else if (eCSSUnit_String == languageOverrideValue->GetUnit()) {
nsAutoString lang;
languageOverrideValue->GetStringValue(lang);
aFont->mFont.languageOverride = ParseFontLanguageOverride(lang);
aFont->mFont.languageOverride =
nsLayoutUtils::ParseFontLanguageOverride(lang);
}
// -moz-min-font-size-ratio: percent, inherit
@ -4149,8 +4018,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
NS_ASSERTION(aFont->mScriptUnconstrainedSize <= aFont->mSize,
"scriptminsize should never be making things bigger");
nsRuleNode::ApplyMinFontSize(aFont, aPresContext,
aPresContext->MinFontSize(aFont->mLanguage));
nsLayoutUtils::ApplyMinFontSize(aFont, aPresContext,
aPresContext->MinFontSize(aFont->mLanguage));
// font-size-adjust: number, none, inherit, initial, -moz-system-font
const nsCSSValue* sizeAdjustValue = aRuleData->ValueForFontSizeAdjust();
@ -4162,80 +4031,6 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, GeckoStyleContext* aContext,
SETFCT_NONE | SETFCT_UNSET_INHERIT);
}
static inline void
AssertValidFontTag(const nsString& aString)
{
// To be valid as a font feature tag, a string MUST be:
MOZ_ASSERT(aString.Length() == 4 && // (1) exactly 4 chars long
NS_IsAscii(aString.BeginReading()) && // (2) entirely ASCII
isprint(aString[0]) && // (3) all printable chars
isprint(aString[1]) &&
isprint(aString[2]) &&
isprint(aString[3]));
}
/* static */ void
nsRuleNode::ComputeFontFeatures(const nsCSSValuePairList *aFeaturesList,
nsTArray<gfxFontFeature>& aFeatureSettings)
{
aFeatureSettings.Clear();
for (const nsCSSValuePairList* p = aFeaturesList; p; p = p->mNext) {
gfxFontFeature feat;
MOZ_ASSERT(aFeaturesList->mXValue.GetUnit() == eCSSUnit_String,
"unexpected value unit");
// tag is a 4-byte ASCII sequence
nsAutoString tag;
p->mXValue.GetStringValue(tag);
AssertValidFontTag(tag);
if (tag.Length() != 4) {
continue;
}
// parsing validates that these are ASCII chars
// tags are always big-endian
feat.mTag = (tag[0] << 24) | (tag[1] << 16) | (tag[2] << 8) | tag[3];
// value
NS_ASSERTION(p->mYValue.GetUnit() == eCSSUnit_Integer,
"should have found an integer unit");
feat.mValue = p->mYValue.GetIntValue();
aFeatureSettings.AppendElement(feat);
}
}
/* static */ void
nsRuleNode::ComputeFontVariations(const nsCSSValuePairList* aVariationsList,
nsTArray<gfxFontVariation>& aVariationSettings)
{
aVariationSettings.Clear();
for (const nsCSSValuePairList* p = aVariationsList; p; p = p->mNext) {
gfxFontVariation var;
MOZ_ASSERT(aVariationsList->mXValue.GetUnit() == eCSSUnit_String,
"unexpected value unit");
// tag is a 4-byte ASCII sequence
nsAutoString tag;
p->mXValue.GetStringValue(tag);
AssertValidFontTag(tag);
if (tag.Length() != 4) {
continue;
}
// parsing validates that these are ASCII chars
// tags are always big-endian
var.mTag = (tag[0] << 24) | (tag[1] << 16) | (tag[2] << 8) | tag[3];
// value
NS_ASSERTION(p->mYValue.GetUnit() == eCSSUnit_Number,
"should have found a number unit");
var.mValue = p->mYValue.GetFloatValue();
aVariationSettings.AppendElement(var);
}
}
// This should die (bug 380915).
//
// SetGenericFont:
@ -4409,26 +4204,6 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
COMPUTE_END_INHERITED(Font, font)
}
/*static*/ uint32_t
nsRuleNode::ParseFontLanguageOverride(const nsAString& aLangTag)
{
if (!aLangTag.Length() || aLangTag.Length() > 4) {
return NO_FONT_LANGUAGE_OVERRIDE;
}
uint32_t index, result = 0;
for (index = 0; index < aLangTag.Length(); ++index) {
char16_t ch = aLangTag[index];
if (!nsCRT::IsAscii(ch)) { // valid tags are pure ASCII
return NO_FONT_LANGUAGE_OVERRIDE;
}
result = (result << 8) + ch;
}
while (index++ < 4) {
result = (result << 8) + 0x20;
}
return result;
}
template <typename T>
inline uint32_t ListLength(const T* aList)
{

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

@ -808,41 +808,12 @@ public:
bool aConvertListItem = false);
static void EnsureInlineDisplay(mozilla::StyleDisplay& display);
enum class FlushUserFontSet {
Yes,
No,
};
static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
bool aIsVertical,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
bool aUseUserFontSet,
FlushUserFontSet aFlushUserFontSet);
static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
nsStyleContext* aStyleContext,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
bool aUseUserFontSet);
/**
* Appropriately add the correct font if we are using DocumentFonts or
* overriding for XUL
*/
static void FixupNoneGeneric(nsFont* aFont,
const nsPresContext* aPresContext,
uint8_t aGenericFontID,
const nsFont* aDefaultVariableFont);
/**
* For an nsStyleFont with mSize set, apply minimum font size constraints
* from preferences, as well as -moz-min-font-size-ratio.
*/
static void ApplyMinFontSize(nsStyleFont* aFont,
const nsPresContext* aPresContext,
nscoord aMinFontSize);
// Transition never returns null; on out of memory it'll just return |this|.
nsRuleNode* Transition(nsIStyleRule* aRule, mozilla::SheetType aLevel,
bool aIsImportantRule);
@ -1059,18 +1030,10 @@ public:
return !!mStyleData.GetStyleData(aSID);
}
static void ComputeFontFeatures(const nsCSSValuePairList* aFeaturesList,
nsTArray<gfxFontFeature>& aFeatureSettings);
static void ComputeFontVariations(const nsCSSValuePairList* aVariationsList,
nsTArray<gfxFontVariation>& aVariationSettings);
static nscoord CalcFontPointSize(int32_t aHTMLSize, int32_t aBasePointSize,
nsPresContext* aPresContext,
nsFontSizeType aFontSizeType = eFontSize_HTML);
static uint32_t ParseFontLanguageOverride(const nsAString& aLangTag);
/**
* @param aValue The color value, returned from nsCSSParser::ParseColorString
* @param aPresContext Presentation context whose preferences are used
@ -1102,11 +1065,6 @@ public:
static void FillAllMaskLists(nsStyleImageLayers& aLayers,
uint32_t aMaxItemCount);
static void ComputeSystemFont(nsFont* aSystemFont,
mozilla::LookAndFeel::FontID aFontID,
const nsPresContext* aPresContext,
const nsFont* aDefaultVariableFont);
private:
#ifdef DEBUG
// non-inline helper function to allow assertions without incomplete

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

@ -10,7 +10,6 @@
#include "nsIContent.h"
#include "nsCSSProps.h"
#include "nsContentUtils.h"
#include "nsRuleNode.h"
#include "nsROCSSPrimitiveValue.h"
#include "nsStyleStruct.h"
#include "nsIContentPolicy.h"
@ -407,7 +406,7 @@ nsStyleUtil::AppendFontFeatureSettings(const nsCSSValue& aSrc,
"improper value unit for font-feature-settings:");
nsTArray<gfxFontFeature> featureSettings;
nsRuleNode::ComputeFontFeatures(aSrc.GetPairListValue(), featureSettings);
nsLayoutUtils::ComputeFontFeatures(aSrc.GetPairListValue(), featureSettings);
AppendFontFeatureSettings(featureSettings, aResult);
}
@ -446,7 +445,8 @@ nsStyleUtil::AppendFontVariationSettings(const nsCSSValue& aSrc,
"improper value unit for font-variation-settings:");
nsTArray<gfxFontVariation> variationSettings;
nsRuleNode::ComputeFontVariations(aSrc.GetPairListValue(), variationSettings);
nsLayoutUtils::ComputeFontVariations(aSrc.GetPairListValue(),
variationSettings);
AppendFontVariationSettings(variationSettings, aResult);
}