summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2018-01-05 15:54:49 -0500
committerMatthias Clasen <mclasen@redhat.com>2018-01-05 15:54:49 -0500
commit36e09f3ad9cd881eb3af0df242da6a1b5b26bb8d (patch)
tree37f59166f3eb0dc581945b8e779e9b2d2a431c9e
parentc8770b3c63096850c6b3c800b3d870c2d7d1dfef (diff)
downloadgtk+-36e09f3ad9cd881eb3af0df242da6a1b5b26bb8d.tar.gz
label: Properly handle multi-line selections
They were rendered as a single rectangle, which is not what is expected. Same for multi-line links.
-rw-r--r--gtk/gtklabel.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 102f199cd5..8df6e8f018 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3921,7 +3921,8 @@ gtk_label_snapshot (GtkWidget *widget,
{
gint range[2];
cairo_region_t *range_clip;
- cairo_rectangle_int_t clip_extents;
+ cairo_rectangle_int_t clip_rect;
+ int i;
range[0] = info->selection_anchor;
range[1] = info->selection_end;
@@ -3936,12 +3937,15 @@ gtk_label_snapshot (GtkWidget *widget,
gtk_style_context_save_to_node (context, info->selection_node);
range_clip = gdk_pango_layout_get_clip_region (priv->layout, lx, ly, range, 1);
- cairo_region_get_extents (range_clip, &clip_extents);
+ for (i = 0; i < cairo_region_num_rectangles (range_clip); i++)
+ {
+ cairo_region_get_rectangle (range_clip, i, &clip_rect);
- gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_extents), "Selected Text");
- gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
- gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
- gtk_snapshot_pop (snapshot);
+ gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_rect), "Selected Text");
+ gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
+ gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
+ gtk_snapshot_pop (snapshot);
+ }
cairo_region_destroy (range_clip);
@@ -3953,7 +3957,8 @@ gtk_label_snapshot (GtkWidget *widget,
GtkLabelLink *active_link;
gint range[2];
cairo_region_t *range_clip;
- cairo_rectangle_int_t clip_extents;
+ cairo_rectangle_int_t clip_rect;
+ int i;
GdkRectangle rect;
if (info->selectable &&
@@ -3980,12 +3985,15 @@ gtk_label_snapshot (GtkWidget *widget,
gtk_style_context_save_to_node (context, active_link->cssnode);
range_clip = gdk_pango_layout_get_clip_region (priv->layout, lx, ly, range, 1);
- cairo_region_get_extents (range_clip, &clip_extents);
+ for (i = 0; i < cairo_region_num_rectangles (range_clip); i++)
+ {
+ cairo_region_get_rectangle (range_clip, i, &clip_rect);
- gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_extents), "Active Link");
- gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
- gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
- gtk_snapshot_pop (snapshot);
+ gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_rect), "Active Link");
+ gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
+ gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
+ gtk_snapshot_pop (snapshot);
+ }
cairo_region_destroy (range_clip);