Browse Source

Bug 1909743

Frank-Rainer Grahl 2 months ago
parent
commit
09415a9a54

+ 84 - 0
comm-release/patches/1909743-suite-prefs-prefers-color-scheme-25320.patch

@@ -0,0 +1,84 @@
+# HG changeset patch
+# User Matt A. Tobin <email@mattatobin.com>
+# Date 1721862455 18000
+# Node ID a8c7c0268a751094352f089f194420454d88750c
+# Parent  4bcd10306f776881ecf0db12c3e18ded2b1ccc1a
+Bug 1909743 - Add UI for browser.display.prefers_color_scheme to the colors prefpane. r=frg a=frg
+
+diff --git a/suite/components/pref/content/pref-colors.xul b/suite/components/pref/content/pref-colors.xul
+--- a/suite/components/pref/content/pref-colors.xul
++++ b/suite/components/pref/content/pref-colors.xul
+@@ -31,16 +31,19 @@
+                   name="browser.visited_color"
+                   type="string"/>
+       <preference id="browser.underline_anchors"
+                   name="browser.underline_anchors"
+                   type="bool"/>
+       <preference id="browser.display.document_color_use"
+                   name="browser.display.document_color_use"
+                   type="int"/>
++      <preference id="browser.display.prefers_color_scheme"
++                  name="browser.display.prefers_color_scheme"
++                  type="int"/>
+     </preferences>
+     <hbox>
+       <groupbox flex="1" id="pageColours">
+         <caption label="&color;"/>
+         <hbox align="center">
+           <label id="browserForegroundColorLabel"
+                  value="&textColor.label;"
+                  accesskey="&textColor.accesskey;"
+@@ -122,10 +125,31 @@
+                accesskey="&alwaysUseDocumentColors.accesskey;"/>
+         <radio value="2" label="&useMyColors.label;"
+                accesskey="&useMyColors.accesskey;"/>
+         <radio value="0" label="&automaticColors.label;"
+                accesskey="&automaticColors.accesskey;"/>
+       </radiogroup>
+ 
+     </groupbox>
++
++    <groupbox>
++      <caption label="&prefersColorScheme;"/>
++
++      <radiogroup id="prefersColorSchemeSelection"
++                  preference="browser.display.prefers_color_scheme">
++        <radio value="1"
++               label="&prefersColorSchemeLight.label;"
++               accesskey="&prefersColorSchemeLight.accesskey;"/>
++        <radio value="2"
++               label="&prefersColorSchemeDark.label;"
++               accesskey="&prefersColorSchemeDark.accesskey;"/>
++        <radio value="0"
++               label="&prefersColorSchemeDisabled.label;"
++               accesskey="&prefersColorSchemeDisabled.accesskey;"/>
++      </radiogroup>
++
++      <description>&prefersColorSchemeWarning;</description>
++
++    </groupbox>
++
+   </prefpane>
+ </overlay>
+diff --git a/suite/locales/en-US/chrome/common/pref/pref-colors.dtd b/suite/locales/en-US/chrome/common/pref/pref-colors.dtd
+--- a/suite/locales/en-US/chrome/common/pref/pref-colors.dtd
++++ b/suite/locales/en-US/chrome/common/pref/pref-colors.dtd
+@@ -28,8 +28,18 @@
+ <!-- LOCALIZATION NOTE (alwaysUseDocColors.label): This is option one, and it appends to 'someProvColors' above. -->
+ <!ENTITY alwaysUseDocumentColors.label     "Always use the colors and background specified by the web page">
+ <!ENTITY alwaysUseDocumentColors.accesskey "A">
+ <!-- LOCALIZATION NOTE (ignoreDocColors.label): This is option two, and it appends to 'someProvColors' above.  -->
+ <!ENTITY useMyColors.label                 "Use my chosen colors, ignoring the colors and background image specified">
+ <!ENTITY useMyColors.accesskey             "m">
+ <!ENTITY automaticColors.label             "Only ignore the page colors when using a High Contrast theme">
+ <!ENTITY automaticColors.accesskey         "O">
++
++<!-- LOCALIZATION NOTE (prefersColorScheme): This is the start of a sentence and will be followed by the following radio buttons. -->
++<!ENTITY prefersColorScheme                     "When a web page wants to use my preferred color scheme">
++<!ENTITY prefersColorSchemeLight.label          "Use light colors">
++<!ENTITY prefersColorSchemeLight.accesskey      "i">
++<!ENTITY prefersColorSchemeDark.label           "Use dark colors">
++<!ENTITY prefersColorSchemeDark.accesskey       "d">
++<!ENTITY prefersColorSchemeDisabled.label       "Do not provide a preferred color scheme">
++<!ENTITY prefersColorSchemeDisabled.accesskey   "p">
++<!ENTITY prefersColorSchemeWarning              "WARNING: Not providing a preferred color scheme may result in websites or services not working properly.">

