Skip to content

Commit e6a1a74

Browse files
jaredhirschjhirsch@mozilla.com
authored andcommitted
Bug 1997455 - Add a pref so forced-colors theme override can optionally be disabled r=emilio,rpl
Differential Revision: https://phabricator.services.mozilla.com/D271323
1 parent 8293a2a commit e6a1a74

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

browser/app/profile/firefox.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,10 @@ pref("browser.dataFeatureRecommendations.enabled", false);
905905
// sets darkTheme data.
906906
pref("browser.theme.dark-private-windows", true);
907907

908+
// Whether to override themes in forced-colors mode and just use the
909+
// system theme and forced-colors palette to style the chrome.
910+
pref("browser.theme.forced-colors-override.enabled", true);
911+
908912
// Pref to control whether or not Private Browsing windows show up
909913
// as separate icons in the Windows taskbar.
910914
pref("browser.privateWindowSeparation.enabled", true);

toolkit/modules/LightweightThemeConsumer.sys.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ export function LightweightThemeConsumer(aDocument) {
222222
this._win = aDocument.defaultView;
223223
this._winId = this._win.docShell.outerWindowID;
224224

225+
XPCOMUtils.defineLazyPreferenceGetter(
226+
this,
227+
"FORCED_COLORS_OVERRIDE_ENABLED",
228+
"browser.theme.forced-colors-override.enabled",
229+
true,
230+
() => this._update(this._lastData)
231+
);
232+
225233
Services.obs.addObserver(this, "lightweight-theme-styling-update");
226234

227235
this.darkThemeMediaQuery = this._win.matchMedia("(-moz-system-dark-theme)");
@@ -309,7 +317,10 @@ LightweightThemeConsumer.prototype = {
309317
})();
310318

311319
let theme = useDarkTheme ? themeData.darkTheme : themeData.theme;
312-
if (!theme || this.forcedColorsMediaQuery?.matches) {
320+
let forcedColorsThemeOverride =
321+
this.FORCED_COLORS_OVERRIDE_ENABLED &&
322+
this.forcedColorsMediaQuery?.matches;
323+
if (!theme || forcedColorsThemeOverride) {
313324
theme = { id: DEFAULT_THEME_ID };
314325
}
315326
let builtinThemeConfig = lazy.BuiltInThemeConfig.get(theme.id);

toolkit/mozapps/extensions/content/aboutaddons.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ XPCOMUtils.defineLazyPreferenceGetter(
5757
"extensions.dataCollectionPermissions.enabled",
5858
false
5959
);
60+
XPCOMUtils.defineLazyPreferenceGetter(
61+
this,
62+
"FORCED_COLORS_OVERRIDE_ENABLED",
63+
"browser.theme.forced-colors-override.enabled",
64+
true
65+
);
6066

6167
const PLUGIN_ICON_URL = "chrome://global/skin/icons/plugin.svg";
6268
const EXTENSION_ICON_URL =
@@ -4172,8 +4178,10 @@ class ForcedColorsNotice extends HTMLElement {
41724178
}
41734179

41744180
render() {
4175-
this.hidden = !this.forcedColorsMediaQuery.matches;
4176-
if (!this.hidden && this.childElementCount == 0) {
4181+
let shouldShowNotice =
4182+
FORCED_COLORS_OVERRIDE_ENABLED && this.forcedColorsMediaQuery.matches;
4183+
this.hidden = !shouldShowNotice;
4184+
if (shouldShowNotice && this.childElementCount == 0) {
41774185
this.appendChild(importTemplate("forced-colors-notice"));
41784186
}
41794187
}

toolkit/mozapps/extensions/test/browser/browser_html_forced_colors_notice.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,17 @@ add_task(async function test_aboutaddons_forced_colors_notice() {
6363
});
6464
await assertForcedColorsNotice(win, { expectVisible: false });
6565

66+
info("Test that forced-colors override is disabled when the pref is false");
67+
await SpecialPowers.pushPrefEnv({
68+
set: [
69+
["browser.theme.forced-colors-override.enabled", false],
70+
["ui.useAccessibilityTheme", 1],
71+
],
72+
});
73+
await closeView(win);
74+
win = await loadInitialView("theme");
75+
await assertForcedColorsNotice(win, { expectVisible: false });
76+
await SpecialPowers.popPrefEnv();
77+
6678
await closeView(win);
6779
});

toolkit/mozapps/extensions/test/browser/browser_theme_forced_colors.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,18 @@ add_task(async function test_forced_colors_themes() {
4646
"should be in forced-colors mode"
4747
);
4848

49+
await SpecialPowers.pushPrefEnv({
50+
set: [["browser.theme.forced-colors-override.enabled", false]],
51+
});
52+
53+
Assert.ok(
54+
docEl.hasAttribute("lwtheme"),
55+
"when forced-colors override is disabled, LWT attribute should be set"
56+
);
57+
Assert.ok(
58+
window.matchMedia("(forced-colors)").matches,
59+
"when forced-colors override is disabled, window should still be in forced-colors mode"
60+
);
61+
4962
await theme.unload();
5063
});

0 commit comments

Comments
 (0)