mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 04:09:50 +00:00
Bug 1570721 - Add an API to nsPresContext to override the prefers-color-scheme
value. r=heycam
Differential Revision: https://phabricator.services.mozilla.com/D40248
This commit is contained in:
parent
d93f6419d8
commit
0548a84746
@ -11,6 +11,7 @@
|
||||
#define mozilla_MediaEmulationData_h
|
||||
|
||||
#include "nsAtom.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -19,6 +20,7 @@ struct MediaEmulationData final {
|
||||
|
||||
RefPtr<nsAtom> mMedium;
|
||||
float mDPPX = 0.0;
|
||||
Maybe<StylePrefersColorScheme> mPrefersColorScheme;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -987,6 +987,17 @@ void nsPresContext::SetOverrideDPPX(float aDPPX) {
|
||||
MediaFeatureValuesChanged({MediaFeatureChangeReason::ResolutionChange});
|
||||
}
|
||||
|
||||
void nsPresContext::SetOverridePrefersColorScheme(
|
||||
const Maybe<StylePrefersColorScheme>& aOverride) {
|
||||
if (GetOverridePrefersColorScheme() == aOverride) {
|
||||
return;
|
||||
}
|
||||
mMediaEmulationData.mPrefersColorScheme = aOverride;
|
||||
// This is a bit of a lie, but it's the code-path that gets taken for regular
|
||||
// system metrics changes via ThemeChanged().
|
||||
MediaFeatureValuesChanged({MediaFeatureChangeReason::SystemMetricsChange});
|
||||
}
|
||||
|
||||
gfxSize nsPresContext::ScreenSizeInchesForFontInflation(bool* aChanged) {
|
||||
if (aChanged) {
|
||||
*aChanged = false;
|
||||
|
@ -134,6 +134,7 @@ class nsPresContext : public nsISupports,
|
||||
template <typename T>
|
||||
using NotNull = mozilla::NotNull<T>;
|
||||
using MediaEmulationData = mozilla::MediaEmulationData;
|
||||
using StylePrefersColorScheme = mozilla::StylePrefersColorScheme;
|
||||
|
||||
typedef mozilla::ScrollStyles ScrollStyles;
|
||||
typedef mozilla::StaticPresData StaticPresData;
|
||||
@ -491,6 +492,11 @@ class nsPresContext : public nsISupports,
|
||||
float GetOverrideDPPX() const { return mMediaEmulationData.mDPPX; }
|
||||
void SetOverrideDPPX(float);
|
||||
|
||||
Maybe<StylePrefersColorScheme> GetOverridePrefersColorScheme() const {
|
||||
return mMediaEmulationData.mPrefersColorScheme;
|
||||
}
|
||||
void SetOverridePrefersColorScheme(const Maybe<StylePrefersColorScheme>&);
|
||||
|
||||
nscoord GetAutoQualityMinFontSize() {
|
||||
return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
|
||||
}
|
||||
|
@ -248,6 +248,10 @@ StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme(
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
if (nsPresContext* pc = aDocument->GetPresContext()) {
|
||||
if (auto devtoolsOverride = pc->GetOverridePrefersColorScheme()) {
|
||||
return *devtoolsOverride;
|
||||
}
|
||||
|
||||
if (pc->IsPrintingOrPrintPreview()) {
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user