Bug 1457194 - [Gtk+\CSD] Don't estimate window offset for Gtk+ < 3.20, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Fri, 27 Apr 2018 12:30:13 +0200
changeset 472120 921741097e18e65b236aa834502f61d78cb0f805
parent 472119 c5afc8caa902b5c213e5c1520c482037f5546e38
child 472121 9c70604962648780c82ae1a4773b0f249b26863f
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1457194
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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)