Bug 1898096 - Replace color settings with "contrast control". r=emilio,fluent-reviewers,settings-reviewers,accessibility-frontend-reviewers,morgan,bolsson,masayuki,mossop,pdfjs-reviewers,calixte

This patch changes the backing prefs by relying on the tristate offered
by browser.display.document_color_use instead of
browser.display.use_system_colors. This simplifies the color
decision tree, and offers a simplified UI.

The tristate preference offered to the user is as follows:
 1. "Use platform's contrast settings" (document_color_use=0)
 2. "Off" - never use HCM, regardless of platform setting (document_color_use=1)
 3. "On" - always use HCM, regardless of platform setting (document_color_use=2)

Option 3 also reveals a colors UI for the user to choose the palette the
browser HCM will use (bg/text/link/visited).

There are three color palettes to choose from in light of the preference
above they are:
 1. WIDGET_COLORS: The OS's configured colors used by its theme.
 2. HARDCODED_COLORS: Colors deemed as standard and are hard coded into
    Firefox (eg. white on black text, blue and purple links).
 3. PREFERENCE_COLORS: Colors that are stored in preferences and are
    configurable from the colors UI (eg. browser.visited_color and
    browser.display.background_color)

The decision over which palette to use is as follows:
 * If we are styling browser UI -> WIDGET_COLORS
 * else, if resist fingerprinting is enabled -> HARDCODED_COLORS
 * else, if document_color_use==0 AND OS HCM is on -> WIDGET_COLORS
 * else, if document_color_use==2 -> PREFERENCE_COLORS
 * else -> HARDCODED_COLORS

Differential Revision: https://phabricator.services.mozilla.com/D211115
This commit is contained in:
Eitan Isaacson
2025-03-05 19:18:08 +00:00
parent fef0b57c45
commit cf6484047a
20 changed files with 264 additions and 409 deletions

View File

@@ -1,42 +1,45 @@
# Colors and High Contrast Mode # Colors and High Contrast Mode
Firefox offers several customisations to improve the accessibility of colors used to render web content and Firefox chrome. This document describes the customisation options available and their behaviour across platforms. It also describes how these options interact with one another. It is intended for developer reference :) Firefox offers several customisations to improve the accessibility of colors used to render web content and Firefox chrome. This document describes the customisation options available and their behaviour across platforms. It also describes how these options interact with one another. It is intended for developer reference :)
## The Colors Dialog ## The Contrast Control Settings
In `about:preferences > Language and Appearance`, you'll find a button labelled "Colors". This button launches the colors dialog, which contains all of our user-facing color customisation options, as well as stylistic customisations like link underlining. This dialog also contains the select that controls what we'll refer to as "Firefox High Contrast Mode", or FF HCM. FF HCM can be enabled "Always", "Never", or "Only with High Contrast Themes". In `about:preferences > Language and Appearance`, you'll find a subsection labeled "Contrast Control". The radio group in this section determines if high contrast mode (HCM) will be used. HCM can either be enabled on the platform level (OS HCM), or forced on in the browser (FF HCM)
The radio buttons alter `browser.display.document_color_use`. HCM can be enabled automatically with OS settings (OS HCM, `document_color_use=0`), it can be forced off (`document_color_use=1`), or forced on (FF HCM, `document_color_use=2`). When HCM is enabled, either automatically or explicitly, web content is rendered with a predetermined palette to give the user full control of the content's color contrast.
> Note: FF HCM only affects web content, so changing the option in this select will only alter color usage for web pages. It will not change FF chrome. Current behaviour on chrome pages (ie. `about:` pages) is undefined. > Note: FF HCM only affects web content, so changing the option in this select will only alter color usage for web pages. It will not change FF chrome. Current behaviour on chrome pages (ie. `about:` pages) is undefined.
### User-customisable Colors ### User-customisable Colors Dialog
Users can choose to override background color, foreground color, visited link color, and/or unvisited link color by selecting a new color from the color inputs in the dialog. Modifications to these colors are stored in their corresponding user preference: If the user has chosen to explicitly turn on Firefox HCM (`document_color_use=2`), they may customize the palette in a modal dialog. Users can choose to override background color, foreground color, visited link color, and/or unvisited link color by selecting a new color from the color inputs in the dialog. Modifications to these colors are stored in their corresponding user preference:
- `browser.background_color` - `browser.background_color`
- `browser.foreground_color` - `browser.foreground_color`
- `browser.visited_color` - `browser.visited_color`
- `browser.anchor_color` - `browser.anchor_color`
### Color Usage and System Colors ## Color Usage and System Colors
Before we render any Firefox/web content, we need to select a color palette to render that content _with_. We don't always use the colors a user has selected in the colors dialog. In fact, there are three different sets of colors we can use to style Firefox and/or web content: Before we render any Firefox/web content, we need to select a color palette to render that content _with_. There are three different sets of colors we can use to style Firefox and/or web content:
- Stand-in colors - Stand-in colors
- System colors - System colors
- Colors-dialog colors - Colors-dialog colors
> Note: Web pages may supply their own style sheets, which override a user's chosen color palette. When FF HCM is set to "Always", or set to "With High Contrast Themes" and OS HCM is enabled, the chosen color palette is _forced_, meaning it cannot be overridden by web pages. FF HCM and OS HCM do not directly change the way a color palette is chosen, but they _do_ change how the color palette is used. > Note: Web pages may supply their palette through style sheets. When FF HCM is set to "On", or set to "Use platform's contrast settings" and OS HCM is enabled, the chosen color palette is _forced_, meaning it cannot be overridden by web pages.
We decide which set of colors to use in `PreferenceSheet::Load`. If `resistFingerprinting` is enabled, we use stand-in colors. These colors are pre-defined constants and are not dynamically fetched from the operating system. Check out `nsXPLookAndFeel::GetStandinForNativeColor` for more information, as well as the constants themselves. We decide which set of colors to use in `PreferenceSheet::Load`. If `resistFingerprinting` is enabled, we use stand-in colors. These colors are pre-defined constants and are not dynamically fetched from the operating system. Check out `nsXPLookAndFeel::GetStandinForNativeColor` for more information, as well as the constants themselves.
If we aren't using stand-in colors, we'll check `browser.display.use_system_colors`, which is set from the "Use system colors" checkbox in the colors dialog. If that pref is true, we'll use system colors to style web content and Firefox chrome. If we aren't using stand-in colors, we'll check the `browser.display.document_color_use` pref. If HCM is explicitly off (`1`), or automatically off (`0`), we will use the system colors as default text and link colors.
System colors are colors queried from the operating system. They help Firefox adapt to OS-level changes that aren't strictly HCM (ie. light/dark themeing). Because these colors are OS-dependent, a user operating Firefox on a Windows machine with system colors enabled will see Firefox differently than a user with system colors enabled on MacOS. System colors are colors queried from the operating system. They help Firefox adapt to OS-level changes that aren't strictly HCM (ie. light/dark themeing). Because these colors are OS-dependent, a user operating Firefox on a Windows machine with system colors enabled will see Firefox differently than a user with system colors enabled on MacOS.
So, how do we _get_ system colors? Our style system has a set of pre-defined `ColorID`'s in `ServoStyleConsts.h`, which are mapped to platform-specific colors in `widget/[cocoa | android | windows | gtk]/LookAndFeel.cpp`. Depending on the `ColorID` queried, we may do a dynamic fetch or simply return a constant. On MacOS, for example, `ColorID::TextForeground` and `ColorID::TextBackground` are hard-coded to return black and white respectively. `ColorID::Highlight`, on the other hand, queries the OS for `NSColor.selectedTextBackgroundColor`, which is set based on the accent color a user has selected in System Preferences. So, how do we _get_ system colors? Our style system has a set of pre-defined `ColorID`'s in `ServoStyleConsts.h`, which are mapped to platform-specific colors in `widget/[cocoa | android | windows | gtk]/LookAndFeel.cpp`. Depending on the `ColorID` queried, we may do a dynamic fetch or simply return a constant. On MacOS, for example, `ColorID::TextForeground` and `ColorID::TextBackground` are hard-coded to return black and white respectively. `ColorID::Highlight`, on the other hand, queries the OS for `NSColor.selectedTextBackgroundColor`, which is set based on the accent color a user has selected in System Preferences.
> Note: The colors we fetch here are theme-relative. If a user has set their OS to a dark theme, we'll fetch colors from that palette, and likewise for a light theme. Windows HCM, though not strictly a "theme", overrides the colors stored for Windows' light theme, leading to [some confusing code, like this](https://searchfox.org/mozilla-central/rev/b462b11e71b500e084f51e61fbd9e19ea0122c78/layout/style/PreferenceSheet.cpp#202-210). > Note: The colors we fetch here are theme-relative. If a user has set their OS to a dark theme, we'll fetch colors from that palette, and likewise for a light theme. Windows HCM, though not strictly a "theme", overrides the colors stored for Windows' light theme, leading to [some confusing code, like this](https://searchfox.org/mozilla-central/rev/b462b11e71b500e084f51e61fbd9e19ea0122c78/layout/style/PreferenceSheet.cpp#202-210).
Lastly, if we are _not_ using system colors AND we are _not_ styling Firefox chrome AND we are _not_ `resistFingerprinting`, we'll use colors-dialog colors to style web content. Lastly, if we explicitly turn on HCM (`document_color_use=2`) AND we are _not_ styling Firefox chrome AND we are _not_ `resistFingerprinting`, we'll use colors-dialog colors to style web content.
By default, `browser.display.use_system_colors` is true on Windows and false elsewhere. This means users on Windows will _not_ see their selections in the colors dialog reflected automatically in Firefox. They'll need to uncheck "Use system colors" first. By default, `browser.display.document_color_use` is set to `2` on Windows. If a user turns on the OS HCM Firefox will automatically go into HCM mode as well.
> Note: This is intentional. When Windows HCM is enabled, the system colors Windows exposes are pulled from the chosen HCM theme. With "Use system colors" checked, a Windows HCM user will see their HCM theme choices reflected in Firefox content automatically. Windows HCM is the most robust HCM offered among the operating systems we support, and so we cater to it here :) > Note: This is intentional. Windows HCM is the most robust HCM offered among the operating systems we support, and so we cater to it here :)
Users on non-Windows platforms will see their selections in the colors dialog reflected automatically, but they will _not_ see OS changes until they check "Use system colors". Users on non-Windows platforms have HCM disabled by default (`document_color_use=1`). In order to enable Firefox HCM, they will either need to turn
it on explicitly (`document_color_use=2`), or set it to use the OS HCM mode and palette (`document_color_use=0`).
For a simplified flow chart of this decision tree, check out our [HCM Settings page](https://firefox-source-docs.mozilla.org/accessible/HCMSettings.html) For a simplified flow chart of this decision tree, check out our [HCM Settings page](HCMSettings.html)
## High Contrast Mode ## High Contrast Mode

View File

@@ -20,26 +20,17 @@ A -->|No| D
``` ```
## Settings that control color usage in content ## Settings that control color usage in content
- Colors Dialog (about:preferences > Manage Colors) - Colors Dialog (about:preferences > Contrast Control)
- Dropdown with options: Always, Only with High Contrast Themes, and Never
- Use System Colors checkbox
- Text, Background, Visited and Unvisited Link color inputs
- Extensions like Dark Reader, or changes to user.css, may override author specified colors independent of HCM. - Extensions like Dark Reader, or changes to user.css, may override author specified colors independent of HCM.
```{mermaid} ```{mermaid}
flowchart TD flowchart TD
A[What is the value of the dropdown in the colors dialog?] A[Which option is selected in 'Contrast Control'?]
A -->|Always|C
A -->|Only with High Contrast Themes| B[Is a OS HCM enabled?] A -->|Use platform's contrast settings| B[Is a OS HCM enabled?]
B -->|Yes| C[Is the Use System Colors checkbox checked?] A -->|Off| H
C -->|Yes, and OS HCM is on| D[Use OS HCM colors to render web content] A --->|On| I[Use colors dialog colors to render all content (HCM)]
C -->|Yes, and OS HCM is off| D2[Use OS dark/light colors to render web content]
C-->|No| E[Use colors dialog colors to render web content]
B -->|No| F[Is a color-modifying web extension or color-modifying user.css change active?] B -->|Yes| C[Use OS colors to render all content (HCM)]
F -->|Yes| G[Use web extension/user.css provided colors to render web content] B -->|No| H[Use system colors for all unstyled content]
F -->|No| H[Use author-provided colors to render web content]
A -->|Never|F
``` ```

View File

@@ -52,14 +52,74 @@ addAccessibleTask(
Assert.deepEqual(attributesList, [ Assert.deepEqual(attributesList, [
// string, fg color, bg color, underline, underline color, heading level, font size, link id, misspelled // string, fg color, bg color, underline, underline color, heading level, font size, link id, misspelled
["hello ", "#000000", "#ffffff", null, null, 1, 32, null, null], [
["world", "#0000ee", "#ffffff", 1, "#0000ee", 1, 32, "a1", null], "hello ",
["this ", "#000000", "#ffffff", null, null, null, 16, null, null], "#000000",
["is", "#ff0000", "#ffff00", null, null, null, 16, null, 1], "#ffffff",
[" ", "#000000", "#ffffff", null, null, null, 16, null, null], undefined,
["a", "#000000", "#ffffff", 1, "#008000", null, 16, null, null], undefined,
[" ", "#000000", "#ffffff", null, null, null, 16, null, null], 1,
["test", "#0000ee", "#ffffff", 1, "#0000ee", null, 16, "a2", null], 32,
null,
undefined,
],
["world", "#0066cc", "#ffffff", 1, "#0066cc", 1, 32, "a1", undefined],
[
"this ",
"#000000",
"#ffffff",
undefined,
undefined,
undefined,
16,
null,
undefined,
],
[
"is",
"#ff0000",
"#ffff00",
undefined,
undefined,
undefined,
16,
null,
1,
],
[
" ",
"#000000",
"#ffffff",
undefined,
undefined,
undefined,
16,
null,
undefined,
],
["a", "#000000", "#ffffff", 1, "#008000", undefined, 16, null, undefined],
[
" ",
"#000000",
"#ffffff",
undefined,
undefined,
undefined,
16,
null,
undefined,
],
[
"test",
"#0066cc",
"#ffffff",
1,
"#0066cc",
undefined,
16,
"a2",
undefined,
],
]); ]);
// Test different NSRange parameters for AXAttributedStringForRange // Test different NSRange parameters for AXAttributedStringForRange

View File

@@ -26,7 +26,6 @@ function reset() {
// state changes. // state changes.
Services.prefs.clearUserPref("browser.display.document_color_use"); Services.prefs.clearUserPref("browser.display.document_color_use");
Services.prefs.clearUserPref("browser.display.permit_backplate"); Services.prefs.clearUserPref("browser.display.permit_backplate");
Services.prefs.clearUserPref("browser.display.use_system_colors");
Services.prefs.clearUserPref("layout.css.always_underline_links"); Services.prefs.clearUserPref("layout.css.always_underline_links");
Services.telemetry.clearEvents(); Services.telemetry.clearEvents();
TelemetryTestUtils.assertNumberOfEvents(0); TelemetryTestUtils.assertNumberOfEvents(0);
@@ -34,49 +33,15 @@ function reset() {
Services.prefs.clearUserPref("browser.display.background_color"); Services.prefs.clearUserPref("browser.display.background_color");
} }
async function openColorsDialog() {
await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
const colorsButton =
gBrowser.selectedBrowser.contentDocument.getElementById("colors");
const dialogOpened = promiseLoadSubDialog(
"chrome://browser/content/preferences/dialogs/colors.xhtml"
);
colorsButton.doCommand();
return dialogOpened;
}
async function closeColorsDialog(dialogWin) {
const dialogClosed = BrowserTestUtils.waitForEvent(dialogWin, "unload");
const button = dialogWin.document
.getElementById("ColorsDialog")
.getButton("accept");
button.focus();
button.doCommand();
return dialogClosed;
}
function verifyBackplate(expectedValue) { function verifyBackplate(expectedValue) {
TelemetryTestUtils.assertScalar( TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true), TelemetryTestUtils.getProcessScalars("parent", false, false),
"a11y.backplate", "a11y.backplate",
expectedValue, expectedValue,
"Backplate scalar is logged as " + expectedValue "Backplate scalar is logged as " + expectedValue
); );
} }
function verifyUseSystemColors(expectedValue) {
const snapshot = TelemetryTestUtils.getProcessScalars("parent", false, false);
ok("a11y.use_system_colors" in snapshot, "System color usage was logged.");
TelemetryTestUtils.assertScalar(
snapshot,
"a11y.use_system_colors",
expectedValue,
"System colors scalar is logged as " + expectedValue
);
}
async function verifyAlwaysUnderlineLinks(expectedValue) { async function verifyAlwaysUnderlineLinks(expectedValue) {
let snapshot = TelemetryTestUtils.getProcessScalars("parent", false, false); let snapshot = TelemetryTestUtils.getProcessScalars("parent", false, false);
ok( ok(
@@ -116,18 +81,14 @@ async function setBackgroundColor(color) {
} }
add_task(async function testInit() { add_task(async function testInit() {
const dialogWin = await openColorsDialog(); await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
const menulistHCM = dialogWin.document.getElementById("useDocumentColors"); const contrastControlRadios =
gBrowser.selectedBrowser.contentDocument.getElementById(
"contrastControlSettings"
);
if (AppConstants.platform == "win") { if (AppConstants.platform == "win") {
is( is(
Services.prefs.getBoolPref("browser.display.use_system_colors"), contrastControlRadios.value,
true,
"Use system colours pref is init'd correctly"
);
verifyUseSystemColors(true);
is(
menulistHCM.value,
"0", "0",
"HCM menulist should be set to only with HCM theme on startup for windows" "HCM menulist should be set to only with HCM theme on startup for windows"
); );
@@ -141,14 +102,7 @@ add_task(async function testInit() {
); );
} else { } else {
is( is(
Services.prefs.getBoolPref("browser.display.use_system_colors"), contrastControlRadios.value,
false,
"Use system colours pref is init'd correctly"
);
verifyUseSystemColors(false);
is(
menulistHCM.value,
"1", "1",
"HCM menulist should be set to never on startup for non-windows platforms" "HCM menulist should be set to never on startup for non-windows platforms"
); );
@@ -161,8 +115,6 @@ add_task(async function testInit() {
false false
); );
await closeColorsDialog(dialogWin);
// We should not have logged any colors // We should not have logged any colors
let snapshot = TelemetryTestUtils.getProcessScalars("parent", false, true); let snapshot = TelemetryTestUtils.getProcessScalars("parent", false, true);
ok( ok(
@@ -194,16 +146,19 @@ add_task(async function testInit() {
}); });
add_task(async function testSetAlways() { add_task(async function testSetAlways() {
const dialogWin = await openColorsDialog(); await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
const menulistHCM = dialogWin.document.getElementById("useDocumentColors"); const contrastControlRadios =
gBrowser.selectedBrowser.contentDocument.getElementById(
"contrastControlSettings"
);
menulistHCM.doCommand(); const newOption =
const newOption = dialogWin.document.getElementById("documentColorAlways"); gBrowser.selectedBrowser.contentDocument.getElementById(
"contrastSettingsOn"
);
newOption.click(); newOption.click();
is(menulistHCM.value, "2", "HCM menulist should be set to always"); is(contrastControlRadios.value, "2", "HCM menulist should be set to always");
await closeColorsDialog(dialogWin);
// Verify correct initial value // Verify correct initial value
let snapshot = TelemetryTestUtils.getProcessScalars("parent", true, true); let snapshot = TelemetryTestUtils.getProcessScalars("parent", true, true);
@@ -214,42 +169,31 @@ add_task(async function testSetAlways() {
testIsWhite("a11y.HCM_background", snapshot); testIsWhite("a11y.HCM_background", snapshot);
testIsBlack("a11y.HCM_foreground", snapshot); testIsBlack("a11y.HCM_foreground", snapshot);
// If we change the colors, our probes update on non-windows platforms.
// On windows, useSystemColors is on by default, and so the values we set here
// will not be written to our telemetry probes, because they capture
// used colors, not the values of browser.foreground/background_color directly.
setBackgroundColor("#000000"); setBackgroundColor("#000000");
snapshot = TelemetryTestUtils.getProcessScalars("parent", false, true); snapshot = TelemetryTestUtils.getProcessScalars("parent", false, true);
if (AppConstants.platform == "win") { testIsBlack("a11y.HCM_background", snapshot);
testIsWhite("a11y.HCM_background", snapshot);
} else {
testIsBlack("a11y.HCM_background", snapshot);
}
setForegroundColor("#ffffff"); setForegroundColor("#ffffff");
snapshot = TelemetryTestUtils.getProcessScalars("parent", false, true); snapshot = TelemetryTestUtils.getProcessScalars("parent", false, true);
if (AppConstants.platform == "win") { testIsWhite("a11y.HCM_foreground", snapshot);
testIsBlack("a11y.HCM_foreground", snapshot);
} else {
testIsWhite("a11y.HCM_foreground", snapshot);
}
reset(); reset();
gBrowser.removeCurrentTab(); gBrowser.removeCurrentTab();
}); });
add_task(async function testSetDefault() { add_task(async function testSetDefault() {
const dialogWin = await openColorsDialog(); await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
const menulistHCM = dialogWin.document.getElementById("useDocumentColors"); const contrastControlRadios =
gBrowser.selectedBrowser.contentDocument.getElementById(
"contrastControlSettings"
);
menulistHCM.doCommand(); const newOption = gBrowser.selectedBrowser.contentDocument.getElementById(
const newOption = dialogWin.document.getElementById("documentColorAutomatic"); "contrastSettingsAuto"
);
newOption.click(); newOption.click();
is(menulistHCM.value, "0", "HCM menulist should be set to default"); is(contrastControlRadios.value, "0", "HCM menulist should be set to default");
await closeColorsDialog(dialogWin);
// Verify correct initial value // Verify correct initial value
TelemetryTestUtils.assertKeyedScalar( TelemetryTestUtils.assertKeyedScalar(
@@ -289,16 +233,18 @@ add_task(async function testSetDefault() {
}); });
add_task(async function testSetNever() { add_task(async function testSetNever() {
const dialogWin = await openColorsDialog(); await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
const menulistHCM = dialogWin.document.getElementById("useDocumentColors"); const contrastControlRadios =
gBrowser.selectedBrowser.contentDocument.getElementById(
"contrastControlSettings"
);
menulistHCM.doCommand(); const newOption = gBrowser.selectedBrowser.contentDocument.getElementById(
const newOption = dialogWin.document.getElementById("documentColorNever"); "contrastSettingsOff"
);
newOption.click(); newOption.click();
is(menulistHCM.value, "1", "HCM menulist should be set to never"); is(contrastControlRadios.value, "1", "HCM menulist should be set to never");
await closeColorsDialog(dialogWin);
// Verify correct initial value // Verify correct initial value
TelemetryTestUtils.assertKeyedScalar( TelemetryTestUtils.assertKeyedScalar(
@@ -351,30 +297,8 @@ add_task(async function testBackplate() {
Services.prefs.setBoolPref("browser.display.permit_backplate", true); Services.prefs.setBoolPref("browser.display.permit_backplate", true);
// Verify correct recorded value // Verify correct recorded value
verifyBackplate(true); verifyBackplate(true);
});
add_task(async function testSystemColors() {
let expectedInitVal = false;
if (AppConstants.platform == "win") {
expectedInitVal = true;
}
const dialogWin = await openColorsDialog();
const checkbox = dialogWin.document.getElementById("browserUseSystemColors");
checkbox.click();
is(
checkbox.checked,
!expectedInitVal,
"System colors checkbox should be modified"
);
await closeColorsDialog(dialogWin);
verifyUseSystemColors(!expectedInitVal);
reset(); reset();
gBrowser.removeCurrentTab();
}); });
add_task(async function testAlwaysUnderlineLinks() { add_task(async function testAlwaysUnderlineLinks() {

View File

@@ -13,10 +13,8 @@ document
.addEventListener("command", event => Preferences.close(event)); .addEventListener("command", event => Preferences.close(event));
Preferences.addAll([ Preferences.addAll([
{ id: "browser.display.document_color_use", type: "int" },
{ id: "browser.anchor_color", type: "string" }, { id: "browser.anchor_color", type: "string" },
{ id: "browser.visited_color", type: "string" }, { id: "browser.visited_color", type: "string" },
{ id: "browser.display.foreground_color", type: "string" }, { id: "browser.display.foreground_color", type: "string" },
{ id: "browser.display.background_color", type: "string" }, { id: "browser.display.background_color", type: "string" },
{ id: "browser.display.use_system_colors", type: "bool" },
]); ]);

View File

@@ -65,14 +65,6 @@
preference="browser.display.background_color" preference="browser.display.background_color"
/> />
</hbox> </hbox>
<separator class="thin" />
<hbox align="center">
<checkbox
id="browserUseSystemColors"
data-l10n-id="colors-use-system"
preference="browser.display.use_system_colors"
/>
</hbox>
</groupbox> </groupbox>
<groupbox flex="1"> <groupbox flex="1">
@@ -106,33 +98,6 @@
</groupbox> </groupbox>
</hbox> </hbox>
<label data-l10n-id="colors-page-override" control="useDocumentColors" />
<hbox>
<menulist
id="useDocumentColors"
preference="browser.display.document_color_use"
flex="1"
>
<menupopup>
<menuitem
data-l10n-id="colors-page-override-option-always"
value="2"
id="documentColorAlways"
/>
<menuitem
data-l10n-id="colors-page-override-option-auto"
value="0"
id="documentColorAutomatic"
/>
<menuitem
data-l10n-id="colors-page-override-option-never"
value="1"
id="documentColorNever"
/>
</menupopup>
</menulist>
</hbox>
<!-- Load the script after the elements for layout issues (bug 1501755). --> <!-- Load the script after the elements for layout issues (bug 1501755). -->
<script src="chrome://browser/content/preferences/dialogs/colors.js" /> <script src="chrome://browser/content/preferences/dialogs/colors.js" />
</dialog> </dialog>

View File

@@ -243,29 +243,36 @@
</groupbox> </groupbox>
<!-- Colors --> <!-- Colors -->
<groupbox id="colorsGroup" data-category="paneGeneral" hidden="true"> <groupbox id="contrastControlGroup" data-category="paneGeneral" hidden="true">
<label><html:h2 data-l10n-id="preferences-colors-header"/></label> <label><html:h2 data-l10n-id="preferences-contrast-control-header"/></label>
<description class="description-deemphasized" data-l10n-id="preferences-contrast-control-description"/>
<hbox id="colorsSettings" align="center" flex="1"> <radiogroup id="contrastControlSettings" preference="browser.display.document_color_use">
<description flex="1" control="colors" data-l10n-id="preferences-colors-description"/> <radio id="contrastSettingsAuto"
<button id="colors" value="0"
is="highlightable-button" data-l10n-id="preferences-contrast-control-use-platform-settings"/>
class="accessory-button" <radio id="contrastSettingsOff"
data-l10n-id="preferences-colors-manage-button" value="1"
search-l10n-ids=" data-l10n-id="preferences-contrast-control-off"/>
colors-page-override, <vbox align="start">
colors-page-override-option-always.label, <radio id="contrastSettingsOn"
colors-page-override-option-auto.label, value="2"
colors-page-override-option-never.label, flex="1"
colors-text-and-background, data-l10n-id="preferences-contrast-control-custom"/>
colors-text-header, <button id="colors"
colors-background, is="highlightable-button"
colors-use-system, class="accessory-button indent"
colors-links-header, data-l10n-id="preferences-colors-manage-button"
colors-unvisited-links, search-l10n-ids="
colors-visited-links colors-text-and-background,
"/> colors-text-header,
</hbox> colors-background,
colors-links-header,
colors-unvisited-links,
colors-visited-links
"/>
</vbox>
</radiogroup>
</groupbox> </groupbox>
<!-- Fonts --> <!-- Fonts -->

View File

@@ -30,7 +30,6 @@ const PREF_CONTAINERS_EXTENSION = "privacy.userContext.extension";
// Strings to identify ExtensionSettingsStore overrides // Strings to identify ExtensionSettingsStore overrides
const CONTAINERS_KEY = "privacy.containers"; const CONTAINERS_KEY = "privacy.containers";
const PREF_USE_SYSTEM_COLORS = "browser.display.use_system_colors";
const PREF_CONTENT_APPEARANCE = const PREF_CONTENT_APPEARANCE =
"layout.css.prefers-color-scheme.content-override"; "layout.css.prefers-color-scheme.content-override";
const FORCED_COLORS_QUERY = matchMedia("(forced-colors)"); const FORCED_COLORS_QUERY = matchMedia("(forced-colors)");
@@ -105,6 +104,9 @@ Preferences.addAll([
type: "bool", type: "bool",
}, },
// High Contrast
{ id: "browser.display.document_color_use", type: "int" },
// Fonts // Fonts
{ id: "font.language.group", type: "wstring" }, { id: "font.language.group", type: "wstring" },
@@ -492,6 +494,11 @@ var gMainPane = {
); );
setEventListener("advancedFonts", "command", gMainPane.configureFonts); setEventListener("advancedFonts", "command", gMainPane.configureFonts);
setEventListener("colors", "command", gMainPane.configureColors); setEventListener("colors", "command", gMainPane.configureColors);
Preferences.get("browser.display.document_color_use").on(
"change",
gMainPane.updateColorsButton.bind(gMainPane)
);
gMainPane.updateColorsButton();
Preferences.get("layers.acceleration.disabled").on( Preferences.get("layers.acceleration.disabled").on(
"change", "change",
gMainPane.updateHardwareAcceleration.bind(gMainPane) gMainPane.updateHardwareAcceleration.bind(gMainPane)
@@ -1043,6 +1050,11 @@ var gMainPane = {
document.getElementById("zoomBox").hidden = false; document.getElementById("zoomBox").hidden = false;
}, },
updateColorsButton() {
document.getElementById("colors").disabled =
Preferences.get("browser.display.document_color_use").value != 2;
},
/** /**
* Initialize the translations view. * Initialize the translations view.
*/ */
@@ -4272,7 +4284,6 @@ const AppearanceChooser = {
this.warning = document.getElementById("web-appearance-override-warning"); this.warning = document.getElementById("web-appearance-override-warning");
FORCED_COLORS_QUERY.addEventListener("change", this); FORCED_COLORS_QUERY.addEventListener("change", this);
Services.prefs.addObserver(PREF_USE_SYSTEM_COLORS, this);
Services.obs.addObserver(this, "look-and-feel-changed"); Services.obs.addObserver(this, "look-and-feel-changed");
this._update(); this._update();
}, },
@@ -4308,7 +4319,6 @@ const AppearanceChooser = {
}, },
destroy() { destroy() {
Services.prefs.removeObserver(PREF_USE_SYSTEM_COLORS, this);
Services.obs.removeObserver(this, "look-and-feel-changed"); Services.obs.removeObserver(this, "look-and-feel-changed");
FORCED_COLORS_QUERY.removeEventListener("change", this); FORCED_COLORS_QUERY.removeEventListener("change", this);
}, },
@@ -4343,10 +4353,6 @@ const AppearanceChooser = {
}, },
_updateWarning() { _updateWarning() {
let forcingColorsAndNoColorSchemeSupport = this.warning.hidden = !FORCED_COLORS_QUERY.matches;
FORCED_COLORS_QUERY.matches &&
(AppConstants.platform == "win" ||
!Services.prefs.getBoolPref(PREF_USE_SYSTEM_COLORS));
this.warning.hidden = !forcingColorsAndNoColorSchemeSupport;
}, },
}; };

View File

@@ -23,7 +23,7 @@ add_task(async function () {
await openPreferencesViaOpenPreferencesAPI("paneGeneral", { await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
leaveOpen: true, leaveOpen: true,
}); });
await evaluateSearchResults("Link Colors", "colorsGroup"); await evaluateSearchResults("Link Colors", "contrastControlGroup");
BrowserTestUtils.removeTab(gBrowser.selectedTab); BrowserTestUtils.removeTab(gBrowser.selectedTab);
}); });

View File

@@ -137,7 +137,7 @@ add_task(async function search_for_password_show_passwordGroup() {
"startupGroup", "startupGroup",
"languagesGroup", "languagesGroup",
"webAppearanceGroup", "webAppearanceGroup",
"colorsGroup", "contrastControlGroup",
"fontsGroup", "fontsGroup",
"zoomGroup", "zoomGroup",
"downloadsGroup", "downloadsGroup",

View File

@@ -197,11 +197,9 @@
if ( if (
Services.prefs.getIntPref("browser.display.document_color_use") == 2 Services.prefs.getIntPref("browser.display.document_color_use") == 2
) { ) {
this.tabpanels.style.backgroundColor = Services.prefs.getBoolPref( this.tabpanels.style.backgroundColor = Services.prefs.getCharPref(
"browser.display.use_system_colors" "browser.display.background_color"
) );
? "canvas"
: Services.prefs.getCharPref("browser.display.background_color");
} }
this._setFindbarData(); this._setFindbarData();

View File

@@ -9,16 +9,6 @@ colors-dialog2 =
colors-close-key = colors-close-key =
.key = w .key = w
colors-page-override = Override the colors specified by the page with your selections above
.accesskey = O
colors-page-override-option-always =
.label = Always
colors-page-override-option-auto =
.label = Only with High Contrast themes
colors-page-override-option-never =
.label = Never
colors-text-and-background = Text and Background colors-text-and-background = Text and Background
colors-text-header = Text colors-text-header = Text
@@ -27,10 +17,6 @@ colors-text-header = Text
colors-background = Background colors-background = Background
.accesskey = B .accesskey = B
colors-use-system =
.label = Use system colors
.accesskey = s
colors-links-header = Link Colors colors-links-header = Link Colors
colors-unvisited-links = Unvisited Links colors-unvisited-links = Unvisited Links

View File

@@ -309,9 +309,21 @@ preferences-web-appearance-override-warning2 =
# to adapt to your language, but should not be changed. # to adapt to your language, but should not be changed.
preferences-web-appearance-footer = Manage { -brand-short-name } themes in <a data-l10n-name="themes-link">Extensions & Themes</a> preferences-web-appearance-footer = Manage { -brand-short-name } themes in <a data-l10n-name="themes-link">Extensions & Themes</a>
preferences-colors-header = Colors preferences-contrast-control-header = Contrast Control
preferences-colors-description = Override { -brand-short-name }s default colors for text, website backgrounds, and links. preferences-contrast-control-description = Websites have a variety of foreground and background colors. Configure { -brand-short-name } to use the same colors across websites for improved readability.
preferences-contrast-control-use-platform-settings =
.label = Automatic (use system settings)
.accesskey = A
preferences-contrast-control-off =
.label = Off
.accesskey = O
preferences-contrast-control-custom =
.label = Custom
.accesskey = C
preferences-colors-manage-button = preferences-colors-manage-button =
.label = Manage Colors… .label = Manage Colors…

View File

@@ -15,6 +15,7 @@
#include "mozilla/mozalloc.h" #include "mozilla/mozalloc.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/ServoCSSParser.h" #include "mozilla/ServoCSSParser.h"
#include "mozilla/StaticPrefs_browser.h"
#include "mozilla/StaticPrefs_editor.h" #include "mozilla/StaticPrefs_editor.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
@@ -614,27 +615,26 @@ CSSEditUtils::RemoveCSSInlineStyleWithTransaction(
// static // static
void CSSEditUtils::GetDefaultBackgroundColor(nsAString& aColor) { void CSSEditUtils::GetDefaultBackgroundColor(nsAString& aColor) {
aColor.AssignLiteral("#ffffff"); // Default to white
if (MOZ_UNLIKELY(StaticPrefs::editor_use_custom_colors())) { if (MOZ_UNLIKELY(StaticPrefs::editor_use_custom_colors())) {
nsresult rv = Preferences::GetString("editor.background_color", aColor); DebugOnly<nsresult> rv =
Preferences::GetString("editor.background_color", aColor);
// XXX Why don't you validate the pref value? // XXX Why don't you validate the pref value?
if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
NS_WARNING("failed to get editor.background_color"); "failed to get editor.background_color");
aColor.AssignLiteral("#ffffff"); // Default to white
}
return; return;
} }
if (Preferences::GetBool("browser.display.use_system_colors", false)) { if (StaticPrefs::browser_display_document_color_use() != 2) {
return; return;
} }
nsresult rv = DebugOnly<nsresult> rv =
Preferences::GetString("browser.display.background_color", aColor); Preferences::GetString("browser.display.background_color", aColor);
// XXX Why don't you validate the pref value? // XXX Why don't you validate the pref value?
if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
NS_WARNING("failed to get browser.display.background_color"); "failed to get browser.display.background_color");
aColor.AssignLiteral("#ffffff"); // Default to white
}
} }
// static // static

View File

@@ -15,7 +15,6 @@ support-files = [
"bug1769161_4_ref.html", "bug1769161_4_ref.html",
"bug551434_childframe.html", "bug551434_childframe.html",
"chrome_content_integration_window.xhtml", "chrome_content_integration_window.xhtml",
"default_background_window.xhtml",
"dialog_with_positioning_window.xhtml", "dialog_with_positioning_window.xhtml",
"file_bug458898.html", "file_bug458898.html",
"green.png", "green.png",
@@ -135,8 +134,6 @@ support-files = [
"frame_css_visibility_propagation.html", "frame_css_visibility_propagation.html",
] ]
["test_default_background.xhtml"]
["test_dialog_with_positioning.html"] ["test_dialog_with_positioning.html"]
tags = "openwindow" tags = "openwindow"

View File

@@ -1,67 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTests()">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
<iframe type="content" id="f" src="about:blank" style="border:1px solid black;"/>
<script>
<![CDATA[
SimpleTest.waitForExplicitFinish();
var imports = [ "SimpleTest", "is", "isnot", "ok" ];
for (var name of imports) {
window[name] = window.arguments[0][name];
}
function snapshot(win) {
var el = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
el.width = win.innerWidth;
el.height = win.innerHeight;
var ctx = el.getContext("2d");
ctx.drawWindow(win, 0, 0,
win.innerWidth, win.innerHeight,
"rgba(0,0,0,0)", 0);
return el;
}
var color = '#2468AC';
var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
var backgroundPref = matchMedia('(prefers-color-scheme:dark)').matches
? 'browser.display.background_color.dark'
: 'browser.display.background_color';
prefs.setCharPref(backgroundPref, color);
// On Windows, this preference is true by default, we make it
// false to ensure we're using the color set above for our reference.
prefs.setBoolPref('browser.display.use_system_colors', false);
function runTests() {
var f = document.getElementById("f");
var testCanvas = snapshot(f.contentWindow);
prefs.clearUserPref(backgroundPref);
// Reset sys colors pref so we're using the system color for our test.
prefs.clearUserPref('browser.display.use_system_colors');
var refCanvas = snapshot(f.contentWindow);
var ctx = refCanvas.getContext('2d');
ctx.fillStyle = color;
ctx.fillRect(0, 0, refCanvas.width, refCanvas.height);
var comparison = compareSnapshots(testCanvas, refCanvas, true);
ok(comparison[0], "Rendering OK, got " + comparison[1] + ", expected " + comparison[2]);
var tester = window.SimpleTest;
window.close();
tester.finish();
}
]]>
</script>
</window>

View File

@@ -1,22 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
// Run the test in a separate window so that the test runs as a chrome
// window
window.openDialog("default_background_window.xhtml", "default_background",
"chrome,width=200,height=300,noopener", window);
]]>
</script>
</window>

View File

@@ -98,7 +98,7 @@ pref(browser.display.use_system_colors,true) pref(browser.display.document_color
!= color-mix.html color-mix-notref.html != color-mix.html color-mix-notref.html
test-pref(browser.display.background_color,"black") test-pref(browser.display.foreground_color,"white") test-pref(ui.-moz-fieldtext,"black") test-pref(ui.-moz-fieldtext.dark,"white") pref(ui.use_standins_for_native_colors,false) pref(browser.display.use_system_colors,false) == no-system-colors-color-scheme.html no-system-colors-color-scheme-ref.html test-pref(browser.display.background_color,"black") test-pref(browser.display.foreground_color,"white") test-pref(ui.-moz-fieldtext,"black") test-pref(ui.-moz-fieldtext.dark,"white") pref(ui.use_standins_for_native_colors,false) pref(browser.display.use_system_colors,false) == no-system-colors-color-scheme.html no-system-colors-color-scheme-ref.html
pref(ui.use_standins_for_native_colors,false) pref(browser.display.use_system_colors,false) pref(browser.display.background_color,"black") pref(browser.display.foreground_color,"white") == prefers-color-scheme.html prefers-color-scheme-dark.html pref(browser.display.document_color_use,2) pref(ui.use_standins_for_native_colors,false) pref(browser.display.use_system_colors,false) pref(browser.display.background_color,"black") pref(browser.display.foreground_color,"white") == prefers-color-scheme.html prefers-color-scheme-dark.html
pref(ui.use_standins_for_native_colors,false) pref(browser.display.use_system_colors,false) pref(browser.display.background_color,"white") pref(browser.display.foreground_color,"black") == prefers-color-scheme.html prefers-color-scheme-light.html pref(ui.use_standins_for_native_colors,false) pref(browser.display.use_system_colors,false) pref(browser.display.background_color,"white") pref(browser.display.foreground_color,"black") == prefers-color-scheme.html prefers-color-scheme-light.html
# Forced color adjust # Forced color adjust

View File

@@ -68,17 +68,6 @@ auto PreferenceSheet::PrefsKindFor(const Document& aDoc) -> PrefsKind {
return PrefsKind::Content; return PrefsKind::Content;
} }
static bool UseDocumentColors(bool aUseAcccessibilityTheme) {
switch (StaticPrefs::browser_display_document_color_use()) {
case 1:
return true;
case 2:
return false;
default:
return !aUseAcccessibilityTheme;
}
}
static bool UseStandinsForNativeColors() { static bool UseStandinsForNativeColors() {
return nsContentUtils::ShouldResistFingerprinting( return nsContentUtils::ShouldResistFingerprinting(
"we want to have consistent colors across the browser if RFP is " "we want to have consistent colors across the browser if RFP is "
@@ -100,52 +89,52 @@ void PreferenceSheet::Prefs::LoadColors(bool aIsLight) {
} }
const auto scheme = aIsLight ? ColorScheme::Light : ColorScheme::Dark; const auto scheme = aIsLight ? ColorScheme::Light : ColorScheme::Dark;
using ColorID = LookAndFeel::ColorID;
// Link colors might be provided by the OS, but they might not be. If they are if (!mIsChrome && (mUseDocumentColors || mUseStandins)) {
// not, then fall back to the pref colors. // Tab content not in HCM, or we need to use standins.
// auto GetStandinColor = [&scheme](ColorID aColorID, nscolor& aColor) {
// In particular, we don't query active link color to the OS. aColor = LookAndFeel::Color(aColorID, scheme,
GetColor("browser.anchor_color", scheme, colors.mLink); LookAndFeel::UseStandins::Yes, aColor);
GetColor("browser.active_color", scheme, colors.mActiveLink); };
GetColor("browser.visited_color", scheme, colors.mVisitedLink);
// Historically we've given more weight to the "use standins" setting than the GetStandinColor(ColorID::Windowtext, colors.mDefault);
// "use system colors" one. In practice most users don't use standins because GetStandinColor(ColorID::Window, colors.mDefaultBackground);
// it's hidden behind prefs. GetStandinColor(ColorID::MozNativehyperlinktext, colors.mLink);
if (mUsePrefColors && !mUseStandins) { GetStandinColor(ColorID::MozNativevisitedhyperlinktext,
colors.mVisitedLink);
// XXX: We don't have a standin for Activetext, so we fall back on the
// initial value
GetStandinColor(ColorID::Activetext, colors.mActiveLink);
} else if (!mIsChrome && mUsePrefColors) {
// Tab content with explicit browser HCM, use our prefs for colors.
GetColor("browser.display.background_color", scheme, GetColor("browser.display.background_color", scheme,
colors.mDefaultBackground); colors.mDefaultBackground);
GetColor("browser.display.foreground_color", scheme, colors.mDefault); GetColor("browser.display.foreground_color", scheme, colors.mDefault);
GetColor("browser.anchor_color", scheme, colors.mLink);
GetColor("browser.active_color", scheme, colors.mActiveLink);
GetColor("browser.visited_color", scheme, colors.mVisitedLink);
} else { } else {
using ColorID = LookAndFeel::ColorID; // Browser UI or OS HCM, use system colors.
const auto standins = LookAndFeel::UseStandins(mUseStandins); auto GetSystemColor = [&scheme](ColorID aColorID, nscolor& aColor) {
colors.mDefault = LookAndFeel::Color(ColorID::Windowtext, scheme, standins, aColor = LookAndFeel::Color(aColorID, scheme,
colors.mDefault); LookAndFeel::UseStandins::No, aColor);
colors.mDefaultBackground = LookAndFeel::Color( };
ColorID::Window, scheme, standins, colors.mDefaultBackground);
colors.mLink = LookAndFeel::Color(ColorID::MozNativehyperlinktext, scheme,
standins, colors.mLink);
if (auto color = LookAndFeel::GetColor( GetSystemColor(ColorID::Windowtext, colors.mDefault);
ColorID::MozNativevisitedhyperlinktext, scheme, standins)) { GetSystemColor(ColorID::Window, colors.mDefaultBackground);
// If the system provides a visited link color, we should use it. GetSystemColor(ColorID::MozNativehyperlinktext, colors.mLink);
colors.mVisitedLink = *color; // The fallback visited link color on HCM (if the system doesn't provide
} else if (mUseAccessibilityTheme) { // one) is produced by preserving the foreground's green and averaging
// The fallback visited link color on HCM (if the system doesn't provide // the foreground and background for the red and blue. This is how IE
// one) is produced by preserving the foreground's green and averaging the // and Edge do it too.
// foreground and background for the red and blue. This is how IE and colors.mVisitedLink = NS_RGB(
// Edge do it too. AVG2(NS_GET_R(colors.mDefault), NS_GET_R(colors.mDefaultBackground)),
colors.mVisitedLink = NS_RGB( NS_GET_G(colors.mDefault),
AVG2(NS_GET_R(colors.mDefault), NS_GET_R(colors.mDefaultBackground)), AVG2(NS_GET_B(colors.mDefault), NS_GET_B(colors.mDefaultBackground)));
NS_GET_G(colors.mDefault), GetSystemColor(ColorID::MozNativevisitedhyperlinktext, colors.mVisitedLink);
AVG2(NS_GET_B(colors.mDefault), NS_GET_B(colors.mDefaultBackground)));
} else {
// Otherwise we keep the default visited link color
}
if (mUseAccessibilityTheme) { colors.mActiveLink = colors.mLink;
colors.mActiveLink = colors.mLink;
}
} }
// Wherever we got the default background color from, ensure it is opaque. // Wherever we got the default background color from, ensure it is opaque.
@@ -192,8 +181,23 @@ void PreferenceSheet::Prefs::Load(bool aIsChrome) {
LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme); LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme);
// Chrome documents always use system colors, not stand-ins, not forced, etc. // Chrome documents always use system colors, not stand-ins, not forced, etc.
if (!aIsChrome) { if (!aIsChrome) {
mUseDocumentColors = UseDocumentColors(mUseAccessibilityTheme); switch (StaticPrefs::browser_display_document_color_use()) {
mUsePrefColors = !StaticPrefs::browser_display_use_system_colors(); case 1:
// Never High Contrast
mUsePrefColors = false;
mUseDocumentColors = true;
break;
case 2:
// Always High Contrast
mUsePrefColors = true;
mUseDocumentColors = false;
break;
default:
// Only with OS HCM
mUsePrefColors = false;
mUseDocumentColors = !mUseAccessibilityTheme;
break;
}
mUseStandins = UseStandinsForNativeColors(); mUseStandins = UseStandinsForNativeColors();
} }
@@ -310,8 +314,6 @@ void PreferenceSheet::Initialize() {
} }
glean::a11y::backplate.Set(StaticPrefs::browser_display_permit_backplate()); glean::a11y::backplate.Set(StaticPrefs::browser_display_permit_backplate());
glean::a11y::use_system_colors.Set(
StaticPrefs::browser_display_use_system_colors());
glean::a11y::always_underline_links.Set( glean::a11y::always_underline_links.Set(
StaticPrefs::layout_css_always_underline_links()); StaticPrefs::layout_css_always_underline_links());
} }

View File

@@ -52,15 +52,6 @@ add_task(async function test() {
info("Pref action: " + handlerInfo.preferredAction); info("Pref action: " + handlerInfo.preferredAction);
await SpecialPowers.pushPrefEnv({
set: [
["browser.display.document_color_use", 0],
["browser.display.background_color", "#ff0000"],
["browser.display.foreground_color", "#00ff00"],
["browser.display.use_system_colors", false],
],
});
await BrowserTestUtils.withNewTab( await BrowserTestUtils.withNewTab(
{ gBrowser, url: "about:blank" }, { gBrowser, url: "about:blank" },
async function (browser) { async function (browser) {
@@ -81,9 +72,13 @@ add_task(async function test() {
} }
); );
// Enable HCM. // Force on custom HCM.
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [["ui.useAccessibilityTheme", 1]], set: [
["browser.display.background_color", "#ff0000"],
["browser.display.foreground_color", "#00ff00"],
["browser.display.document_color_use", 2],
],
}); });
await BrowserTestUtils.withNewTab( await BrowserTestUtils.withNewTab(