From d96854eeb1372069f1af16409724b05298435a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 11 Feb 2021 16:36:54 +0000 Subject: [PATCH] Bug 1691781 - Make Linux tab bar use the darker of the highlight / highlighttext colors. r=dao Some GTK themes use very soft colors for selection backgrounds, using darker colors for the text. This makes the tab and focus outlines in the tab bar not have sufficient contrast with usual backgrounds. I needed to do this for bug 1690778, but it seems worth doing it on the front-end as well. Differential Revision: https://phabricator.services.mozilla.com/D104547 --- browser/themes/linux/browser.css | 2 +- browser/themes/shared/urlbar-searchbar.inc.css | 2 +- servo/components/style/values/specified/color.rs | 8 ++++++++ widget/android/nsLookAndFeel.cpp | 2 ++ widget/cocoa/nsLookAndFeel.mm | 2 ++ widget/gtk/nsLookAndFeel.cpp | 14 ++++++++++++++ widget/gtk/nsLookAndFeel.h | 2 ++ widget/nsNativeBasicTheme.cpp | 10 ++++------ widget/nsXPLookAndFeel.cpp | 2 ++ widget/windows/nsLookAndFeel.cpp | 2 ++ 10 files changed, 38 insertions(+), 8 deletions(-) diff --git a/browser/themes/linux/browser.css b/browser/themes/linux/browser.css index 34cf9673b766..cbe544287d27 100644 --- a/browser/themes/linux/browser.css +++ b/browser/themes/linux/browser.css @@ -32,7 +32,7 @@ } #tabbrowser-tabs { - --tab-line-color: highlight; + --tab-line-color: -moz-accent-color; } :root:-moz-lwtheme { diff --git a/browser/themes/shared/urlbar-searchbar.inc.css b/browser/themes/shared/urlbar-searchbar.inc.css index 04e13b1548a0..02e8255b34d4 100644 --- a/browser/themes/shared/urlbar-searchbar.inc.css +++ b/browser/themes/shared/urlbar-searchbar.inc.css @@ -10,7 +10,7 @@ %define urlbarSearchButtonWidth calc(16px + 2 * @identityBoxPaddingInline@) :root { - --toolbar-field-focus-border-color: Highlight; + --toolbar-field-focus-border-color: -moz-accent-color; /* 28x28 box - 16x16 image = 12x12 padding, 6 on each side */ --urlbar-icon-padding: 6px; diff --git a/servo/components/style/values/specified/color.rs b/servo/components/style/values/specified/color.rs index e44568fb5bf5..e64910496195 100644 --- a/servo/components/style/values/specified/color.rs +++ b/servo/components/style/values/specified/color.rs @@ -227,6 +227,14 @@ pub enum SystemColor { MozMacActiveSourceListSelection, MozMacTooltip, + /// Theme accent color. + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] + MozAccentColor, + + /// Foreground for the accent color. + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] + MozAccentColorForeground, + /// Accent color for title bar. MozWinAccentcolor, /// Color from drawing text over the accent color. diff --git a/widget/android/nsLookAndFeel.cpp b/widget/android/nsLookAndFeel.cpp index b6dec95a9bbd..c9bb3d8b7b62 100644 --- a/widget/android/nsLookAndFeel.cpp +++ b/widget/android/nsLookAndFeel.cpp @@ -195,12 +195,14 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) { case ColorID::MozCellhighlight: case ColorID::MozHtmlCellhighlight: case ColorID::Highlight: + case ColorID::MozAccentColor: // background of selected item aColor = NS_RGB(0xfa, 0xd1, 0x84); break; case ColorID::MozCellhighlighttext: case ColorID::MozHtmlCellhighlighttext: case ColorID::Highlighttext: + case ColorID::MozAccentColorForeground: case ColorID::Fieldtext: aColor = NS_RGB(0x1a, 0x1a, 0x1a); break; diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index a8d6fcf4f677..916fc3e47466 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -191,6 +191,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) { aColor = ProcessSelectionBackground(mColorTextSelectBackgroundDisabled); break; case ColorID::Highlight: // CSS2 color + case ColorID::MozAccentColor: aColor = mColorHighlight; break; case ColorID::MozMenuhover: @@ -200,6 +201,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) { aColor = mColorTextSelectForeground; break; case ColorID::Highlighttext: // CSS2 color + case ColorID::MozAccentColorForeground: case ColorID::MozMenuhovertext: aColor = mColorMenuHoverText; break; diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index def91c85944b..db1bdd05979e 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -385,6 +385,12 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) { case ColorID::Highlight: // preference selected item, aColor = mTextSelectedBackground; break; + case ColorID::MozAccentColor: + aColor = mAccentColor; + break; + case ColorID::MozAccentColorForeground: + aColor = mAccentColorForeground; + break; case ColorID::WidgetSelectForeground: case ColorID::TextSelectForeground: case ColorID::IMESelectedRawTextForeground: @@ -1298,6 +1304,14 @@ void nsLookAndFeel::EnsureInit() { // fall back to the regular text view style. GrabSelectionColors(style); } + + // Accent is the darker of the selection background / foreground. + mAccentColor = mTextSelectedBackground; + mAccentColorForeground = mTextSelectedText; + if (RelativeLuminanceUtils::Compute(mAccentColor) > + RelativeLuminanceUtils::Compute(mAccentColorForeground)) { + std::exchange(mAccentColor, mAccentColorForeground); + } } // Button text color diff --git a/widget/gtk/nsLookAndFeel.h b/widget/gtk/nsLookAndFeel.h index c8e4ec83b1c1..90ae7166d426 100644 --- a/widget/gtk/nsLookAndFeel.h +++ b/widget/gtk/nsLookAndFeel.h @@ -92,6 +92,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel { nscolor mMozCellHighlightText = kBlack; nscolor mTextSelectedText = kBlack; nscolor mTextSelectedBackground = kWhite; + nscolor mAccentColor = kWhite; + nscolor mAccentColorForeground = kWhite; nscolor mMozScrollbar = kWhite; nscolor mInfoBarText = kBlack; nscolor mMozColHeaderText = kBlack; diff --git a/widget/nsNativeBasicTheme.cpp b/widget/nsNativeBasicTheme.cpp index 8c4cfc72e76b..9f41e1ecb7c7 100644 --- a/widget/nsNativeBasicTheme.cpp +++ b/widget/nsNativeBasicTheme.cpp @@ -67,13 +67,11 @@ static LayoutDeviceIntCoord SnapBorderWidth( return aLuminance >= 0.18f ? aLuminance * aFactor : aLuminance / aFactor; } -static nscolor ThemedAccentColor(bool aDarker) { +static nscolor ThemedAccentColor(bool aBackground) { MOZ_ASSERT(StaticPrefs::widget_non_native_use_theme_accent()); - nscolor a = LookAndFeel::GetColor(LookAndFeel::ColorID::Highlight); - nscolor b = LookAndFeel::GetColor(LookAndFeel::ColorID::Highlighttext); - const bool darker = - RelativeLuminanceUtils::Compute(b) > RelativeLuminanceUtils::Compute(a); - nscolor color = darker == aDarker ? a : b; + nscolor color = LookAndFeel::GetColor( + aBackground ? LookAndFeel::ColorID::MozAccentColor + : LookAndFeel::ColorID::MozAccentColorForeground); if (NS_GET_A(color) != 0xff) { // Blend with white, ensuring the color is opaque to avoid surprises if we // overdraw. diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index 6ad7bab3dd41..0d5fc0ce156c 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -227,6 +227,8 @@ const char nsXPLookAndFeel::sColorPrefs[][41] = { "ui.-moz-mac-source-list-selection", "ui.-moz-mac-active-source-list-selection", "ui.-moz-mac-tooltip", + "ui.-moz-accent-color", + "ui.-moz-accent-color-foreground", "ui.-moz-win-accentcolor", "ui.-moz-win-accentcolortext", "ui.-moz-win-mediatext", diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 4b7b73272773..6289c0fc17b7 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -226,6 +226,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) { idx = COLOR_GRAYTEXT; break; case ColorID::Highlight: + case ColorID::MozAccentColor: case ColorID::MozHtmlCellhighlight: case ColorID::MozMenuhover: idx = COLOR_HIGHLIGHT; @@ -244,6 +245,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) { } // Fall through case ColorID::Highlighttext: + case ColorID::MozAccentColorForeground: case ColorID::MozHtmlCellhighlighttext: idx = COLOR_HIGHLIGHTTEXT; break;