Bug 1453930 - Use gtk_style_context_get_state() instead of GTK_STATE_FLAG_NORMAL to get widget border/margin/padding, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Fri, 13 Apr 2018 13:41:27 +0200
changeset 781687 f006c5851557bfc485bbc154125a5bc2ba750618
parent 780873 2318adaec61f07eccf66c3f742497aa973b15f2f
push id106371
push userstransky@redhat.com
push dateFri, 13 Apr 2018 12:18:16 +0000
reviewersjhorak
bugs1453930
milestone61.0a1
Bug 1453930 - Use gtk_style_context_get_state() instead of GTK_STATE_FLAG_NORMAL to get widget border/margin/padding, r?jhorak MozReview-Commit-ID: 6FaUpaaBt2Q
widget/gtk/gtk3drawing.cpp
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -68,31 +68,31 @@ moz_gtk_add_style_margin(GtkStyleContext
 }
 
 static void
 moz_gtk_add_style_border(GtkStyleContext* style,
                          gint* left, gint* top, gint* right, gint* bottom)
 {
     GtkBorder border;
 
-    gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
+    gtk_style_context_get_border(style, gtk_style_context_get_state(style), &border);
 
     *left += border.left;
     *right += border.right;
     *top += border.top;
     *bottom += border.bottom;
 }
 
 static void
 moz_gtk_add_style_padding(GtkStyleContext* style,
                           gint* left, gint* top, gint* right, gint* bottom)
 {
     GtkBorder padding;
 
-    gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
+    gtk_style_context_get_padding(style, gtk_style_context_get_state(style), &padding);
 
     *left += padding.left;
     *right += padding.right;
     *top += padding.top;
     *bottom += padding.bottom;
 }
 
 static void
