bug 1272194 explicitly invalidate after change style contexts belonging to widgets r=stransky draft
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 17 May 2016 18:15:12 +1200
changeset 369014 c00471a623f740ca028caee76dcfcbdb1d620735
parent 368608 6f19b911e455c619b7360156ee966eb3701624b6
child 521426 ea5dc36d9de9306db90629ec0a75bc61b52eb975
push id18697
push userktomlinson@mozilla.com
push dateFri, 20 May 2016 01:46:15 +0000
reviewersstransky
bugs1272194
milestone49.0a1
bug 1272194 explicitly invalidate after change style contexts belonging to widgets r=stransky This fixes menu item rendering during hover. MozReview-Commit-ID: CEa6aorqBZM
widget/gtk/WidgetStyleCache.cpp
widget/gtk/mozgtk/mozgtk.c
--- 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)