# HG changeset patch
# User Matt A. Tobin <email@mattatobin.com>
# Date 1722098520 18000
# Node ID 3bcdb48f9c502425d0ea515aea7051e8e6a1eb24
# Parent  2d22e9808a070702aad9f60d080e453c9df34754
No Bug - Add support for CSS prefers-reduced-transparency media feature.

diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h
--- a/dom/base/nsGkAtomList.h
+++ b/dom/base/nsGkAtomList.h
@@ -2264,16 +2264,17 @@ GK_ATOM(scrollbar_start_backward, "scrol
 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(prefers_contrast, "prefers-contrast")
 GK_ATOM(prefers_reduced_motion, "prefers-reduced-motion")
+GK_ATOM(prefers_reduced_transparency, "prefers-reduced-transparency")
 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/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -65,16 +65,22 @@ static const nsCSSProps::KTableEntry kPr
 };
 
 static const nsCSSProps::KTableEntry kPrefersReducedMotionKeywords[] = {
   { eCSSKeyword_no_preference,          NS_STYLE_PREFERS_REDUCED_MOTION_NO_PREFERENCE },
   { eCSSKeyword_reduce,                 NS_STYLE_PREFERS_REDUCED_MOTION_REDUCE },
   { eCSSKeyword_UNKNOWN,                -1 },
 };
 
+static const nsCSSProps::KTableEntry kPrefersReducedTransparencyKeywords[] = {
+  { eCSSKeyword_no_preference,          NS_STYLE_PREFERS_REDUCED_TRANSPARENCY_NO_PREFERENCE },
+  { eCSSKeyword_reduce,                 NS_STYLE_PREFERS_REDUCED_TRANSPARENCY_REDUCE },
+  { 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[] = {
@@ -586,16 +592,31 @@ GetPrefersReducedMotion(nsIDocument* aDo
   }
   else {
     aResult.SetIntValue(NS_STYLE_PREFERS_REDUCED_MOTION_NO_PREFERENCE,
                         eCSSUnit_Enumerated);
   }
 }
 
 static void
+GetPrefersReducedTransparency(nsIDocument* aDocument, const nsMediaFeature* aFeature,
+                        nsCSSValue& aResult)
+{
+  if (Preferences::GetInt("browser.display.document_color_use", 0) == 2 ||
+      LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0)) {
+    aResult.SetIntValue(NS_STYLE_PREFERS_REDUCED_TRANSPARENCY_REDUCE,
+                        eCSSUnit_Enumerated);
+  }
+  else {
+    aResult.SetIntValue(NS_STYLE_PREFERS_REDUCED_TRANSPARENCY_NO_PREFERENCE,
+                        eCSSUnit_Enumerated);
+  }
+}
+
+static void
 GetIsGlyph(nsIDocument* aDocument, const nsMediaFeature* aFeature,
            nsCSSValue& aResult)
 {
   MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
   aResult.SetIntValue(aDocument->IsSVGGlyphsDocument() ? 1 : 0, eCSSUnit_Integer);
 }
 
 /*
@@ -709,16 +730,24 @@ nsMediaFeatures::features[] = {
     &nsGkAtoms::prefers_reduced_motion,
     nsMediaFeature::eMinMaxNotAllowed,
     nsMediaFeature::eEnumerated,
     nsMediaFeature::eNoRequirements,
     { kPrefersReducedMotionKeywords },
     GetPrefersReducedMotion
   },
   {
+    &nsGkAtoms::prefers_reduced_transparency,
+    nsMediaFeature::eMinMaxNotAllowed,
+    nsMediaFeature::eEnumerated,
+    nsMediaFeature::eNoRequirements,
+    { kPrefersReducedTransparencyKeywords },
+    GetPrefersReducedTransparency
+  },
+  {
     &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
@@ -1230,11 +1230,15 @@ enum class StyleOverscrollBehavior : uin
 #define NS_STYLE_PREFERS_CONTRAST_LESS          1
 #define NS_STYLE_PREFERS_CONTRAST_MORE          2
 #define NS_STYLE_PREFERS_CONTRAST_CUSTOM        3
 
 // prefers-reduced-motion
 #define NS_STYLE_PREFERS_REDUCED_MOTION_NO_PREFERENCE   0
 #define NS_STYLE_PREFERS_REDUCED_MOTION_REDUCE          1
 
+// prefers-reduced-transparency
+#define NS_STYLE_PREFERS_REDUCED_TRANSPARENCY_NO_PREFERENCE   0
+#define NS_STYLE_PREFERS_REDUCED_TRANSPARENCY_REDUCE          1
+
 } // namespace mozilla
 
 #endif /* nsStyleConsts_h___ */
