[gtk+/wip/matthiasc/caret: 1/8] Add the caret-shape CSS property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/caret: 1/8] Add the caret-shape CSS property
- Date: Mon, 11 Jan 2016 05:10:42 +0000 (UTC)
commit 016e510f9b1e4de3e759ca6c25e4fb130b156f68
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 10 18:26:42 2016 -0500
Add the caret-shape CSS property
This allows to override the text caret shape (I-beam or block) from
the theme. The default value, auto, means to do things as we always have.
gtk/gtkcssenumvalue.c | 55 +++++++++++++++++++++++++++++++++++++++++
gtk/gtkcssenumvalueprivate.h | 4 +++
gtk/gtkcssstylepropertyimpl.c | 21 +++++++++++++++
gtk/gtkcsstypesprivate.h | 8 ++++++
4 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index f8828ec..67ffef0 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -1009,3 +1009,58 @@ _gtk_css_icon_style_value_get (const GtkCssValue *value)
return value->value;
}
+
+/* GtkCssCaretShape */
+
+static const GtkCssValueClass GTK_CSS_VALUE_CARET_SHAPE = {
+ gtk_css_value_enum_free,
+ gtk_css_value_enum_compute,
+ gtk_css_value_enum_equal,
+ gtk_css_value_enum_transition,
+ gtk_css_value_enum_print
+};
+
+static GtkCssValue caret_shape_values[] = {
+ { >K_CSS_VALUE_CARET_SHAPE, 1, GTK_CSS_CARET_SHAPE_AUTO, "auto" },
+ { >K_CSS_VALUE_CARET_SHAPE, 1, GTK_CSS_CARET_SHAPE_BAR, "bar" },
+ { >K_CSS_VALUE_CARET_SHAPE, 1, GTK_CSS_CARET_SHAPE_BLOCK, "block" },
+ { >K_CSS_VALUE_CARET_SHAPE, 1, GTK_CSS_CARET_SHAPE_UNDERSCORE, "underscore" },
+};
+
+GtkCssValue *
+_gtk_css_caret_shape_value_new (GtkCssCaretShape caret_shape)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (caret_shape_values); i++)
+ {
+ if (caret_shape_values[i].value == caret_shape)
+ return _gtk_css_value_ref (&caret_shape_values[i]);
+ }
+
+ g_return_val_if_reached (NULL);
+}
+
+GtkCssValue *
+_gtk_css_caret_shape_value_try_parse (GtkCssParser *parser)
+{
+ guint i;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS (caret_shape_values); i++)
+ {
+ if (_gtk_css_parser_try (parser, caret_shape_values[i].name, TRUE))
+ return _gtk_css_value_ref (&caret_shape_values[i]);
+ }
+
+ return NULL;
+}
+
+GtkCssCaretShape
+_gtk_css_caret_shape_value_get (const GtkCssValue *value)
+{
+ g_return_val_if_fail (value->class == >K_CSS_VALUE_CARET_SHAPE, GTK_CSS_CARET_SHAPE_AUTO);
+
+ return value->value;
+}
diff --git a/gtk/gtkcssenumvalueprivate.h b/gtk/gtkcssenumvalueprivate.h
index 884a243..4d774c9 100644
--- a/gtk/gtkcssenumvalueprivate.h
+++ b/gtk/gtkcssenumvalueprivate.h
@@ -86,6 +86,10 @@ GtkCssValue * _gtk_css_icon_style_value_new (GtkCssIconStyle icon_s
GtkCssValue * _gtk_css_icon_style_value_try_parse (GtkCssParser *parser);
GtkCssIconStyle _gtk_css_icon_style_value_get (const GtkCssValue *value);
+GtkCssValue * _gtk_css_caret_shape_value_new (GtkCssCaretShape caret_shape);
+GtkCssValue * _gtk_css_caret_shape_value_try_parse (GtkCssParser *parser);
+GtkCssCaretShape _gtk_css_caret_shape_value_get (const GtkCssValue *value);
+
G_END_DECLS
#endif /* __GTK_CSS_ENUM_VALUE_PRIVATE_H__ */
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index fa86507..7048dd2 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -1007,6 +1007,18 @@ icon_theme_value_parse (GtkCssStyleProperty *property,
return gtk_css_icon_theme_value_parse (parser);
}
+static GtkCssValue *
+caret_shape_parse (GtkCssStyleProperty *property,
+ GtkCssParser *parser)
+{
+ GtkCssValue *value = _gtk_css_caret_shape_value_try_parse (parser);
+
+ if (value == NULL)
+ _gtk_css_parser_error (parser, "unknown value for property");
+
+ return value;
+}
+
/*** REGISTRATION ***/
void
@@ -1820,4 +1832,13 @@ G_GNUC_END_IGNORE_DEPRECATIONS
color_query,
color_assign,
_gtk_css_color_value_new_current_color ());
+ gtk_css_style_property_register ("caret-shape",
+ GTK_CSS_PROPERTY_CARET_SHAPE,
+ G_TYPE_NONE,
+ GTK_STYLE_PROPERTY_INHERIT,
+ GTK_CSS_AFFECTS_TEXT,
+ caret_shape_parse,
+ NULL,
+ NULL,
+ _gtk_css_caret_shape_value_new (GTK_CSS_CARET_SHAPE_AUTO));
}
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 082b3f6..597c293 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -224,6 +224,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_GTK_KEY_BINDINGS,
GTK_CSS_PROPERTY_CARET_COLOR,
GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR,
+ GTK_CSS_PROPERTY_CARET_SHAPE,
/* add more */
GTK_CSS_PROPERTY_N_PROPERTIES
};
@@ -363,6 +364,13 @@ typedef enum /*< skip >*/ {
GTK_CSS_MS,
} GtkCssUnit;
+typedef enum /*< skip >*/ {
+ GTK_CSS_CARET_SHAPE_AUTO,
+ GTK_CSS_CARET_SHAPE_BAR,
+ GTK_CSS_CARET_SHAPE_BLOCK,
+ GTK_CSS_CARET_SHAPE_UNDERSCORE
+} GtkCssCaretShape;
+
GtkCssChange _gtk_css_change_for_sibling (GtkCssChange match);
GtkCssChange _gtk_css_change_for_child (GtkCssChange match);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]