[gtk+/wip/matthiasc/caret: 2/8] entry: Respect caret-shape CSS property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/caret: 2/8] entry: Respect caret-shape CSS property
- Date: Mon, 11 Jan 2016 05:10:47 +0000 (UTC)
commit 1283f42bac6a5794ee62a9dadeed05ae32fade16
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 10 18:27:49 2016 -0500
entry: Respect caret-shape CSS property
When drawing the text cursor, consult the caret-shape property
to determine what kind of cursor to draw.
gtk/gtkentry.c | 34 ++++++++++++++++++++++++++++------
1 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index ca13c3f..8af9479 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -71,6 +71,7 @@
#include "gtkmagnifierprivate.h"
#include "gtkcssnodeprivate.h"
#include "gtkcsscustomgadgetprivate.h"
+#include "gtkcssenumvalueprivate.h"
#include "a11y/gtkentryaccessible.h"
@@ -6634,6 +6635,8 @@ gtk_entry_draw_cursor (GtkEntry *entry,
PangoLayout *layout;
const char *text;
gint x, y;
+ GtkCssValue *value;
+ GtkCssCaretShape shape;
context = gtk_widget_get_style_context (widget);
@@ -6646,19 +6649,32 @@ gtk_entry_draw_cursor (GtkEntry *entry,
else
cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
- if (!priv->overwrite_mode)
- block = FALSE;
- else
- block = _gtk_text_util_get_block_cursor_location (layout,
- cursor_index, &cursor_rect, &block_at_line_end);
+ block = _gtk_text_util_get_block_cursor_location (layout,
+ cursor_index, &cursor_rect, &block_at_line_end);
if (!block)
+ shape = GTK_CSS_CARET_SHAPE_BAR;
+ else
+ {
+ value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_CARET_SHAPE);
+ shape = _gtk_css_caret_shape_value_get (value);
+
+ if (shape == GTK_CSS_CARET_SHAPE_AUTO)
+ {
+ if (priv->overwrite_mode)
+ shape = GTK_CSS_CARET_SHAPE_BLOCK;
+ else
+ shape = GTK_CSS_CARET_SHAPE_BAR;
+ }
+ }
+
+ if (shape == GTK_CSS_CARET_SHAPE_BAR)
{
gtk_render_insertion_cursor (context, cr,
x, y,
layout, cursor_index, priv->resolved_dir);
}
- else /* overwrite_mode */
+ else
{
GdkRGBA cursor_color;
GdkRectangle rect;
@@ -6670,6 +6686,12 @@ gtk_entry_draw_cursor (GtkEntry *entry,
rect.width = PANGO_PIXELS (cursor_rect.width);
rect.height = PANGO_PIXELS (cursor_rect.height);
+ if (shape == GTK_CSS_CARET_SHAPE_UNDERSCORE)
+ {
+ rect.y = rect.y + rect.height - 1;
+ rect.height = 1;
+ }
+
_gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
gdk_cairo_set_source_rgba (cr, &cursor_color);
gdk_cairo_rectangle (cr, &rect);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]