[gtk+] entry: Simplify selection rendering



commit 27d70cbb10c1d4b1d51b846c0833e436d09f5ab9
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Nov 10 20:13:06 2015 -0500

    entry: Simplify selection rendering
    
    Calling gtk_render_background for each rectangle in the region
    leads to suboptimal and sometimes weird results. Getting this
    right requires more work in Pango first. Go back to just rendering
    a single background, and clip it to the selection region. This
    matches what GtkLabel does.

 gtk/gtkentry.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index c2b35d1..251edd8 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -6493,14 +6493,14 @@ draw_text_with_color (GtkEntry *entry,
 {
   GtkEntryPrivate *priv = entry->priv;
   PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
-  GtkWidget *widget;
   gint x, y;
   gint start_pos, end_pos;
-
-  widget = GTK_WIDGET (entry);
+  GtkAllocation allocation;
 
   cairo_save (cr);
 
+  gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
+
   get_layout_position (entry, &x, &y);
 
   if (show_placeholder_text (entry))
@@ -6518,22 +6518,20 @@ draw_text_with_color (GtkEntry *entry,
       GdkRGBA text_color;
       GtkStyleContext *context;
 
-      context = gtk_widget_get_style_context (widget);
+      context = gtk_widget_get_style_context (GTK_WIDGET (entry));
       gtk_style_context_save_to_node (context, priv->selection_node);
 
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
       gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
       for (i = 0; i < n_ranges; ++i)
-        gtk_render_background (context, cr,
-                               - priv->scroll_offset + ranges[2 * i], y,
-                              ranges[2 * i + 1], logical_rect.height);
-
-      for (i = 0; i < n_ranges; ++i)
         cairo_rectangle (cr,
                          - priv->scroll_offset + ranges[2 * i], y,
                         ranges[2 * i + 1], logical_rect.height);
       cairo_clip (cr);
 
+      gtk_render_background (context, cr,
+                             0, 0, allocation.width, allocation.height);
+
       cairo_move_to (cr, x, y);
       gtk_style_context_get_color (context, gtk_style_context_get_state (context), &text_color);
       gdk_cairo_set_source_rgba (cr, &text_color);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]