Commit 736b350d authored by Cosimo Cecchi's avatar Cosimo Cecchi

css: Add a GtkCssValue for GtkCssImageEffect

This will allow us to use the CSS machinery to apply a highlight or dim
effect when images are prelit or insensitive.

https://bugzilla.gnome.org/show_bug.cgi?id=705443
parent 723a589b
......@@ -653,3 +653,56 @@ _gtk_css_fill_mode_value_get (const GtkCssValue *value)
return value->value;
}
/* GtkCssImageEffect */
static const GtkCssValueClass GTK_CSS_VALUE_IMAGE_EFFECT = {
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 image_effect_values[] = {
{ &GTK_CSS_VALUE_IMAGE_EFFECT, 1, GTK_CSS_IMAGE_EFFECT_NONE, "none" },
{ &GTK_CSS_VALUE_IMAGE_EFFECT, 1, GTK_CSS_IMAGE_EFFECT_HIGHLIGHT, "highlight" },
{ &GTK_CSS_VALUE_IMAGE_EFFECT, 1, GTK_CSS_IMAGE_EFFECT_DIM, "dim" }
};
GtkCssValue *
_gtk_css_image_effect_value_new (GtkCssImageEffect image_effect)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (image_effect_values); i++)
{
if (image_effect_values[i].value == image_effect)
return _gtk_css_value_ref (&image_effect_values[i]);
}
g_return_val_if_reached (NULL);
}
GtkCssValue *
_gtk_css_image_effect_value_try_parse (GtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (image_effect_values); i++)
{
if (_gtk_css_parser_try (parser, image_effect_values[i].name, TRUE))
return _gtk_css_value_ref (&image_effect_values[i]);
}
return NULL;
}
GtkCssImageEffect
_gtk_css_image_effect_value_get (const GtkCssValue *value)
{
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IMAGE_EFFECT, GTK_CSS_IMAGE_EFFECT_NONE);
return value->value;
}
......@@ -64,6 +64,10 @@ GtkCssValue * _gtk_css_fill_mode_value_new (GtkCssFillMode fill_m
GtkCssValue * _gtk_css_fill_mode_value_try_parse (GtkCssParser *parser);
GtkCssFillMode _gtk_css_fill_mode_value_get (const GtkCssValue *value);
GtkCssValue * _gtk_css_image_effect_value_new (GtkCssImageEffect image_effect);
GtkCssValue * _gtk_css_image_effect_value_try_parse (GtkCssParser *parser);
GtkCssImageEffect _gtk_css_image_effect_value_get (const GtkCssValue *value);
G_END_DECLS
#endif /* __GTK_CSS_ENUM_VALUE_PRIVATE_H__ */
......@@ -464,6 +464,18 @@ parse_css_fill_mode (GtkCssStyleProperty *property,
return _gtk_css_array_value_parse (parser, parse_one_css_fill_mode);
}
static GtkCssValue *
image_effect_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
GtkCssValue *value = _gtk_css_image_effect_value_try_parse (parser);
if (value == NULL)
_gtk_css_parser_error (parser, "unknown value for property");
return value;
}
static GtkCssValue *
bindings_value_parse_one (GtkCssParser *parser)
{
......@@ -1398,6 +1410,14 @@ _gtk_css_style_property_init_properties (void)
NULL,
NULL,
_gtk_css_number_value_new (1, GTK_CSS_NUMBER));
gtk_css_style_property_register ("-gtk-image-effect",
GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT,
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_NO_RESIZE,
image_effect_parse,
NULL,
NULL,
_gtk_css_image_effect_value_new (GTK_CSS_IMAGE_EFFECT_NONE));
gtk_css_style_property_register ("engine",
GTK_CSS_PROPERTY_ENGINE,
......
......@@ -133,6 +133,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_ANIMATION_DELAY,
GTK_CSS_PROPERTY_ANIMATION_FILL_MODE,
GTK_CSS_PROPERTY_OPACITY,
GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT,
GTK_CSS_PROPERTY_ENGINE,
GTK_CSS_PROPERTY_GTK_KEY_BINDINGS,
/* add more */
......@@ -164,6 +165,12 @@ typedef enum /*< skip >*/ {
GTK_CSS_FILL_BOTH
} GtkCssFillMode;
typedef enum /*< skip >*/ {
GTK_CSS_IMAGE_EFFECT_NONE,
GTK_CSS_IMAGE_EFFECT_HIGHLIGHT,
GTK_CSS_IMAGE_EFFECT_DIM
} GtkCssImageEffect;
typedef enum /*< skip >*/ {
/* relative font sizes */
GTK_CSS_FONT_SIZE_SMALLER,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment