From 0b9136842d92456a921d5d2c4d69c07fa60e0ee8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 2 Dec 2015 23:49:07 -0500 Subject: [PATCH] Use :dnd pseudoclass for drag highlighting Instead of a ::draw handler with a hardcoded outline, use CSS for drawing the highlight. --- gtk/gtkdnd.c | 58 ++---------------------- gtk/theme/Adwaita/_common.scss | 4 ++ gtk/theme/Adwaita/gtk-contained-dark.css | 4 ++ gtk/theme/Adwaita/gtk-contained.css | 4 ++ 4 files changed, 16 insertions(+), 54 deletions(-) diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index fb6c1ab35b..52023afdf5 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -983,48 +983,6 @@ gtk_drag_finish (GdkDragContext *context, gdk_drop_finish (context, success, time); } -static gboolean -gtk_drag_highlight_draw (GtkWidget *widget, - cairo_t *cr, - gpointer data) -{ - GtkAllocation alloc; - GtkStyleContext *context; - - if (GTK_IS_WINDOW (widget)) - { - /* We don't want to draw the drag highlight around the - * CSD window decorations - */ - gtk_widget_get_allocation (gtk_bin_get_child (GTK_BIN (widget)), &alloc); - } - else - { - alloc.x = 0; - alloc.y = 0; - alloc.width = gtk_widget_get_allocated_width (widget); - alloc.height = gtk_widget_get_allocated_height (widget); - } - - context = gtk_widget_get_style_context (widget); - - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_DND); - - gtk_render_frame (context, cr, alloc.x, alloc.y, alloc.width, alloc.height); - - gtk_style_context_restore (context); - - cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */ - cairo_set_line_width (cr, 1.0); - cairo_rectangle (cr, - alloc.x + 0.5, alloc.y + 0.5, - alloc.width - 1, alloc.height - 1); - cairo_stroke (cr); - - return FALSE; -} - /** * gtk_drag_highlight: (method) * @widget: a widget to highlight @@ -1034,16 +992,12 @@ gtk_drag_highlight_draw (GtkWidget *widget, * will continue to be displayed until gtk_drag_unhighlight() * is called. */ -void +void gtk_drag_highlight (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - g_signal_connect_after (widget, "draw", - G_CALLBACK (gtk_drag_highlight_draw), - NULL); - - gtk_widget_queue_draw (widget); + gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_DND, FALSE); } /** @@ -1053,16 +1007,12 @@ gtk_drag_highlight (GtkWidget *widget) * Removes a highlight set by gtk_drag_highlight() from * a widget. */ -void +void gtk_drag_unhighlight (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - g_signal_handlers_disconnect_by_func (widget, - gtk_drag_highlight_draw, - NULL); - - gtk_widget_queue_draw (widget); + gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_DND); } static void diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss index 7fef5610bf..0049141750 100644 --- a/gtk/theme/Adwaita/_common.scss +++ b/gtk/theme/Adwaita/_common.scss @@ -3438,3 +3438,7 @@ frame.keycap { padding: 3px 8px 3px 8px; } +*:dnd:focus, +*:dnd { + border: 1px solid black; +} diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css index 3d4d4dfec9..a3b1cf4d3d 100644 --- a/gtk/theme/Adwaita/gtk-contained-dark.css +++ b/gtk/theme/Adwaita/gtk-contained-dark.css @@ -4665,6 +4665,10 @@ frame.keycap { color: #555753; padding: 3px 8px 3px 8px; } +*:dnd:focus, +*:dnd { + border: 1px solid black; } + /* GTK NAMED COLORS ---------------- use responsibly! */ diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css index 77c1b67a86..cac2b0e044 100644 --- a/gtk/theme/Adwaita/gtk-contained.css +++ b/gtk/theme/Adwaita/gtk-contained.css @@ -4838,6 +4838,10 @@ frame.keycap { color: #555753; padding: 3px 8px 3px 8px; } +*:dnd:focus, +*:dnd { + border: 1px solid black; } + /* GTK NAMED COLORS ---------------- use responsibly! */