Fix enumerated values of font-size to depend on the right preference. b=389464 r+sr=bzbarsky

git-svn-id: svn://10.0.0.236/trunk@230988 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbaron%dbaron.org
2007-07-25 23:14:47 +00:00
parent 01a6e1eabe
commit 1a0669a4e8
5 changed files with 129 additions and 30 deletions

View File

@@ -270,6 +270,19 @@ public:
/**
* Get the default font corresponding to the given ID. This object is
* read-only, you must copy the font to modify it.
*
* When aFontID is kPresContext_DefaultVariableFontID or
* kPresContext_DefaultFixedFontID (which equals
* kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
* the nsFont returned has its name as a CSS generic family (serif or
* sans-serif for the former, monospace for the latter), and its size
* as the default font size for variable or fixed fonts for the pres
* context's language group.
*
* For aFontID corresponds to a CSS Generic, the nsFont returned has
* its name as the name or names of the fonts in the user's
* preferences for the given generic and the pres context's language
* group, and its size set to the default variable font size.
*/
virtual NS_HIDDEN_(const nsFont*) GetDefaultFontExternal(PRUint8 aFontID) const;
NS_HIDDEN_(const nsFont*) GetDefaultFontInternal(PRUint8 aFontID) const;

View File

@@ -1917,8 +1917,8 @@ nsRuleNode::AdjustLogicalBoxProp(nsStyleContext* aContext,
/* static */ void
nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
nscoord aMinFontSize,
PRBool aIsGeneric, const nsRuleDataFont& aFontData,
const nsFont& aDefaultFont, const nsStyleFont* aParentFont,
PRUint8 aGenericFontID, const nsRuleDataFont& aFontData,
const nsStyleFont* aParentFont,
nsStyleFont* aFont, PRBool& aInherited)
{
const nsFont* defaultVariableFont =
@@ -1997,33 +1997,51 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
if (eCSSUnit_String == aFontData.mFamily.GetUnit()) {
// set the correct font if we are using DocumentFonts OR we are overriding for XUL
// MJA: bug 31816
if (!aIsGeneric) {
if (aGenericFontID == kGenericFont_NONE) {
// only bother appending fallback fonts if this isn't a fallback generic font itself
if (!aFont->mFont.name.IsEmpty())
aFont->mFont.name.Append((PRUnichar)',');
// XXXldb Should this name be quoted?
aFont->mFont.name.Append(aDefaultFont.name);
// defaultVariableFont.name should always be "serif" or "sans-serif".
aFont->mFont.name.Append(defaultVariableFont->name);
}
aFont->mFont.familyNameQuirks =
(aPresContext->CompatibilityMode() == eCompatibility_NavQuirks &&
aFontData.mFamilyFromHTML);
aFont->mFont.systemFont = PR_FALSE;
aFont->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
// Technically this is redundant with the code below, but it's good
// to have since we'll still want it once we get rid of
// SetGenericFont (bug 380915).
aFont->mFlags |= aGenericFontID;
}
else if (eCSSUnit_System_Font == aFontData.mFamily.GetUnit()) {
aFont->mFont.name = systemFont.name;
aFont->mFont.familyNameQuirks = PR_FALSE;
aFont->mFont.systemFont = PR_TRUE;
aFont->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
}
else if (eCSSUnit_Inherit == aFontData.mFamily.GetUnit()) {
aInherited = PR_TRUE;
aFont->mFont.name = aParentFont->mFont.name;
aFont->mFont.familyNameQuirks = aParentFont->mFont.familyNameQuirks;
aFont->mFont.systemFont = aParentFont->mFont.systemFont;
aFont->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
aFont->mFlags |= (aParentFont->mFlags & NS_STYLE_FONT_FACE_MASK);
}
else if (eCSSUnit_Initial == aFontData.mFamily.GetUnit()) {
aFont->mFont.name = defaultVariableFont->name;
aFont->mFont.familyNameQuirks = PR_FALSE;
aFont->mFont.systemFont = defaultVariableFont->systemFont;
aFont->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
}
// When we're in the loop in SetGenericFont, we must ensure that we
// always keep aFont->mFlags set to the correct generic. But we have
// to be careful not to touch it when we're called directly from
// ComputeFontData, because we could have a start struct.
if (aGenericFontID != kGenericFont_NONE) {
aFont->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
aFont->mFlags |= aGenericFontID;
}
// font-style: enum, normal, inherit
@@ -2096,6 +2114,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
// font-size: enum, length, percent, inherit
PRBool zoom = PR_FALSE;
PRInt32 baseSize = (PRInt32) aPresContext->
GetDefaultFont(aFont->mFlags & NS_STYLE_FONT_FACE_MASK)->size;
if (eCSSUnit_Enumerated == aFontData.mSize.GetUnit()) {
PRInt32 value = aFontData.mSize.GetIntValue();
PRInt32 scaler = aPresContext->FontScaler();
@@ -2104,11 +2124,13 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
zoom = PR_TRUE;
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, baseSize,
scaleFactor, aPresContext, eFontSize_CSS);
}
else if (NS_STYLE_FONT_SIZE_XXXLARGE == value) {
// <font size="7"> is not specified in CSS, so we don't use eFontSize_CSS.
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext);
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, baseSize,
scaleFactor, aPresContext);
}
else if (NS_STYLE_FONT_SIZE_LARGER == value ||
NS_STYLE_FONT_SIZE_SMALLER == value) {
@@ -2121,15 +2143,17 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
nsStyleFont::UnZoomText(aPresContext, aParentFont->mSize);
if (NS_STYLE_FONT_SIZE_LARGER == value) {
aFont->mSize = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
NS_ASSERTION(aFont->mSize > parentSize, "FindNextLargerFontSize failed.");
aFont->mSize = nsStyleUtil::FindNextLargerFontSize(parentSize,
baseSize, scaleFactor, aPresContext, eFontSize_CSS);
NS_ASSERTION(aFont->mSize > parentSize,
"FindNextLargerFontSize failed");
}
else {
aFont->mSize = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
NS_ASSERTION(aFont->mSize < parentSize,
"FindNextSmallerFontSize failed; this is expected if parentFont size <= 1px");
aFont->mSize = nsStyleUtil::FindNextSmallerFontSize(parentSize,
baseSize, scaleFactor, aPresContext, eFontSize_CSS);
NS_ASSERTION(aFont->mSize < parentSize ||
parentSize <= nsPresContext::CSSPixelsToAppUnits(1),
"FindNextSmallerFontSize failed");
}
} else {
NS_NOTREACHED("unexpected value");
@@ -2159,7 +2183,7 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
else if (eCSSUnit_Initial == aFontData.mSize.GetUnit()) {
// The initial value is 'medium', which has magical sizing based on
// the generic font family, so do that here too.
aFont->mSize = aDefaultFont.size;
aFont->mSize = baseSize;
zoom = PR_TRUE;
}
@@ -2260,8 +2284,7 @@ nsRuleNode::SetGenericFont(nsPresContext* aPresContext,
fontData.mFamily.Reset(); // avoid unnecessary operations in SetFont()
nsRuleNode::SetFont(aPresContext, context, aMinFontSize,
PR_TRUE, fontData, *defaultFont,
&parentFont, aFont, dummy);
aGenericFontID, fontData, &parentFont, aFont, dummy);
// XXX Not sure if we need to do this here
// If we have a post-resolve callback, handle that now.
@@ -2277,8 +2300,7 @@ nsRuleNode::SetGenericFont(nsPresContext* aPresContext,
// already has the current cascading information that we want. We
// can just compute the delta from the parent.
nsRuleNode::SetFont(aPresContext, aContext, aMinFontSize,
PR_TRUE, aFontData, *defaultFont,
&parentFont, aFont, dummy);
aGenericFontID, aFontData, &parentFont, aFont, dummy);
}
static PRBool ExtractGeneric(const nsString& aFamily, PRBool aGeneric,
@@ -2359,12 +2381,8 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct,
// Now compute our font struct
if (generic == kGenericFont_NONE) {
// continue the normal processing
// our default font is the user's default (serif or sans-serif)
const nsFont* defaultFont =
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID);
nsRuleNode::SetFont(mPresContext, aContext, minimumFontSize, PR_FALSE,
fontData, *defaultFont, parentFont, font, inherited);
nsRuleNode::SetFont(mPresContext, aContext, minimumFontSize, generic,
fontData, parentFont, font, inherited);
}
else {
// re-calculate the font as a generic font
@@ -2372,9 +2390,6 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct,
nsRuleNode::SetGenericFont(mPresContext, aContext, fontData, generic,
minimumFontSize, font);
}
// Set our generic font's bit to inform our descendants
font->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
font->mFlags |= generic;
COMPUTE_END_INHERITED(Font, font)
}

