[gtk+] label: Use a CSS node for selection rendering
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] label: Use a CSS node for selection rendering
- Date: Wed, 11 Nov 2015 01:34:11 +0000 (UTC)
commit fafa75ac192f9eb9599c6b1b57dc9b23ec84fc0a
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Nov 10 20:28:10 2015 -0500
label: Use a CSS node for selection rendering
This adds new possibilities for themes to render the selection
in fancy ways.
gtk/gtklabel.c | 41 ++++++++++++++++++++++++++++-------------
1 files changed, 28 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index e669ed9..e0f564e 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -54,6 +54,8 @@
#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
#include "gtkwindow.h"
+#include "gtkcssnodeprivate.h"
+#include "gtkwidgetprivate.h"
#include "a11y/gtklabelaccessibleprivate.h"
@@ -312,6 +314,7 @@ struct _GtkLabelSelectionInfo
gint selection_anchor;
gint selection_end;
GtkWidget *popup_menu;
+ GtkCssNode *selection_node;
GList *links;
GtkLabelLink *active_link;
@@ -4244,14 +4247,9 @@ gtk_label_draw (GtkWidget *widget,
cairo_translate (cr, -allocation.x, -allocation.y);
- gtk_render_layout (context, cr,
- x, y,
- priv->layout);
-
- state = gtk_widget_get_state_flags (widget);
+ gtk_render_layout (context, cr, x, y, priv->layout);
- if (info &&
- (info->selection_anchor != info->selection_end))
+ if (info && (info->selection_anchor != info->selection_end))
{
gint range[2];
cairo_region_t *clip;
@@ -4272,20 +4270,16 @@ gtk_label_draw (GtkWidget *widget,
1);
cairo_save (cr);
- gtk_style_context_save (context);
+ gtk_style_context_save_to_node (context, info->selection_node);
gdk_cairo_region (cr, clip);
cairo_clip (cr);
- gtk_style_context_set_state (context, state | GTK_STATE_FLAG_SELECTED);
-
gtk_render_background (context, cr,
allocation.x, allocation.y,
allocation.width, allocation.height);
- gtk_render_layout (context, cr,
- x, y,
- priv->layout);
+ gtk_render_layout (context, cr, x, y, priv->layout);
gtk_style_context_restore (context);
cairo_restore (cr);
@@ -4327,10 +4321,13 @@ gtk_label_draw (GtkWidget *widget,
x, y,
range,
1);
+
gdk_cairo_region (cr, clip);
cairo_clip (cr);
cairo_region_destroy (clip);
+ state = gtk_style_context_get_state (context);
+
if (info->link_clicked)
state |= GTK_STATE_FLAG_ACTIVE;
else
@@ -5765,12 +5762,30 @@ gtk_label_select_region_index (GtkLabel *label,
gtk_target_table_free (targets, n_targets);
gtk_target_list_unref (list);
+
+ if (!priv->select_info->selection_node)
+ {
+ GtkCssNode *widget_node;
+
+ widget_node = gtk_widget_get_css_node (GTK_WIDGET (label));
+ priv->select_info->selection_node = gtk_css_node_new ();
+ gtk_css_node_set_name (priv->select_info->selection_node, I_("selection"));
+ gtk_css_node_set_parent (priv->select_info->selection_node, widget_node);
+ gtk_css_node_set_state (priv->select_info->selection_node, gtk_css_node_get_state
(widget_node));
+ g_object_unref (priv->select_info->selection_node);
+ }
}
else
{
if (clipboard &&
gtk_clipboard_get_owner (clipboard) == G_OBJECT (label))
gtk_clipboard_clear (clipboard);
+
+ if (priv->select_info->selection_node)
+ {
+ gtk_css_node_set_parent (priv->select_info->selection_node, NULL);
+ priv->select_info->selection_node = NULL;
+ }
}
gtk_widget_queue_draw (GTK_WIDGET (label));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]