diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index 023ae38b8b5..e578cad9703 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -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; diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index 488dc880988..f0a6f42e860 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -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) { // 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) } diff --git a/mozilla/layout/style/nsRuleNode.h b/mozilla/layout/style/nsRuleNode.h index 746fc964ebc..aec3d6eb24b 100644 --- a/mozilla/layout/style/nsRuleNode.h +++ b/mozilla/layout/style/nsRuleNode.h @@ -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); diff --git a/mozilla/layout/style/test/Makefile.in b/mozilla/layout/style/test/Makefile.in index 1b87426a316..c9dc3ac1dbf 100644 --- a/mozilla/layout/style/test/Makefile.in +++ b/mozilla/layout/style/test/Makefile.in @@ -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 \ diff --git a/mozilla/layout/style/test/test_bug389464.html b/mozilla/layout/style/test/test_bug389464.html new file mode 100644 index 00000000000..074b49f29e4 --- /dev/null +++ b/mozilla/layout/style/test/test_bug389464.html @@ -0,0 +1,71 @@ + + + + + + + Test for preference not to use document colors + + + + + + +Mozilla Bug 58048 +Mozilla Bug 255411 +
+ +
text
+

text

+ +
+
+
+
+ +