Bug 1457194 - [Gtk+\CSD] Don't estimate window offset for Gtk+ < 3.20, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Fri, 27 Apr 2018 12:30:13 +0200
changeset 789022 2a6d4221f1ed67f01accc6e5112fe24816d46c3e
parent 788990 2700101341f79f6da70203ce4d23378226c28a98
child 789023 48c3f1104cfde45d70b6c72e8e5cb78c98264d1a
push id108133
push userstransky@redhat.com
push dateFri, 27 Apr 2018 10:36:36 +0000
reviewersjhorak
bugs1457194
milestone61.0a1
Bug 1457194 - [Gtk+\CSD] Don't estimate window offset for Gtk+ < 3.20, r?jhorak MozReview-Commit-ID: JtxujODEHBO
widget/gtk/gtk3drawing.cpp
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -3117,77 +3117,65 @@ GetActiveScrollbarMetrics(GtkOrientation
 
 /*
  * get_shadow_width() from gtkwindow.c is not public so we need
  * to implement it.
  */
 bool
 GetCSDDecorationSize(GtkWindow *aGtkWindow, GtkBorder* aDecorationSize)
 {
+    // Available on GTK 3.20+.
+    static auto sGtkRenderBackgroundGetClip =
+        (void (*)(GtkStyleContext*, gdouble, gdouble, gdouble, gdouble, GdkRectangle*))
+        dlsym(RTLD_DEFAULT, "gtk_render_background_get_clip");
+
+    if (!sGtkRenderBackgroundGetClip) {
+        *aDecorationSize = {0,0,0,0};
+        return false;
+    }
+
     GtkStyleContext* context = gtk_widget_get_style_context(GTK_WIDGET(aGtkWindow));
     bool solidDecorations = gtk_style_context_has_class(context, "solid-csd");
     context = GetStyleContext(solidDecorations ?
                               MOZ_GTK_WINDOW_DECORATION_SOLID :
                               MOZ_GTK_WINDOW_DECORATION);
 
     /* Always sum border + padding */
     GtkBorder padding;
     GtkStateFlags state = gtk_style_context_get_state(context);
     gtk_style_context_get_border(context, state, aDecorationSize);
     gtk_style_context_get_padding(context, state, &padding);
     *aDecorationSize += padding;
 
-    // Available on GTK 3.20+.
-    static auto sGtkRenderBackgroundGetClip =
-        (void (*)(GtkStyleContext*, gdouble, gdouble, gdouble, gdouble, GdkRectangle*))
-        dlsym(RTLD_DEFAULT, "gtk_render_background_get_clip");
 
     GtkBorder margin;
     gtk_style_context_get_margin(context, state, &margin);
 
-    GtkBorder extents = {0, 0, 0, 0};
-    if (sGtkRenderBackgroundGetClip) {
-        /* Get shadow extents but combine with style margin; use the bigger value.
-         */
-        GdkRectangle clip;
-        sGtkRenderBackgroundGetClip(context, 0, 0, 0, 0, &clip);
-
-        extents.top = -clip.y;
-        extents.right = clip.width + clip.x;
-        extents.bottom = clip.height + clip.y;
-        extents.left = -clip.x;
-
-        // Margin is used for resize grip size - it's not present on
-        // popup windows.
-        if (gtk_window_get_window_type(aGtkWindow) != GTK_WINDOW_POPUP) {
-            extents.top = MAX(extents.top, margin.top);
-            extents.right = MAX(extents.right, margin.right);
-            extents.bottom = MAX(extents.bottom, margin.bottom);
-            extents.left = MAX(extents.left, margin.left);
-        }
-    } else {
-        /* If we can't get shadow extents use decoration-resize-handle instead
-         * as a workaround. This is inspired by update_border_windows()
-         * from gtkwindow.c although this is not 100% accurate as we emulate
-         * the extents here.
-         */
-        gint handle;
-        gtk_widget_style_get(GetWidget(MOZ_GTK_WINDOW),
-                             "decoration-resize-handle", &handle,
-                             NULL);
-
-        extents.top = handle + margin.top;
-        extents.right = handle + margin.right;
-        extents.bottom = handle + margin.bottom;
-        extents.left = handle + margin.left;
+    /* Get shadow extents but combine with style margin; use the bigger value.
+     */
+    GdkRectangle clip;
+    sGtkRenderBackgroundGetClip(context, 0, 0, 0, 0, &clip);
+
+    GtkBorder extents;
+    extents.top = -clip.y;
+    extents.right = clip.width + clip.x;
+    extents.bottom = clip.height + clip.y;
+    extents.left = -clip.x;
+
+    // Margin is used for resize grip size - it's not present on
+    // popup windows.
+    if (gtk_window_get_window_type(aGtkWindow) != GTK_WINDOW_POPUP) {
+        extents.top = MAX(extents.top, margin.top);
+        extents.right = MAX(extents.right, margin.right);
+        extents.bottom = MAX(extents.bottom, margin.bottom);
+        extents.left = MAX(extents.left, margin.left);
     }
 
     *aDecorationSize += extents;
-
-    return (sGtkRenderBackgroundGetClip != nullptr);
+    return true;
 }
 
 /* cairo_t *cr argument has to be a system-cairo. */
 gint
 moz_gtk_widget_paint(WidgetNodeType widget, cairo_t *cr,
                      GdkRectangle* rect,
                      GtkWidgetState* state, gint flags,
                      GtkTextDirection direction)