bug 1272194 only add menubar class to menu items with GTK 3.4 r=stransky draft
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 17 May 2016 18:02:00 +1200
changeset 368607 8a1a98a46cc80dd6e20b5a1fe0b8ff910c3ee07f
parent 368606 02aeda4f9cd8ba7c78c16dcd7f62a90c0733d17c
child 368608 6f19b911e455c619b7360156ee966eb3701624b6
push id18602
push userktomlinson@mozilla.com
push dateThu, 19 May 2016 05:18:04 +0000
reviewersstransky
bugs1272194
milestone49.0a1
bug 1272194 only add menubar class to menu items with GTK 3.4 r=stransky and save/restore context consistent with GTK 3.4. MozReview-Commit-ID: GdMoAmzOJlf
widget/gtk/gtk3drawing.cpp
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -2468,35 +2468,42 @@ moz_gtk_menu_item_paint(WidgetNodeType w
             ensure_menu_bar_item_widget();
             item_widget = gMenuBarItemWidget;
         } else {
             ensure_menu_item_widget();
             item_widget = gMenuItemWidget;
         }
         style = gtk_widget_get_style_context(item_widget);
 
-        if (widget == MOZ_GTK_MENUBARITEM) {
-            gtk_style_context_add_class(style, GTK_STYLE_CLASS_MENUBAR);
+        bool pre_3_6 = gtk_check_version(3, 6, 0) != nullptr;
+        if (pre_3_6) {
+            // GTK+ 3.4 saves the style context and adds the menubar class to
+            // menubar children, but does each of these only when drawing, not
+            // during layout.
+            gtk_style_context_save(style);
+            if (widget == MOZ_GTK_MENUBARITEM) {
+                gtk_style_context_add_class(style, GTK_STYLE_CLASS_MENUBAR);
+            }
         }
 
         gtk_widget_set_direction(item_widget, direction);
         gtk_style_context_set_state(style, GetStateFlagsFromGtkWidgetState(state));
 
         border_width = gtk_container_get_border_width(GTK_CONTAINER(item_widget));
 
         x = rect->x + border_width;
         y = rect->y + border_width;
         w = rect->width - border_width * 2;
         h = rect->height - border_width * 2;
 
         gtk_render_background(style, cr, x, y, w, h);
         gtk_render_frame(style, cr, x, y, w, h);
 
-        if (widget == MOZ_GTK_MENUBARITEM) {
-            gtk_style_context_remove_class(style, GTK_STYLE_CLASS_MENUBAR);
+        if (pre_3_6) {
+            gtk_style_context_restore(style);
         }
         gtk_style_context_set_state(style, GTK_STATE_FLAG_NORMAL);
     }
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint