Bug 1698272 - Respect system colors in the color and background-color properties. r=morgan

The reason why this doesn't work is because these styles come from
datetimebox.css, which is really an author style.

We could special-case these elements, but the approach that the CSSWG resolved
on for the new forced-colors spec is to respect system colors specified by
authors, see:

https://drafts.csswg.org/css-color-adjust-1/#forced-colors-properties

So this moves us towards that, and fixes the issue nicely.

Differential Revision: https://phabricator.services.mozilla.com/D108321
This commit is contained in:
Emilio Cobos Alvarez 2021-03-16 20:09:56 +00:00
Родитель 8f5950e5be
Коммит 8ebccdd08d
5 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -85,3 +85,5 @@ test-pref(browser.display.document_color_use,0) == forced-colors-002.html prefer
# boolean context
== forced-colors-001.html prefers-contrast-black-ref.html
test-pref(browser.display.document_color_use,0) != forced-colors-001.html prefers-contrast-black-ref.html
!= system-colors.html system-colors-notref.html

Просмотреть файл

@ -0,0 +1,2 @@
<!doctype html>
<div>ABC</div>

Просмотреть файл

@ -0,0 +1,2 @@
<!doctype html>
<div style="background-color: highlight; color: highlighttext;">ABC</div>

Просмотреть файл

@ -423,6 +423,10 @@ fn tweak_when_ignoring_colors(
// A few special-cases ahead.
match **declaration {
PropertyDeclaration::BackgroundColor(ref color) => {
// We honor system colors.
if color.is_system() {
return;
}
// For background-color, we revert or initial-with-preserved-alpha
// otherwise, this is needed to preserve semi-transparent
// backgrounds.
@ -440,7 +444,10 @@ fn tweak_when_ignoring_colors(
}
},
PropertyDeclaration::Color(ref color) => {
// We honor color: transparent, and "revert-or-initial" otherwise.
// We honor color: transparent and system colors.
if color.0.is_system() {
return;
}
if alpha_channel(&color.0, context) == 0 {
return;
}

Просмотреть файл

@ -549,6 +549,11 @@ fn parse_hash_color(value: &[u8]) -> Result<RGBA, ()> {
}
impl Color {
/// Returns whether this color is a system color.
pub fn is_system(&self) -> bool {
matches!(self, Color::System(..))
}
/// Returns currentcolor value.
#[inline]
pub fn currentcolor() -> Color {