gtk-css-engine r161 - in trunk: . libccss/ccss src themes/gtk-css-test/gtk-2.0



Author: robsta
Date: Mon Oct  6 09:35:22 2008
New Revision: 161
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=161&view=rev

Log:
* libccss/ccss/ccss-color.c:
* libccss/ccss/ccss-function.c:
* src/gce-functions.c:
* themes/gtk-css-test/gtk-2.0/styles.css:
Finish basic color functions support.



Modified:
   trunk/ChangeLog
   trunk/libccss/ccss/ccss-color.c
   trunk/libccss/ccss/ccss-function.c
   trunk/src/gce-functions.c
   trunk/themes/gtk-css-test/gtk-2.0/styles.css

Modified: trunk/libccss/ccss/ccss-color.c
==============================================================================
--- trunk/libccss/ccss/ccss-color.c	(original)
+++ trunk/libccss/ccss/ccss-color.c	Mon Oct  6 09:35:22 2008
@@ -308,17 +308,29 @@
 		*value = (*value)->next;
 		return CCSS_PROPERTY_SPEC_SET;
 	case TERM_FUNCTION:
-		/* FIXME: ATM only "hex" representation can be fed back. */
-		/* TODO: recurse to set up the functions. */
 		function = cr_string_peek_raw_str ((*value)->content.str);
 		color = ccss_function_invoke (function, (*value)->ext_content.func_param);
 		if (color) {
-			ret = parse_hex (self, color);
-			if (ret) {
-				*value = (*value)->next;
+			if (g_str_has_prefix (color, "rgb(")) {
+
+				/* FIXME error handling. */
+				char *iter;
+				iter = color + strlen ("rgb(");
+
+				self->red = g_ascii_strtod (iter, &iter);
+				if (!iter) { g_warning ("Could not parse '%s'", color); goto bail; }
+
+				self->green = g_ascii_strtod (iter + 1, &iter);
+				if (!iter) { g_warning ("Could not parse '%s'", color); goto bail; }
+
+				self->blue = g_ascii_strtod (iter + 1, &iter);
+				if (!iter) { g_warning ("Could not parse '%s'", color); goto bail; }
+
 				g_free (color), color = NULL;
 				return CCSS_PROPERTY_SPEC_SET;
 			}
+			/* FIXME recognize "rgba". */
+bail:
 			g_free (color), color = NULL;
 		}
 		return CCSS_PROPERTY_SPEC_UNSET;
@@ -329,6 +341,7 @@
 	case TERM_URI:
 	case TERM_UNICODERANGE:
 	default:
+		g_assert_not_reached ();
 		return CCSS_PROPERTY_SPEC_UNSET;
 	}
 }

Modified: trunk/libccss/ccss/ccss-function.c
==============================================================================
--- trunk/libccss/ccss/ccss-function.c	(original)
+++ trunk/libccss/ccss/ccss-function.c	Mon Oct  6 09:35:22 2008
@@ -47,40 +47,19 @@
 	}
 }
 
-char *
-ccss_function_invoke (char const		*name,
-		     CRTerm const	*values)
+static GSList *
+parse_args_r (GSList		 *args,
+	      CRTerm const	**values)
 {
-	ccss_function_f	 function;
-	GSList		*args;
-	GSList		*iter;
 	char		*val;
 	char const	*unit;
-	char		*ret;
-
-	g_return_val_if_fail (_vtable && name, NULL);
-
-	function = NULL;
-	for (unsigned int i = 0; _vtable[i].name; i++) {
-		if (0 == strcmp (name, _vtable[i].name)) {
-			function = _vtable[i].function;
-			break;
-		}
-	}
-
-	if (!function) {
-		g_warning ("Function `%s' could not be resolved", name);
-		return NULL;
-	}
+	CRTerm const	*args_term;
 
-	/* parse args */
-	args = NULL;
-	iter = NULL;
-	while (values) {
+	while (*values) {
 		val = NULL;
-		switch (values->type) {
+		switch ((*values)->type) {
 		case TERM_NUMBER:
-			switch (values->content.num->type) {
+			switch ((*values)->content.num->type) {
 			case NUM_GENERIC:
 				unit = "";
 				break;
@@ -94,45 +73,108 @@
 				g_assert_not_reached ();
 				unit = "";
 			}
-			val = g_strdup_printf ("%f%s", values->content.num->val, unit);
+			val = g_strdup_printf ("%f%s", (*values)->content.num->val, unit);
+			args = g_slist_prepend (args, val);
 			break;
 		case TERM_STRING:
 		case TERM_IDENT:
 		case TERM_URI:
-			val = g_strdup_printf ("%s", cr_string_peek_raw_str (values->content.str));			
+			val = g_strdup_printf ("%s", cr_string_peek_raw_str ((*values)->content.str));
+			args = g_slist_prepend (args, val);
 			break;
 		case TERM_HASH:
-			val = g_strdup_printf ("#%s", cr_string_peek_raw_str (values->content.str));			
+			val = g_strdup_printf ("#%s", cr_string_peek_raw_str ((*values)->content.str));
+			args = g_slist_prepend (args, val);			
 			break;
-		case TERM_NO_TYPE:
 		case TERM_FUNCTION:
+
+			val = g_strdup_printf ("%s(", cr_string_peek_raw_str ((*values)->content.str));
+			args = g_slist_prepend (args, val);
+
+			args_term = (*values)->ext_content.func_param;
+			args = parse_args_r (args, &args_term);
+
+			val = g_strdup (")");
+			args = g_slist_prepend (args, val);
+
+			break;
 		case TERM_RGB:
+
+			val = g_strdup ("rgb(");
+			args = g_slist_prepend (args, val);
+
+			val = g_strdup_printf ("%f", (*values)->content.rgb->red / 255.);
+			args = g_slist_prepend (args, val);
+
+			val = g_strdup (",");
+			args = g_slist_prepend (args, val);
+
+			val = g_strdup_printf ("%f", (*values)->content.rgb->green / 255.);
+			args = g_slist_prepend (args, val);
+
+			val = g_strdup (",");
+			args = g_slist_prepend (args, val);
+
+			val = g_strdup_printf ("%f", (*values)->content.rgb->blue / 255.);
+			args = g_slist_prepend (args, val);
+
+			val = g_strdup (")");
+			args = g_slist_prepend (args, val);
+
+			break;
+		case TERM_NO_TYPE:
 		case TERM_UNICODERANGE:
 		default:
 			g_assert_not_reached ();
-			values = values->next;
+			*values = (*values)->next;
 			continue;
 		}
 
-		if (args == NULL) {
-			args = g_slist_append (NULL, val);
-			iter = args;
-		} else {
-			iter->next = g_slist_append (NULL, val);
+		if ((*values)->next) {
+			val = g_strdup (",");
+			args = g_slist_prepend (args, val);
 		}
 
-		values = values->next;
+		*values = (*values)->next;
 	}
 
+	return args;
+}
+
+char *
+ccss_function_invoke (char const	*name,
+		     CRTerm const	*values)
+{
+	ccss_function_f	 function;
+	GSList		*args;
+	char		*ret;
+
+	g_return_val_if_fail (_vtable && name, NULL);
+
+	function = NULL;
+	for (unsigned int i = 0; _vtable[i].name; i++) {
+		if (0 == strcmp (name, _vtable[i].name)) {
+			function = _vtable[i].function;
+			break;
+		}
+	}
+
+	if (!function) {
+		g_warning ("Function `%s' could not be resolved", name);
+		return NULL;
+	}
+
+	/* parse args */
+	args = parse_args_r (NULL, &values);
+	args = g_slist_reverse (args);
+
 	/* dispatch */
 	ret = function (args);
 
 	/* free args */
-	iter = args;
-	while (iter) {
-		val = (char *) iter->data;
-		iter = g_slist_remove (iter, val);
-		g_free (val);
+	while (args) {
+		g_free (args->data);
+		args = g_slist_delete_link (args, args);
 	}
 
 	return ret;

Modified: trunk/src/gce-functions.c
==============================================================================
--- trunk/src/gce-functions.c	(original)
+++ trunk/src/gce-functions.c	Mon Oct  6 09:35:22 2008
@@ -63,43 +63,51 @@
 }
 
 static gboolean
-_color_walk (GdkColor		 *color,
-	     GSList const	**args)
+color_walk_r (GdkColor		 *color,
+	     GSList const	**args,
+	     char const		 *function)
 {
 	double		 factor;
 	char const	*token;
+	gboolean	 ret;
 
 	g_return_val_if_fail (*args && (*args)->data, FALSE);
 
-	token = (char const *) (*args)->data;
+	if (function)
+		token = function;
+	else
+		token = (char const *) (*args)->data;
 
 	if (0 == g_strcmp0 ("rgb(", token)) {
 
 		double red, green, blue;
 
+		if (!function) { *args = (*args)->next; if (!*args) return FALSE; }
+
 		/* red */
-		*args = (*args)->next; if (!*args) return FALSE;
 		red = g_ascii_strtod ((char const *) (*args)->data, NULL);
+		*args = (*args)->next; if (!*args) return FALSE;
 		
 		/* "," */
-		*args = (*args)->next; if (!*args) return FALSE;
 		if (0 != g_strcmp0(",", (char const *) (*args)->data)) return FALSE;
+		*args = (*args)->next; if (!*args) return FALSE;
 
 		/* green */
-		*args = (*args)->next; if (!*args) return FALSE;
 		green = g_ascii_strtod ((char const *) (*args)->data, NULL);
+		*args = (*args)->next; if (!*args) return FALSE;
 		
 		/* "," */
-		*args = (*args)->next; if (!*args) return FALSE;
 		if (0 != g_strcmp0(",", (char const *) (*args)->data)) return FALSE;
+		*args = (*args)->next; if (!*args) return FALSE;
 
 		/* blue */
-		*args = (*args)->next; if (!*args) return FALSE;
 		blue = g_ascii_strtod ((char const *) (*args)->data, NULL);
 		
-		/* ")" */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		if (!function) {
+			/* ")" */
+			*args = (*args)->next; if (!*args) return FALSE;
+			if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		}
 
 		color->red = (guint16) (red * 65535.0);
 		color->green = (guint16) (green * 65535.0);
@@ -109,15 +117,16 @@
 
 	} else if (0 == g_strcmp0 ("gtk-color(", token)) {
 
-		gboolean ret;
+		if (!function) { *args = (*args)->next; if (!*args) return FALSE; }
 
 		/* color */
-		*args = (*args)->next; if (!*args) return FALSE;
 		ret = gce_color_lookup ((char const *) (*args)->data, color);
 
-		/* ")" */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		if (!function) {
+			/* ")" */
+			*args = (*args)->next; if (!*args) return FALSE;
+			if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		}
 
 		return ret;
 
@@ -126,108 +135,236 @@
 		GdkColor color1;
 		GdkColor color2;
 
+		if (!function) { *args = (*args)->next; if (!*args) return FALSE; }
+
 		/* factor */
-		*args = (*args)->next; if (!*args) return FALSE;
 		factor = g_ascii_strtod ((char const *) (*args)->data, NULL);
+		*args = (*args)->next; if (!*args) return FALSE;
 		
 		/* "," */
-		*args = (*args)->next; if (!*args) return FALSE;
 		if (0 != g_strcmp0(",", (char const *) (*args)->data)) return FALSE;
+		*args = (*args)->next; if (!*args) return FALSE;
 
 		/* color1 */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (!_color_walk (&color1, args)) return FALSE;
+		if (!color_walk_r (&color1, args, NULL)) return FALSE;
 
 		/* "," */
-		*args = (*args)->next; if (!*args) return FALSE;
 		if (0 != g_strcmp0(",", (char const *) (*args)->data)) return FALSE;
+		*args = (*args)->next; if (!*args) return FALSE;
 
 		/* color2 */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (!_color_walk (&color2, args)) return FALSE;
+		if (!color_walk_r (&color2, args, NULL)) return FALSE;
 
-		/* ")" */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		if (!function) {
+			/* ")" */
+			*args = (*args)->next; if (!*args) return FALSE;
+			if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		}
 
 		return gce_color_mix (factor, &color1, &color2, color);
 
 	} else if (0 == g_strcmp0 ("gtk-shade(", token)) {
 
+		if (!function) { *args = (*args)->next; if (!*args) return FALSE; }
+
 		/* factor */
-		*args = (*args)->next; if (!*args) return FALSE;
 		factor = g_ascii_strtod ((char const *) (*args)->data, NULL);
+		*args = (*args)->next; if (!*args) return FALSE;
 		
 		/* "," */
-		*args = (*args)->next; if (!*args) return FALSE;
 		if (0 != g_strcmp0(",", (char const *) (*args)->data)) return FALSE;
+		*args = (*args)->next; if (!*args) return FALSE;
 
 		/* color */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (!_color_walk (color, args)) return FALSE;
+		if (!color_walk_r (color, args, NULL)) return FALSE;
 
-		/* ")" */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		if (!function) {
+			/* ")" */
+			*args = (*args)->next; if (!*args) return FALSE;
+			if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		}
 
 		return gce_color_shade (factor, color);
 
 	} else if (0 == g_strcmp0 ("gtk-darker(", token)) {
 
+		if (!function) { *args = (*args)->next; if (!*args) return FALSE; }
+
 		/* color */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (!_color_walk (color, args)) return FALSE;
+		if (!color_walk_r (color, args, NULL)) return FALSE;
 
-		/* ")" */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		if (!function) {
+			/* ")" */
+			*args = (*args)->next; if (!*args) return FALSE;
+			if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		}
 
 		return gce_color_shade (0.7, color);
 
 	} else if (0 == g_strcmp0 ("gtk-lighter(", token)) {
 
+		if (!function) { *args = (*args)->next; if (!*args) return FALSE; }
+
 		/* color */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (!_color_walk (color, args)) return FALSE;
+		if (!color_walk_r (color, args, NULL)) return FALSE;
 
-		/* ")" */
-		*args = (*args)->next; if (!*args) return FALSE;
-		if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		if (!function) {
+			/* ")" */
+			*args = (*args)->next; if (!*args) return FALSE;
+			if (0 != g_strcmp0(")", (char const *) (*args)->data)) return FALSE;
+		}
 
 		return gce_color_shade (1.3, color);
 
 	} else {
 
 		/* Color. */
-		return gce_color_lookup (token, color);
+		ret = gce_color_lookup (token, color);
+		*args = (*args)->next;
+		return ret;
 	}
 
 	return FALSE;
 }
 
 static char *
+dump (GSList const *args)
+{
+	GSList const	*iter;
+	GString		*str;
+
+	str = g_string_new (NULL);
+
+	for ( iter = args; iter != NULL; iter = iter->next) {
+		g_string_append (str, (char const *) iter->data);
+	}
+
+	return g_string_free (str, FALSE);
+}
+
+static char *
 color (GSList const *args)
 {
+	GSList const	*iter;
 	GdkColor	 result;
 	gboolean	 ret;
 
 	g_return_val_if_fail (args && args->data, NULL);
 
-	ret = _color_walk (&result, &args);
+	ret = color_walk_r (&result, &args, "gtk-color(");
+	if (!ret) {
+		char *data;
+		data = dump (args);
+		g_warning ("Color could not be resolved: `gtk-color(%s)'", data);
+		return NULL;
+	}
+
+	return g_strdup_printf ("rgb(%f,%f,%f)", result.red / 65535.0, 
+						 result.green / 65535.0,
+						 result.blue / 65535.0);
+}
+
+static char *
+mix (GSList const *args)
+{
+	GSList const	*iter;
+	GdkColor	 result;
+	gboolean	 ret;
+
+	g_return_val_if_fail (args && args->data, NULL);
+
+	iter = args;
+	ret = color_walk_r (&result, &iter, "gtk-mix(");
+	if (!ret) {
+		char *data;
+		data = dump (args);
+		g_warning ("Color could not be resolved: `gtk-mix(%s)'", data);
+		return NULL;
+	}
+
+	return g_strdup_printf ("rgb(%f,%f,%f)", result.red / 65535.0, 
+						 result.green / 65535.0,
+						 result.blue / 65535.0);
+}
+
+static char *
+shade (GSList const *args)
+{
+	GSList const	*iter;
+	GdkColor	 result;
+	gboolean	 ret;
+
+	g_return_val_if_fail (args && args->data, NULL);
+
+	iter = args;
+	ret = color_walk_r (&result, &iter, "gtk-shade(");
+	if (!ret) {
+		char *data;
+		data = dump (args);
+		g_warning ("Color could not be resolved: `gtk-shade(%s)'", data);
+		return NULL;
+	}
 
-	return g_strdup_printf ("#%0x%0x%0x", result.red >> 8, 
-					      result.green >> 8,
-					      result.blue >> 8);
+	return g_strdup_printf ("rgb(%f,%f,%f)", result.red / 65535.0, 
+						 result.green / 65535.0,
+						 result.blue / 65535.0);
 }
 
+static char *
+lighter (GSList const *args)
+{
+	GSList const	*iter;
+	GdkColor	 result;
+	gboolean	 ret;
+
+	g_return_val_if_fail (args && args->data, NULL);
+
+	iter = args;
+	ret = color_walk_r (&result, &iter, "gtk-lighter(");
+	if (!ret) {
+		char *data;
+		data = dump (args);
+		g_warning ("Color could not be resolved: `gtk-lighter(%s)'", data);
+		return NULL;
+	}
+
+	return g_strdup_printf ("rgb(%f,%f,%f)", result.red / 65535.0, 
+						 result.green / 65535.0,
+						 result.blue / 65535.0);
+}
+
+static char *
+darker (GSList const *args)
+{
+	GSList const	*iter;
+	GdkColor	 result;
+	gboolean	 ret;
+
+	g_return_val_if_fail (args && args->data, NULL);
+
+	iter = args;
+	ret = color_walk_r (&result, &iter, "gtk-darker(");
+	if (!ret) {
+		char *data;
+		data = dump (args);
+		g_warning ("Color could not be resolved: `gtk-darker(%s)'", data);
+		return NULL;
+	}
+
+	return g_strdup_printf ("rgb(%f,%f,%f)", result.red / 65535.0, 
+						 result.green / 65535.0,
+						 result.blue / 65535.0);
+}
+
+
 static ccss_function_t const _functions[] = 
 {
   { "url",		url	},
   { "gtk-color",	color	},
-  { "gtk-mix",		color	},
-  { "gtk-shade",	color	},
-  { "gtk-lighter",	color	},
-  { "gtk-darker",	color	},
+  { "gtk-mix",		mix	},
+  { "gtk-shade",	shade	},
+  { "gtk-lighter",	lighter	},
+  { "gtk-darker",	darker	},
   { NULL }
 };
 

Modified: trunk/themes/gtk-css-test/gtk-2.0/styles.css
==============================================================================
--- trunk/themes/gtk-css-test/gtk-2.0/styles.css	(original)
+++ trunk/themes/gtk-css-test/gtk-2.0/styles.css	Mon Oct  6 09:35:22 2008
@@ -1,7 +1,6 @@
 
 * {
-	background-color: gtk-mix(0.5, bg_color, fg_color);
-	color: black;
+	background-color: gtk-color(bg_color);
 }
 
 arrow {
@@ -53,7 +52,6 @@
 }
 
 flatbox {
-	background-color: darkkhaki;
 	border: 1px solid black;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]