Skip to content

Commit

Permalink
Bug 1869271 - Use known foreground when accent-color matches the exis…
Browse files Browse the repository at this point in the history
…ting AccentColor. r=mstange

Allowing to use two colors for accent-color would be IMO a better
solution, but it was rejected by the working group, see
w3c/csswg-drafts#6159. Maybe we should make
the second color optional?

Anyways, this seems reasonable, and avoids weird behavior differences
between accent-color: AccentColor and other things...

Differential Revision: https://phabricator.services.mozilla.com/D196039
  • Loading branch information
emilio committed Dec 11, 2023
1 parent 7ce51c5 commit 3e26db3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!doctype html>
<input type=checkbox checked>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!doctype html>
<input type=checkbox checked style="accent-color: AccentColor">
2 changes: 2 additions & 0 deletions layout/reftests/forms/input/checkbox/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
== checkbox-clamp-01.html checkbox-clamp-01-ref.html
== checkbox-clamp-02.html checkbox-clamp-02-ref.html
!= checkbox-minimum-size.html checkbox-minimum-size-notref.html

pref(ui.accentcolor,"#3daee9") pref("ui.accentcolortext","white") == accent-color-accentcolor.html accent-color-accentcolor-ref.html
20 changes: 12 additions & 8 deletions widget/ThemeColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,20 @@ ColorPalette::ColorPalette(nscolor aAccent, nscolor aForeground) {
}

ThemeAccentColor::ThemeAccentColor(const ComputedStyle& aStyle,
ColorScheme aScheme) {
ColorScheme aScheme)
: mDefaultPalette(aScheme == ColorScheme::Light ? &sDefaultLightPalette
: &sDefaultDarkPalette) {
const auto& color = aStyle.StyleUI()->mAccentColor;
if (color.IsColor()) {
mAccentColor.emplace(
ColorPalette::EnsureOpaque(color.AsColor().CalcColor(aStyle)));
} else {
MOZ_ASSERT(color.IsAuto());
mDefaultPalette = aScheme == ColorScheme::Light ? &sDefaultLightPalette
: &sDefaultDarkPalette;
if (color.IsAuto()) {
return;
}
MOZ_ASSERT(color.IsColor());
nscolor accentColor =
ColorPalette::EnsureOpaque(color.AsColor().CalcColor(aStyle));
if (sRGBColor::FromABGR(accentColor) == mDefaultPalette->mAccent) {
return;
}
mAccentColor.emplace(accentColor);
}

sRGBColor ThemeAccentColor::Get() const {
Expand Down

0 comments on commit 3e26db3

Please sign in to comment.