styleprovider: Change function prototype

Make _gtk_style_provider_private_get_color() return a GtkCssValue (a
GtkCssColorValue to be exact) instead of GtkSymbolicColor.

With this, the symbolic color usage inside GTK is minimized.
This commit is contained in:
Benjamin Otte 2012-11-25 02:28:59 +01:00
parent 08ac1504d2
commit 42dc0ea0fd
10 changed files with 35 additions and 42 deletions

View File

@ -161,14 +161,13 @@ _gtk_css_color_value_resolve (GtkCssValue *color,
return _gtk_css_value_ref (color->last_value); return _gtk_css_value_ref (color->last_value);
case COLOR_TYPE_NAME: case COLOR_TYPE_NAME:
{ {
GtkSymbolicColor *symbolic; GtkCssValue *named;
symbolic = _gtk_style_provider_private_get_color (provider, color->sym_col.name); named = _gtk_style_provider_private_get_color (provider, color->sym_col.name);
if (named == NULL)
if (!symbolic)
return NULL; return NULL;
value = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (symbolic), provider, current, current_deps, dependencies); value = _gtk_css_color_value_resolve (named, provider, current, current_deps, dependencies);
} }
break; break;

View File

@ -27,13 +27,13 @@
#include "gtkbitmaskprivate.h" #include "gtkbitmaskprivate.h"
#include "gtkcssarrayvalueprivate.h" #include "gtkcssarrayvalueprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcsskeyframesprivate.h" #include "gtkcsskeyframesprivate.h"
#include "gtkcssparserprivate.h" #include "gtkcssparserprivate.h"
#include "gtkcsssectionprivate.h" #include "gtkcsssectionprivate.h"
#include "gtkcssselectorprivate.h" #include "gtkcssselectorprivate.h"
#include "gtkcssshorthandpropertyprivate.h" #include "gtkcssshorthandpropertyprivate.h"
#include "gtkcssstylefuncsprivate.h" #include "gtkcssstylefuncsprivate.h"
#include "gtksymboliccolor.h"
#include "gtkstyleprovider.h" #include "gtkstyleprovider.h"
#include "gtkstylecontextprivate.h" #include "gtkstylecontextprivate.h"
#include "gtkstylepropertiesprivate.h" #include "gtkstylepropertiesprivate.h"
@ -1403,7 +1403,7 @@ gtk_css_provider_init (GtkCssProvider *css_provider)
priv->symbolic_colors = g_hash_table_new_full (g_str_hash, g_str_equal, priv->symbolic_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free, (GDestroyNotify) g_free,
(GDestroyNotify) gtk_symbolic_color_unref); (GDestroyNotify) _gtk_css_value_unref);
priv->keyframes = g_hash_table_new_full (g_str_hash, g_str_equal, priv->keyframes = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free, (GDestroyNotify) g_free,
(GDestroyNotify) _gtk_css_value_unref); (GDestroyNotify) _gtk_css_value_unref);
@ -1479,7 +1479,7 @@ gtk_css_style_provider_iface_init (GtkStyleProviderIface *iface)
iface->get_style_property = gtk_css_provider_get_style_property; iface->get_style_property = gtk_css_provider_get_style_property;
} }
static GtkSymbolicColor * static GtkCssValue *
gtk_css_style_provider_get_color (GtkStyleProviderPrivate *provider, gtk_css_style_provider_get_color (GtkStyleProviderPrivate *provider,
const char *name) const char *name)
{ {
@ -1838,7 +1838,7 @@ parse_import (GtkCssScanner *scanner)
static gboolean static gboolean
parse_color_definition (GtkCssScanner *scanner) parse_color_definition (GtkCssScanner *scanner)
{ {
GtkSymbolicColor *symbolic; GtkCssValue *color;
char *name; char *name;
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION); gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
@ -1862,8 +1862,8 @@ parse_color_definition (GtkCssScanner *scanner)
return TRUE; return TRUE;
} }
symbolic = _gtk_css_symbolic_value_new (scanner->parser); color = _gtk_css_color_value_parse (scanner->parser);
if (symbolic == NULL) if (color == NULL)
{ {
g_free (name); g_free (name);
_gtk_css_parser_resync (scanner->parser, TRUE, 0); _gtk_css_parser_resync (scanner->parser, TRUE, 0);
@ -1874,7 +1874,7 @@ parse_color_definition (GtkCssScanner *scanner)
if (!_gtk_css_parser_try (scanner->parser, ";", TRUE)) if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
{ {
g_free (name); g_free (name);
gtk_symbolic_color_unref (symbolic); _gtk_css_value_unref (color);
gtk_css_provider_error_literal (scanner->provider, gtk_css_provider_error_literal (scanner->provider,
scanner, scanner,
GTK_CSS_PROVIDER_ERROR, GTK_CSS_PROVIDER_ERROR,
@ -1886,7 +1886,7 @@ parse_color_definition (GtkCssScanner *scanner)
return TRUE; return TRUE;
} }
g_hash_table_insert (scanner->provider->priv->symbolic_colors, name, symbolic); g_hash_table_insert (scanner->provider->priv->symbolic_colors, name, color);
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION); gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
return TRUE; return TRUE;
@ -2878,7 +2878,6 @@ gtk_css_provider_print_colors (GHashTable *colors,
GString *str) GString *str)
{ {
GList *keys, *walk; GList *keys, *walk;
char *s;
keys = g_hash_table_get_keys (colors); keys = g_hash_table_get_keys (colors);
/* so the output is identical for identical styles */ /* so the output is identical for identical styles */
@ -2887,14 +2886,12 @@ gtk_css_provider_print_colors (GHashTable *colors,
for (walk = keys; walk; walk = walk->next) for (walk = keys; walk; walk = walk->next)
{ {
const char *name = walk->data; const char *name = walk->data;
GtkSymbolicColor *symbolic = g_hash_table_lookup (colors, (gpointer) name); GtkCssValue *color = g_hash_table_lookup (colors, (gpointer) name);
g_string_append (str, "@define-color "); g_string_append (str, "@define-color ");
g_string_append (str, name); g_string_append (str, name);
g_string_append (str, " "); g_string_append (str, " ");
s = gtk_symbolic_color_to_string (symbolic); _gtk_css_value_print (color, str);
g_string_append (str, s);
g_free (s);
g_string_append (str, ";\n"); g_string_append (str, ";\n");
} }

View File

@ -122,7 +122,7 @@ gtk_modifier_style_provider_init (GtkStyleProviderIface *iface)
iface->get_style_property = gtk_modifier_style_get_style_property; iface->get_style_property = gtk_modifier_style_get_style_property;
} }
static GtkSymbolicColor * static GtkCssValue *
gtk_modifier_style_provider_get_color (GtkStyleProviderPrivate *provider, gtk_modifier_style_provider_get_color (GtkStyleProviderPrivate *provider,
const char *name) const char *name)
{ {

View File

@ -32,7 +32,6 @@
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkcssproviderprivate.h" #include "gtkcssproviderprivate.h"
#include "gtkstyleproviderprivate.h" #include "gtkstyleproviderprivate.h"
#include "gtksymboliccolor.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
#include "gtkversion.h" #include "gtkversion.h"
@ -1460,7 +1459,7 @@ gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
{ {
} }
static GtkSymbolicColor * static GtkCssValue *
gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider, gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider,
const char *name) const char *name)
{ {

View File

@ -123,13 +123,13 @@ gtk_style_cascade_provider_iface_init (GtkStyleProviderIface *iface)
iface->get_style_property = gtk_style_cascade_get_style_property; iface->get_style_property = gtk_style_cascade_get_style_property;
} }
static GtkSymbolicColor * static GtkCssValue *
gtk_style_cascade_get_color (GtkStyleProviderPrivate *provider, gtk_style_cascade_get_color (GtkStyleProviderPrivate *provider,
const char *name) const char *name)
{ {
GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider); GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider);
GtkStyleCascadeIter iter; GtkStyleCascadeIter iter;
GtkSymbolicColor *symbolic; GtkCssValue *color;
GtkStyleProvider *item; GtkStyleProvider *item;
for (item = gtk_style_cascade_iter_init (cascade, &iter); for (item = gtk_style_cascade_iter_init (cascade, &iter);
@ -138,9 +138,9 @@ gtk_style_cascade_get_color (GtkStyleProviderPrivate *provider,
{ {
if (GTK_IS_STYLE_PROVIDER_PRIVATE (item)) if (GTK_IS_STYLE_PROVIDER_PRIVATE (item))
{ {
symbolic = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (item), name); color = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (item), name);
if (symbolic) if (color)
return symbolic; return color;
} }
else else
{ {

View File

@ -2298,7 +2298,7 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
else else
g_value_init (&pcache->value, GDK_TYPE_COLOR); g_value_init (&pcache->value, GDK_TYPE_COLOR);
if (_gtk_style_context_resolve_color (context, color, &rgba, NULL)) if (_gtk_style_context_resolve_color (context, _gtk_symbolic_color_get_css_value (color), &rgba, NULL))
{ {
if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA) if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
g_value_set_boxed (&pcache->value, &rgba); g_value_set_boxed (&pcache->value, &rgba);
@ -2704,7 +2704,7 @@ gtk_style_context_get_junction_sides (GtkStyleContext *context)
gboolean gboolean
_gtk_style_context_resolve_color (GtkStyleContext *context, _gtk_style_context_resolve_color (GtkStyleContext *context,
GtkSymbolicColor *color, GtkCssValue *color,
GdkRGBA *result, GdkRGBA *result,
GtkCssDependencies *dependencies) GtkCssDependencies *dependencies)
{ {
@ -2714,7 +2714,7 @@ _gtk_style_context_resolve_color (GtkStyleContext *context,
g_return_val_if_fail (color != NULL, FALSE); g_return_val_if_fail (color != NULL, FALSE);
g_return_val_if_fail (result != NULL, FALSE); g_return_val_if_fail (result != NULL, FALSE);
val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (color), val = _gtk_css_color_value_resolve (color,
GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR), _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
GTK_CSS_DEPENDS_ON_COLOR, GTK_CSS_DEPENDS_ON_COLOR,
@ -2742,17 +2742,17 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
const gchar *color_name, const gchar *color_name,
GdkRGBA *color) GdkRGBA *color)
{ {
GtkSymbolicColor *sym_color; GtkCssValue *value;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE); g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
g_return_val_if_fail (color_name != NULL, FALSE); g_return_val_if_fail (color_name != NULL, FALSE);
g_return_val_if_fail (color != NULL, FALSE); g_return_val_if_fail (color != NULL, FALSE);
sym_color = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name); value = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name);
if (sym_color == NULL) if (value == NULL)
return FALSE; return FALSE;
return _gtk_style_context_resolve_color (context, sym_color, color, NULL); return _gtk_style_context_resolve_color (context, value, color, NULL);
} }
/** /**

View File

@ -20,7 +20,6 @@
#include "gtkstylecontext.h" #include "gtkstylecontext.h"
#include "gtkstyleproviderprivate.h" #include "gtkstyleproviderprivate.h"
#include "gtksymboliccolor.h"
#include "gtkbitmaskprivate.h" #include "gtkbitmaskprivate.h"
#include "gtkcssvalueprivate.h" #include "gtkcssvalueprivate.h"
@ -46,7 +45,7 @@ void _gtk_style_context_queue_invalidate (GtkStyleContext *c
gboolean _gtk_style_context_check_region_name (const gchar *str); gboolean _gtk_style_context_check_region_name (const gchar *str);
gboolean _gtk_style_context_resolve_color (GtkStyleContext *context, gboolean _gtk_style_context_resolve_color (GtkStyleContext *context,
GtkSymbolicColor *color, GtkCssValue *color,
GdkRGBA *result, GdkRGBA *result,
GtkCssDependencies *dependencies); GtkCssDependencies *dependencies);
void _gtk_style_context_get_cursor_color (GtkStyleContext *context, void _gtk_style_context_get_cursor_color (GtkStyleContext *context,

View File

@ -284,11 +284,11 @@ gtk_style_properties_provider_init (GtkStyleProviderIface *iface)
{ {
} }
static GtkSymbolicColor * static GtkCssValue *
gtk_style_properties_provider_get_color (GtkStyleProviderPrivate *provider, gtk_style_properties_provider_get_color (GtkStyleProviderPrivate *provider,
const char *name) const char *name)
{ {
return gtk_style_properties_lookup_color (GTK_STYLE_PROPERTIES (provider), name); return _gtk_symbolic_color_get_css_value (gtk_style_properties_lookup_color (GTK_STYLE_PROPERTIES (provider), name));
} }
static void static void

View File

@ -44,7 +44,7 @@ _gtk_style_provider_private_default_init (GtkStyleProviderPrivateInterface *ifac
} }
GtkSymbolicColor * GtkCssValue *
_gtk_style_provider_private_get_color (GtkStyleProviderPrivate *provider, _gtk_style_provider_private_get_color (GtkStyleProviderPrivate *provider,
const char *name) const char *name)
{ {

View File

@ -22,8 +22,7 @@
#include "gtk/gtkcsskeyframesprivate.h" #include "gtk/gtkcsskeyframesprivate.h"
#include "gtk/gtkcsslookupprivate.h" #include "gtk/gtkcsslookupprivate.h"
#include "gtk/gtkcssmatcherprivate.h" #include "gtk/gtkcssmatcherprivate.h"
#include <gtk/gtkenums.h> #include "gtk/gtkcssvalueprivate.h"
#include <gtk/gtksymboliccolor.h>
#include <gtk/gtktypes.h> #include <gtk/gtktypes.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -40,7 +39,7 @@ struct _GtkStyleProviderPrivateInterface
{ {
GTypeInterface g_iface; GTypeInterface g_iface;
GtkSymbolicColor * (* get_color) (GtkStyleProviderPrivate *provider, GtkCssValue * (* get_color) (GtkStyleProviderPrivate *provider,
const char *name); const char *name);
GtkCssKeyframes * (* get_keyframes) (GtkStyleProviderPrivate *provider, GtkCssKeyframes * (* get_keyframes) (GtkStyleProviderPrivate *provider,
const char *name); const char *name);
@ -56,7 +55,7 @@ struct _GtkStyleProviderPrivateInterface
GType _gtk_style_provider_private_get_type (void) G_GNUC_CONST; GType _gtk_style_provider_private_get_type (void) G_GNUC_CONST;
GtkSymbolicColor * _gtk_style_provider_private_get_color (GtkStyleProviderPrivate *provider, GtkCssValue * _gtk_style_provider_private_get_color (GtkStyleProviderPrivate *provider,
const char *name); const char *name);
GtkCssKeyframes * _gtk_style_provider_private_get_keyframes(GtkStyleProviderPrivate *provider, GtkCssKeyframes * _gtk_style_provider_private_get_keyframes(GtkStyleProviderPrivate *provider,
const char *name); const char *name);