bug 1315668 remove use of gtk_container_get_border_width from menuitems r?stransky draft
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 14 Nov 2016 16:13:50 +1300
changeset 438825 25855843ac77acd859857de2e4a6c71cb63393a1
parent 438550 71fd23fa0803a548b6e571aa25d0533a06cd0421
child 438826 c80f440a7152d0e0c91671c0343b85a1b74628e1
push id35825
push userktomlinson@mozilla.com
push dateTue, 15 Nov 2016 04:01:18 +0000
reviewersstransky
bugs1315668
milestone53.0a1
bug 1315668 remove use of gtk_container_get_border_width from menuitems r?stransky The GtkContainer border-width property defaults to zero. It is not influenced by theme CSS. While theme engines can theoretically modify default values for properties of any class, I don't think that is something that needs to be supported. Removing this code is necessary to switch from caching GtkWidgets to caching GtkStyleContexts only. MozReview-Commit-ID: IxgM8qjfK3a
widget/gtk/gtk3drawing.cpp
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -1763,29 +1763,25 @@ moz_gtk_menu_popup_paint(cairo_t *cr, Gd
 // See gtk_menu_item_draw() for reference.
 static gint
 moz_gtk_menu_separator_paint(cairo_t *cr, GdkRectangle* rect,
                              GtkTextDirection direction)
 {
     GtkStyleContext* style;
     gboolean wide_separators;
     gint separator_height;
-    guint border_width;
     gint x, y, w;
     GtkBorder padding;
 
-    border_width =
-        gtk_container_get_border_width(GTK_CONTAINER(
-                                       GetWidget(MOZ_GTK_MENUSEPARATOR)));
     style = ClaimStyleContext(MOZ_GTK_MENUSEPARATOR, direction);
     gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
 
-    x = rect->x + border_width;
-    y = rect->y + border_width;
-    w = rect->width - border_width * 2;
+    x = rect->x;
+    y = rect->y;
+    w = rect->width;
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_SEPARATOR);
 
     gtk_style_context_get_style(style,
                                 "wide-separators",    &wide_separators,
                                 "separator-height",   &separator_height,
                                 NULL);
@@ -1813,37 +1809,35 @@ moz_gtk_menu_separator_paint(cairo_t *cr
 // See gtk_menu_item_draw() for reference.
 static gint
 moz_gtk_menu_item_paint(WidgetNodeType widget, cairo_t *cr, GdkRectangle* rect,
                         GtkWidgetState* state, GtkTextDirection direction)
 {
     gint x, y, w, h;
 
     if (state->inHover && !state->disabled) {   
-        guint border_width =
-            gtk_container_get_border_width(GTK_CONTAINER(GetWidget(widget)));
         GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
         GtkStyleContext* style =
             ClaimStyleContext(widget, direction, state_flags);
 
         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);
             }
         }
 
-        x = rect->x + border_width;
-        y = rect->y + border_width;
-        w = rect->width - border_width * 2;
-        h = rect->height - border_width * 2;
+        x = rect->x;
+        y = rect->y;
+        w = rect->width;
+        h = rect->height;
 
         gtk_render_background(style, cr, x, y, w, h);
         gtk_render_frame(style, cr, x, y, w, h);
 
         if (pre_3_6) {
             gtk_style_context_restore(style);
         }
         ReleaseStyleContext(style);
@@ -1872,17 +1866,16 @@ static gint
 moz_gtk_check_menu_item_paint(cairo_t *cr, GdkRectangle* rect,
                               GtkWidgetState* state,
                               gboolean checked, gboolean isradio,
                               GtkTextDirection direction)
 {
     GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
     GtkStyleContext* style;
     GtkBorder padding;
-    gint offset;
     gint indicator_size, horizontal_padding;
     gint x, y;
 
     moz_gtk_menu_item_paint(MOZ_GTK_MENUITEM, cr, rect, state, direction);
 
     if (checked) {
       state_flags = static_cast<GtkStateFlags>(state_flags|checkbox_check_state);
     }
@@ -1895,19 +1888,17 @@ moz_gtk_check_menu_item_paint(cairo_t *c
                                 "horizontal-padding", &horizontal_padding,
                                 NULL);
     ReleaseStyleContext(style);
 
     style = ClaimStyleContext(isradio ? MOZ_GTK_RADIOMENUITEM :
                                         MOZ_GTK_CHECKMENUITEM,
                               direction, state_flags);
     gtk_style_context_get_padding(style, state_flags, &padding);
-    offset = gtk_container_get_border_width(GTK_CONTAINER(
-                                            GetWidget(MOZ_GTK_CHECKMENUITEM_CONTAINER)));
-    offset += padding.left + 2;
+    gint offset = padding.left + 2;
 
     if (direction == GTK_TEXT_DIR_RTL) {
         x = rect->width - indicator_size - offset - horizontal_padding;
     }
     else {
         x = rect->x + offset + horizontal_padding;
     }
     y = rect->y + (rect->height - indicator_size) / 2;
@@ -2162,17 +2153,16 @@ moz_gtk_get_widget_border(WidgetNodeType
         {
             if (widget == MOZ_GTK_MENUBARITEM || widget == MOZ_GTK_MENUITEM) {
                 // Bug 1274143 for MOZ_GTK_MENUBARITEM
                 w = GetWidget(MOZ_GTK_MENUITEM);
             } else {
                 w = GetWidget(MOZ_GTK_CHECKMENUITEM_CONTAINER);
             }
 
-            *left = *top = *right = *bottom = gtk_container_get_border_width(GTK_CONTAINER(w));
             moz_gtk_add_style_padding(gtk_widget_get_style_context(w),
                                       left, top, right, bottom);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_INFO_BAR:
         w = GetWidget(MOZ_GTK_INFO_BAR);
         break;
     case MOZ_GTK_TOOLTIP:
@@ -2439,38 +2429,31 @@ moz_gtk_get_treeview_expander_size(gint*
 
 // See gtk_menu_item_draw() for reference.
 gint
 moz_gtk_get_menu_separator_height(gint *size)
 {
     gboolean  wide_separators;
     gint      separator_height;
     GtkBorder padding;
-    GtkStyleContext* style;
-    guint border_width;
-
-    border_width =
-        gtk_container_get_border_width(GTK_CONTAINER(
-                                       GetWidget(MOZ_GTK_MENUSEPARATOR)));
-
-    style = ClaimStyleContext(MOZ_GTK_MENUSEPARATOR);
+    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_MENUSEPARATOR);
     gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_SEPARATOR);
 
     gtk_style_context_get_style(style,
                                 "wide-separators",  &wide_separators,
                                 "separator-height", &separator_height,
                                 NULL);
 
     gtk_style_context_restore(style);
     ReleaseStyleContext(style);
 
-    *size = padding.top + padding.bottom + border_width*2;
+    *size = padding.top + padding.bottom;
     *size += (wide_separators) ? separator_height : 1;
 
     return MOZ_GTK_SUCCESS;
 }
 
 void
 moz_gtk_get_entry_min_height(gint* height)
 {