Bug 1073117 - [gtk3] Use GTK_STYLE_CLASS_VIEW style for selected text rendering. r=karlt

It also merges some duplicated colors and adds GTK_STATE_FLAG_FOCUSED for selected text.
This commit is contained in:
Martin Stransky 2014-12-08 01:35:00 -05:00
parent 81e1b1a96e
commit 0504bfc33a
2 changed files with 26 additions and 47 deletions

View File

@ -38,7 +38,6 @@ nsLookAndFeel::nsLookAndFeel()
mStyle(nullptr),
#else
mBackgroundStyle(nullptr),
mViewStyle(nullptr),
mButtonStyle(nullptr),
#endif
mDefaultFontCached(false), mButtonFontCached(false),
@ -53,7 +52,6 @@ nsLookAndFeel::~nsLookAndFeel()
g_object_unref(mStyle);
#else
g_object_unref(mBackgroundStyle);
g_object_unref(mViewStyle);
g_object_unref(mButtonStyle);
#endif
}
@ -114,13 +112,19 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
case eColorID_IMESelectedRawTextBackground:
case eColorID_IMESelectedConvertedTextBackground:
case eColorID__moz_dragtargetzone:
aColor = sMozWindowSelectedBackground;
case eColorID__moz_cellhighlight:
case eColorID__moz_html_cellhighlight:
case eColorID_highlight: // preference selected item,
aColor = sTextSelectedBackground;
break;
case eColorID_WidgetSelectForeground:
case eColorID_TextSelectForeground:
case eColorID_IMESelectedRawTextForeground:
case eColorID_IMESelectedConvertedTextForeground:
aColor = sMozWindowSelectedText;
case eColorID_highlighttext:
case eColorID__moz_cellhighlighttext:
case eColorID__moz_html_cellhighlighttext:
aColor = sTextSelectedText;
break;
#endif
case eColorID_Widget3DHighlight:
@ -238,19 +242,6 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
GTK_STATE_FLAG_INSENSITIVE, &gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID_highlight: // preference selected item,
// background of selected item
gtk_style_context_get_background_color(mViewStyle,
GTK_STATE_FLAG_SELECTED,
&gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID_highlighttext:
// text of selected item
gtk_style_context_get_color(mViewStyle,
GTK_STATE_FLAG_SELECTED, &gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID_inactivecaption:
// inactive window caption
gtk_style_context_get_background_color(mBackgroundStyle,
@ -393,19 +384,6 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
case eColorID__moz_buttonhovertext:
aColor = sButtonHoverText;
break;
case eColorID__moz_cellhighlight:
case eColorID__moz_html_cellhighlight:
gtk_style_context_get_background_color(mViewStyle,
GTK_STATE_FLAG_SELECTED,
&gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID__moz_cellhighlighttext:
case eColorID__moz_html_cellhighlighttext:
gtk_style_context_get_color(mViewStyle,
GTK_STATE_FLAG_SELECTED, &gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
#endif
case eColorID__moz_menuhover:
aColor = sMenuHover;
@ -967,7 +945,7 @@ nsLookAndFeel::Init()
GtkStyleContext *style;
// Gtk manages a screen's CSS in the settings object so we
// ask Gtk to create it explicitly. Otherwise we may end up
// ask Gtk to create it explicitly. Otherwise we may end up
// with wrong color theme, see Bug 972382
(void)gtk_settings_get_for_screen(gdk_screen_get_default());
@ -977,9 +955,6 @@ nsLookAndFeel::Init()
mBackgroundStyle = create_context(path);
gtk_style_context_add_class(mBackgroundStyle, GTK_STYLE_CLASS_BACKGROUND);
mViewStyle = create_context(path);
gtk_style_context_add_class(mViewStyle, GTK_STYLE_CLASS_VIEW);
mButtonStyle = create_context(path);
gtk_style_context_add_class(mButtonStyle, GTK_STYLE_CLASS_BUTTON);
@ -992,11 +967,24 @@ nsLookAndFeel::Init()
g_object_unref(style);
// Text colors
gtk_style_context_get_background_color(mViewStyle, GTK_STATE_FLAG_NORMAL, &color);
style = create_context(path);
gtk_style_context_add_class(style, GTK_STYLE_CLASS_VIEW);
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
sMozFieldBackground = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_get_color(mViewStyle, GTK_STATE_FLAG_NORMAL, &color);
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
sMozFieldText = GDK_RGBA_TO_NS_RGBA(color);
// Selected text and background
gtk_style_context_get_background_color(style,
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_SELECTED),
&color);
sTextSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_get_color(style,
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_SELECTED),
&color);
sTextSelectedText = GDK_RGBA_TO_NS_RGBA(color);
g_object_unref(style);
// Window colors
style = create_context(path);
gtk_style_context_save(style);
@ -1005,12 +993,6 @@ nsLookAndFeel::Init()
sMozWindowBackground = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
sMozWindowText = GDK_RGBA_TO_NS_RGBA(color);
// Selected text and background
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_SELECTED, &color);
sMozWindowSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_get_color(style, GTK_STATE_FLAG_SELECTED, &color);
sMozWindowSelectedText = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_restore(style);
// tooltip foreground and background
@ -1256,11 +1238,9 @@ nsLookAndFeel::RefreshImpl()
mStyle = nullptr;
#else
g_object_unref(mBackgroundStyle);
g_object_unref(mViewStyle);
g_object_unref(mButtonStyle);
mBackgroundStyle = nullptr;
mViewStyle = nullptr;
mButtonStyle = nullptr;
#endif

View File

@ -35,7 +35,6 @@ protected:
struct _GtkStyle *mStyle;
#else
struct _GtkStyleContext *mBackgroundStyle;
struct _GtkStyleContext *mViewStyle;
struct _GtkStyleContext *mButtonStyle;
#endif
@ -75,8 +74,8 @@ protected:
nscolor sMozFieldBackground;
nscolor sMozWindowText;
nscolor sMozWindowBackground;
nscolor sMozWindowSelectedText;
nscolor sMozWindowSelectedBackground;
nscolor sTextSelectedText;
nscolor sTextSelectedBackground;
nscolor sMozScrollbar;
char16_t sInvisibleCharacter;
float sCaretRatio;