From 522e6c9366aa7bc2107f31290262e45749ed40e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 19 Feb 2019 11:17:28 +0000 Subject: [PATCH] Bug 1528712 - Remove a couple trivial dependencies on nsPresContext. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D20141 --HG-- extra : moz-landing-system : lando --- dom/base/nsContentUtils.cpp | 7 +- dom/base/nsContentUtils.h | 4 +- layout/base/nsLayoutUtils.cpp | 14 ++-- layout/base/nsLayoutUtils.h | 5 +- layout/base/nsPresContext.cpp | 5 -- layout/base/nsPresContext.h | 11 +-- layout/style/CSSMozDocumentRule.cpp | 2 +- layout/style/CSSMozDocumentRule.h | 2 +- layout/style/GeckoBindings.cpp | 73 ++++++++----------- layout/style/GeckoBindings.h | 65 ++++++++--------- layout/style/nsMediaFeatures.cpp | 44 +++++------ modules/libpref/init/StaticPrefList.h | 6 ++ .../components/style/gecko/media_features.rs | 2 +- servo/components/style/gecko/media_queries.rs | 8 +- servo/components/style/gecko/values.rs | 8 +- servo/components/style/properties/cascade.rs | 4 +- .../components/style/properties/gecko.mako.rs | 36 ++++----- .../style/properties/longhands/color.mako.rs | 2 +- .../style/properties/longhands/font.mako.rs | 2 +- .../style/properties/properties.mako.rs | 2 +- .../style/stylesheets/document_rule.rs | 2 +- 21 files changed, 143 insertions(+), 161 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index a124f38f2cf3..5ded41bd62f4 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -2090,7 +2090,7 @@ bool nsContentUtils::ShouldResistFingerprinting(nsIDocShell* aDocShell) { } /* static */ -bool nsContentUtils::ShouldResistFingerprinting(Document* aDoc) { +bool nsContentUtils::ShouldResistFingerprinting(const Document* aDoc) { if (!aDoc) { return false; } @@ -6515,7 +6515,8 @@ nsContentUtils::FindInternalContentViewer(const nsACString& aType, } static void ReportPatternCompileFailure(nsAString& aPattern, - Document* aDocument, JSContext* cx) { + const Document* aDocument, + JSContext* cx) { MOZ_ASSERT(JS_IsExceptionPending(cx)); JS::RootedValue exn(cx); @@ -6554,7 +6555,7 @@ static void ReportPatternCompileFailure(nsAString& aPattern, // static bool nsContentUtils::IsPatternMatching(nsAString& aValue, nsAString& aPattern, - Document* aDocument) { + const Document* aDocument) { NS_ASSERTION(aDocument, "aDocument should be a valid pointer (not null)"); // The fact that we're using a JS regexp under the hood should not be visible diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index b1941e8952dc..6294c7172d62 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -307,7 +307,7 @@ class nsContentUtils { // This function can be called both in the main thread and worker threads. static bool ShouldResistFingerprinting(); static bool ShouldResistFingerprinting(nsIDocShell* aDocShell); - static bool ShouldResistFingerprinting(Document* aDoc); + static bool ShouldResistFingerprinting(const Document* aDoc); // Prevent system colors from being exposed to CSS or canvas. static bool UseStandinsForNativeColors(); @@ -2546,7 +2546,7 @@ class nsContentUtils { * @result whether the given string is matches the pattern. */ static bool IsPatternMatching(nsAString& aValue, nsAString& aPattern, - Document* aDocument); + const Document* aDocument); /** * Calling this adds support for diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 633f7d34c629..7dd76dce208c 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -9559,10 +9559,8 @@ already_AddRefed nsLayoutUtils::GetMetricsFor( } /* static */ void nsLayoutUtils::FixupNoneGeneric( - nsFont* aFont, const nsPresContext* aPresContext, uint8_t aGenericFontID, - const nsFont* aDefaultVariableFont) { - bool useDocumentFonts = - aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts); + nsFont* aFont, uint8_t aGenericFontID, const nsFont* aDefaultVariableFont) { + bool useDocumentFonts = StaticPrefs::browser_display_use_document_fonts(); if (aGenericFontID == kGenericFont_NONE || (!useDocumentFonts && (aGenericFontID == kGenericFont_cursive || aGenericFontID == kGenericFont_fantasy))) { @@ -9587,9 +9585,9 @@ already_AddRefed nsLayoutUtils::GetMetricsFor( } } -/* static */ void nsLayoutUtils::ApplyMinFontSize( - nsStyleFont* aFont, const nsPresContext* aPresContext, - nscoord aMinFontSize) { +/* static */ void nsLayoutUtils::ApplyMinFontSize(nsStyleFont* aFont, + const Document* aDocument, + nscoord aMinFontSize) { nscoord fontSize = aFont->mSize; // enforce the user' specified minimum font-size on the value that we expose @@ -9600,7 +9598,7 @@ already_AddRefed nsLayoutUtils::GetMetricsFor( } else { aMinFontSize = (aMinFontSize * aFont->mMinFontSizeRatio) / 100; } - if (fontSize < aMinFontSize && !aPresContext->IsChrome()) { + if (fontSize < aMinFontSize && !nsContentUtils::IsChromeDoc(aDocument)) { // override the minimum font-size constraint fontSize = aMinFontSize; } diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index cf381e71ba7f..690bfe8860bd 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2946,8 +2946,7 @@ class nsLayoutUtils { * Appropriately add the correct font if we are using DocumentFonts or * overriding for XUL */ - static void FixupNoneGeneric(nsFont* aFont, const nsPresContext* aPresContext, - uint8_t aGenericFontID, + static void FixupNoneGeneric(nsFont* aFont, uint8_t aGenericFontID, const nsFont* aDefaultVariableFont); /** @@ -2955,7 +2954,7 @@ class nsLayoutUtils { * from preferences, as well as -moz-min-font-size-ratio. */ static void ApplyMinFontSize(nsStyleFont* aFont, - const nsPresContext* aPresContext, + const mozilla::dom::Document*, nscoord aMinFontSize); static void ComputeSystemFont(nsFont* aSystemFont, diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 03f4effe8797..a8c14721a073 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -194,7 +194,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType) mHasPendingInterrupt(false), mPendingInterruptFromTest(false), mInterruptsEnabled(false), - mUseDocumentFonts(true), mUseDocumentColors(true), mUnderlineLinks(true), mSendAfterPaintToContent(false), @@ -518,10 +517,6 @@ void nsPresContext::GetUserPreferences() { mBodyTextColor = mDefaultColor; - // * use fonts? - mUseDocumentFonts = - Preferences::GetInt("browser.display.use_document_fonts") != 0; - mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side"); Document()->ResetLangPrefs(); diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 4876037b3c25..a916198015f5 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -87,10 +87,10 @@ class Element; } // namespace mozilla // supported values for cached bool types -enum nsPresContext_CachedBoolPrefType { - kPresContext_UseDocumentFonts = 1, - kPresContext_UnderlineLinks -}; +// +// FIXME(emilio): We have StaticPrefs now, probably all of these should be +// migrated. +enum nsPresContext_CachedBoolPrefType { kPresContext_UnderlineLinks = 1 }; // supported values for cached integer pref types enum nsPresContext_CachedIntPrefType { @@ -365,8 +365,6 @@ class nsPresContext : public nsISupports, // If called with a constant parameter, the compiler should optimize // this switch statement away. switch (aPrefType) { - case kPresContext_UseDocumentFonts: - return mUseDocumentFonts; case kPresContext_UnderlineLinks: return mUnderlineLinks; default: @@ -1283,7 +1281,6 @@ class nsPresContext : public nsISupports, unsigned mHasPendingInterrupt : 1; unsigned mPendingInterruptFromTest : 1; unsigned mInterruptsEnabled : 1; - unsigned mUseDocumentFonts : 1; unsigned mUseDocumentColors : 1; unsigned mUnderlineLinks : 1; unsigned mSendAfterPaintToContent : 1; diff --git a/layout/style/CSSMozDocumentRule.cpp b/layout/style/CSSMozDocumentRule.cpp index 536b3fee846d..20943debf5f9 100644 --- a/layout/style/CSSMozDocumentRule.cpp +++ b/layout/style/CSSMozDocumentRule.cpp @@ -19,7 +19,7 @@ using namespace mozilla::css; return CSSMozDocumentRule_Binding::Wrap(aCx, this, aGivenProto); } -bool CSSMozDocumentRule::Match(Document* aDoc, nsIURI* aDocURI, +bool CSSMozDocumentRule::Match(const Document* aDoc, nsIURI* aDocURI, const nsACString& aDocURISpec, const nsACString& aPattern, DocumentMatchingFunction aMatchingFunction) { diff --git a/layout/style/CSSMozDocumentRule.h b/layout/style/CSSMozDocumentRule.h index 94ed531119c6..02a41442bb30 100644 --- a/layout/style/CSSMozDocumentRule.h +++ b/layout/style/CSSMozDocumentRule.h @@ -22,7 +22,7 @@ class CSSMozDocumentRule final : public css::ConditionRule { NS_DECL_ISUPPORTS_INHERITED - static bool Match(Document* aDoc, nsIURI* aDocURI, + static bool Match(const Document*, nsIURI* aDocURI, const nsACString& aDocURISpec, const nsACString& aPattern, css::DocumentMatchingFunction); diff --git a/layout/style/GeckoBindings.cpp b/layout/style/GeckoBindings.cpp index 9b7190237e58..efecf941cd9d 100644 --- a/layout/style/GeckoBindings.cpp +++ b/layout/style/GeckoBindings.cpp @@ -101,14 +101,14 @@ ServoTraversalStatistics ServoTraversalStatistics::sSingleton; static RWLock* sServoFFILock = nullptr; -static const nsFont* ThreadSafeGetDefaultFontHelper( - const nsPresContext* aPresContext, nsAtom* aLanguage, uint8_t aGenericId) { +static const nsFont* ThreadSafeGetDefaultFontHelper(const Document& aDocument, + nsAtom* aLanguage, + uint8_t aGenericId) { bool needsCache = false; const nsFont* retval; auto GetDefaultFont = [&](bool* aNeedsToCache) { - auto* prefs = - aPresContext->Document()->GetFontPrefsForLang(aLanguage, aNeedsToCache); + auto* prefs = aDocument.GetFontPrefsForLang(aLanguage, aNeedsToCache); return prefs ? prefs->GetDefaultFont(aGenericId) : nullptr; }; @@ -710,9 +710,8 @@ bool Gecko_IsDocumentBody(RawGeckoElementBorrowed aElement) { return doc && doc->GetBodyElement() == aElement; } -nscolor Gecko_GetLookAndFeelSystemColor( - int32_t aId, RawGeckoPresContextBorrowed aPresContext) { - bool useStandinsForNativeColors = aPresContext && !aPresContext->IsChrome(); +nscolor Gecko_GetLookAndFeelSystemColor(int32_t aId, const Document* aDoc) { + bool useStandinsForNativeColors = !nsContentUtils::IsChromeDoc(aDoc); nscolor result; LookAndFeel::ColorID colorId = static_cast(aId); AutoWriteLock guard(*sServoFFILock); @@ -1013,17 +1012,15 @@ void Gecko_CopyFontFamilyFrom(nsFont* dst, const nsFont* src) { void Gecko_nsFont_InitSystem(nsFont* aDest, int32_t aFontId, const nsStyleFont* aFont, - RawGeckoPresContextBorrowed aPresContext) { + const Document* aDocument) { const nsFont* defaultVariableFont = ThreadSafeGetDefaultFontHelper( - aPresContext, aFont->mLanguage, kPresContext_DefaultVariableFont_ID); + *aDocument, aFont->mLanguage, kPresContext_DefaultVariableFont_ID); // We have passed uninitialized memory to this function, // initialize it. We can't simply return an nsFont because then // we need to know its size beforehand. Servo cannot initialize nsFont // itself, so this will do. - nsFont* system = new (aDest) nsFont(*defaultVariableFont); - - MOZ_RELEASE_ASSERT(system); + new (aDest) nsFont(*defaultVariableFont); *aDest = *defaultVariableFont; LookAndFeel::FontID fontID = static_cast(aFontId); @@ -1117,8 +1114,7 @@ void Gecko_CopyAlternateValuesFrom(nsFont* aDest, const nsFont* aSrc) { aDest->featureValueLookup = aSrc->featureValueLookup; } -void Gecko_SetCounterStyleToName(CounterStylePtr* aPtr, nsAtom* aName, - RawGeckoPresContextBorrowed aPresContext) { +void Gecko_SetCounterStyleToName(CounterStylePtr* aPtr, nsAtom* aName) { RefPtr name = already_AddRefed(aName); *aPtr = name.forget(); } @@ -1907,19 +1903,19 @@ void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont, aFont->mLanguage = aSource->mLanguage; } -void Gecko_nsStyleFont_FixupNoneGeneric( - nsStyleFont* aFont, RawGeckoPresContextBorrowed aPresContext) { +void Gecko_nsStyleFont_FixupNoneGeneric(nsStyleFont* aFont, + const Document* aDocument) { const nsFont* defaultVariableFont = ThreadSafeGetDefaultFontHelper( - aPresContext, aFont->mLanguage, kPresContext_DefaultVariableFont_ID); - nsLayoutUtils::FixupNoneGeneric(&aFont->mFont, aPresContext, - aFont->mGenericID, defaultVariableFont); + *aDocument, aFont->mLanguage, kPresContext_DefaultVariableFont_ID); + nsLayoutUtils::FixupNoneGeneric(&aFont->mFont, aFont->mGenericID, + defaultVariableFont); } -void Gecko_nsStyleFont_PrefillDefaultForGeneric( - nsStyleFont* aFont, RawGeckoPresContextBorrowed aPresContext, - uint8_t aGenericId) { - const nsFont* defaultFont = ThreadSafeGetDefaultFontHelper( - aPresContext, aFont->mLanguage, aGenericId); +void Gecko_nsStyleFont_PrefillDefaultForGeneric(nsStyleFont* aFont, + const Document* aDocument, + uint8_t aGenericId) { + const nsFont* defaultFont = + ThreadSafeGetDefaultFontHelper(*aDocument, aFont->mLanguage, aGenericId); // In case of just the language changing, the parent could have had no // generic, which Gecko just does regular cascading with. Do the same. This // can only happen in the case where the language changed but the family did @@ -1932,14 +1928,14 @@ void Gecko_nsStyleFont_PrefillDefaultForGeneric( } } -void Gecko_nsStyleFont_FixupMinFontSize( - nsStyleFont* aFont, RawGeckoPresContextBorrowed aPresContext) { +void Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* aFont, + const Document* aDocument) { nscoord minFontSize; bool needsCache = false; auto MinFontSize = [&](bool* aNeedsToCache) { - auto* prefs = aPresContext->Document()->GetFontPrefsForLang( - aFont->mLanguage, aNeedsToCache); + auto* prefs = + aDocument->GetFontPrefsForLang(aFont->mLanguage, aNeedsToCache); return prefs ? prefs->mMinimumFontSize : 0; }; @@ -1953,7 +1949,7 @@ void Gecko_nsStyleFont_FixupMinFontSize( minFontSize = MinFontSize(nullptr); } - nsLayoutUtils::ApplyMinFontSize(aFont, aPresContext, minFontSize); + nsLayoutUtils::ApplyMinFontSize(aFont, aDocument, minFontSize); } void FontSizePrefs::CopyFrom(const LangGroupFontPrefs& prefs) { @@ -2058,12 +2054,6 @@ GeckoFontMetrics Gecko_GetFontMetrics(RawGeckoPresContextBorrowed aPresContext, return ret; } -int32_t Gecko_GetAppUnitsPerPhysicalInch( - RawGeckoPresContextBorrowed aPresContext) { - nsPresContext* presContext = const_cast(aPresContext); - return presContext->DeviceContext()->AppUnitsPerPhysicalInch(); -} - NS_IMPL_THREADSAFE_FFI_REFCOUNTING(SheetLoadDataHolder, SheetLoadDataHolder); void Gecko_StyleSheet_FinishAsyncParse( @@ -2192,9 +2182,9 @@ NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsCSSValueSharedList, CSSValueSharedList); #define STYLE_STRUCT(name) \ \ - void Gecko_Construct_Default_nsStyle##name( \ - nsStyle##name* ptr, const nsPresContext* pres_context) { \ - new (ptr) nsStyle##name(*pres_context->Document()); \ + void Gecko_Construct_Default_nsStyle##name(nsStyle##name* ptr, \ + const Document* doc) { \ + new (ptr) nsStyle##name(*doc); \ } \ \ void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr, \ @@ -2213,12 +2203,11 @@ void Gecko_RegisterProfilerThread(const char* name) { void Gecko_UnregisterProfilerThread() { PROFILER_UNREGISTER_THREAD(); } bool Gecko_DocumentRule_UseForPresentation( - RawGeckoPresContextBorrowed aPresContext, const nsACString* aPattern, + const Document* aDocument, const nsACString* aPattern, css::DocumentMatchingFunction aMatchingFunction) { MOZ_ASSERT(NS_IsMainThread()); - Document* doc = aPresContext->Document(); - nsIURI* docURI = doc->GetDocumentURI(); + nsIURI* docURI = aDocument->GetDocumentURI(); nsAutoCString docURISpec; if (docURI) { // If GetSpec fails (due to OOM) just skip these URI-specific CSS rules. @@ -2226,7 +2215,7 @@ bool Gecko_DocumentRule_UseForPresentation( NS_ENSURE_SUCCESS(rv, false); } - return CSSMozDocumentRule::Match(doc, docURI, docURISpec, *aPattern, + return CSSMozDocumentRule::Match(aDocument, docURI, docURISpec, *aPattern, aMatchingFunction); } diff --git a/layout/style/GeckoBindings.h b/layout/style/GeckoBindings.h index 6a658e986bfb..288f3901a674 100644 --- a/layout/style/GeckoBindings.h +++ b/layout/style/GeckoBindings.h @@ -278,7 +278,7 @@ NS_DECL_THREADSAFE_FFI_REFCOUNTING(mozilla::SharedFontList, SharedFontList); // font_id is LookAndFeel::FontID void Gecko_nsFont_InitSystem(nsFont* dst, int32_t font_id, const nsStyleFont* font, - RawGeckoPresContextBorrowed pres_context); + const mozilla::dom::Document*); void Gecko_nsFont_Destroy(nsFont* dst); @@ -313,8 +313,7 @@ void Gecko_CopyImageOrientationFrom(nsStyleVisibility* aDst, // Counter style. // This function takes an already addrefed nsAtom -void Gecko_SetCounterStyleToName(mozilla::CounterStylePtr* ptr, nsAtom* name, - RawGeckoPresContextBorrowed pres_context); +void Gecko_SetCounterStyleToName(mozilla::CounterStylePtr* ptr, nsAtom* name); void Gecko_SetCounterStyleToSymbols(mozilla::CounterStylePtr* ptr, uint8_t symbols_type, @@ -671,15 +670,15 @@ void Gecko_nsStyleFont_SetLang(nsStyleFont* font, nsAtom* atom); void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont, const nsStyleFont* aSource); -void Gecko_nsStyleFont_FixupNoneGeneric( - nsStyleFont* font, RawGeckoPresContextBorrowed pres_context); +void Gecko_nsStyleFont_FixupNoneGeneric(nsStyleFont* font, + const mozilla::dom::Document*); -void Gecko_nsStyleFont_PrefillDefaultForGeneric( - nsStyleFont* font, RawGeckoPresContextBorrowed pres_context, - uint8_t generic_id); +void Gecko_nsStyleFont_PrefillDefaultForGeneric(nsStyleFont* font, + const mozilla::dom::Document*, + uint8_t generic_id); -void Gecko_nsStyleFont_FixupMinFontSize( - nsStyleFont* font, RawGeckoPresContextBorrowed pres_context); +void Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* font, + const mozilla::dom::Document*); mozilla::FontSizePrefs Gecko_GetBaseSize(nsAtom* lang); @@ -702,9 +701,6 @@ GeckoFontMetrics Gecko_GetFontMetrics(RawGeckoPresContextBorrowed pres_context, nscoord font_size, bool use_user_font_set); -int32_t Gecko_GetAppUnitsPerPhysicalInch( - RawGeckoPresContextBorrowed pres_context); - mozilla::StyleSheet* Gecko_StyleSheet_Clone( const mozilla::StyleSheet* aSheet, const mozilla::StyleSheet* aNewParentSheet); @@ -717,17 +713,17 @@ bool Gecko_IsDocumentBody(RawGeckoElementBorrowed element); // We use an int32_t here instead of a LookAndFeel::ColorID // because forward-declaring a nested enum/struct is impossible -nscolor Gecko_GetLookAndFeelSystemColor( - int32_t color_id, RawGeckoPresContextBorrowed pres_context); +nscolor Gecko_GetLookAndFeelSystemColor(int32_t color_id, + const mozilla::dom::Document*); void Gecko_AddPropertyToSet(nsCSSPropertyIDSetBorrowedMut, nsCSSPropertyID); // Style-struct management. -#define STYLE_STRUCT(name) \ - void Gecko_Construct_Default_nsStyle##name( \ - nsStyle##name* ptr, RawGeckoPresContextBorrowed pres_context); \ - void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr, \ - const nsStyle##name* other); \ +#define STYLE_STRUCT(name) \ + void Gecko_Construct_Default_nsStyle##name(nsStyle##name* ptr, \ + const mozilla::dom::Document*); \ + void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr, \ + const nsStyle##name* other); \ void Gecko_Destroy_nsStyle##name(nsStyle##name* ptr); #include "nsStyleStructList.h" #undef STYLE_STRUCT @@ -736,7 +732,7 @@ void Gecko_RegisterProfilerThread(const char* name); void Gecko_UnregisterProfilerThread(); bool Gecko_DocumentRule_UseForPresentation( - RawGeckoPresContextBorrowed, const nsACString* aPattern, + const mozilla::dom::Document*, const nsACString* aPattern, mozilla::css::DocumentMatchingFunction); // Allocator hinting. @@ -790,32 +786,33 @@ bool Gecko_IsMainThread(); // // Defined in nsMediaFeatures.cpp. mozilla::StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode( - mozilla::dom::Document*); + const mozilla::dom::Document*); -uint32_t Gecko_MediaFeatures_GetColorDepth(mozilla::dom::Document*); +uint32_t Gecko_MediaFeatures_GetColorDepth(const mozilla::dom::Document*); -void Gecko_MediaFeatures_GetDeviceSize(mozilla::dom::Document*, nscoord* width, - nscoord* height); +void Gecko_MediaFeatures_GetDeviceSize(const mozilla::dom::Document*, + nscoord* width, nscoord* height); -float Gecko_MediaFeatures_GetResolution(mozilla::dom::Document*); -bool Gecko_MediaFeatures_PrefersReducedMotion(mozilla::dom::Document*); +float Gecko_MediaFeatures_GetResolution(const mozilla::dom::Document*); +bool Gecko_MediaFeatures_PrefersReducedMotion(const mozilla::dom::Document*); mozilla::StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme( - mozilla::dom::Document*); + const mozilla::dom::Document*); mozilla::PointerCapabilities Gecko_MediaFeatures_PrimaryPointerCapabilities( - mozilla::dom::Document*); + const mozilla::dom::Document*); mozilla::PointerCapabilities Gecko_MediaFeatures_AllPointerCapabilities( - mozilla::dom::Document*); + const mozilla::dom::Document*); -float Gecko_MediaFeatures_GetDevicePixelRatio(mozilla::dom::Document*); +float Gecko_MediaFeatures_GetDevicePixelRatio(const mozilla::dom::Document*); -bool Gecko_MediaFeatures_HasSystemMetric(mozilla::dom::Document*, +bool Gecko_MediaFeatures_HasSystemMetric(const mozilla::dom::Document*, nsAtom* metric, bool is_accessible_from_content); -bool Gecko_MediaFeatures_IsResourceDocument(mozilla::dom::Document*); -nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(mozilla::dom::Document*); +bool Gecko_MediaFeatures_IsResourceDocument(const mozilla::dom::Document*); +nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion( + const mozilla::dom::Document*); } // extern "C" diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index b3ed17208ef4..9d95cc9fb123 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -25,6 +25,7 @@ #include "mozilla/GeckoBindings.h" using namespace mozilla; +using mozilla::dom::Document; static nsTArray* sSystemMetrics = nullptr; @@ -42,7 +43,7 @@ const OperatingSystemVersionInfo kOsVersionStrings[] = { #endif // A helper for four features below -static nsSize GetSize(Document* aDocument) { +static nsSize GetSize(const Document* aDocument) { nsPresContext* pc = aDocument->GetPresContext(); // Per spec, return a 0x0 viewport if we're not being rendered. See: @@ -64,7 +65,7 @@ static nsSize GetSize(Document* aDocument) { return pc->GetVisibleArea().Size(); } -static bool IsDeviceSizePageSize(Document* aDocument) { +static bool IsDeviceSizePageSize(const Document* aDocument) { nsIDocShell* docShell = aDocument->GetDocShell(); if (!docShell) { return false; @@ -73,7 +74,7 @@ static bool IsDeviceSizePageSize(Document* aDocument) { } // A helper for three features below. -static nsSize GetDeviceSize(Document* aDocument) { +static nsSize GetDeviceSize(const Document* aDocument) { if (nsContentUtils::ShouldResistFingerprinting(aDocument) || IsDeviceSizePageSize(aDocument)) { return GetSize(aDocument); @@ -99,11 +100,11 @@ static nsSize GetDeviceSize(Document* aDocument) { return size; } -bool Gecko_MediaFeatures_IsResourceDocument(Document* aDocument) { +bool Gecko_MediaFeatures_IsResourceDocument(const Document* aDocument) { return aDocument->IsResourceDoc(); } -static nsDeviceContext* GetDeviceContextFor(Document* aDocument) { +static nsDeviceContext* GetDeviceContextFor(const Document* aDocument) { nsPresContext* pc = aDocument->GetPresContext(); if (!pc) { return nullptr; @@ -115,14 +116,14 @@ static nsDeviceContext* GetDeviceContextFor(Document* aDocument) { return pc->DeviceContext(); } -void Gecko_MediaFeatures_GetDeviceSize(Document* aDocument, nscoord* aWidth, - nscoord* aHeight) { +void Gecko_MediaFeatures_GetDeviceSize(const Document* aDocument, + nscoord* aWidth, nscoord* aHeight) { nsSize size = GetDeviceSize(aDocument); *aWidth = size.width; *aHeight = size.height; } -uint32_t Gecko_MediaFeatures_GetColorDepth(Document* aDocument) { +uint32_t Gecko_MediaFeatures_GetColorDepth(const Document* aDocument) { // Use depth of 24 when resisting fingerprinting, or when we're not being // rendered. uint32_t depth = 24; @@ -140,7 +141,7 @@ uint32_t Gecko_MediaFeatures_GetColorDepth(Document* aDocument) { return depth / 3; } -float Gecko_MediaFeatures_GetResolution(Document* aDocument) { +float Gecko_MediaFeatures_GetResolution(const Document* aDocument) { // We're returning resolution in terms of device pixels per css pixel, since // that is the preferred unit for media queries of resolution. This avoids // introducing precision error from conversion to and from less-used @@ -162,16 +163,16 @@ float Gecko_MediaFeatures_GetResolution(Document* aDocument) { pc->DeviceContext()->AppUnitsPerDevPixel(); } -static Document* TopDocument(Document* aDocument) { - Document* current = aDocument; - while (Document* parent = current->GetParentDocument()) { +static const Document* TopDocument(const Document* aDocument) { + const Document* current = aDocument; + while (const Document* parent = current->GetParentDocument()) { current = parent; } return current; } -StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(Document* aDocument) { - Document* rootDocument = TopDocument(aDocument); +StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(const Document* aDocument) { + const Document* rootDocument = TopDocument(aDocument); nsCOMPtr container = rootDocument->GetContainer(); if (nsCOMPtr baseWindow = do_QueryInterface(container)) { @@ -199,7 +200,8 @@ StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(Document* aDocument) { return static_cast(docShell->GetDisplayMode()); } -bool Gecko_MediaFeatures_HasSystemMetric(Document* aDocument, nsAtom* aMetric, +bool Gecko_MediaFeatures_HasSystemMetric(const Document* aDocument, + nsAtom* aMetric, bool aIsAccessibleFromContent) { if (aIsAccessibleFromContent && nsContentUtils::ShouldResistFingerprinting(aDocument)) { @@ -210,7 +212,7 @@ bool Gecko_MediaFeatures_HasSystemMetric(Document* aDocument, nsAtom* aMetric, return sSystemMetrics->IndexOf(aMetric) != sSystemMetrics->NoIndex; } -nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(Document* aDocument) { +nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(const Document* aDocument) { if (nsContentUtils::ShouldResistFingerprinting(aDocument)) { return nullptr; } @@ -231,7 +233,7 @@ nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(Document* aDocument) { return nullptr; } -bool Gecko_MediaFeatures_PrefersReducedMotion(Document* aDocument) { +bool Gecko_MediaFeatures_PrefersReducedMotion(const Document* aDocument) { if (nsContentUtils::ShouldResistFingerprinting(aDocument)) { return false; } @@ -239,7 +241,7 @@ bool Gecko_MediaFeatures_PrefersReducedMotion(Document* aDocument) { } StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme( - Document* aDocument) { + const Document* aDocument) { if (nsContentUtils::ShouldResistFingerprinting(aDocument)) { return StylePrefersColorScheme::Light; } @@ -264,7 +266,7 @@ StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme( } } -static PointerCapabilities GetPointerCapabilities(Document* aDocument, +static PointerCapabilities GetPointerCapabilities(const Document* aDocument, LookAndFeel::IntID aID) { MOZ_ASSERT(aID == LookAndFeel::eIntID_PrimaryPointerCapabilities || aID == LookAndFeel::eIntID_AllPointerCapabilities); @@ -297,13 +299,13 @@ static PointerCapabilities GetPointerCapabilities(Document* aDocument, } PointerCapabilities Gecko_MediaFeatures_PrimaryPointerCapabilities( - Document* aDocument) { + const Document* aDocument) { return GetPointerCapabilities(aDocument, LookAndFeel::eIntID_PrimaryPointerCapabilities); } PointerCapabilities Gecko_MediaFeatures_AllPointerCapabilities( - Document* aDocument) { + const Document* aDocument) { return GetPointerCapabilities(aDocument, LookAndFeel::eIntID_AllPointerCapabilities); } diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index 0b2cf4299c85..dd04824077c5 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -548,6 +548,12 @@ VARCACHE_PREF( // Graphics prefs //--------------------------------------------------------------------------- +VARCACHE_PREF( + "browser.display.use_document_fonts", + browser_display_use_document_fonts, + RelaxedAtomicBool, true +) + VARCACHE_PREF( "gfx.font_rendering.opentype_svg.enabled", gfx_font_rendering_opentype_svg_enabled, diff --git a/servo/components/style/gecko/media_features.rs b/servo/components/style/gecko/media_features.rs index 24f2009a3a8a..2547f2a45d47 100644 --- a/servo/components/style/gecko/media_features.rs +++ b/servo/components/style/gecko/media_features.rs @@ -461,7 +461,7 @@ fn eval_moz_is_glyph( query_value: Option, _: Option, ) -> bool { - let is_glyph = unsafe { (*device.document()).mIsSVGGlyphsDocument() }; + let is_glyph = device.document().mIsSVGGlyphsDocument(); query_value.map_or(is_glyph, |v| v == is_glyph) } diff --git a/servo/components/style/gecko/media_queries.rs b/servo/components/style/gecko/media_queries.rs index 851422467ce6..6d509cf6903e 100644 --- a/servo/components/style/gecko/media_queries.rs +++ b/servo/components/style/gecko/media_queries.rs @@ -85,7 +85,7 @@ impl Device { assert!(!pres_context.is_null()); Device { pres_context, - default_values: ComputedValues::default_values(unsafe { &*pres_context }), + default_values: ComputedValues::default_values(unsafe { &*(*pres_context).mDocument.mRawPtr }), // FIXME(bz): Seems dubious? root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize), body_text_color: AtomicUsize::new(unsafe { &*pres_context }.mDefaultColor as usize), @@ -162,13 +162,13 @@ impl Device { /// Gets the document pointer. #[inline] - pub fn document(&self) -> *mut structs::Document { - self.pres_context().mDocument.mRawPtr + pub fn document(&self) -> &structs::Document { + unsafe { &*self.pres_context().mDocument.mRawPtr } } /// Recreates the default computed values. pub fn reset_computed_values(&mut self) { - self.default_values = ComputedValues::default_values(self.pres_context()); + self.default_values = ComputedValues::default_values(self.document()); } /// Rebuild all the cached data. diff --git a/servo/components/style/gecko/values.rs b/servo/components/style/gecko/values.rs index 8aad380ab44a..56f0ed4464d9 100644 --- a/servo/components/style/gecko/values.rs +++ b/servo/components/style/gecko/values.rs @@ -10,7 +10,6 @@ use crate::counter_style::{Symbol, Symbols}; use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr}; use crate::gecko_bindings::structs::{StyleGridTrackBreadth, StyleShapeRadius}; use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue}; -use crate::media_queries::Device; use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; use crate::values::computed::{Angle, Length, LengthPercentage}; use crate::values::computed::{Number, NumberOrPercentage, Percentage}; @@ -387,16 +386,15 @@ pub fn round_border_to_device_pixels(width: Au, au_per_device_px: Au) -> Au { impl CounterStyleOrNone { /// Convert this counter style to a Gecko CounterStylePtr. - pub fn to_gecko_value(self, gecko_value: &mut CounterStylePtr, device: &Device) { + pub fn to_gecko_value(self, gecko_value: &mut CounterStylePtr) { use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToName as set_name; use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToSymbols as set_symbols; - let pres_context = device.pres_context(); match self { CounterStyleOrNone::None => unsafe { - set_name(gecko_value, atom!("none").into_addrefed(), pres_context); + set_name(gecko_value, atom!("none").into_addrefed()); }, CounterStyleOrNone::Name(name) => unsafe { - set_name(gecko_value, name.0.into_addrefed(), pres_context); + set_name(gecko_value, name.0.into_addrefed()); }, CounterStyleOrNone::Symbols(symbols_type, symbols) => { let symbols: Vec<_> = symbols diff --git a/servo/components/style/properties/cascade.rs b/servo/components/style/properties/cascade.rs index d881524deb5a..9a0ce9d365d9 100644 --- a/servo/components/style/properties/cascade.rs +++ b/servo/components/style/properties/cascade.rs @@ -745,13 +745,13 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // FIXME(emilio): Why both setting the generic and passing it // down? - let pres_context = self.context.builder.device.pres_context(); + let doc = self.context.builder.device.document(); let gecko_font = self.context.builder.mutate_font().gecko_mut(); gecko_font.mGenericID = generic; unsafe { crate::gecko_bindings::bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric( gecko_font, - pres_context, + doc, generic, ); } diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 4466ebc06d52..0fd57cd3842e 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -35,7 +35,6 @@ use crate::gecko_bindings::bindings::Gecko_SetListStyleImageNone; use crate::gecko_bindings::bindings::Gecko_SetListStyleImageImageValue; use crate::gecko_bindings::bindings::Gecko_SetNullImageValue; use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}; -use crate::gecko_bindings::bindings::RawGeckoPresContextBorrowed; use crate::gecko_bindings::structs; use crate::gecko_bindings::structs::nsCSSPropertyID; use crate::gecko_bindings::structs::mozilla::CSSPseudoElementType; @@ -102,7 +101,7 @@ impl ComputedValues { ).to_outer(pseudo) } - pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc { + pub fn default_values(doc: &structs::Document) -> Arc { ComputedValuesInner::new( /* custom_properties = */ None, /* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious @@ -110,7 +109,7 @@ impl ComputedValues { /* rules = */ None, /* visited_style = */ None, % for style_struct in data.style_structs: - style_structs::${style_struct.name}::default(pres_context), + style_structs::${style_struct.name}::default(doc), % endfor ).to_outer(None) } @@ -1257,11 +1256,13 @@ pub fn clone_transform_from_list( <%def name="impl_style_struct(style_struct)"> impl ${style_struct.gecko_struct_name} { #[allow(dead_code, unused_variables)] - pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc { + pub fn default(document: &structs::Document) -> Arc { let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } }); unsafe { - Gecko_Construct_Default_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko, - pres_context); + Gecko_Construct_Default_${style_struct.gecko_ffi_name}( + &mut Arc::get_mut(&mut result).unwrap().gecko, + document, + ); } result } @@ -2209,7 +2210,7 @@ fn static_assert() { pub fn fixup_none_generic(&mut self, device: &Device) { self.gecko.mFont.systemFont = false; unsafe { - bindings::Gecko_nsStyleFont_FixupNoneGeneric(&mut self.gecko, device.pres_context()) + bindings::Gecko_nsStyleFont_FixupNoneGeneric(&mut self.gecko, device.document()) } } @@ -2325,7 +2326,7 @@ fn static_assert() { } pub fn fixup_font_min_size(&mut self, device: &Device) { - unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.pres_context()) } + unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.document()) } } pub fn apply_unconstrained_font_size(&mut self, v: NonNegativeLength) { @@ -2647,9 +2648,11 @@ fn static_assert() { ${impl_simple("_moz_script_level", "mScriptLevel")} <% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %> - pub fn set_font_variant_alternates(&mut self, - v: values::computed::font::FontVariantAlternates, - device: &Device) { + pub fn set_font_variant_alternates( + &mut self, + v: values::computed::font::FontVariantAlternates, + device: &Device, + ) { use crate::gecko_bindings::bindings::{Gecko_ClearAlternateValues, Gecko_AppendAlternateValues}; use crate::gecko_bindings::bindings::Gecko_nsFont_ResetFontFeatureValuesLookup; use crate::gecko_bindings::bindings::Gecko_nsFont_SetFontFeatureValuesLookup; @@ -3963,12 +3966,12 @@ fn static_assert() { } } - pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T, device: &Device) { + pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T) { use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToString; use nsstring::{nsACString, nsCStr}; use self::longhands::list_style_type::computed_value::T; match v { - T::CounterStyle(s) => s.to_gecko_value(&mut self.gecko.mCounterStyle, device), + T::CounterStyle(s) => s.to_gecko_value(&mut self.gecko.mCounterStyle), T::String(s) => unsafe { Gecko_SetCounterStyleToString(&mut self.gecko.mCounterStyle, &nsCStr::from(&s) as &nsACString) @@ -5210,7 +5213,7 @@ clip-path self.gecko.mContents.is_empty() } - pub fn set_content(&mut self, v: longhands::content::computed_value::T, device: &Device) { + pub fn set_content(&mut self, v: longhands::content::computed_value::T) { use crate::values::CustomIdent; use crate::values::generics::counters::{Content, ContentItem}; use crate::values::generics::CounterStyleOrNone; @@ -5235,7 +5238,6 @@ clip-path name: &CustomIdent, sep: &str, style: CounterStyleOrNone, - device: &Device, ) { debug_assert!(content_type == StyleContentType::Counter || content_type == StyleContentType::Counters); @@ -5246,7 +5248,7 @@ clip-path if content_type == StyleContentType::Counters { counter_func.mSeparator.assign_str(sep); } - style.to_gecko_value(&mut counter_func.mCounterStyle, device); + style.to_gecko_value(&mut counter_func.mCounterStyle); } match v { @@ -5321,7 +5323,6 @@ clip-path &name, "", style.clone(), - device, ); } ContentItem::Counters(ref name, ref sep, ref style) => { @@ -5331,7 +5332,6 @@ clip-path &name, &sep, style.clone(), - device, ); } ContentItem::Url(ref url) => { diff --git a/servo/components/style/properties/longhands/color.mako.rs b/servo/components/style/properties/longhands/color.mako.rs index 13b1fda545c2..487814935aa3 100644 --- a/servo/components/style/properties/longhands/color.mako.rs +++ b/servo/components/style/properties/longhands/color.mako.rs @@ -98,7 +98,7 @@ pub mod system_colors { unsafe { Gecko_GetLookAndFeelSystemColor( *self as i32, - cx.device().pres_context(), + cx.device().document(), ) } } diff --git a/servo/components/style/properties/longhands/font.mako.rs b/servo/components/style/properties/longhands/font.mako.rs index 755797711e1e..047ec90c480a 100644 --- a/servo/components/style/properties/longhands/font.mako.rs +++ b/servo/components/style/properties/longhands/font.mako.rs @@ -396,7 +396,7 @@ ${helpers.predefined_type( &mut system, id as i32, cx.style().get_font().gecko(), - cx.device().pres_context() + cx.device().document() ) } let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight); diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index d818306e96cc..1573fba6f51b 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -3507,7 +3507,7 @@ impl<'a> StyleBuilder<'a> { self.modified_reset = true; % endif - <% props_need_device = ["content", "list_style_type", "font_variant_alternates"] %> + <% props_need_device = ["font_variant_alternates"] %> self.${property.style_struct.ident}.mutate() .set_${property.ident}( value, diff --git a/servo/components/style/stylesheets/document_rule.rs b/servo/components/style/stylesheets/document_rule.rs index 4813a0e91504..c73b96bcd9d9 100644 --- a/servo/components/style/stylesheets/document_rule.rs +++ b/servo/components/style/stylesheets/document_rule.rs @@ -198,7 +198,7 @@ impl DocumentMatchingFunction { MediaDocumentKind::Video => "video", }, }); - unsafe { Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func) } + unsafe { Gecko_DocumentRule_UseForPresentation(device.document(), &*pattern, func) } } #[cfg(not(feature = "gecko"))]