diff options
author | athenian200 <athenian200@outlook.com> | 2021-06-22 18:14:44 +0000 |
---|---|---|
committer | New Tobin Paradigm <mattatobin@no-reply.palemoon.org> | 2021-06-22 18:14:44 +0000 |
commit | a0461e377582be71ca2e8669fef9a102e42a43c4 (patch) | |
tree | 7875d4047e7cdb3050c69cf93a4c09a684b1a268 /layout/style/nsMediaFeatures.cpp | |
parent | 4490f61f580237de9f7d1f81ddff214f1c0fb035 (diff) | |
download | uxp-a0461e377582be71ca2e8669fef9a102e42a43c4.tar.gz |
Issue #1784 - Add -moz-dark-theme media query and allow prefers-color-scheme to follow it.
Diffstat (limited to 'layout/style/nsMediaFeatures.cpp')
-rw-r--r-- | layout/style/nsMediaFeatures.cpp | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index 983dee839a..ab423ad9ef 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -459,20 +459,60 @@ GetOperatingSystemVersion(nsPresContext* aPresContext, const nsMediaFeature* aFe static nsresult GetPrefersColorScheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature, - nsCSSValue& aResult) + nsCSSValue& aResult) { switch(Preferences::GetInt("browser.display.prefers_color_scheme", 1)) { case 1: - aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT, - eCSSUnit_Enumerated); - break; + aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT, + eCSSUnit_Enumerated); + break; case 2: - aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_DARK, - eCSSUnit_Enumerated); - break; + aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_DARK, + eCSSUnit_Enumerated); + break; + case 3: + // If the pref is 3, we follow ui.color_scheme instead. When following + // ui.color_scheme, light theme is the fallback behavior. + switch(Preferences::GetInt("ui.color_scheme", 1)) { + case 2: + aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_DARK, + eCSSUnit_Enumerated); + break; + default: + aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT, + eCSSUnit_Enumerated); + } + break; default: + aResult.Reset(); + } + + return NS_OK; +} + +static nsresult +GetDarkTheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature, + nsCSSValue& aResult) +{ +#ifdef XP_WIN + // Under Windows, do nothing if High Contrast Theme is on. + if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0)) { aResult.Reset(); + return NS_OK; } +#endif + + switch(Preferences::GetInt("ui.color_scheme", 1)) { + case 1: + aResult.SetIntValue(0, eCSSUnit_Integer); + break; + case 2: + aResult.SetIntValue(1, eCSSUnit_Integer); + break; + default: + aResult.Reset(); + } + return NS_OK; } @@ -639,6 +679,14 @@ nsMediaFeatures::features[] = { // Mozilla extensions { + &nsGkAtoms::_moz_dark_theme, + nsMediaFeature::eMinMaxNotAllowed, + nsMediaFeature::eBoolInteger, + nsMediaFeature::eNoRequirements, + { nullptr }, + GetDarkTheme + }, + { &nsGkAtoms::_moz_device_pixel_ratio, nsMediaFeature::eMinMaxAllowed, nsMediaFeature::eFloat, |