Bug 1457194 - [Gtk+\CSD] Don't estimate window offset for Gtk+ < 3.20, r=jhorak

MozReview-Commit-ID: JtxujODEHBO

--HG--
extra : rebase_source : ff6a571ae1a882556cdc8074c35847c8e71ecdb6
This commit is contained in:
Martin Stransky 2018-04-27 12:30:13 +02:00
parent 95e51a092f
commit 8a535137df

View File

@ -3122,6 +3122,16 @@ GetActiveScrollbarMetrics(GtkOrientation aOrientation)
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 ?
@ -3135,54 +3145,32 @@ GetCSDDecorationSize(GtkWindow *aGtkWindow, GtkBorder* 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);
/* 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;
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);
}
} 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;
// 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. */