+ 1 - 0
comm-release/patches/series

@@ -2173,3 +2173,4 @@ TOP-1906540-mozdevice-removal-comm-25320.patch
 1470307-1-PARTIAL-BACKOUT-25320.patch
 1470307-1-PARTIAL-BACKOUT-25320.patch
 9999999-removemsnicq-25320.patch
 9999999-removemsnicq-25320.patch
 9999999-venkman-25320.patch
 9999999-venkman-25320.patch
+1909743-suite-prefs-prefers-color-scheme-25320.patch

+ 216 - 0
mozilla-release/patches/TOP-1909743-nsstyle-prefers-color-scheme-25320.patch

@@ -0,0 +1,216 @@
+# HG changeset patch
+# User Matt A. Tobin <email@mattatobin.com>
+# Date 1721847757 18000
+# Node ID 8af210a884c8c3c677dbd92defe767ad6a5b8fc4
+# Parent  781ba690d1c20d755331840f78c904d39362ef30
+No Bug - Add support for CSS prefers-color-scheme media feature as a user preference.
+
+Based on an nsStyle port of Bug 1494034 to UXP by athenian200 <athenian200@outlook.com>
+
+diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h
+--- a/dom/base/nsGkAtomList.h
++++ b/dom/base/nsGkAtomList.h
+@@ -2261,16 +2261,17 @@ GK_ATOM(forcemessagemanager, "forcemessa
+ 
+ // Names for system metrics
+ GK_ATOM(scrollbar_start_backward, "scrollbar-start-backward")
+ GK_ATOM(scrollbar_start_forward, "scrollbar-start-forward")
+ 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_in_titlebar, "windows-accent-color-in-titlebar")
+ GK_ATOM(windows_default_theme, "windows-default-theme")
+ GK_ATOM(mac_graphite_theme, "mac-graphite-theme")
+ GK_ATOM(mac_yosemite_theme, "mac-yosemite-theme")
+ GK_ATOM(windows_compositor, "windows-compositor")
+ GK_ATOM(windows_glass, "windows-glass")
+ GK_ATOM(touch_enabled, "touch-enabled")
+ GK_ATOM(menubar_drag, "menubar-drag")
+diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h
+--- a/layout/style/nsCSSKeywordList.h
++++ b/layout/style/nsCSSKeywordList.h
+@@ -220,16 +220,17 @@ CSS_KEY(copy, copy)
+ CSS_KEY(contextual, contextual)
+ CSS_KEY(cover, cover)
+ CSS_KEY(crop, crop)
+ CSS_KEY(cross, cross)
+ 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)
+ CSS_KEY(decimal, decimal)
+ CSS_KEY(default, default)
+ CSS_KEY(deg, deg)
+ CSS_KEY(diagonal-fractions, diagonal_fractions)
+ CSS_KEY(dialog, dialog)
+@@ -355,16 +356,17 @@ CSS_KEY(khz, khz)
+ CSS_KEY(landscape, landscape)
+ CSS_KEY(large, large)
+ CSS_KEY(larger, larger)
+ CSS_KEY(last, last)
+ 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)
+ CSS_KEY(linear, linear)
+ CSS_KEY(lining-nums, lining_nums)
+ CSS_KEY(list-item, list_item)
+ CSS_KEY(local, local)
+ CSS_KEY(logical, logical)
+diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp
+--- a/layout/style/nsMediaFeatures.cpp
++++ b/layout/style/nsMediaFeatures.cpp
+@@ -19,16 +19,17 @@
+ #include "nsCSSRuleProcessor.h"
+ #endif
+ #include "nsDeviceContext.h"
+ #include "nsIBaseWindow.h"
+ #include "nsIDocShell.h"
+ #include "nsIDocument.h"
+ #include "nsIWidget.h"
+ #include "nsContentUtils.h"
++#include "mozilla/Preferences.h"
+ #include "mozilla/StyleSheet.h"
+ #include "mozilla/StyleSheetInlines.h"
+ 
+ using namespace mozilla;
+ 
+ static const nsCSSProps::KTableEntry kOrientationKeywords[] = {
+   { eCSSKeyword_portrait,                 NS_STYLE_ORIENTATION_PORTRAIT },
+   { eCSSKeyword_landscape,                NS_STYLE_ORIENTATION_LANDSCAPE },
+@@ -44,16 +45,22 @@ static const nsCSSProps::KTableEntry kSc
+ static const nsCSSProps::KTableEntry kDisplayModeKeywords[] = {
+   { eCSSKeyword_browser,                 NS_STYLE_DISPLAY_MODE_BROWSER },
+   { eCSSKeyword_minimal_ui,              NS_STYLE_DISPLAY_MODE_MINIMAL_UI },
+   { eCSSKeyword_standalone,              NS_STYLE_DISPLAY_MODE_STANDALONE },
+   { eCSSKeyword_fullscreen,              NS_STYLE_DISPLAY_MODE_FULLSCREEN },
+   { 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;
+   const wchar_t* name;
+ };
+ 
+ // Windows theme identities used in the -moz-windows-theme media query.
+ const WindowsThemeName themeStrings[] = {
+@@ -501,16 +508,34 @@ GetOperatingSystemVersion(nsIDocument* a
+         break;
+       }
+     }
+   }
+ #endif
+ }
+ 
+ static void
++GetPrefersColorScheme(nsIDocument* aDocument, 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();
++  }
++}
++
++static void
+ GetIsGlyph(nsIDocument* aDocument, const nsMediaFeature* aFeature,
+            nsCSSValue& aResult)
+ {
+   MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
+   aResult.SetIntValue(aDocument->IsSVGGlyphsDocument() ? 1 : 0, eCSSUnit_Integer);
+ }
+ 
+ /*
+@@ -600,16 +625,24 @@ nsMediaFeatures::features[] = {
+     &nsGkAtoms::monochrome,
+     nsMediaFeature::eMinMaxAllowed,
+     nsMediaFeature::eInteger,
+     nsMediaFeature::eNoRequirements,
+     { nullptr },
+     GetMonochrome
+   },
+   {
++    &nsGkAtoms::prefers_color_scheme,
++    nsMediaFeature::eMinMaxNotAllowed,
++    nsMediaFeature::eEnumerated,
++    nsMediaFeature::eNoRequirements,
++    { kPrefersColorSchemeKeywords },
++    GetPrefersColorScheme
++  },
++  {
+     &nsGkAtoms::resolution,
+     nsMediaFeature::eMinMaxAllowed,
+     nsMediaFeature::eResolution,
+     nsMediaFeature::eNoRequirements,
+     { nullptr },
+     GetResolution
+   },
+   {
+diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h
+--- a/layout/style/nsStyleConsts.h
++++ b/layout/style/nsStyleConsts.h
+@@ -1216,11 +1216,15 @@ enum class StyleOverscrollBehavior : uin
+ #define NS_STYLE_SCAN_INTERLACE                 1
+ 
+ // display-mode
+ #define NS_STYLE_DISPLAY_MODE_BROWSER           0
+ #define NS_STYLE_DISPLAY_MODE_MINIMAL_UI        1
+ #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
+--- a/modules/libpref/init/all.js
++++ b/modules/libpref/init/all.js
+@@ -398,16 +398,20 @@ pref("ui.menu.incremental_search.timeout
+ // If true, all popups won't hide automatically on blur
+ pref("ui.popup.disable_autohide", false);
+ 
+ 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
+ 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");
+ pref("browser.display.force_inline_alttext", false); // true = force ALT text for missing images to be layed out inline
+ // 0 = no external leading,
+ // 1 = use external leading only when font provides,
+ // 2 = add extra leading both internal leading and external leading are zero
+ pref("browser.display.normal_lineheight_calc_control", 2);

+ 1 - 0
mozilla-release/patches/series

@@ -7193,3 +7193,4 @@ TOP-NOBUG-fixups-25320.patch
 1699950-1-88a1.patch
 1699950-1-88a1.patch
 1699950-2-88a1.patch
 1699950-2-88a1.patch
 1699950-3-88a1.patch
 1699950-3-88a1.patch
+TOP-1909743-nsstyle-prefers-color-scheme-25320.patch