Bug 1367275 - Part 5: stylo: Support -moz-min-font-size-ratio; r=xidorn

MozReview-Commit-ID: xRxkFJodeK
This commit is contained in:
Manish Goregaokar 2017-05-23 18:15:47 -07:00
parent 15ca68fab4
commit f588139b16
6 changed files with 62 additions and 20 deletions

View File

@ -583,8 +583,11 @@ public:
* the language-specific global preference with the per-presentation
* base minimum font size.
*/
int32_t MinFontSize(nsIAtom *aLanguage) const {
const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage);
int32_t MinFontSize(nsIAtom *aLanguage, bool* aNeedsToCache = nullptr) const {
const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage, aNeedsToCache);
if (aNeedsToCache && *aNeedsToCache) {
return 0;
}
return std::max(mBaseMinFontSize, prefs->mMinimumFontSize);
}

View File

@ -369,7 +369,7 @@ fuzzy-if(OSX,1,100) fuzzy-if(skiaContent,1,14) == mfrac-D-1.html mfrac-D-1-ref.h
== mfrac-E-1.html mfrac-E-1-ref.html
test-pref(dom.webcomponents.enabled,true) == shadow-dom-1.html shadow-dom-1-ref.html
pref(font.size.inflation.emPerLine,25) == font-inflation-1.html font-inflation-1-ref.html
test-pref(font.minimum-size.x-math,40) fails-if(styloVsGecko||stylo) == default-font.html default-font-ref.html
test-pref(font.minimum-size.x-math,40) == default-font.html default-font-ref.html
!= radicalbar-1.html about:blank
!= radicalbar-1a.html about:blank
!= radicalbar-1b.html about:blank

View File

@ -2022,6 +2022,26 @@ Gecko_nsStyleFont_FixupNoneGeneric(nsStyleFont* aFont,
aFont->mGenericID, defaultVariableFont);
}
void
Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* aFont,
RawGeckoPresContextBorrowed aPresContext)
{
nscoord minFontSize;
bool needsCache = false;
{
AutoReadLock guard(*sServoLangFontPrefsLock);
minFontSize = aPresContext->MinFontSize(aFont->mLanguage, &needsCache);
}
if (needsCache) {
AutoWriteLock guard(*sServoLangFontPrefsLock);
minFontSize = aPresContext->MinFontSize(aFont->mLanguage, nullptr);
}
nsRuleNode::ApplyMinFontSize(aFont, aPresContext, minFontSize);
}
void
FontSizePrefs::CopyFrom(const LangGroupFontPrefs& prefs)
{

View File

@ -507,6 +507,8 @@ void Gecko_nsStyleFont_SetLang(nsStyleFont* font, nsIAtom* atom);
void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont, const nsStyleFont* aSource);
void Gecko_nsStyleFont_FixupNoneGeneric(nsStyleFont* font,
RawGeckoPresContextBorrowed pres_context);
void Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* font,
RawGeckoPresContextBorrowed pres_context);
FontSizePrefs Gecko_GetBaseSize(nsIAtom* lang);
struct GeckoFontMetrics

View File

@ -443,6 +443,30 @@ nsRuleNode::FixupNoneGeneric(nsFont* aFont,
}
}
/* 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;
}
static nsSize CalcViewportUnitsScale(nsPresContext* aPresContext)
{
// The caller is making use of viewport units, so notify the pres context
@ -4041,23 +4065,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
NS_ASSERTION(aFont->mScriptUnconstrainedSize <= aFont->mSize,
"scriptminsize should never be making things bigger");
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) {
nscoord minFontSize = aPresContext->MinFontSize(aFont->mLanguage);
if (minFontSize < 0) {
minFontSize = 0;
} else {
minFontSize = (minFontSize * aFont->mMinFontSizeRatio) / 100;
}
if (fontSize < minFontSize && !aPresContext->IsChrome()) {
// override the minimum font-size constraint
fontSize = minFontSize;
}
}
aFont->mFont.size = fontSize;
nsRuleNode::ApplyMinFontSize(aFont, aPresContext,
aPresContext->MinFontSize(aFont->mLanguage));
// font-size-adjust: number, none, inherit, initial, -moz-system-font
const nsCSSValue* sizeAdjustValue = aRuleData->ValueForFontSizeAdjust();

View File

@ -820,6 +820,14 @@ public:
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);