зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1351200 - Part 3: stylo: Bypass cache when fetching font size prefs from Stylo; r=emilio
MozReview-Commit-ID: 7WBduQ6lBTC --HG-- extra : rebase_source : f3bee21a7d105cad96231aa5bec5660cdbface06
This commit is contained in:
Родитель
4a8c6b3fa0
Коммит
8bfdb295a6
|
@ -35,8 +35,13 @@ class nsILanguageAtomService : public nsISupports
|
|||
|
||||
virtual nsIAtom* GetLocaleLanguage() = 0;
|
||||
|
||||
virtual nsIAtom* GetLanguageGroup(nsIAtom *aLanguage,
|
||||
nsresult *aError = nullptr) = 0;
|
||||
virtual nsIAtom* GetLanguageGroup(nsIAtom* aLanguage,
|
||||
nsresult* aError = nullptr) = 0;
|
||||
|
||||
// Same as GetLanguageGroup, but will not cache anything
|
||||
// and can be used from a different thread
|
||||
virtual already_AddRefed<nsIAtom> GetUncachedLanguageGroup(nsIAtom* aLanguage,
|
||||
nsresult* aError = nullptr) const = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsILanguageAtomService,
|
||||
|
|
|
@ -62,44 +62,54 @@ nsLanguageAtomService::GetLocaleLanguage()
|
|||
}
|
||||
|
||||
nsIAtom*
|
||||
nsLanguageAtomService::GetLanguageGroup(nsIAtom *aLanguage,
|
||||
nsresult *aError)
|
||||
nsLanguageAtomService::GetLanguageGroup(nsIAtom* aLanguage,
|
||||
nsresult* aError)
|
||||
{
|
||||
nsIAtom *retVal;
|
||||
nsresult res = NS_OK;
|
||||
nsIAtom* retVal;
|
||||
|
||||
retVal = mLangToGroup.GetWeak(aLanguage);
|
||||
|
||||
if (!retVal) {
|
||||
nsAutoCString langStr;
|
||||
aLanguage->ToUTF8String(langStr);
|
||||
nsCOMPtr<nsIAtom> uncached = GetUncachedLanguageGroup(aLanguage, aError);
|
||||
retVal = uncached.get();
|
||||
|
||||
nsAutoCString langGroupStr;
|
||||
// The hashtable will keep an owning reference to the atom
|
||||
mLangToGroup.Put(aLanguage, uncached);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIAtom>
|
||||
nsLanguageAtomService::GetUncachedLanguageGroup(nsIAtom* aLanguage,
|
||||
nsresult* aError) const
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
nsAutoCString langStr;
|
||||
aLanguage->ToUTF8String(langStr);
|
||||
|
||||
nsAutoCString langGroupStr;
|
||||
res = nsUConvPropertySearch::SearchPropertyValue(kLangGroups,
|
||||
ArrayLength(kLangGroups),
|
||||
langStr, langGroupStr);
|
||||
while (NS_FAILED(res)) {
|
||||
int32_t hyphen = langStr.RFindChar('-');
|
||||
if (hyphen <= 0) {
|
||||
langGroupStr.AssignLiteral("x-unicode");
|
||||
break;
|
||||
}
|
||||
langStr.Truncate(hyphen);
|
||||
res = nsUConvPropertySearch::SearchPropertyValue(kLangGroups,
|
||||
ArrayLength(kLangGroups),
|
||||
langStr, langGroupStr);
|
||||
while (NS_FAILED(res)) {
|
||||
int32_t hyphen = langStr.RFindChar('-');
|
||||
if (hyphen <= 0) {
|
||||
langGroupStr.AssignLiteral("x-unicode");
|
||||
break;
|
||||
}
|
||||
langStr.Truncate(hyphen);
|
||||
res = nsUConvPropertySearch::SearchPropertyValue(kLangGroups,
|
||||
ArrayLength(kLangGroups),
|
||||
langStr, langGroupStr);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAtom> langGroup = NS_Atomize(langGroupStr);
|
||||
|
||||
// The hashtable will keep an owning reference to the atom
|
||||
mLangToGroup.Put(aLanguage, langGroup);
|
||||
retVal = langGroup.get();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAtom> langGroup = NS_Atomize(langGroupStr);
|
||||
|
||||
if (aError) {
|
||||
*aError = res;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return langGroup.forget();
|
||||
}
|
||||
|
|
|
@ -28,8 +28,10 @@ public:
|
|||
|
||||
virtual nsIAtom* GetLocaleLanguage() override;
|
||||
|
||||
virtual nsIAtom* GetLanguageGroup(nsIAtom *aLanguage,
|
||||
nsresult *aError) override;
|
||||
virtual nsIAtom* GetLanguageGroup(nsIAtom* aLanguage,
|
||||
nsresult* aError) override;
|
||||
virtual already_AddRefed<nsIAtom> GetUncachedLanguageGroup(nsIAtom* aLanguage,
|
||||
nsresult* aError) const final;
|
||||
|
||||
nsLanguageAtomService();
|
||||
|
||||
|
|
|
@ -247,6 +247,17 @@ StaticPresData::GetLangGroup(nsIAtom* aLanguage) const
|
|||
return langGroupAtom;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIAtom>
|
||||
StaticPresData::GetUncachedLangGroup(nsIAtom* aLanguage) const
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIAtom> langGroupAtom = mLangService->GetUncachedLanguageGroup(aLanguage, &rv);
|
||||
if (NS_FAILED(rv) || !langGroupAtom) {
|
||||
langGroupAtom = nsGkAtoms::x_western; // Assume x-western is safe...
|
||||
}
|
||||
return langGroupAtom.forget();
|
||||
}
|
||||
|
||||
const LangGroupFontPrefs*
|
||||
StaticPresData::GetFontPrefsForLangHelper(nsIAtom* aLanguage,
|
||||
const LangGroupFontPrefs* aPrefs) const
|
||||
|
|
|
@ -100,6 +100,12 @@ public:
|
|||
*/
|
||||
nsIAtom* GetLangGroup(nsIAtom* aLanguage) const;
|
||||
|
||||
/**
|
||||
* Same as GetLangGroup, but will not cache the result
|
||||
*
|
||||
*/
|
||||
already_AddRefed<nsIAtom> GetUncachedLangGroup(nsIAtom* aLanguage) const;
|
||||
|
||||
/**
|
||||
* Fetch the user's font preferences for the given aLanguage's
|
||||
* langugage group.
|
||||
|
|
|
@ -1584,10 +1584,27 @@ Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont, const nsStyleFont* aSource)
|
|||
aFont->mLanguage = aSource->mLanguage;
|
||||
}
|
||||
|
||||
nscoord
|
||||
Gecko_nsStyleFont_GetBaseSize(const nsStyleFont* aFont, RawGeckoPresContextBorrowed aPresContext)
|
||||
FontSizePrefs::FontSizePrefs(const LangGroupFontPrefs& prefs)
|
||||
: mDefaultVariableSize(prefs.mDefaultVariableFont.size),
|
||||
mDefaultFixedSize(prefs.mDefaultFixedFont.size),
|
||||
mDefaultSerifSize(prefs.mDefaultSerifFont.size),
|
||||
mDefaultSansSerifSize(prefs.mDefaultSansSerifFont.size),
|
||||
mDefaultMonospaceSize(prefs.mDefaultMonospaceFont.size),
|
||||
mDefaultCursiveSize(prefs.mDefaultCursiveFont.size),
|
||||
mDefaultFantasySize(prefs.mDefaultFantasyFont.size)
|
||||
{
|
||||
return aPresContext->GetDefaultFont(aFont->mGenericID, aFont->mLanguage)->size;
|
||||
}
|
||||
|
||||
FontSizePrefs
|
||||
Gecko_GetBaseSize(nsIAtom* aLanguage)
|
||||
{
|
||||
LangGroupFontPrefs prefs;
|
||||
nsCOMPtr<nsIAtom> langGroupAtom = StaticPresData::Get()->GetUncachedLangGroup(aLanguage);
|
||||
|
||||
prefs.Initialize(langGroupAtom);
|
||||
FontSizePrefs sizes(prefs);
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace mozilla {
|
|||
struct URLValue;
|
||||
};
|
||||
enum class UpdateAnimationsTasks : uint8_t;
|
||||
struct LangGroupFontPrefs;
|
||||
}
|
||||
using mozilla::FontFamilyList;
|
||||
using mozilla::FontFamilyType;
|
||||
|
@ -94,6 +95,18 @@ public:
|
|||
mozilla::URLExtraData* mExtraData;
|
||||
};
|
||||
|
||||
struct FontSizePrefs
|
||||
{
|
||||
FontSizePrefs(const mozilla::LangGroupFontPrefs&);
|
||||
nscoord mDefaultVariableSize;
|
||||
nscoord mDefaultFixedSize;
|
||||
nscoord mDefaultSerifSize;
|
||||
nscoord mDefaultSansSerifSize;
|
||||
nscoord mDefaultMonospaceSize;
|
||||
nscoord mDefaultCursiveSize;
|
||||
nscoord mDefaultFantasySize;
|
||||
};
|
||||
|
||||
// DOM Traversal.
|
||||
uint32_t Gecko_ChildrenCount(RawGeckoNodeBorrowed node);
|
||||
bool Gecko_NodeIsElement(RawGeckoNodeBorrowed node);
|
||||
|
@ -384,7 +397,7 @@ bool Gecko_PropertyId_IsPrefEnabled(nsCSSPropertyID id);
|
|||
|
||||
void Gecko_nsStyleFont_SetLang(nsStyleFont* font, nsIAtom* atom);
|
||||
void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont, const nsStyleFont* aSource);
|
||||
nscoord Gecko_nsStyleFont_GetBaseSize(const nsStyleFont* font, RawGeckoPresContextBorrowed pres_context);
|
||||
FontSizePrefs Gecko_GetBaseSize(nsIAtom* lang);
|
||||
|
||||
const nsMediaFeature* Gecko_GetMediaFeatures();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче