зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1691793 - set prefers-contrast to more when accessibilityDisplayShouldIncreaseContrast setting is set to true. r=morgan
Differential Revision: https://phabricator.services.mozilla.com/D104562
This commit is contained in:
Родитель
9a0eedc087
Коммит
8eb52b667b
|
@ -280,12 +280,6 @@ StyleContrastPref Gecko_MediaFeatures_PrefersContrast(
|
|||
// Neither Linux, Windows, nor Mac have a way to indicate that low
|
||||
// contrast is prefered so the presence of an accessibility theme
|
||||
// implies that high contrast is prefered.
|
||||
//
|
||||
// Note that MacOS does not expose whether or not high contrast is
|
||||
// enabled so for MacOS users this will always evaluate to
|
||||
// false. For more information and discussion see:
|
||||
// https://github.com/w3c/csswg-drafts/issues/3856#issuecomment-642313572
|
||||
// https://github.com/w3c/csswg-drafts/issues/2943
|
||||
if (!!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
|
||||
return StyleContrastPref::More;
|
||||
}
|
||||
|
|
|
@ -284,6 +284,8 @@ skip-if = xorigin # Crashes, Assertion failure: mInFlightProcessId == 0, at /bui
|
|||
support-files = mq_changes_child.html
|
||||
run-if = !headless && (os == 'mac' || toolkit == 'android' || toolkit == 'gtk')
|
||||
[test_mq_hover_and_pointer.html]
|
||||
[test_mq_prefers_contrast_dynamic.html]
|
||||
run-if = !headless && (os == 'mac' || toolkit == 'android' || toolkit == 'gtk')
|
||||
[test_mq_prefers_reduced_motion_dynamic.html]
|
||||
run-if = !headless && (os == 'mac' || toolkit == 'android' || toolkit == 'gtk')
|
||||
[test_moz_device_pixel_ratio.html]
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1691793
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1691793</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1691793">Mozilla Bug 1691793</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
SimpleTest.registerCleanupFunction(async () => {
|
||||
await SpecialPowers.flushPrefEnv();
|
||||
});
|
||||
|
||||
// Returns a Promise which will be resolved when the "change" event is received
|
||||
// for the given media query string.
|
||||
function promiseForChange(mediaQuery) {
|
||||
return new Promise(resolve => {
|
||||
window.matchMedia(mediaQuery).addEventListener("change", event => {
|
||||
resolve(event.matches);
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async () => {
|
||||
await SpecialPowers.pushPrefEnv({ set: [["layout.css.prefers-contrast.enabled", true]]});
|
||||
const initiallyMatches =
|
||||
window.matchMedia("(prefers-contrast: more)").matches;
|
||||
const changePromise = initiallyMatches ?
|
||||
promiseForChange("(prefers-contrast: more)") : null;
|
||||
await SpecialPowers.pushPrefEnv({ set: [["ui.useAccessibilityTheme", 0]]});
|
||||
|
||||
if (changePromise) {
|
||||
await changePromise;
|
||||
}
|
||||
|
||||
ok(!window.matchMedia("(prefers-contrast: more)").matches,
|
||||
"Does not match prefers-contrast: more) when the system unsets " +
|
||||
"UseAccessibilityTheme");
|
||||
ok(!window.matchMedia("(prefers-contrast)").matches,
|
||||
"Does not match (prefers-contrast) when the system unsets " +
|
||||
"UseAccessibilityTheme");
|
||||
ok(window.matchMedia("(prefers-contrast: no-preference)").matches,
|
||||
"Matches (prefers-contrast: no-preference) when the system unsets " +
|
||||
"UseAccessibilityTheme");
|
||||
});
|
||||
|
||||
add_task(async () => {
|
||||
const more = promiseForChange("(prefers-contrast: more)");
|
||||
const booleanContext = promiseForChange("(prefers-contrast)");
|
||||
const noPreference = promiseForChange("(prefers-contrast: no-preference)");
|
||||
|
||||
await SpecialPowers.pushPrefEnv({ set: [["ui.useAccessibilityTheme", 1]]});
|
||||
|
||||
const [ moreResult, booleanContextResult, noPreferenceResult ] =
|
||||
await Promise.all([ more, booleanContext, noPreference ]);
|
||||
|
||||
ok(moreResult,
|
||||
"Matches (prefers-contrast: more) when the system sets " +
|
||||
"UseAccessibilityTheme");
|
||||
ok(booleanContextResult,
|
||||
"Matches (prefers-contrast) when the system sets UseAccessibilityTheme");
|
||||
ok(!noPreferenceResult,
|
||||
"Does not match (prefers-contrast: no-preference) when the " +
|
||||
"system sets UseAccessibilityTheme");
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -50,6 +50,9 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
int32_t mPrefersReducedMotion = -1;
|
||||
bool mPrefersReducedMotionCached = false;
|
||||
|
||||
int32_t mUseAccessibilityTheme;
|
||||
bool mUseAccessibilityThemeCached;
|
||||
|
||||
nscolor mColorTextSelectBackground;
|
||||
nscolor mColorTextSelectBackgroundDisabled;
|
||||
nscolor mColorHighlight;
|
||||
|
|
|
@ -69,6 +69,8 @@ nsLookAndFeel::nsLookAndFeel(const LookAndFeelCache* aCache)
|
|||
mColorEvenTreeRow(0),
|
||||
mColorOddTreeRow(0),
|
||||
mColorActiveSourceListSelection(0),
|
||||
mUseAccessibilityTheme(-1),
|
||||
mUseAccessibilityThemeCached(false),
|
||||
mInitialized(false) {
|
||||
if (aCache) {
|
||||
DoSetCache(*aCache);
|
||||
|
@ -105,6 +107,7 @@ void nsLookAndFeel::RefreshImpl() {
|
|||
mAllowOverlayScrollbarsOverlapCached = false;
|
||||
mPrefersReducedMotionCached = false;
|
||||
mSystemUsesDarkThemeCached = false;
|
||||
mUseAccessibilityThemeCached = false;
|
||||
}
|
||||
|
||||
// Fetch colors next time they are requested.
|
||||
|
@ -585,6 +588,21 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
|
|||
}
|
||||
aResult = mPrefersReducedMotion;
|
||||
break;
|
||||
case IntID::UseAccessibilityTheme:
|
||||
// Without native event loops,
|
||||
// NSWorkspace.accessibilityDisplayShouldIncreaseContrast returns stale
|
||||
// information, so we get the information only on the parent processes
|
||||
// or when it's the initial query on child processes. Otherwise we will
|
||||
// get the info via LookAndFeel::SetIntCache on child processes.
|
||||
if (!mUseAccessibilityThemeCached &&
|
||||
[[NSWorkspace sharedWorkspace]
|
||||
respondsToSelector:@selector(accessibilityDisplayShouldIncreaseContrast)]) {
|
||||
mUseAccessibilityTheme =
|
||||
[[NSWorkspace sharedWorkspace] accessibilityDisplayShouldIncreaseContrast] ? 1 : 0;
|
||||
mUseAccessibilityThemeCached = true;
|
||||
}
|
||||
aResult = mUseAccessibilityTheme;
|
||||
break;
|
||||
default:
|
||||
aResult = 0;
|
||||
res = NS_ERROR_FAILURE;
|
||||
|
@ -669,6 +687,11 @@ mozilla::widget::LookAndFeelCache nsLookAndFeel::GetCacheImpl() {
|
|||
prefersReducedMotion.value() = GetInt(IntID::PrefersReducedMotion);
|
||||
cache.mInts().AppendElement(prefersReducedMotion);
|
||||
|
||||
LookAndFeelInt useAccessibilityTheme;
|
||||
useAccessibilityTheme.id() = IntID::UseAccessibilityTheme;
|
||||
useAccessibilityTheme.value() = GetInt(IntID::UseAccessibilityTheme);
|
||||
cache.mInts().AppendElement(useAccessibilityTheme);
|
||||
|
||||
LookAndFeelInt systemUsesDarkTheme;
|
||||
systemUsesDarkTheme.id() = IntID::SystemUsesDarkTheme;
|
||||
systemUsesDarkTheme.value() = GetInt(IntID::SystemUsesDarkTheme);
|
||||
|
@ -698,6 +721,10 @@ void nsLookAndFeel::DoSetCache(const LookAndFeelCache& aCache) {
|
|||
mPrefersReducedMotion = entry.value();
|
||||
mPrefersReducedMotionCached = true;
|
||||
break;
|
||||
case IntID::UseAccessibilityTheme:
|
||||
mUseAccessibilityTheme = entry.value();
|
||||
mUseAccessibilityThemeCached = true;
|
||||
break;
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Bogus Int ID in cache");
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче