css: Add a -gtk-icon-style property

The values can be:
  "requested" - the style as requested
  "regular"   - use a regular full-color icon
  "symbolic"  - use a symbolic icon

The property defaults to "requested", so no changes should be seen
unless CSS overrides it.
It is also inherited, so that using this CSS
  .toolbar { -gtk-icon-style: symbolic; }
is enough to force the whole toolbar to use symbolic icons.
This commit is contained in:
Benjamin Otte 2014-05-06 16:06:33 +02:00
parent 55f473f4e6
commit 109fcb987b
4 changed files with 85 additions and 0 deletions

View File

@ -706,3 +706,57 @@ _gtk_css_image_effect_value_get (const GtkCssValue *value)
return value->value;
}
/* GtkCssIconStyle */
static const GtkCssValueClass GTK_CSS_VALUE_ICON_STYLE = {
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 icon_style_values[] = {
{ &GTK_CSS_VALUE_ICON_STYLE, 1, GTK_CSS_ICON_STYLE_REQUESTED, "requested" },
{ &GTK_CSS_VALUE_ICON_STYLE, 1, GTK_CSS_ICON_STYLE_REGULAR, "regular" },
{ &GTK_CSS_VALUE_ICON_STYLE, 1, GTK_CSS_ICON_STYLE_SYMBOLIC, "symbolic" }
};
GtkCssValue *
_gtk_css_icon_style_value_new (GtkCssIconStyle icon_style)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (icon_style_values); i++)
{
if (icon_style_values[i].value == icon_style)
return _gtk_css_value_ref (&icon_style_values[i]);
}
g_return_val_if_reached (NULL);
}
GtkCssValue *
_gtk_css_icon_style_value_try_parse (GtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (icon_style_values); i++)
{
if (_gtk_css_parser_try (parser, icon_style_values[i].name, TRUE))
return _gtk_css_value_ref (&icon_style_values[i]);
}
return NULL;
}
GtkCssIconStyle
_gtk_css_icon_style_value_get (const GtkCssValue *value)
{
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ICON_STYLE, GTK_CSS_ICON_STYLE_REQUESTED);
return value->value;
}

View File

@ -68,6 +68,10 @@ GtkCssValue * _gtk_css_image_effect_value_new (GtkCssImageEffect imag
GtkCssValue * _gtk_css_image_effect_value_try_parse (GtkCssParser *parser);
GtkCssImageEffect _gtk_css_image_effect_value_get (const GtkCssValue *value);
GtkCssValue * _gtk_css_icon_style_value_new (GtkCssIconStyle icon_style);
GtkCssValue * _gtk_css_icon_style_value_try_parse (GtkCssParser *parser);
GtkCssIconStyle _gtk_css_icon_style_value_get (const GtkCssValue *value);
G_END_DECLS
#endif /* __GTK_CSS_ENUM_VALUE_PRIVATE_H__ */

View File

@ -477,6 +477,18 @@ image_effect_parse (GtkCssStyleProperty *property,
return value;
}
static GtkCssValue *
icon_style_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
GtkCssValue *value = _gtk_css_icon_style_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)
{
@ -981,6 +993,14 @@ _gtk_css_style_property_init_properties (void)
NULL,
NULL,
_gtk_css_shadows_value_new_none ());
gtk_css_style_property_register ("-gtk-icon-style",
GTK_CSS_PROPERTY_ICON_STYLE,
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_NO_RESIZE,
icon_style_parse,
NULL,
NULL,
_gtk_css_icon_style_value_new (GTK_CSS_ICON_STYLE_REQUESTED));
gtk_css_style_property_register ("-gtk-icon-transform",
GTK_CSS_PROPERTY_ICON_TRANSFORM,
G_TYPE_NONE,

View File

@ -82,6 +82,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_TEXT_SHADOW,
GTK_CSS_PROPERTY_ICON_SOURCE,
GTK_CSS_PROPERTY_ICON_SHADOW,
GTK_CSS_PROPERTY_ICON_STYLE,
GTK_CSS_PROPERTY_ICON_TRANSFORM,
GTK_CSS_PROPERTY_BOX_SHADOW,
GTK_CSS_PROPERTY_MARGIN_TOP,
@ -177,6 +178,12 @@ typedef enum /*< skip >*/ {
GTK_CSS_IMAGE_EFFECT_DIM
} GtkCssImageEffect;
typedef enum /*< skip >*/ {
GTK_CSS_ICON_STYLE_REQUESTED,
GTK_CSS_ICON_STYLE_REGULAR,
GTK_CSS_ICON_STYLE_SYMBOLIC
} GtkCssIconStyle;
typedef enum /*< skip >*/ {
/* relative font sizes */
GTK_CSS_FONT_SIZE_SMALLER,