bug 1272194 explicitly invalidate after change style contexts belonging to widgets r=stransky
This fixes menu item rendering during hover.
MozReview-Commit-ID: CEa6aorqBZM
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -275,23 +275,42 @@ ResetWidgetCache(void)
/* Clear already freed arrays */
mozilla::PodArrayZero(sWidgetStorage);
}
GtkStyleContext*
ClaimStyleContext(WidgetNodeType aNodeType, GtkTextDirection aDirection,
GtkStateFlags aStateFlags, StyleFlags aFlags)
{
+ MOZ_ASSERT(!sStyleContextNeedsRestore);
GtkStyleContext* style = GetStyleInternal(aNodeType);
#ifdef DEBUG
MOZ_ASSERT(!sCurrentStyleContext);
sCurrentStyleContext = style;
#endif
- gtk_style_context_set_state(style, aStateFlags);
- gtk_style_context_set_direction(style, aDirection);
+ GtkStateFlags oldState = gtk_style_context_get_state(style);
+ GtkTextDirection oldDirection = gtk_style_context_get_direction(style);
+ if (oldState != aStateFlags || oldDirection != aDirection) {
+ // From GTK 3.8, set_state() will overwrite the direction, so set
+ // direction after state.
+ gtk_style_context_set_state(style, aStateFlags);
+ gtk_style_context_set_direction(style, aDirection);
+
+ // This invalidate is necessary for unsaved style contexts from GtkWidgets
+ // in pre-3.18 GTK, because automatic invalidation of such contexts
+ // was delayed until a resize event runs.
+ //
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1272194#c7
+ //
+ // Avoid calling invalidate on saved contexts to avoid performing
+ // build_properties() (in 3.16 stylecontext.c) unnecessarily early.
+ if (!sStyleContextNeedsRestore) {
+ gtk_style_context_invalidate(style);
+ }
+ }
return style;
}
void
ReleaseStyleContext(GtkStyleContext* aStyleContext)
{
if (sStyleContextNeedsRestore) {
gtk_style_context_restore(aStyleContext);
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -543,23 +543,25 @@ STUB(gtk_scale_new)
STUB(gtk_scrollbar_new)
STUB(gtk_style_context_add_class)
STUB(gtk_style_context_add_region)
STUB(gtk_style_context_get)
STUB(gtk_style_context_get_background_color)
STUB(gtk_style_context_get_border)
STUB(gtk_style_context_get_border_color)
STUB(gtk_style_context_get_color)
+STUB(gtk_style_context_get_direction)
STUB(gtk_style_context_get_margin)
STUB(gtk_style_context_get_padding)
STUB(gtk_style_context_get_path)
STUB(gtk_style_context_get_property)
STUB(gtk_style_context_get_state)
STUB(gtk_style_context_get_style)
STUB(gtk_style_context_has_class)
+STUB(gtk_style_context_invalidate)
STUB(gtk_style_context_new)
STUB(gtk_style_context_remove_class)
STUB(gtk_style_context_remove_region)
STUB(gtk_style_context_restore)
STUB(gtk_style_context_save)
STUB(gtk_style_context_set_direction)
STUB(gtk_style_context_set_path)
STUB(gtk_style_context_set_parent)