summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorathenian200 <athenian200@outlook.com>2021-06-22 18:14:44 +0000
committerNew Tobin Paradigm <mattatobin@no-reply.palemoon.org>2021-06-22 18:14:44 +0000
commit9af14b15018bc581fe8d37007890b482cb54e41c (patch)
tree7875d4047e7cdb3050c69cf93a4c09a684b1a268
parent604fc95340d90d5c973478ac142f49667013f61e (diff)
downloadaura-central-9af14b15018bc581fe8d37007890b482cb54e41c.tar.gz
Issue mcp-graveyard/UXP%1784 - Add -moz-dark-theme media query and allow prefers-color-scheme to follow it.
-rw-r--r--dom/base/nsGkAtomList.h1
-rw-r--r--layout/style/nsMediaFeatures.cpp62
-rw-r--r--modules/libpref/init/all.js8
3 files changed, 64 insertions, 7 deletions
diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h
index 57df1d6d1..bd0583598 100644
--- a/dom/base/nsGkAtomList.h
+++ b/dom/base/nsGkAtomList.h
@@ -2261,6 +2261,7 @@ GK_ATOM(windows_theme_generic, "windows-theme-generic")
// And the same again, as media query keywords.
GK_ATOM(_moz_color_picker_available, "-moz-color-picker-available")
+GK_ATOM(_moz_dark_theme, "-moz-dark-theme")
GK_ATOM(_moz_scrollbar_start_backward, "-moz-scrollbar-start-backward")
GK_ATOM(_moz_scrollbar_start_forward, "-moz-scrollbar-start-forward")
GK_ATOM(_moz_scrollbar_end_backward, "-moz-scrollbar-end-backward")
diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp
index 983dee839..ab423ad9e 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,
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js
index 6a14339a6..ad98f7a07 100644
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -250,6 +250,13 @@ pref("browser.sessionhistory.max_total_viewers", -1);
// See https://github.com/MoonchildProductions/UXP/issues/719
pref("browser.newtabpage.add_to_session_history", false);
+
+// Determines whether the browser's current theme should be light or dark.
+// 0 = feature disabled
+// 1 = default: light theme
+// 2 = dark theme
+pref("ui.color_scheme", 1);
+
pref("ui.use_native_colors", true);
#ifdef MOZ_WIDGET_GTK
// Determines whether the menubar is shown in the global menubar or not.
@@ -269,6 +276,7 @@ pref("browser.display.document_color_use", 0);
// 0 = feature disabled
// 1 = default: light theme preferred
// 2 = dark theme preferred
+// 3 = match ui.color_scheme
pref("browser.display.prefers_color_scheme", 1);
pref("browser.display.use_system_colors", false);
pref("browser.display.foreground_color", "#000000");