summaryrefslogtreecommitdiff
path: root/gtk/gtkcssparser.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2012-04-05 21:09:35 +0200
committerBenjamin Otte <otte@redhat.com>2012-04-17 08:59:19 +0200
commit1223d53a826bddd23318afd6eb8c69d5900882b7 (patch)
tree5b19a800ad9cd6d7bc4b6a2309fb2f80afc816e5 /gtk/gtkcssparser.c
parent7606fcb52e6840da82b4a6a22b4af36ddda73fc9 (diff)
downloadgtk+-1223d53a826bddd23318afd6eb8c69d5900882b7.tar.gz
cssparser: Move symbolic color parser to gtksymboliccolor.c
Diffstat (limited to 'gtk/gtkcssparser.c')
-rw-r--r--gtk/gtkcssparser.c264
1 files changed, 13 insertions, 251 deletions
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 96c367e8fd..62d911324c 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -736,278 +736,40 @@ _gtk_css_parser_try_enum (GtkCssParser *parser,
return result;
}
-typedef enum {
- COLOR_RGBA,
- COLOR_RGB,
- COLOR_LIGHTER,
- COLOR_DARKER,
- COLOR_SHADE,
- COLOR_ALPHA,
- COLOR_MIX,
- COLOR_WIN32
-} ColorType;
-
-static GtkSymbolicColor *
-gtk_css_parser_read_symbolic_color_function (GtkCssParser *parser,
- ColorType color)
-{
- GtkSymbolicColor *symbolic;
- GtkSymbolicColor *child1, *child2;
- double value;
-
- if (!_gtk_css_parser_try (parser, "(", TRUE))
- {
- _gtk_css_parser_error (parser, "Missing opening bracket in color definition");
- return NULL;
- }
-
- if (color == COLOR_RGB || color == COLOR_RGBA)
- {
- GdkRGBA rgba;
- double tmp;
- guint i;
-
- for (i = 0; i < 3; i++)
- {
- if (i > 0 && !_gtk_css_parser_try (parser, ",", TRUE))
- {
- _gtk_css_parser_error (parser, "Expected ',' in color definition");
- return NULL;
- }
-
- if (!_gtk_css_parser_try_double (parser, &tmp))
- {
- _gtk_css_parser_error (parser, "Invalid number for color value");
- return NULL;
- }
- if (_gtk_css_parser_try (parser, "%", TRUE))
- tmp /= 100.0;
- else
- tmp /= 255.0;
- if (i == 0)
- rgba.red = tmp;
- else if (i == 1)
- rgba.green = tmp;
- else if (i == 2)
- rgba.blue = tmp;
- else
- g_assert_not_reached ();
- }
-
- if (color == COLOR_RGBA)
- {
- if (i > 0 && !_gtk_css_parser_try (parser, ",", TRUE))
- {
- _gtk_css_parser_error (parser, "Expected ',' in color definition");
- return NULL;
- }
-
- if (!_gtk_css_parser_try_double (parser, &rgba.alpha))
- {
- _gtk_css_parser_error (parser, "Invalid number for alpha value");
- return NULL;
- }
- }
- else
- rgba.alpha = 1.0;
-
- symbolic = gtk_symbolic_color_new_literal (&rgba);
- }
- else if (color == COLOR_WIN32)
- {
- symbolic = _gtk_win32_theme_color_parse (parser);
- if (symbolic == NULL)
- return NULL;
- }
- else
- {
- child1 = _gtk_css_parser_read_symbolic_color (parser);
- if (child1 == NULL)
- return NULL;
-
- if (color == COLOR_MIX)
- {
- if (!_gtk_css_parser_try (parser, ",", TRUE))
- {
- _gtk_css_parser_error (parser, "Expected ',' in color definition");
- gtk_symbolic_color_unref (child1);
- return NULL;
- }
-
- child2 = _gtk_css_parser_read_symbolic_color (parser);
- if (child2 == NULL)
- {
- gtk_symbolic_color_unref (child1);
- return NULL;
- }
- }
- else
- child2 = NULL;
-
- if (color == COLOR_LIGHTER)
- value = 1.3;
- else if (color == COLOR_DARKER)
- value = 0.7;
- else
- {
- if (!_gtk_css_parser_try (parser, ",", TRUE))
- {
- _gtk_css_parser_error (parser, "Expected ',' in color definition");
- gtk_symbolic_color_unref (child1);
- if (child2)
- gtk_symbolic_color_unref (child2);
- return NULL;
- }
-
- if (!_gtk_css_parser_try_double (parser, &value))
- {
- _gtk_css_parser_error (parser, "Expected number in color definition");
- gtk_symbolic_color_unref (child1);
- if (child2)
- gtk_symbolic_color_unref (child2);
- return NULL;
- }
- }
-
- switch (color)
- {
- case COLOR_LIGHTER:
- case COLOR_DARKER:
- case COLOR_SHADE:
- symbolic = gtk_symbolic_color_new_shade (child1, value);
- break;
- case COLOR_ALPHA:
- symbolic = gtk_symbolic_color_new_alpha (child1, value);
- break;
- case COLOR_MIX:
- symbolic = gtk_symbolic_color_new_mix (child1, child2, value);
- break;
- default:
- g_assert_not_reached ();
- symbolic = NULL;
- }
-
- gtk_symbolic_color_unref (child1);
- if (child2)
- gtk_symbolic_color_unref (child2);
- }
-
- if (!_gtk_css_parser_try (parser, ")", TRUE))
- {
- _gtk_css_parser_error (parser, "Expected ')' in color definition");
- gtk_symbolic_color_unref (symbolic);
- return NULL;
- }
-
- return symbolic;
-}
-
-static GtkSymbolicColor *
-gtk_css_parser_try_hash_color (GtkCssParser *parser)
+gboolean
+_gtk_css_parser_try_hash_color (GtkCssParser *parser,
+ GdkRGBA *rgba)
{
if (parser->data[0] == '#' &&
g_ascii_isxdigit (parser->data[1]) &&
g_ascii_isxdigit (parser->data[2]) &&
g_ascii_isxdigit (parser->data[3]))
{
- GdkRGBA rgba;
-
if (g_ascii_isxdigit (parser->data[4]) &&
g_ascii_isxdigit (parser->data[5]) &&
g_ascii_isxdigit (parser->data[6]))
{
- rgba.red = ((get_xdigit (parser->data[1]) << 4) + get_xdigit (parser->data[2])) / 255.0;
- rgba.green = ((get_xdigit (parser->data[3]) << 4) + get_xdigit (parser->data[4])) / 255.0;
- rgba.blue = ((get_xdigit (parser->data[5]) << 4) + get_xdigit (parser->data[6])) / 255.0;
- rgba.alpha = 1.0;
+ rgba->red = ((get_xdigit (parser->data[1]) << 4) + get_xdigit (parser->data[2])) / 255.0;
+ rgba->green = ((get_xdigit (parser->data[3]) << 4) + get_xdigit (parser->data[4])) / 255.0;
+ rgba->blue = ((get_xdigit (parser->data[5]) << 4) + get_xdigit (parser->data[6])) / 255.0;
+ rgba->alpha = 1.0;
parser->data += 7;
}
else
{
- rgba.red = get_xdigit (parser->data[1]) / 15.0;
- rgba.green = get_xdigit (parser->data[2]) / 15.0;
- rgba.blue = get_xdigit (parser->data[3]) / 15.0;
- rgba.alpha = 1.0;
+ rgba->red = get_xdigit (parser->data[1]) / 15.0;
+ rgba->green = get_xdigit (parser->data[2]) / 15.0;
+ rgba->blue = get_xdigit (parser->data[3]) / 15.0;
+ rgba->alpha = 1.0;
parser->data += 4;
}
_gtk_css_parser_skip_whitespace (parser);
- return gtk_symbolic_color_new_literal (&rgba);
- }
-
- return NULL;
-}
-
-GtkSymbolicColor *
-_gtk_css_parser_read_symbolic_color (GtkCssParser *parser)
-{
- GtkSymbolicColor *symbolic;
- guint color;
- const char *names[] = {"rgba", "rgb", "lighter", "darker", "shade", "alpha", "mix",
- GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME};
- char *name;
-
- g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), NULL);
-
- if (_gtk_css_parser_try (parser, "transparent", TRUE))
- {
- GdkRGBA transparent = { 0, 0, 0, 0 };
-
- return gtk_symbolic_color_new_literal (&transparent);
- }
-
- if (_gtk_css_parser_try (parser, "@", FALSE))
- {
- name = _gtk_css_parser_try_name (parser, TRUE);
-
- if (name)
- {
- symbolic = gtk_symbolic_color_new_name (name);
- }
- else
- {
- _gtk_css_parser_error (parser, "'%s' is not a valid symbolic color name", name);
- symbolic = NULL;
- }
-
- g_free (name);
- return symbolic;
- }
-
- for (color = 0; color < G_N_ELEMENTS (names); color++)
- {
- if (_gtk_css_parser_try (parser, names[color], TRUE))
- break;
- }
-
- if (color < G_N_ELEMENTS (names))
- return gtk_css_parser_read_symbolic_color_function (parser, color);
-
- symbolic = gtk_css_parser_try_hash_color (parser);
- if (symbolic)
- return symbolic;
-
- name = _gtk_css_parser_try_name (parser, TRUE);
- if (name)
- {
- GdkRGBA rgba;
-
- if (gdk_rgba_parse (&rgba, name))
- {
- symbolic = gtk_symbolic_color_new_literal (&rgba);
- }
- else
- {
- _gtk_css_parser_error (parser, "'%s' is not a valid color name", name);
- symbolic = NULL;
- }
- g_free (name);
- return symbolic;
+ return TRUE;
}
- _gtk_css_parser_error (parser, "Not a color definition");
- return NULL;
+ return FALSE;
}
GFile *