summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2021-03-24 08:58:18 +0000
committerMoonchild <moonchild@palemoon.org>2021-03-24 08:58:18 +0000
commitc1b064b99f6874f9d670ba40f9d266cf4689539b (patch)
treeaff4c2f37a80c6f4c79e32df564bb18a31172536
parentd3543ca2fecf39a83952872c0b936e4566fe02ff (diff)
parente946ca91fb032149131087ce24fbba886c53ee18 (diff)
downloaduxp-c1b064b99f6874f9d670ba40f9d266cf4689539b.tar.gz
Merge pull request 'Implement "prefers-color-scheme" as a user preference.' (#1753) from athenian200/UXP:prefers-color-scheme into master
Reviewed-on: https://repo.palemoon.org/MoonchildProductions/UXP/pulls/1753
-rw-r--r--dom/base/nsGkAtomList.h1
-rw-r--r--layout/style/nsCSSKeywordList.h2
-rw-r--r--layout/style/nsMediaFeatures.cpp34
-rw-r--r--layout/style/nsStyleConsts.h4
-rw-r--r--modules/libpref/init/all.js4
5 files changed, 45 insertions, 0 deletions
diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h
index 5e08fdc20b..caf8061bbc 100644
--- a/dom/base/nsGkAtomList.h
+++ b/dom/base/nsGkAtomList.h
@@ -2239,6 +2239,7 @@ GK_ATOM(scrollbar_end_backward, "scrollbar-end-backward")
GK_ATOM(scrollbar_end_forward, "scrollbar-end-forward")
GK_ATOM(scrollbar_thumb_proportional, "scrollbar-thumb-proportional")
GK_ATOM(overlay_scrollbars, "overlay-scrollbars")
+GK_ATOM(prefers_color_scheme, "prefers-color-scheme")
GK_ATOM(windows_accent_color_applies, "windows-accent-color-applies")
GK_ATOM(windows_accent_color_is_dark, "windows-accent-color-is-dark")
GK_ATOM(windows_default_theme, "windows-default-theme")
diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h
index 689ff47eb6..be1691e629 100644
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -224,6 +224,7 @@ CSS_KEY(crosshair, crosshair)
CSS_KEY(currentcolor, currentcolor)
CSS_KEY(cursive, cursive)
CSS_KEY(cyclic, cyclic)
+CSS_KEY(dark, dark)
CSS_KEY(darken, darken)
CSS_KEY(dashed, dashed)
CSS_KEY(dense, dense)
@@ -364,6 +365,7 @@ CSS_KEY(last baseline, last_baseline) // only used for DevTools auto-completion
CSS_KEY(layout, layout)
CSS_KEY(left, left)
CSS_KEY(legacy, legacy)
+CSS_KEY(light, light)
CSS_KEY(lighten, lighten)
CSS_KEY(lighter, lighter)
CSS_KEY(line-through, line_through)
diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp
index e44003ce48..9b5331a4a1 100644
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -20,6 +20,7 @@
#include "nsIDocument.h"
#include "nsIWidget.h"
#include "nsContentUtils.h"
+#include "mozilla/Preferences.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
@@ -45,6 +46,12 @@ static const nsCSSProps::KTableEntry kDisplayModeKeywords[] = {
{ eCSSKeyword_UNKNOWN, -1 }
};
+static const nsCSSProps::KTableEntry kPrefersColorSchemeKeywords[] = {
+ { eCSSKeyword_light, NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT },
+ { eCSSKeyword_dark, NS_STYLE_PREFERS_COLOR_SCHEME_DARK },
+ { eCSSKeyword_UNKNOWN, -1 },
+};
+
#ifdef XP_WIN
struct WindowsThemeName {
LookAndFeel::WindowsTheme id;
@@ -456,6 +463,25 @@ GetOperatingSystemVersion(nsPresContext* aPresContext, const nsMediaFeature* aFe
}
static nsresult
+GetPrefersColorScheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
+ nsCSSValue& aResult)
+{
+ switch(Preferences::GetInt("browser.display.prefers_color_scheme", 1)) {
+ case 1:
+ aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT,
+ eCSSUnit_Enumerated);
+ break;
+ case 2:
+ aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_DARK,
+ eCSSUnit_Enumerated);
+ break;
+ default:
+ aResult.Reset();
+ }
+ return NS_OK;
+}
+
+static nsresult
GetIsGlyph(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
nsCSSValue& aResult)
{
@@ -555,6 +581,14 @@ nsMediaFeatures::features[] = {
GetMonochrome
},
{
+ &nsGkAtoms::prefers_color_scheme,
+ nsMediaFeature::eMinMaxNotAllowed,
+ nsMediaFeature::eEnumerated,
+ nsMediaFeature::eNoRequirements,
+ { kPrefersColorSchemeKeywords },
+ GetPrefersColorScheme
+ },
+ {
&nsGkAtoms::resolution,
nsMediaFeature::eMinMaxAllowed,
nsMediaFeature::eResolution,
diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h
index 308a66647b..60377928b0 100644
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -1306,6 +1306,10 @@ enum class StyleDisplay : uint8_t {
#define NS_STYLE_DISPLAY_MODE_STANDALONE 2
#define NS_STYLE_DISPLAY_MODE_FULLSCREEN 3
+// prefers-color-scheme
+#define NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT 0
+#define NS_STYLE_PREFERS_COLOR_SCHEME_DARK 1
+
} // namespace mozilla
#endif /* nsStyleConsts_h___ */
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js
index 993eef3914..a24bec7a5a 100644
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -266,6 +266,10 @@ pref("browser.display.use_document_fonts", 1); // 0 = never, 1 = quick, 2 = al
// 1 = always
// 2 = never
pref("browser.display.document_color_use", 0);
+// 0 = feature disabled
+// 1 = default: light theme preferred
+// 2 = dark theme preferred
+pref("browser.display.prefers_color_scheme", 1);
pref("browser.display.use_system_colors", false);
pref("browser.display.foreground_color", "#000000");
pref("browser.display.background_color", "#FFFFFF");