@@ -211,18 +211,18 @@ moz_gtk_radio_get_metrics(gint* indicato
 }
 
 static gint
 moz_gtk_get_focus_outline_size(GtkStyleContext* style,
                                gint* focus_h_width, gint* focus_v_width)
 {
     GtkBorder border;
     GtkBorder padding;
-    gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
-    gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
+    gtk_style_context_get_border(style, gtk_style_context_get_state(style), &border);
+    gtk_style_context_get_padding(style, gtk_style_context_get_state(style), &padding);
     *focus_h_width = border.left + padding.left;
     *focus_v_width = border.top + padding.top;
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_focus_outline_size(gint* focus_h_width, gint* focus_v_width)
 {
@@ -670,18 +670,18 @@ calculate_button_inner_rect(GtkWidget* b
 {
     GtkStyleContext* style;
     GtkBorder border;
     GtkBorder padding = {0, 0, 0, 0};
 
     style = gtk_widget_get_style_context(button);
 
     /* This mirrors gtkbutton's child positioning */
-    gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
-    gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
+    gtk_style_context_get_border(style, gtk_style_context_get_state(style), &border);
+    gtk_style_context_get_padding(style, gtk_style_context_get_state(style), &padding);
 
     inner_rect->x = rect->x + border.left + padding.left;
     inner_rect->y = rect->y + padding.top + border.top;
     inner_rect->width = MAX(1, rect->width - padding.left -
        padding.right - border.left * 2);
     inner_rect->height = MAX(1, rect->height - padding.top -
        padding.bottom - border.top * 2);
 
@@ -1599,17 +1599,17 @@ moz_gtk_toolbar_separator_paint(cairo_t 
 
         gtk_render_frame(style, cr,
                           rect->x + (rect->width - separator_width) / 2,
                           rect->y + rect->height * start_fraction,
                           separator_width,
                           rect->height * (end_fraction - start_fraction));
     } else {
         GtkBorder padding;
-        gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
+        gtk_style_context_get_padding(style, gtk_style_context_get_state(style), &padding);
 
         paint_width = padding.left;
         if (paint_width > rect->width)
             paint_width = rect->width;
 
         gtk_render_line(style, cr,
                         rect->x + (rect->width - paint_width) / 2,
                         rect->y + rect->height * start_fraction,
@@ -1768,17 +1768,17 @@ moz_gtk_progress_chunk_paint(cairo_t *cr
 
 static gint
 moz_gtk_get_tab_thickness(GtkStyleContext *style)
 {
     if (!notebook_has_tab_gap)
       return 0; /* tabs do not overdraw the tabpanel border with "no gap" style */
 
     GtkBorder border;
-    gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
+    gtk_style_context_get_border(style, gtk_style_context_get_state(style), &border);
     if (border.top < 2)
         return 2; /* some themes don't set ythickness correctly */
 
     return border.top;
 }
 
 gint
 moz_gtk_get_tab_thickness(WidgetNodeType aNodeType)
@@ -2105,17 +2105,17 @@ moz_gtk_menu_separator_paint(cairo_t *cr
 
     GtkStyleContext* style;
     gboolean wide_separators;
     gint separator_height;
     gint x, y, w;
     GtkBorder padding;
 
     style = GetStyleContext(MOZ_GTK_MENUSEPARATOR, direction);
-    gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
+    gtk_style_context_get_padding(style, gtk_style_context_get_state(style), &padding);
 
     x = rect->x;
     y = rect->y;
     w = rect->width;
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_SEPARATOR);
 
@@ -2411,17 +2411,17 @@ moz_gtk_get_widget_border(WidgetNodeType
             if (comboBoxSeparator) {
                 style = gtk_widget_get_style_context(comboBoxSeparator);
                 gtk_style_context_get_style(style,
                                             "wide-separators", &wide_separators,
                                             "separator-width", &separator_width,
                                             NULL);
 
                 if (!wide_separators) {
-                    gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL,
+                    gtk_style_context_get_border(style, gtk_style_context_get_state(style),
                                                  &border);
                     separator_width = border.left;
                 }
             }
 
             gtk_widget_get_preferred_size(GetWidget(MOZ_GTK_COMBOBOX_ARROW),
                                           NULL, &arrow_req);
 
@@ -2584,23 +2584,23 @@ moz_gtk_get_tab_border(gint* left, gint*
             if (direction == GTK_TEXT_DIR_RTL)
                 *right += initial_gap;
             else
                 *left += initial_gap;
         }
     } else {
         GtkBorder margin;
 
-        gtk_style_context_get_margin(style, GTK_STATE_FLAG_NORMAL, &margin);
+        gtk_style_context_get_margin(style, gtk_style_context_get_state(style), &margin);
         *left += margin.left;
         *right += margin.right;
 
         if (flags & MOZ_GTK_TAB_FIRST) {
             style = GetStyleContext(MOZ_GTK_NOTEBOOK_HEADER, direction);
-            gtk_style_context_get_margin(style, GTK_STATE_FLAG_NORMAL, &margin);
+            gtk_style_context_get_margin(style, gtk_style_context_get_state(style), &margin);
             *left += margin.left;
             *right += margin.right;
         }
     }
 
     return MOZ_GTK_SUCCESS;
 }
 
@@ -2665,17 +2665,17 @@ moz_gtk_get_toolbar_separator_width(gint
 
     GtkStyleContext* style = GetStyleContext(MOZ_GTK_TOOLBAR);
     gtk_style_context_get_style(style,
                                 "space-size", size,
                                 "wide-separators",  &wide_separators,
                                 "separator-width", &separator_width,
                                 NULL);
     /* Just in case... */
-    gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
+    gtk_style_context_get_border(style, gtk_style_context_get_state(style), &border);
     *size = MAX(*size, (wide_separators ? separator_width : border.left));
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_expander_size(gint* size)
 {
     GtkStyleContext* style = GetStyleContext(MOZ_GTK_EXPANDER);
@@ -2696,17 +2696,17 @@ 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 = GetStyleContext(MOZ_GTK_MENUSEPARATOR);
-    gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
+    gtk_style_context_get_padding(style, gtk_style_context_get_state(style), &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);
@@ -2728,18 +2728,18 @@ moz_gtk_get_entry_min_height(gint* heigh
                               "min-height", height,
                               nullptr);
     } else {
         *height = 0;
     }
 
     GtkBorder border;
     GtkBorder padding;
-    gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
-    gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
+    gtk_style_context_get_border(style, gtk_style_context_get_state(style), &border);
+    gtk_style_context_get_padding(style, gtk_style_context_get_state(style), &padding);
 
     *height += (border.top + border.bottom + padding.top + padding.bottom);
 }
 
 void
 moz_gtk_get_scale_metrics(GtkOrientation orient, gint* scale_width,
                           gint* scale_height)
 {
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -177,17 +177,17 @@ GetBorderColors(GtkStyleContext* aContex
     gtk_style_context_get(aContext, state, GTK_STYLE_PROPERTY_BORDER_STYLE,
                           &borderStyle, nullptr);
     bool visible = borderStyle != GTK_BORDER_STYLE_NONE &&
         borderStyle != GTK_BORDER_STYLE_HIDDEN;
     if (visible) {
         // GTK has an initial value of zero for border-widths, and so themes
         // need to explicitly set border-widths to make borders visible.
         GtkBorder border;
-        gtk_style_context_get_border(aContext, GTK_STATE_FLAG_NORMAL, &border);
+        gtk_style_context_get_border(aContext, state, &border);
         visible = border.top != 0 || border.right != 0 ||
             border.bottom != 0 || border.left != 0;
     }
 
     if (visible &&
         GetUnicoBorderGradientColors(aContext, aLightColor, aDarkColor))
         return true;