Skip to content

Commit

Permalink
Bug 1665317 - Fall back to regular text colors if the selection node …
Browse files Browse the repository at this point in the history
…doesn't work out. r=stransky

This fixes selection colors in some old distros.

Differential Revision: https://phabricator.services.mozilla.com/D90386
  • Loading branch information
emilio committed Sep 16, 2020
1 parent e1d5250 commit 8429f37
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions widget/gtk/nsLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,19 +1125,30 @@ void nsLookAndFeel::EnsureInit() {
mFieldText = GDK_RGBA_TO_NS_RGBA(color);

// Selected text and background
style = GetStyleContext(MOZ_GTK_TEXT_VIEW_TEXT_SELECTION);
gtk_style_context_get_background_color(
style,
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED |
GTK_STATE_FLAG_SELECTED),
&color);
mTextSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_get_color(
style,
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED |
GTK_STATE_FLAG_SELECTED),
&color);
mTextSelectedText = GDK_RGBA_TO_NS_RGBA(color);
{
GtkStyleContext* selectionStyle =
GetStyleContext(MOZ_GTK_TEXT_VIEW_TEXT_SELECTION);
auto GrabSelectionColors = [&](GtkStyleContext* style) {
gtk_style_context_get_background_color(
style,
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED |
GTK_STATE_FLAG_SELECTED),
&color);
mTextSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_get_color(
style,
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED |
GTK_STATE_FLAG_SELECTED),
&color);
mTextSelectedText = GDK_RGBA_TO_NS_RGBA(color);
};
GrabSelectionColors(selectionStyle);
if (mTextSelectedBackground == mTextSelectedText) {
// Some old distros/themes don't properly use the .selection style, so
// fall back to the regular text view style.
GrabSelectionColors(style);
}
}

// Button text color
style = GetStyleContext(MOZ_GTK_BUTTON);
Expand Down

0 comments on commit 8429f37

Please sign in to comment.