mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-11 22:41:02 +00:00
Bug 1701825 - Allow passing some colors from GTK even in dark themes. r=stransky
Selection and accent color should be uncontroversial, since we ensure the darker variant goes in the background, and the scrollbars were intended to get passed from the parent theme in bug 1669368, but it was regressed by the initial RemoteLookAndFeel work. Differential Revision: https://phabricator.services.mozilla.com/D110175
This commit is contained in:
parent
9238b03fbe
commit
b0cf81da8b
@ -10938,6 +10938,27 @@
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether selection colors get passed from the real GTK theme even if
|
||||
# allow-gtk-dark-theme is false.
|
||||
- name: widget.content.allow-gtk-dark-theme.selection
|
||||
type: bool
|
||||
value: true
|
||||
mirror: always
|
||||
|
||||
# Whether form control accent colors get passed from the real GTK theme even if
|
||||
# allow-gtk-dark-theme is false.
|
||||
- name: widget.content.allow-gtk-dark-theme.accent
|
||||
type: bool
|
||||
value: true
|
||||
mirror: always
|
||||
|
||||
# Whether scrollbars colors get passed from the real GTK theme even if
|
||||
# allow-gtk-dark-theme is false.
|
||||
- name: widget.content.allow-gtk-dark-theme.scrollbars
|
||||
type: bool
|
||||
value: true
|
||||
mirror: always
|
||||
|
||||
# Whether to use gtk high contrast themes to disable content styling like on
|
||||
# windows high contrast mode.
|
||||
- name: widget.content.gtk-high-contrast.enabled
|
||||
|
@ -154,18 +154,22 @@ static bool AddIDsToMap(nsXPLookAndFeel* aImpl, FullLookAndFeel* aLf,
|
||||
NS_SUCCEEDED(rv) ? Some(theInt) : Nothing{});
|
||||
}
|
||||
|
||||
// The rest of IDs only come from the child content theme.
|
||||
if (aFromParentTheme) {
|
||||
return anyFromOtherTheme;
|
||||
}
|
||||
|
||||
for (auto id : MakeEnumeratedRange(ColorID::End)) {
|
||||
if (aDifferentTheme && aImpl->FromParentTheme(id) != aFromParentTheme) {
|
||||
anyFromOtherTheme = true;
|
||||
continue;
|
||||
}
|
||||
nscolor theColor;
|
||||
nsresult rv = aImpl->NativeGetColor(id, theColor);
|
||||
AddToMap(aLf->tables().colors(), aLf->tables().colorMap(), id,
|
||||
NS_SUCCEEDED(rv) ? Some(theColor) : Nothing{});
|
||||
}
|
||||
|
||||
// The rest of IDs only come from the child content theme.
|
||||
if (aFromParentTheme) {
|
||||
return anyFromOtherTheme;
|
||||
}
|
||||
|
||||
for (auto id : MakeEnumeratedRange(FloatID::End)) {
|
||||
float theFloat;
|
||||
nsresult rv = aImpl->NativeGetFloat(id, theFloat);
|
||||
|
@ -347,11 +347,52 @@ void nsLookAndFeel::DoSetCache(const LookAndFeelCache& aCache) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsSelectionColorForeground(LookAndFeel::ColorID aID) {
|
||||
using ColorID = LookAndFeel::ColorID;
|
||||
switch (aID) {
|
||||
case ColorID::WidgetSelectForeground:
|
||||
case ColorID::TextSelectForeground:
|
||||
case ColorID::IMESelectedRawTextForeground:
|
||||
case ColorID::IMESelectedConvertedTextForeground:
|
||||
case ColorID::Highlighttext:
|
||||
case ColorID::MozHtmlCellhighlighttext:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsSelectionColorBackground(LookAndFeel::ColorID aID) {
|
||||
using ColorID = LookAndFeel::ColorID;
|
||||
switch (aID) {
|
||||
case ColorID::WidgetSelectBackground:
|
||||
case ColorID::TextSelectBackground:
|
||||
case ColorID::IMESelectedRawTextBackground:
|
||||
case ColorID::IMESelectedConvertedTextBackground:
|
||||
case ColorID::MozDragtargetzone:
|
||||
case ColorID::MozHtmlCellhighlight:
|
||||
case ColorID::Highlight:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
||||
EnsureInit();
|
||||
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (IsSelectionColorBackground(aID)) {
|
||||
aColor = mTextSelectedBackground;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (IsSelectionColorForeground(aID)) {
|
||||
aColor = mTextSelectedText;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
switch (aID) {
|
||||
// These colors don't seem to be used for anything anymore in Mozilla
|
||||
// (except here at least TextSelectBackground and TextSelectForeground)
|
||||
@ -392,14 +433,6 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
||||
case ColorID::MozAccentColorForeground:
|
||||
aColor = mAccentColorForeground;
|
||||
break;
|
||||
case ColorID::WidgetSelectForeground:
|
||||
case ColorID::TextSelectForeground:
|
||||
case ColorID::IMESelectedRawTextForeground:
|
||||
case ColorID::IMESelectedConvertedTextForeground:
|
||||
case ColorID::Highlighttext:
|
||||
case ColorID::MozHtmlCellhighlighttext:
|
||||
aColor = mTextSelectedText;
|
||||
break;
|
||||
case ColorID::MozCellhighlight:
|
||||
aColor = mMozCellHighlightBackground;
|
||||
break;
|
||||
@ -895,7 +928,7 @@ static void GetSystemFontInfo(GtkStyleContext* aStyle, nsString* aFontName,
|
||||
bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) {
|
||||
switch (aID) {
|
||||
case FontID::Menu: // css2
|
||||
case FontID::Menu: // css2
|
||||
case FontID::MozPullDownMenu: // css3
|
||||
aFontName = mMenuFontName;
|
||||
aFontStyle = mMenuFontStyle;
|
||||
@ -1082,6 +1115,26 @@ bool nsLookAndFeel::FromParentTheme(IntID aID) {
|
||||
}
|
||||
}
|
||||
|
||||
bool nsLookAndFeel::FromParentTheme(ColorID aID) {
|
||||
if (IsSelectionColorBackground(aID) || IsSelectionColorForeground(aID)) {
|
||||
return StaticPrefs::widget_content_allow_gtk_dark_theme_selection();
|
||||
}
|
||||
switch (aID) {
|
||||
case ColorID::ThemedScrollbar:
|
||||
case ColorID::ThemedScrollbarInactive:
|
||||
case ColorID::ThemedScrollbarThumb:
|
||||
case ColorID::ThemedScrollbarThumbHover:
|
||||
case ColorID::ThemedScrollbarThumbActive:
|
||||
case ColorID::ThemedScrollbarThumbInactive:
|
||||
return StaticPrefs::widget_content_allow_gtk_dark_theme_scrollbars();
|
||||
case ColorID::MozAccentColor:
|
||||
case ColorID::MozAccentColorForeground:
|
||||
return StaticPrefs::widget_content_allow_gtk_dark_theme_accent();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool nsLookAndFeel::ConfigureContentGtkTheme() {
|
||||
bool changed = false;
|
||||
|
||||
@ -1345,9 +1398,10 @@ void nsLookAndFeel::EnsureInit() {
|
||||
GrabSelectionColors(style);
|
||||
}
|
||||
|
||||
// Accent is the darker of the selection background / foreground.
|
||||
mAccentColor = mTextSelectedBackground;
|
||||
mAccentColorForeground = mTextSelectedText;
|
||||
|
||||
// Accent is the darker of the selection background / foreground.
|
||||
if (RelativeLuminanceUtils::Compute(mAccentColor) >
|
||||
RelativeLuminanceUtils::Compute(mAccentColorForeground)) {
|
||||
std::swap(mAccentColor, mAccentColorForeground);
|
||||
|
@ -38,6 +38,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
||||
void WithThemeConfiguredForContent(
|
||||
const std::function<void(const LookAndFeelTheme&, bool)>& aFn) override;
|
||||
bool FromParentTheme(IntID) override;
|
||||
bool FromParentTheme(ColorID) override;
|
||||
|
||||
static void ConfigureTheme(const LookAndFeelTheme& aTheme);
|
||||
|
||||
|
@ -80,6 +80,12 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
|
||||
"theme");
|
||||
return false;
|
||||
}
|
||||
virtual bool FromParentTheme(ColorID) {
|
||||
MOZ_ASSERT_UNREACHABLE(
|
||||
"Should override if WithThemeConfiguredForContent can change the "
|
||||
"theme");
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsXPLookAndFeel() = default;
|
||||
|
Loading…
x
Reference in New Issue
Block a user