$OpenBSD$ index 9f1e295..62f564f 100644 --- layout/style/nsRuleNode.cpp.orig Fri Feb 20 15:40:37 2015 +++ layout/style/nsRuleNode.cpp Fri Feb 20 15:40:37 2015 @@ -31,6 +31,7 @@ #include "nsStyleStruct.h" #include "nsSize.h" #include "nsRuleData.h" +#include "gfxUserFontSet.h" #include "nsIStyleRule.h" #include "nsBidiUtils.h" #include "nsStyleStructInlines.h" @@ -886,7 +887,10 @@ static bool SetColor(const nsCSSValue& aValue, const nscolor aParentColor, int32_t intValue = aValue.GetIntValue(); if (0 <= intValue) { LookAndFeel::ColorID colorID = (LookAndFeel::ColorID) intValue; - if (NS_SUCCEEDED(LookAndFeel::GetColor(colorID, &aResult))) { + bool useStandinsForNativeColors = aPresContext && + !aPresContext->IsChrome(); + if (NS_SUCCEEDED(LookAndFeel::GetColor(colorID, + useStandinsForNativeColors, &aResult))) { result = true; } } @@ -3249,6 +3253,7 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext, aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, aFont->mLanguage); + // XXX: Bleh. Disable these somehow? // -moz-system-font: enum (never inherit!) static_assert( NS_STYLE_FONT_CAPTION == LookAndFeel::eFont_Caption && @@ -3861,6 +3866,31 @@ static bool ExtractGeneric(const nsString& aFamily, bool aGeneric, return true; } +struct smugglerStruct { + nsStyleFont *font; + gfxUserFontSet *userFonts; +}; + +/* This function forces the use of the first @font-face font we find */ +static bool ForceFirstWebFont(const nsString& aFamily, bool aGeneric, + void *smuggled) +{ + smugglerStruct *sm = static_cast(smuggled); + + if (aGeneric) { + return true; + } + + if (sm->userFonts->HasFamily(aFamily)) { + // Force use of this exact @font-face font since we have it. + sm->font->mFont.name = aFamily; + + return false; // Stop enumeration. + } + + return true; +} + const void* nsRuleNode::ComputeFontData(void* aStartStruct, const nsRuleData* aRuleData, @@ -3884,14 +3914,16 @@ nsRuleNode::ComputeFontData(void* aStartStruct, bool useDocumentFonts = mPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts); + bool isXUL = PR_FALSE; + bool forcedWebFont = false; // See if we are in the chrome // We only need to know this to determine if we have to use the // document fonts (overriding the useDocumentFonts flag). - if (!useDocumentFonts && mPresContext->IsChrome()) { + if (mPresContext->IsChrome()) { // if we are not using document fonts, but this is a XUL document, // then we use the document fonts anyway - useDocumentFonts = true; + isXUL = true; } // Figure out if we are a generic font @@ -3905,9 +3937,28 @@ nsRuleNode::ComputeFontData(void* aStartStruct, // generic? nsFont::GetGenericID(font->mFont.name, &generic); + if (!isXUL) { + gfxUserFontSet *userFonts = mPresContext->GetUserFontSet(); + if (userFonts) { + smugglerStruct sm; + sm.userFonts = userFonts; + sm.font = font; + + if (!sm.font->mFont.EnumerateFamilies(ForceFirstWebFont, &sm)) { + isXUL = true; // Always allow WebFont use. + forcedWebFont = true; + } + } + } + + if (!forcedWebFont && generic == kGenericFont_NONE) + mPresContext->AddFontAttempt(font->mFont); + // If we aren't allowed to use document fonts, then we are only entitled // to use the user's default variable-width font and fixed-width font - if (!useDocumentFonts) { + if (!isXUL && (!useDocumentFonts || + mPresContext->FontAttemptCountReached(font->mFont) || + mPresContext->FontUseCountReached(font->mFont))) { // Extract the generic from the specified font family... nsAutoString genericName; if (!font->mFont.EnumerateFamilies(ExtractGeneric, &genericName)) { @@ -3943,6 +3994,8 @@ nsRuleNode::ComputeFontData(void* aStartStruct, font); } + if (!forcedWebFont && font->mGenericID == kGenericFont_NONE) + mPresContext->AddFontUse(font->mFont); COMPUTE_END_INHERITED(Font, font) }