Bug 1528712 - Remove a couple trivial dependencies on nsPresContext. r=heycam

Differential Revision: https://phabricator.services.mozilla.com/D20141
This commit is contained in:
Emilio Cobos Álvarez 2019-02-19 11:17:28 +00:00
Родитель dad3a20b22
Коммит 8ccb77e27d
22 изменённых файлов: 145 добавлений и 162 удалений

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

@ -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

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

@ -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

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

@ -9559,10 +9559,8 @@ already_AddRefed<nsFontMetrics> 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<nsFontMetrics> 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<nsFontMetrics> 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;
}

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

@ -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,

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

@ -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();

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

@ -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;

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

@ -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) {

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

@ -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);

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

@ -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;
};
@ -701,9 +701,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<LookAndFeel::ColorID>(aId);
AutoWriteLock guard(*sServoFFILock);
@ -1004,17 +1003,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<LookAndFeel::FontID>(aFontId);
@ -1108,8 +1105,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<nsAtom> name = already_AddRefed<nsAtom>(aName);
*aPtr = name.forget();
}
@ -1898,19 +1894,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
@ -1923,14 +1919,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;
};
@ -1944,7 +1940,7 @@ void Gecko_nsStyleFont_FixupMinFontSize(
minFontSize = MinFontSize(nullptr);
}
nsLayoutUtils::ApplyMinFontSize(aFont, aPresContext, minFontSize);
nsLayoutUtils::ApplyMinFontSize(aFont, aDocument, minFontSize);
}
void FontSizePrefs::CopyFrom(const LangGroupFontPrefs& prefs) {
@ -2049,12 +2045,6 @@ GeckoFontMetrics Gecko_GetFontMetrics(RawGeckoPresContextBorrowed aPresContext,
return ret;
}
int32_t Gecko_GetAppUnitsPerPhysicalInch(
RawGeckoPresContextBorrowed aPresContext) {
nsPresContext* presContext = const_cast<nsPresContext*>(aPresContext);
return presContext->DeviceContext()->AppUnitsPerPhysicalInch();
}
NS_IMPL_THREADSAFE_FFI_REFCOUNTING(SheetLoadDataHolder, SheetLoadDataHolder);
void Gecko_StyleSheet_FinishAsyncParse(
@ -2183,9 +2173,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, \
@ -2204,12 +2194,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.
@ -2217,7 +2206,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);
}

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

@ -277,7 +277,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);
@ -312,8 +312,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,
@ -670,15 +669,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);
@ -701,9 +700,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);
@ -716,17 +712,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
@ -735,7 +731,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.
@ -789,32 +785,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"

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

@ -25,6 +25,7 @@
#include "mozilla/GeckoBindings.h"
using namespace mozilla;
using mozilla::dom::Document;
static nsTArray<const nsStaticAtom*>* 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<nsISupports> container = rootDocument->GetContainer();
if (nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container)) {
@ -199,7 +200,8 @@ StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(Document* aDocument) {
return static_cast<StyleDisplayMode>(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);
}

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

@ -548,6 +548,14 @@ VARCACHE_PREF(
// Graphics prefs
//---------------------------------------------------------------------------
// In theory: 0 = never, 1 = quick, 2 = always, though we always just use it as
// a bool!
VARCACHE_PREF(
"browser.display.use_document_fonts",
browser_display_use_document_fonts,
RelaxedAtomicInt32, 1
)
VARCACHE_PREF(
"gfx.font_rendering.opentype_svg.enabled",
gfx_font_rendering_opentype_svg_enabled,

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

@ -293,7 +293,6 @@ pref("ui.popup.disable_autohide", false);
pref("ui.touchbar.layout", "Back,Reload,OpenOrFocus,AddBookmark,NewTab,Share");
#endif
pref("browser.display.use_document_fonts", 1); // 0 = never, 1 = quick, 2 = always
// 0 = default: always, except in high contrast mode
// 1 = always
// 2 = never

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

@ -461,7 +461,7 @@ fn eval_moz_is_glyph(
query_value: Option<bool>,
_: Option<RangeOrOperator>,
) -> bool {
let is_glyph = unsafe { (*device.document()).mIsSVGGlyphsDocument() };
let is_glyph = device.document().mIsSVGGlyphsDocument();
query_value.map_or(is_glyph, |v| v == is_glyph)
}

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

@ -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.

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

@ -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

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

@ -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,
);
}

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

@ -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::PseudoStyleType;
@ -102,7 +101,7 @@ impl ComputedValues {
).to_outer(pseudo)
}
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
pub fn default_values(doc: &structs::Document) -> Arc<Self> {
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)
}
@ -1247,11 +1246,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<Self> {
pub fn default(document: &structs::Document) -> Arc<Self> {
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
}
@ -2199,7 +2200,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())
}
}
@ -2315,7 +2316,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) {
@ -2637,9 +2638,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;
@ -3953,12 +3956,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)
@ -5200,7 +5203,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;
@ -5225,7 +5228,6 @@ clip-path
name: &CustomIdent,
sep: &str,
style: CounterStyleOrNone,
device: &Device,
) {
debug_assert!(content_type == StyleContentType::Counter ||
content_type == StyleContentType::Counters);
@ -5236,7 +5238,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 {
@ -5311,7 +5313,6 @@ clip-path
&name,
"",
style.clone(),
device,
);
}
ContentItem::Counters(ref name, ref sep, ref style) => {
@ -5321,7 +5322,6 @@ clip-path
&name,
&sep,
style.clone(),
device,
);
}
ContentItem::Url(ref url) => {

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

@ -98,7 +98,7 @@ pub mod system_colors {
unsafe {
Gecko_GetLookAndFeelSystemColor(
*self as i32,
cx.device().pres_context(),
cx.device().document(),
)
}
}

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

@ -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);

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

@ -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,

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

@ -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"))]