279 lines
10 KiB
Diff
279 lines
10 KiB
Diff
|
# HG changeset patch
|
||
|
# Parent 18188c19a3c3ec9cd4474de5bd1f5558ec750a36
|
||
|
# User Martin Stransky <stransky@redhat.com>
|
||
|
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.
|
||
|
|
||
|
|
||
|
diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp
|
||
|
--- a/widget/gtk/nsLookAndFeel.cpp
|
||
|
+++ b/widget/gtk/nsLookAndFeel.cpp
|
||
|
@@ -33,32 +33,30 @@ using mozilla::LookAndFeel;
|
||
|
(int)((c).blue*255), (int)((c).alpha*255)))
|
||
|
|
||
|
nsLookAndFeel::nsLookAndFeel()
|
||
|
: nsXPLookAndFeel(),
|
||
|
#if (MOZ_WIDGET_GTK == 2)
|
||
|
mStyle(nullptr),
|
||
|
#else
|
||
|
mBackgroundStyle(nullptr),
|
||
|
- mViewStyle(nullptr),
|
||
|
mButtonStyle(nullptr),
|
||
|
#endif
|
||
|
mDefaultFontCached(false), mButtonFontCached(false),
|
||
|
mFieldFontCached(false), mMenuFontCached(false)
|
||
|
{
|
||
|
Init();
|
||
|
}
|
||
|
|
||
|
nsLookAndFeel::~nsLookAndFeel()
|
||
|
{
|
||
|
#if (MOZ_WIDGET_GTK == 2)
|
||
|
g_object_unref(mStyle);
|
||
|
#else
|
||
|
g_object_unref(mBackgroundStyle);
|
||
|
- g_object_unref(mViewStyle);
|
||
|
g_object_unref(mButtonStyle);
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
nsresult
|
||
|
nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
|
||
|
{
|
||
|
#if (MOZ_WIDGET_GTK == 3)
|
||
|
@@ -109,23 +107,29 @@ nsLookAndFeel::NativeGetColor(ColorID aI
|
||
|
case eColorID__moz_dialogtext:
|
||
|
aColor = sMozWindowText;
|
||
|
break;
|
||
|
case eColorID_WidgetSelectBackground:
|
||
|
case eColorID_TextSelectBackground:
|
||
|
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:
|
||
|
aColor = NS_RGB(0xa0,0xa0,0xa0);
|
||
|
break;
|
||
|
case eColorID_Widget3DShadow:
|
||
|
aColor = NS_RGB(0x40,0x40,0x40);
|
||
|
break;
|
||
|
@@ -233,29 +237,16 @@ nsLookAndFeel::NativeGetColor(ColorID aI
|
||
|
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
|
||
|
break;
|
||
|
case eColorID_graytext: // disabled text in windows, menus, etc.
|
||
|
case eColorID_inactivecaptiontext: // text in inactive window caption
|
||
|
gtk_style_context_get_color(mBackgroundStyle,
|
||
|
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,
|
||
|
GTK_STATE_FLAG_INSENSITIVE,
|
||
|
&gdk_color);
|
||
|
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
|
||
|
break;
|
||
|
#endif
|
||
|
@@ -388,29 +379,16 @@ nsLookAndFeel::NativeGetColor(ColorID aI
|
||
|
gtk_style_context_get_background_color(mButtonStyle,
|
||
|
GTK_STATE_FLAG_PRELIGHT,
|
||
|
&gdk_color);
|
||
|
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
|
||
|
break;
|
||
|
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;
|
||
|
break;
|
||
|
case eColorID__moz_menuhovertext:
|
||
|
aColor = sMenuHoverText;
|
||
|
break;
|
||
|
case eColorID__moz_oddtreerow:
|
||
|
@@ -962,60 +940,66 @@ nsLookAndFeel::Init()
|
||
|
}
|
||
|
|
||
|
g_object_unref(menu);
|
||
|
#else
|
||
|
GdkRGBA color;
|
||
|
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());
|
||
|
|
||
|
GtkWidgetPath *path = gtk_widget_path_new();
|
||
|
gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
|
||
|
|
||
|
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);
|
||
|
|
||
|
// Scrollbar colors
|
||
|
style = create_context(path);
|
||
|
gtk_style_context_add_class(style, GTK_STYLE_CLASS_SCROLLBAR);
|
||
|
gtk_style_context_add_class(style, GTK_STYLE_CLASS_TROUGH);
|
||
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
||
|
sMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);
|
||
|
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);
|
||
|
gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
|
||
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
||
|
sMozWindowBackground = GDK_RGBA_TO_NS_RGBA(color);
|
||
|
+
|
||
|
+ // Text colors
|
||
|
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
|
||
|
gtk_style_context_add_class(style, GTK_STYLE_CLASS_TOOLTIP);
|
||
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
||
|
sInfoBackground = GDK_RGBA_TO_NS_RGBA(color);
|
||
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
||
|
sInfoText = GDK_RGBA_TO_NS_RGBA(color);
|
||
|
@@ -1251,21 +1235,19 @@ nsLookAndFeel::RefreshImpl()
|
||
|
mFieldFontCached = false;
|
||
|
mMenuFontCached = false;
|
||
|
|
||
|
#if (MOZ_WIDGET_GTK == 2)
|
||
|
g_object_unref(mStyle);
|
||
|
mStyle = nullptr;
|
||
|
#else
|
||
|
g_object_unref(mBackgroundStyle);
|
||
|
- g_object_unref(mViewStyle);
|
||
|
g_object_unref(mButtonStyle);
|
||
|
|
||
|
mBackgroundStyle = nullptr;
|
||
|
- mViewStyle = nullptr;
|
||
|
mButtonStyle = nullptr;
|
||
|
#endif
|
||
|
|
||
|
Init();
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
nsLookAndFeel::GetEchoPasswordImpl() {
|
||
|
diff --git a/widget/gtk/nsLookAndFeel.h b/widget/gtk/nsLookAndFeel.h
|
||
|
--- a/widget/gtk/nsLookAndFeel.h
|
||
|
+++ b/widget/gtk/nsLookAndFeel.h
|
||
|
@@ -30,17 +30,16 @@ public:
|
||
|
virtual char16_t GetPasswordCharacterImpl();
|
||
|
virtual bool GetEchoPasswordImpl();
|
||
|
|
||
|
protected:
|
||
|
#if (MOZ_WIDGET_GTK == 2)
|
||
|
struct _GtkStyle *mStyle;
|
||
|
#else
|
||
|
struct _GtkStyleContext *mBackgroundStyle;
|
||
|
- struct _GtkStyleContext *mViewStyle;
|
||
|
struct _GtkStyleContext *mButtonStyle;
|
||
|
#endif
|
||
|
|
||
|
// Cached fonts
|
||
|
bool mDefaultFontCached;
|
||
|
bool mButtonFontCached;
|
||
|
bool mFieldFontCached;
|
||
|
bool mMenuFontCached;
|
||
|
@@ -70,18 +69,18 @@ protected:
|
||
|
nscolor sOddCellBackground;
|
||
|
nscolor sNativeHyperLinkText;
|
||
|
nscolor sComboBoxText;
|
||
|
nscolor sComboBoxBackground;
|
||
|
nscolor sMozFieldText;
|
||
|
nscolor sMozFieldBackground;
|
||
|
nscolor sMozWindowText;
|
||
|
nscolor sMozWindowBackground;
|
||
|
- nscolor sMozWindowSelectedText;
|
||
|
- nscolor sMozWindowSelectedBackground;
|
||
|
+ nscolor sTextSelectedText;
|
||
|
+ nscolor sTextSelectedBackground;
|
||
|
nscolor sMozScrollbar;
|
||
|
char16_t sInvisibleCharacter;
|
||
|
float sCaretRatio;
|
||
|
bool sMenuSupportsDrag;
|
||
|
|
||
|
void Init();
|
||
|
};
|
||
|
|