Bug 1430623 - Move the lang font prefs to Document instead of nsPresContext. r=jfkthame

This will allow me to (in different patches):

 * Make the default style structs constructible without a pres context (default
   color and co. would need to be faked or moved to Document as well, but that's
   ok, since those cannot affect media queries, the default font-size does).

 * Remove the nsPresContext pointer from ComputedStyle (moving it to nsFrame,
   probably).

That would in turn allow me to have the default style computed without a pres
context, which allows us to fix both bug 1490401 and bug 1471231.

Differential Revision: https://phabricator.services.mozilla.com/D16926

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-01-18 13:43:06 +00:00
Родитель 8ddc948f81
Коммит 62fdf6f313
13 изменённых файлов: 191 добавлений и 223 удалений

Просмотреть файл

@ -1208,6 +1208,7 @@ Document::Document(const char* aContentType)
mStyledLinksCleared(false),
#endif
mBidiEnabled(false),
mFontGroupCacheDirty(true),
mMathMLEnabled(false),
mIsInitialDocumentInWindow(false),
mIgnoreDocGroupMismatches(false),
@ -1356,6 +1357,8 @@ Document::Document(const char* aContentType)
// void state used to differentiate an empty source from an unselected source
mPreloadPictureFoundSource.SetIsVoid(true);
RecomputeLanguageFromCharset();
}
void Document::ClearAllBoxObjects() {
@ -3411,6 +3414,7 @@ void Document::SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding) {
if (mCharacterSet != aEncoding) {
mCharacterSet = aEncoding;
mEncodingMenuDisabled = aEncoding == UTF_8_ENCODING;
RecomputeLanguageFromCharset();
if (nsPresContext* context = GetPresContext()) {
context->DispatchCharSetChange(aEncoding);
@ -3474,6 +3478,7 @@ void Document::SetHeaderData(nsAtom* aHeaderField, const nsAString& aData) {
if (aHeaderField == nsGkAtoms::headerContentLanguage) {
CopyUTF16toUTF8(aData, mContentLanguage);
ResetLangPrefs();
if (auto* presContext = GetPresContext()) {
presContext->ContentLanguageChanged();
}
@ -10889,6 +10894,9 @@ void Document::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const {
mPresShell->AddSizeOfIncludingThis(aWindowSizes);
}
aWindowSizes.mDOMOtherSize += mLangGroupFontPrefs.SizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
aWindowSizes.mPropertyTablesSize +=
mPropertyTable.SizeOfExcludingThis(aWindowSizes.mState.mMallocSizeOf);
@ -12498,5 +12506,62 @@ bool Document::StorageAccessSandboxed() const {
(GetSandboxFlags() & SANDBOXED_STORAGE_ACCESS) != 0;
}
already_AddRefed<nsAtom> Document::GetContentLanguageAsAtomForStyle() const {
nsAutoString contentLang;
GetContentLanguage(contentLang);
contentLang.StripWhitespace();
// Content-Language may be a comma-separated list of language codes,
// in which case the HTML5 spec says to treat it as unknown
if (!contentLang.IsEmpty() && !contentLang.Contains(char16_t(','))) {
return NS_Atomize(contentLang);
}
return nullptr;
}
already_AddRefed<nsAtom> Document::GetLanguageForStyle() const {
RefPtr<nsAtom> lang = GetContentLanguageAsAtomForStyle();
if (!lang) {
lang = mLanguageFromCharset;
}
return lang.forget();
}
const LangGroupFontPrefs* Document::GetFontPrefsForLang(
nsAtom* aLanguage, bool* aNeedsToCache) const {
nsAtom* lang = aLanguage ? aLanguage : mLanguageFromCharset.get();
return StaticPresData::Get()->GetFontPrefsForLangHelper(
lang, &mLangGroupFontPrefs, aNeedsToCache);
}
void Document::DoCacheAllKnownLangPrefs() {
MOZ_ASSERT(mFontGroupCacheDirty);
RefPtr<nsAtom> lang = GetLanguageForStyle();
GetFontPrefsForLang(lang.get());
GetFontPrefsForLang(nsGkAtoms::x_math);
// https://bugzilla.mozilla.org/show_bug.cgi?id=1362599#c12
GetFontPrefsForLang(nsGkAtoms::Unicode);
for (auto iter = mLanguagesUsed.Iter(); !iter.Done(); iter.Next()) {
GetFontPrefsForLang(iter.Get()->GetKey());
}
mFontGroupCacheDirty = false;
}
void Document::RecomputeLanguageFromCharset() {
nsLanguageAtomService* service = nsLanguageAtomService::GetService();
RefPtr<nsAtom> language = service->LookupCharSet(mCharacterSet);
if (language == nsGkAtoms::Unicode) {
language = service->GetLocaleLanguage();
}
if (language == mLanguageFromCharset) {
return;
}
ResetLangPrefs();
mLanguageFromCharset = language.forget();
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -43,6 +43,7 @@
#include "mozilla/net/ReferrerPolicy.h" // for member
#include "mozilla/UseCounter.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/StaticPresData.h"
#include "Units.h"
#include "nsContentListDeclarations.h"
#include "nsExpirationTracker.h"
@ -123,6 +124,7 @@ class nsDOMCaretPosition;
class nsViewportInfo;
class nsIGlobalObject;
class nsIXULWindow;
struct nsFont;
namespace mozilla {
class AbstractThread;
@ -3458,7 +3460,39 @@ class Document : public nsINode,
public:
bool IsThirdPartyForFlashClassifier();
bool IsScopedStyleEnabled();
private:
void DoCacheAllKnownLangPrefs();
void RecomputeLanguageFromCharset();
public:
void ResetLangPrefs() {
mLangGroupFontPrefs.Reset();
mFontGroupCacheDirty = true;
}
already_AddRefed<nsAtom> GetContentLanguageAsAtomForStyle() const;
already_AddRefed<nsAtom> GetLanguageForStyle() const;
/**
* Fetch the user's font preferences for the given aLanguage's
* language group.
*/
const LangGroupFontPrefs* GetFontPrefsForLang(
nsAtom* aLanguage, bool* aNeedsToCache = nullptr) const;
void ForceCacheLang(nsAtom* aLanguage) {
if (!mLanguagesUsed.EnsureInserted(aLanguage)) {
return;
}
GetFontPrefsForLang(aLanguage);
}
void CacheAllKnownLangPrefs() {
if (!mFontGroupCacheDirty) {
return;
}
DoCacheAllKnownLangPrefs();
}
nsINode* GetServoRestyleRoot() const { return mServoRestyleRoot; }
@ -3804,6 +3838,8 @@ class Document : public nsINode,
// True if BIDI is enabled.
bool mBidiEnabled : 1;
// True if mLangGroupFontPrefs is not initialized or dirty in some other way.
bool mFontGroupCacheDirty : 1;
// True if a MathML element has ever been owned by this document.
bool mMathMLEnabled : 1;
@ -4433,6 +4469,18 @@ class Document : public nsINode,
// resolution.
nsTHashtable<nsPtrHashKey<SVGElement>> mLazySVGPresElements;
// Most documents will only use one (or very few) language groups. Rather
// than have the overhead of a hash lookup, we simply look along what will
// typically be a very short (usually of length 1) linked list. There are 31
// language groups, so in the worst case scenario we'll need to traverse 31
// link items.
LangGroupFontPrefs mLangGroupFontPrefs;
nsTHashtable<nsRefPtrHashKey<nsAtom>> mLanguagesUsed;
// TODO(emilio): Is this hot enough to warrant to be cached?
RefPtr<nsAtom> mLanguageFromCharset;
// Restyle root for servo's style system.
//
// We store this as an nsINode, rather than as an Element, so that we can

Просмотреть файл

@ -282,43 +282,4 @@ const LangGroupFontPrefs* StaticPresData::GetFontPrefsForLangHelper(
return prefs;
}
const nsFont* StaticPresData::GetDefaultFontHelper(
uint8_t aFontID, nsAtom* aLanguage,
const LangGroupFontPrefs* aPrefs) const {
MOZ_ASSERT(aLanguage);
MOZ_ASSERT(aPrefs);
const nsFont* font;
switch (aFontID) {
// Special (our default variable width font and fixed width font)
case kPresContext_DefaultVariableFont_ID:
font = &aPrefs->mDefaultVariableFont;
break;
case kPresContext_DefaultFixedFont_ID:
font = &aPrefs->mDefaultFixedFont;
break;
// CSS
case kGenericFont_serif:
font = &aPrefs->mDefaultSerifFont;
break;
case kGenericFont_sans_serif:
font = &aPrefs->mDefaultSansSerifFont;
break;
case kGenericFont_monospace:
font = &aPrefs->mDefaultMonospaceFont;
break;
case kGenericFont_cursive:
font = &aPrefs->mDefaultCursiveFont;
break;
case kGenericFont_fantasy:
font = &aPrefs->mDefaultFantasyFont;
break;
default:
font = nullptr;
NS_ERROR("invalid arg");
break;
}
return font;
}
} // namespace mozilla

Просмотреть файл

@ -61,6 +61,50 @@ struct LangGroupFontPrefs {
// Initialize this with the data for a given language
void Initialize(nsAtom* aLangGroupAtom);
/**
* Get the default font for the given language and generic font ID.
* aLanguage may not be nullptr.
*
* 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
* language group.
*
* For aFontID corresponding to a CSS Generic, the nsFont returned has
* its name set to that generic font's name, and its size set to
* the user's preference for font size for that generic and the
* given language.
*/
const nsFont* GetDefaultFont(uint8_t aFontID) const {
switch (aFontID) {
// Special (our default variable width font and fixed width font)
case kGenericFont_moz_variable:
return &mDefaultVariableFont;
case kGenericFont_moz_fixed:
return &mDefaultFixedFont;
// CSS
case kGenericFont_serif:
return &mDefaultSerifFont;
case kGenericFont_sans_serif:
return &mDefaultSansSerifFont;
case kGenericFont_monospace:
return &mDefaultMonospaceFont;
case kGenericFont_cursive:
return &mDefaultCursiveFont;
case kGenericFont_fantasy:
return &mDefaultFantasyFont;
break;
default:
MOZ_ASSERT_UNREACHABLE("invalid font id");
return nullptr;
}
}
RefPtr<nsAtom> mLangGroup;
nscoord mMinimumFontSize;
nsFont mDefaultVariableFont;
@ -134,52 +178,14 @@ class StaticPresData {
const LangGroupFontPrefs* GetFontPrefsForLangHelper(
nsAtom* aLanguage, const LangGroupFontPrefs* aPrefs,
bool* aNeedsToCache = nullptr) const;
/**
* Get the default font for the given language and generic font ID.
* aLanguage may not be nullptr.
*
* 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
* language group.
*
* For aFontID corresponding to a CSS Generic, the nsFont returned has
* its name set to that generic font's name, and its size set to
* the user's preference for font size for that generic and the
* given language.
*/
const nsFont* GetDefaultFontHelper(uint8_t aFontID, nsAtom* aLanguage,
const LangGroupFontPrefs* aPrefs) const;
/*
* These versions operate on the font pref cache on StaticPresData.
*/
const nsFont* GetDefaultFont(uint8_t aFontID, nsAtom* aLanguage) const {
MOZ_ASSERT(aLanguage);
return GetDefaultFontHelper(aFontID, aLanguage,
GetFontPrefsForLang(aLanguage));
}
const LangGroupFontPrefs* GetFontPrefsForLang(
nsAtom* aLanguage, bool* aNeedsToCache = nullptr) const {
MOZ_ASSERT(aLanguage);
return GetFontPrefsForLangHelper(aLanguage, &mStaticLangGroupFontPrefs,
aNeedsToCache);
}
void ResetCachedFontPrefs() { mStaticLangGroupFontPrefs.Reset(); }
private:
StaticPresData();
~StaticPresData() {}
nsLanguageAtomService* mLangService;
LangGroupFontPrefs mStaticLangGroupFontPrefs;
};
} // namespace mozilla

Просмотреть файл

@ -175,7 +175,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
mLastFontInflationScreenSize(gfxSize(-1.0, -1.0)),
mCurAppUnitsPerDevPixel(0),
mAutoQualityMinFontSizePixelsPref(0),
mLangService(nsLanguageAtomService::GetService()),
mPageSize(-1, -1),
mPageScale(0.0),
mPPScale(1.0f),
@ -193,7 +192,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
mExistThrottledUpdates(false),
// mImageAnimationMode is initialised below, in constructor body
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
mFontGroupCacheDirty(true),
mInterruptChecksToSkip(0),
mElementsRestyled(0),
mFramesConstructed(0),
@ -339,7 +337,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsPresContext)
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLanguage); // an atom
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTheme); // a service
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLangService); // a service
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrintSettings);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -350,7 +347,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEffectCompositor);
// NS_RELEASE(tmp->mLanguage); // an atom
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mTheme); // a service
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mLangService); // a service
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrintSettings);
tmp->Destroy();
@ -540,9 +536,7 @@ void nsPresContext::GetUserPreferences() {
mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
mLangGroupFontPrefs.Reset();
mFontGroupCacheDirty = true;
StaticPresData::Get()->ResetCachedFontPrefs();
Document()->ResetLangPrefs();
// * image animation
nsAutoCString animatePref;
@ -921,17 +915,6 @@ void nsPresContext::DoChangeCharSet(NotNull<const Encoding*> aCharSet) {
}
void nsPresContext::UpdateCharSet(NotNull<const Encoding*> aCharSet) {
mLanguage = mLangService->LookupCharSet(aCharSet);
// this will be a language group (or script) code rather than a true language
// code
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
if (mLanguage == nsGkAtoms::Unicode) {
mLanguage = mLangService->GetLocaleLanguage();
}
mLangGroupFontPrefs.Reset();
mFontGroupCacheDirty = true;
switch (GET_BIDI_OPTION_TEXTTYPE(GetBidi())) {
case IBMBIDI_TEXTTYPE_LOGICAL:
SetVisualMode(false);
@ -1130,21 +1113,6 @@ void nsPresContext::SetImageAnimationMode(uint16_t aMode) {
mImageAnimationMode = aMode;
}
already_AddRefed<nsAtom> nsPresContext::GetContentLanguage() const {
nsAutoString language;
Document()->GetContentLanguage(language);
language.StripWhitespace();
// Content-Language may be a comma-separated list of language codes,
// in which case the HTML5 spec says to treat it as unknown
if (!language.IsEmpty() && !language.Contains(char16_t(','))) {
return NS_Atomize(language);
// NOTE: This does *not* count as an explicit language; in other
// words, it doesn't trigger language-specific hyphenation.
}
return nullptr;
}
void nsPresContext::UpdateEffectiveTextZoom() {
float newZoom = mSystemFontScale * mTextZoom;
float minZoom = nsLayoutUtils::MinZoom();
@ -1694,28 +1662,7 @@ void nsPresContext::StopEmulatingMedium() {
}
}
void nsPresContext::ForceCacheLang(nsAtom* aLanguage) {
// force it to be cached
GetDefaultFont(kPresContext_DefaultVariableFont_ID, aLanguage);
mLanguagesUsed.PutEntry(aLanguage);
}
void nsPresContext::CacheAllLangs() {
if (mFontGroupCacheDirty) {
RefPtr<nsAtom> thisLang = nsStyleFont::GetLanguage(this);
GetDefaultFont(kPresContext_DefaultVariableFont_ID, thisLang.get());
GetDefaultFont(kPresContext_DefaultVariableFont_ID, nsGkAtoms::x_math);
// https://bugzilla.mozilla.org/show_bug.cgi?id=1362599#c12
GetDefaultFont(kPresContext_DefaultVariableFont_ID, nsGkAtoms::Unicode);
for (auto iter = mLanguagesUsed.Iter(); !iter.Done(); iter.Next()) {
GetDefaultFont(kPresContext_DefaultVariableFont_ID, iter.Get()->GetKey());
}
}
mFontGroupCacheDirty = false;
}
void nsPresContext::ContentLanguageChanged() {
mFontGroupCacheDirty = true;
PostRebuildAllStyleDataEvent(nsChangeHint(0), eRestyle_ForceDescendants);
}
@ -2561,10 +2508,8 @@ nsIFrame* nsPresContext::GetPrimaryFrameFor(nsIContent* aContent) {
}
size_t nsPresContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
return mLangGroupFontPrefs.SizeOfExcludingThis(aMallocSizeOf);
// Measurement of other members may be added later if DMD finds it is
// worthwhile.
// Measurement may be added later if DMD finds it is worthwhile.
return 0;
}
bool nsPresContext::IsRootContentDocument() const {

Просмотреть файл

@ -28,7 +28,6 @@
#include "nsITimer.h"
#include "nsCRT.h"
#include "nsIWidgetListener.h"
#include "nsLanguageAtomService.h"
#include "nsGkAtoms.h"
#include "nsCycleCollectionParticipant.h"
#include "nsChangeHint.h"
@ -136,7 +135,6 @@ class nsPresContext : public nsISupports,
using Encoding = mozilla::Encoding;
template <typename T>
using NotNull = mozilla::NotNull<T>;
typedef mozilla::LangGroupFontPrefs LangGroupFontPrefs;
typedef mozilla::ScrollStyles ScrollStyles;
typedef mozilla::StaticPresData StaticPresData;
using TransactionId = mozilla::layers::TransactionId;
@ -361,25 +359,6 @@ class nsPresContext : public nsISupports,
*/
void StopEmulatingMedium();
/**
* Get the default font for the given language and generic font ID.
* If aLanguage is nullptr, the document's language is used.
*
* See the comment in StaticPresData::GetDefaultFont.
*/
const nsFont* GetDefaultFont(uint8_t aFontID, nsAtom* aLanguage,
bool* aNeedsToCache = nullptr) const {
nsAtom* lang = aLanguage ? aLanguage : mLanguage.get();
const LangGroupFontPrefs* prefs = GetFontPrefsForLang(lang, aNeedsToCache);
if (aNeedsToCache && *aNeedsToCache) {
return nullptr;
}
return StaticPresData::Get()->GetDefaultFontHelper(aFontID, lang, prefs);
}
void ForceCacheLang(nsAtom* aLanguage);
void CacheAllLangs();
/** Get a cached boolean pref, by its type */
// * - initially created for bugs 31816, 20760, 22963
bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const {
@ -532,8 +511,6 @@ class nsPresContext : public nsISupports,
nsDeviceContext* DeviceContext() const { return mDeviceContext; }
mozilla::EventStateManager* EventStateManager() { return mEventManager; }
nsAtom* GetLanguageFromCharset() const { return mLanguage; }
already_AddRefed<nsAtom> GetContentLanguage() const;
/**
* Get/set a text zoom factor that is applied on top of the normal text zoom
@ -589,8 +566,8 @@ class nsPresContext : public nsISupports,
* base minimum font size.
*/
int32_t MinFontSize(nsAtom* aLanguage, bool* aNeedsToCache = nullptr) const {
const LangGroupFontPrefs* prefs =
GetFontPrefsForLang(aLanguage, aNeedsToCache);
const auto* prefs =
Document()->GetFontPrefsForLang(aLanguage, aNeedsToCache);
if (aNeedsToCache && *aNeedsToCache) {
return 0;
}
@ -1171,17 +1148,6 @@ class nsPresContext : public nsISupports,
void GetUserPreferences();
/**
* Fetch the user's font preferences for the given aLanguage's
* langugage group.
*/
const LangGroupFontPrefs* GetFontPrefsForLang(
nsAtom* aLanguage, bool* aNeedsToCache = nullptr) const {
nsAtom* lang = aLanguage ? aLanguage : mLanguage.get();
return StaticPresData::Get()->GetFontPrefsForLangHelper(
lang, &mLangGroupFontPrefs, aNeedsToCache);
}
void UpdateCharSet(NotNull<const Encoding*> aCharSet);
static bool NotifyDidPaintSubdocumentCallback(
@ -1261,13 +1227,6 @@ class nsPresContext : public nsISupports,
// the classes which set it. (using SetLinkHandler() again).
nsILinkHandler* MOZ_NON_OWNING_REF mLinkHandler;
// Formerly mLangGroup; moving from charset-oriented langGroup to
// maintaining actual language settings everywhere (see bug 524107).
// This may in fact hold a langGroup such as x-western rather than
// a specific language, however (e.g, if it is inferred from the
// charset rather than explicitly specified as a lang attribute).
RefPtr<nsAtom> mLanguage;
public:
// The following are public member variables so that we can use them
// with mozilla::AutoToggle or mozilla::AutoRestore.
@ -1293,7 +1252,6 @@ class nsPresContext : public nsISupports,
int32_t mAutoQualityMinFontSizePixelsPref;
nsCOMPtr<nsITheme> mTheme;
nsLanguageAtomService* mLangService;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
mozilla::UniquePtr<nsBidi> mBidiEngine;
@ -1339,16 +1297,6 @@ class nsPresContext : public nsISupports,
uint16_t mImageAnimationMode;
uint16_t mImageAnimationModePref;
// Most documents will only use one (or very few) language groups. Rather
// than have the overhead of a hash lookup, we simply look along what will
// typically be a very short (usually of length 1) linked list. There are 31
// language groups, so in the worst case scenario we'll need to traverse 31
// link items.
LangGroupFontPrefs mLangGroupFontPrefs;
bool mFontGroupCacheDirty;
nsTHashtable<nsRefPtrHashKey<nsAtom>> mLanguagesUsed;
uint32_t mInterruptChecksToSkip;
// Counters for tests and tools that want to detect frame construction

Просмотреть файл

@ -53,8 +53,11 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame(ComputedStyle* aStyle)
// XXX Unsafe to assume successful allocation
mPageData = new nsSharedPageData();
mPageData->mHeadFootFont = *PresContext()->GetDefaultFont(
kGenericFont_serif, aStyle->StyleFont()->mLanguage);
mPageData->mHeadFootFont =
*PresContext()
->Document()
->GetFontPrefsForLang(aStyle->StyleFont()->mLanguage)
->GetDefaultFont(kGenericFont_serif);
mPageData->mHeadFootFont.size = nsPresContext::CSSPointsToAppUnits(10);
// Doing this here so we only have to go get these formats once

Просмотреть файл

@ -5733,8 +5733,9 @@ gfxFloat nsTextFrame::ComputeSelectionUnderlineHeight(
// computed value from the default font size can be too thick for the
// current font size.
nscoord defaultFontSize =
aPresContext
->GetDefaultFont(kPresContext_DefaultVariableFont_ID, nullptr)
aPresContext->Document()
->GetFontPrefsForLang(nullptr)
->GetDefaultFont(kPresContext_DefaultVariableFont_ID)
->size;
int32_t zoomedFontSize = aPresContext->AppUnitsToDevPixels(
nsStyleFont::ZoomText(aPresContext, defaultFontSize));

Просмотреть файл

@ -106,16 +106,22 @@ static const nsFont* ThreadSafeGetDefaultFontHelper(
bool needsCache = false;
const nsFont* retval;
auto GetDefaultFont = [&](bool* aNeedsToCache) {
auto* prefs =
aPresContext->Document()->GetFontPrefsForLang(aLanguage, aNeedsToCache);
return prefs ? prefs->GetDefaultFont(aGenericId) : nullptr;
};
{
AutoReadLock guard(*sServoFFILock);
retval = aPresContext->GetDefaultFont(aGenericId, aLanguage, &needsCache);
retval = GetDefaultFont(&needsCache);
}
if (!needsCache) {
return retval;
}
{
AutoWriteLock guard(*sServoFFILock);
retval = aPresContext->GetDefaultFont(aGenericId, aLanguage, nullptr);
retval = GetDefaultFont(nullptr);
}
return retval;
}

Просмотреть файл

@ -23,9 +23,7 @@ void MappedDeclarations::SetIdentAtomValue(nsCSSPropertyID aId,
// FIXME(emilio): Can we move mapped attribute declarations across
// documents? Isn't this wrong in that case? This is pretty out of place
// anyway.
if (nsPresContext* pc = mDocument->GetPresContext()) {
pc->ForceCacheLang(aValue);
}
mDocument->ForceCacheLang(aValue);
}
}

Просмотреть файл

@ -387,10 +387,13 @@ void ServoStyleSet::PreTraverseSync() {
LookAndFeel::NativeInit();
nsPresContext* presContext = GetPresContext();
MOZ_ASSERT(presContext,
"For now, we don't call into here without a pres context");
mDocument->CacheAllKnownLangPrefs();
if (gfxUserFontSet* userFontSet = mDocument->GetUserFontSet()) {
nsPresContext* presContext = GetPresContext();
MOZ_ASSERT(presContext,
"For now, we don't call into here without a pres context");
// Ensure that the @font-face data is not stale
uint64_t generation = userFontSet->GetGeneration();
if (generation != mUserFontSetUpdateGeneration) {
@ -401,7 +404,6 @@ void ServoStyleSet::PreTraverseSync() {
}
MOZ_ASSERT(!StylistNeedsUpdate());
presContext->CacheAllLangs();
}
void ServoStyleSet::PreTraverse(ServoTraversalFlags aFlags, Element* aRoot) {

Просмотреть файл

@ -110,8 +110,8 @@ nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
}
nsStyleFont::nsStyleFont(const nsPresContext* aContext)
: mFont(*aContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID,
nullptr)),
: mFont(*aContext->Document()->GetFontPrefsForLang(nullptr)->GetDefaultFont(
kPresContext_DefaultVariableFont_ID)),
mSize(ZoomText(aContext, mFont.size)),
mFontSizeFactor(1.0),
mFontSizeOffset(0),
@ -127,7 +127,7 @@ nsStyleFont::nsStyleFont(const nsPresContext* aContext)
mScriptMinSize(nsPresContext::CSSTwipsToAppUnits(
NS_POINTS_TO_TWIPS(NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT))),
mScriptSizeMultiplier(NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER),
mLanguage(GetLanguage(aContext)) {
mLanguage(aContext->Document()->GetLanguageForStyle()) {
MOZ_COUNT_CTOR(nsStyleFont);
MOZ_ASSERT(NS_IsMainThread());
nscoord minimumFontSize = aContext->MinFontSize(mLanguage);
@ -180,20 +180,6 @@ nsChangeHint nsStyleFont::CalcDifference(const nsStyleFont& aNewData) const {
aPresContext->EffectiveTextZoom());
}
/* static */ already_AddRefed<nsAtom> nsStyleFont::GetLanguage(
const nsPresContext* aPresContext) {
RefPtr<nsAtom> language = aPresContext->GetContentLanguage();
if (!language) {
// we didn't find a (usable) Content-Language, so we fall back
// to whatever the presContext guessed from the charset
// NOTE this should not be used elsewhere, because we want websites
// to use UTF-8 with proper language tag, instead of relying on
// deriving language from charset. See bug 1040668 comment 67.
language = aPresContext->GetLanguageFromCharset();
}
return language.forget();
}
nsStyleMargin::nsStyleMargin(const nsPresContext* aContext) {
MOZ_COUNT_CTOR(nsStyleMargin);
nsStyleCoord zero(0, nsStyleCoord::CoordConstructor);
@ -3825,7 +3811,8 @@ nsStyleText::nsStyleText(const nsPresContext* aContext)
mWebkitTextStrokeWidth(0),
mTextShadow(nullptr) {
MOZ_COUNT_CTOR(nsStyleText);
RefPtr<nsAtom> language = aContext->GetContentLanguage();
RefPtr<nsAtom> language =
aContext->Document()->GetContentLanguageAsAtomForStyle();
mTextEmphasisPosition =
language && nsStyleUtil::MatchesLanguagePrefix(language, u"zh")
? NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH

Просмотреть файл

@ -99,8 +99,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
* negative results. The result is clamped to nscoord_MIN .. nscoord_MAX.
*/
static nscoord ZoomText(const nsPresContext* aPresContext, nscoord aSize);
static already_AddRefed<nsAtom> GetLanguage(
const nsPresContext* aPresContext);
nsFont mFont;
nscoord mSize; // Our "computed size". Can be different