View File

@@ -603,9 +603,8 @@ protected:
static NS_HIDDEN_(void) SetFont(nsPresContext* aPresContext,
nsStyleContext* aContext,
nscoord aMinFontSize,
PRBool aIsGeneric,
PRUint8 aGenericFontID,
const nsRuleDataFont& aFontData,
const nsFont& aDefaultFont,
const nsStyleFont* aParentFont,
nsStyleFont* aFont, PRBool& aInherited);

View File

@@ -79,6 +79,7 @@ _TEST_FILES = test_bug74880.html \
test_bug379741.html \
test_bug383075.html \
test_bug387615.html \
test_bug389464.html \
test_compute_data_with_start_struct.html \
test_dont_use_document_colors.html \
test_inherit_storage.html \

View File

@@ -0,0 +1,71 @@
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- above is to force x-western language group -->
<title>Test for preference not to use document colors</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style type="text/css">
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=58048">Mozilla Bug 58048</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=255411">Mozilla Bug 255411</a>
<div id="display">
<pre><font id="one" size="-1">text</font></pre>
<p><font id="two" size="-1">text</font></p>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
var fontSizeBranch = prefService.getBranch("font.size.");
function get_pref(pref)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
return fontSizeBranch.getIntPref(pref);
}
function set_pref(pref, val)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
fontSizeBranch.setIntPref(pref, val);
}
var cs1 = getComputedStyle(document.getElementById("one"), "");
var cs2 = getComputedStyle(document.getElementById("two"), "");
var oldVariable = get_pref("variable.x-western");
var oldFixed = get_pref("fixed.x-western");
set_pref("variable.x-western", 25);
set_pref("fixed.x-western", 20);
setTimeout(part1, 0);
function part1()
{
var fs1 = cs1.fontSize.match(/(.*)px/)[1];
var fs2 = cs2.fontSize.match(/(.*)px/)[1];
ok(fs1 < fs2, "<font size=-1> shrinks relative to font-family: -moz-fixed");
set_pref("variable.x-western", oldVariable);
set_pref("fixed.x-western", oldFixed);
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>