diff options
author | Benjamin Otte <otte@redhat.com> | 2015-12-03 00:33:51 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-12-03 00:47:00 +0100 |
commit | 7fa37e4bf886745e8e7b07b6653513ac4c5172d3 (patch) | |
tree | 78aaf1fffad34b65afda31dcfab5ec84cb37e09b /gtk/gtkicontheme.c | |
parent | 109c3aa65a66c4a0bbae546500f68f82178d6d36 (diff) | |
download | gtk+-7fa37e4bf886745e8e7b07b6653513ac4c5172d3.tar.gz |
css: Introduct -gtk-icon-palette
This borrows heavily from the CSS4 fonts draft's font-palette, currently
found at https://drafts.csswg.org/css-fonts-4/#font-palette-control
The palette is mainly meant to trigger invalidations when colors used for
symbolic icons change, to potentially allow extending supported colors
in symbolic icons and to recolor all colors of a symbolic icon, not just
the main one.
The syntax for the property goes like this:
Name: -gtk-icon-palette
Value: default | name <color> [ , name <color> ]*
Initial: default
Applies to: all elements with icons
Inherited: yes
Animatable: yes, each color animated separately
The property defines a list of named colors to be used when looking up
icons. If a name is not defined, the value of the current "color"
property is used. Which names are relevant depends on the icons in use.
Currently symbolic icons make use of the names "success", "warning" and
"error".
"default" is the current behavior of the GTK when coloring symbolic
icons and is equal to the string
success @success_color, warning @warning_color, error @error_color
Animation is crudely implemented by animating colors that are in both
palettes that are animated and otherwise keeping the color from the
palette that defined it. Note that this can cause a sharp cut at the
beginning or end of the animation when the color goes away and will
therefore be replaced with the color property.
You can see an example of animations at
http://gfycat.com/CautiousPeacefulIaerismetalmark
Diffstat (limited to 'gtk/gtkicontheme.c')
-rw-r--r-- | gtk/gtkicontheme.c | 96 |
1 files changed, 42 insertions, 54 deletions
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 38d5d36602..a440510139 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -38,6 +38,8 @@ #endif /* G_OS_WIN32 */ #include "gtkicontheme.h" +#include "gtkcsspalettevalueprivate.h" +#include "gtkcssrgbavalueprivate.h" #include "gtkdebug.h" #include "deprecated/gtkiconfactory.h" #include "gtkiconcache.h" @@ -45,6 +47,7 @@ #include "gtkmain.h" #include "deprecated/gtknumerableiconprivate.h" #include "gtksettingsprivate.h" +#include "gtkstylecontextprivate.h" #include "gtkprivate.h" #undef GDK_DEPRECATED @@ -4663,6 +4666,39 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info, error); } +static void +lookup_colors_from_style_context (GtkStyleContext *context, + GdkRGBA *color_out, + GdkRGBA *success_out, + GdkRGBA *warning_out, + GdkRGBA *error_out) +{ + GtkCssValue *palette, *color; + const GdkRGBA *lookup; + + color = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR); + palette = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_PALETTE); + *color_out = *_gtk_css_rgba_value_get_rgba (color); + + lookup = gtk_css_palette_value_get_color (palette, "success"); + if (lookup) + *success_out = *lookup; + else + *success_out = *color_out; + + lookup = gtk_css_palette_value_get_color (palette, "warning"); + if (lookup) + *warning_out = *lookup; + else + *warning_out = *color_out; + + lookup = gtk_css_palette_value_get_color (palette, "error"); + if (lookup) + *error_out = *lookup; + else + *error_out = *color_out; +} + /** * gtk_icon_info_load_symbolic_for_context: * @icon_info: a #GtkIconInfo @@ -4694,16 +4730,10 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info, gboolean *was_symbolic, GError **error) { - GdkRGBA *color = NULL; GdkRGBA fg; - GdkRGBA *fgp; GdkRGBA success_color; - GdkRGBA *success_colorp; GdkRGBA warning_color; - GdkRGBA *warning_colorp; GdkRGBA error_color; - GdkRGBA *error_colorp; - GtkStateFlags state; gboolean is_symbolic; g_return_val_if_fail (icon_info != NULL, NULL); @@ -4717,29 +4747,11 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info, if (!is_symbolic) return gtk_icon_info_load_icon (icon_info, error); - fgp = success_colorp = warning_colorp = error_colorp = NULL; - - state = gtk_style_context_get_state (context); - gtk_style_context_get (context, state, "color", &color, NULL); - if (color) - { - fg = *color; - fgp = &fg; - gdk_rgba_free (color); - } - - if (gtk_style_context_lookup_color (context, "success_color", &success_color)) - success_colorp = &success_color; - - if (gtk_style_context_lookup_color (context, "warning_color", &warning_color)) - warning_colorp = &warning_color; - - if (gtk_style_context_lookup_color (context, "error_color", &error_color)) - error_colorp = &error_color; + lookup_colors_from_style_context (context, &fg, &success_color, &warning_color, &error_color); return gtk_icon_info_load_symbolic_internal (icon_info, - fgp, success_colorp, - warning_colorp, error_colorp, + &fg, &success_color, + &warning_color, &error_color, TRUE, error); } @@ -4991,43 +5003,19 @@ gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info, GAsyncReadyCallback callback, gpointer user_data) { - GdkRGBA *color = NULL; GdkRGBA fg; - GdkRGBA *fgp; GdkRGBA success_color; - GdkRGBA *success_colorp; GdkRGBA warning_color; - GdkRGBA *warning_colorp; GdkRGBA error_color; - GdkRGBA *error_colorp; - GtkStateFlags state; g_return_if_fail (icon_info != NULL); g_return_if_fail (context != NULL); - fgp = success_colorp = warning_colorp = error_colorp = NULL; - - state = gtk_style_context_get_state (context); - gtk_style_context_get (context, state, "color", &color, NULL); - if (color) - { - fg = *color; - fgp = &fg; - gdk_rgba_free (color); - } - - if (gtk_style_context_lookup_color (context, "success_color", &success_color)) - success_colorp = &success_color; - - if (gtk_style_context_lookup_color (context, "warning_color", &warning_color)) - warning_colorp = &warning_color; - - if (gtk_style_context_lookup_color (context, "error_color", &error_color)) - error_colorp = &error_color; + lookup_colors_from_style_context (context, &fg, &success_color, &warning_color, &error_color); gtk_icon_info_load_symbolic_async (icon_info, - fgp, success_colorp, - warning_colorp, error_colorp, + &fg, &success_color, + &warning_color, &error_color, cancellable, callback, user_data); } |