[gtkhtml/gnome-3-12] Bug 537825 - Text cursor not erased when moved to new position



commit 8d107adf1caa825b6cb8c1b09ea6b636c86697d9
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Oct 7 18:45:30 2014 +0200

    Bug 537825 - Text cursor not erased when moved to new position
    
    When we repaint and the cursor is visible, draw the cursor to the
    main cairo context we are using, rather than separately. This makes
    sure that we draw the cursor on top of the content and clipped to
    the redraw area, and thus preserve the shown/hidden state properly.
    
    Some combination of redraw ordering or drawing outside the clipped
    area caused the shown/hidden state of the cursor to be flipped
    on redraw, causing a left-over cursor on next cursor move.

 gtkhtml/htmlengine-edit-cursor.c |   28 ++++++++++++++++++++++++++--
 gtkhtml/htmlengine.c             |    3 ++-
 2 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/gtkhtml/htmlengine-edit-cursor.c b/gtkhtml/htmlengine-edit-cursor.c
index bac61a7..68f0c34 100644
--- a/gtkhtml/htmlengine-edit-cursor.c
+++ b/gtkhtml/htmlengine-edit-cursor.c
@@ -28,6 +28,7 @@
 #include "htmlengine-edit-cursor.h"
 #include "htmlengine-edit-table.h"
 #include "htmlengine-edit-tablecell.h"
+#include "htmlgdkpainter.h"
 #include "htmlimage.h"
 #include "htmlobject.h"
 #include "htmltable.h"
@@ -357,7 +358,26 @@ html_engine_draw_cursor_in_area (HTMLEngine *engine,
 
        if (clip_cursor (engine, x, y, width, height, &x1, &y1, &x2, &y2)) {
                cairo_t *cr;
-               cr = gdk_cairo_create (engine->window);
+               gboolean using_painter_cr;
+
+               using_painter_cr = engine->painter &&
+                   HTML_IS_GDK_PAINTER (engine->painter) &&
+                   HTML_GDK_PAINTER (engine->painter)->cr != NULL;
+
+               if (using_painter_cr) {
+                       HTMLGdkPainter *gdk_painter = HTML_GDK_PAINTER (engine->painter);
+
+                       cr = gdk_painter->cr;
+                       cairo_save (cr);
+
+                       x1 -= gdk_painter->x1;
+                       y1 -= gdk_painter->y1;
+                       x2 -= gdk_painter->x1;
+                       y2 -= gdk_painter->y1;
+               } else {
+                       cr = gdk_cairo_create (engine->window);
+               }
+
                cairo_set_source_rgb (cr, 1, 1, 1);
                cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
                cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
@@ -365,7 +385,11 @@ html_engine_draw_cursor_in_area (HTMLEngine *engine,
                cairo_line_to (cr, x2 + 0.5, y2 - 0.5);
                cairo_set_line_width (cr, 1);
                cairo_stroke (cr);
-               cairo_destroy (cr);
+
+               if (using_painter_cr)
+                       cairo_restore (cr);
+               else
+                       cairo_destroy (cr);
        }
 }
 
diff --git a/gtkhtml/htmlengine.c b/gtkhtml/htmlengine.c
index b47f920..3c56cce 100644
--- a/gtkhtml/htmlengine.c
+++ b/gtkhtml/htmlengine.c
@@ -5290,11 +5290,12 @@ html_engine_draw_real (HTMLEngine *e,
                e->clue->y = html_engine_get_top_border (e) + e->clue->ascent;
                html_object_draw (e->clue, e->painter, x1, y1, x2 - x1, y2 - y1, 0, 0);
        }
-       html_painter_end (e->painter);
 
        if (e->editable || e->caret_mode)
                html_engine_draw_cursor_in_area (e, x1, y1, x2 - x1, y2 - y1);
 
+       html_painter_end (e->painter);
+
        e->expose = FALSE;
 }
 


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