gtk-css-engine r129 - in trunk: . libccd/ccd libccd/doc libccd/doc/tmpl src



Author: robsta
Date: Thu Sep 25 13:27:00 2008
New Revision: 129
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=129&view=rev

Log:
* TODO: remember splitting out a CSS2 style sometime.
* libccd/ccd/ccd-node.c:
* libccd/ccd/ccd-node.h:
Improve clarity of node-class vtable lifecycle.
* libccd/ccd/ccd-selector-group.c:
* libccd/ccd/ccd-selector.c:
Use new node-class vtable API.
* libccd/ccd/ccd-stylesheet.c:
* libccd/ccd/ccd-stylesheet.h:
* libccd/ccd/exports.sym:
* libccd/doc/ccd-sections.txt:
* libccd/doc/tmpl/stylesheet.sgml:
New API to iterate over a stylesheet.
* src/gce-node.c: stricter const-ness.
* src/gce-parser.c:
* src/gce-parser.h:
* src/gce-rc-style.c:
Use stylesheet iteration API, not hooked up yet.


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/TODO
   trunk/libccd/ccd/ccd-node.c
   trunk/libccd/ccd/ccd-node.h
   trunk/libccd/ccd/ccd-selector-group.c
   trunk/libccd/ccd/ccd-selector.c
   trunk/libccd/ccd/ccd-stylesheet.c
   trunk/libccd/ccd/ccd-stylesheet.h
   trunk/libccd/ccd/exports.sym
   trunk/libccd/doc/ccd-sections.txt
   trunk/libccd/doc/tmpl/stylesheet.sgml
   trunk/src/gce-node.c
   trunk/src/gce-parser.c
   trunk/src/gce-parser.h
   trunk/src/gce-rc-style.c

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	(original)
+++ trunk/TODO	Thu Sep 25 13:27:00 2008
@@ -64,6 +64,10 @@
 * Unit tests.
 * Test using the theme torturer.
 * Test using valgrind.
+* Investigate splitting out ccd_css2_style_t from ccd_style_t making it
+  an opaque "unsigned char[x]". Install only a minimal number of of required
+  headers (ccd, stylesheet, selector-group, style*, node).
+* Think about per-stylesheet node-class and functions interface.
 
 0.5 "Performance"
 -----------------
@@ -116,6 +120,7 @@
 Out of band
 -----------
 
+* Find a more cairo-esque name? Giza? CairoCSS?
 * Libcroco: fix "#foo" and ".bar" global selectors.
 * Investigate libcroco CSS3 compliance: sequences, tuples (see background-image)
 * Create a spiffy website, possibly on http://gnome.org/projects. 

Modified: trunk/libccd/ccd/ccd-node.c
==============================================================================
--- trunk/libccd/ccd/ccd-node.c	(original)
+++ trunk/libccd/ccd/ccd-node.c	Thu Sep 25 13:27:00 2008
@@ -99,15 +99,30 @@
 	.release		= release
 };
 
+typedef void (*node_f) (void);
+#define N_ELEMENTS(vtable_) (sizeof (vtable_) / sizeof (node_f))
+
+void
+ccd_node_fill_class (ccd_node_class_t *node_class)
+{
+	node_f const	*node_vtable;
+	node_f		*new_node_vtable;
+
+	g_return_if_fail (node_class);
+
+	node_vtable = (node_f const *) &_node_class;
+	new_node_vtable = (node_f *) node_class;
+	for (unsigned int i = 0; i < N_ELEMENTS (_node_class); i++) {
+		new_node_vtable[i] = node_vtable[i];
+	}
+}
+
 ccd_node_class_t const *
-ccd_node_get_class (void)
+ccd_node_peek_class (void)
 {
 	return &_node_class;
 }
 
-typedef void (*node_f) (void);
-#define N_ELEMENTS(vtable_) (sizeof (vtable_) / sizeof (node_f))
-
 void
 ccd_node_set_class (ccd_node_class_t const *node_class)
 {
@@ -116,6 +131,12 @@
 
 	g_return_if_fail (node_class);
 
+	/* Reset if not resetting already, to allow for partial 
+	 * node class implementations. */
+	if (node_class != &_default_node_class) {
+		ccd_node_set_class (&_default_node_class);
+	}
+
 	node_vtable = (node_f *) &_node_class;
 	new_node_vtable = (node_f *) node_class;
 	for (unsigned int i = 0; i < N_ELEMENTS (_node_class); i++) {

Modified: trunk/libccd/ccd/ccd-node.h
==============================================================================
--- trunk/libccd/ccd/ccd-node.h	(original)
+++ trunk/libccd/ccd/ccd-node.h	Thu Sep 25 13:27:00 2008
@@ -162,7 +162,8 @@
 	ccd_node_release_f		release;
 } ccd_node_class_t;
 
-ccd_node_class_t const *	ccd_node_get_class	(void);
+void				ccd_node_fill_class	(ccd_node_class_t *node_class);
+ccd_node_class_t const *	ccd_node_peek_class	(void);
 void				ccd_node_set_class	(ccd_node_class_t const *node_class);
 void				ccd_node_reset_class	(void);
 

Modified: trunk/libccd/ccd/ccd-selector-group.c
==============================================================================
--- trunk/libccd/ccd/ccd-selector-group.c	(original)
+++ trunk/libccd/ccd/ccd-selector-group.c	Thu Sep 25 13:27:00 2008
@@ -116,7 +116,7 @@
 
 	g_assert (self->min_specificity_e >= 0);
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	specificity_e = self->min_specificity_e;
 	base = node_class->get_base_style (node);

Modified: trunk/libccd/ccd/ccd-selector.c
==============================================================================
--- trunk/libccd/ccd/ccd-selector.c	(original)
+++ trunk/libccd/ccd/ccd-selector.c	Thu Sep 25 13:27:00 2008
@@ -761,7 +761,7 @@
 	ccd_node_t		*container;
 	bool			 is_matching;
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	container = node_class->get_container (node);
 	if (container) {
@@ -792,7 +792,7 @@
 
 	g_return_val_if_fail (self && node, false);
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	is_matching = false;
 	switch (self->modality) {

Modified: trunk/libccd/ccd/ccd-stylesheet.c
==============================================================================
--- trunk/libccd/ccd/ccd-stylesheet.c	(original)
+++ trunk/libccd/ccd/ccd-stylesheet.c	Thu Sep 25 13:27:00 2008
@@ -211,7 +211,7 @@
 	char const		*type_name;
 	bool			 ret;
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	if (!iter) {
 		iter = node;
@@ -263,7 +263,7 @@
 	ccd_selector_group_t const	*group;
 	bool				 ret;
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	g_return_val_if_fail (self && node && result_group, false);
 
@@ -304,7 +304,7 @@
 	char const		*type_name;
 	bool			 ret;
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	if (!iter) {
 		iter = node;
@@ -350,7 +350,7 @@
 	char const		*class_name;
 	bool			 ret;
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	ret = false;
 	class_name = node_class->get_class (node);
@@ -378,7 +378,7 @@
 	char const		*id;
 	bool			 ret;
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	ret = false;
 	id = node_class->get_id (node);
@@ -412,7 +412,7 @@
 	bool			 have_class;
 	bool			 have_id;
 
-	node_class = ccd_node_get_class ();
+	node_class = ccd_node_peek_class ();
 
 	g_return_val_if_fail (self && node && style, false);
 
@@ -428,6 +428,39 @@
 	return have_type || have_class || have_id;
 }
 
+/**
+ * ccd_stylesheet_iter_init:
+ * @self:	a #ccd_stylesheet_iter_t.
+ * @stylesheet:	the stylesheet to iterate.
+ *
+ * Modifying the underlying stylesheet invalidates the iterator.
+ **/
+void
+ccd_stylesheet_iter_init (ccd_stylesheet_iter_t		*self,
+			  ccd_stylesheet_t const	*stylesheet)
+{
+	g_return_if_fail (stylesheet && stylesheet->type_rules);
+
+	g_hash_table_iter_init (self, stylesheet->type_rules);
+}
+
+/**
+ * ccd_stylesheet_iter_next:
+ * @self:	a #ccd_stylesheet_iter_t.
+ * @type_name:	type the selector group regards, e.g. DIV in HTML.
+ * @group:	the #ccd_selector_group_t containing rules for #type_name.
+ *
+ * Returns: %FALSE when the last element is reached.
+ **/
+bool
+ccd_stylesheet_iter_next (ccd_stylesheet_iter_t		 *self,
+			  char const			**type_name,
+			  ccd_selector_group_t const	**group)
+{
+	return g_hash_table_iter_next (self, (gpointer *) type_name,
+				       (gpointer *) group);
+}
+
 #ifdef CCD_DEBUG
 
 /**

Modified: trunk/libccd/ccd/ccd-stylesheet.h
==============================================================================
--- trunk/libccd/ccd/ccd-stylesheet.h	(original)
+++ trunk/libccd/ccd/ccd-stylesheet.h	Thu Sep 25 13:27:00 2008
@@ -44,6 +44,20 @@
 bool ccd_stylesheet_query_apply (ccd_stylesheet_t const *self, ccd_node_t const *node, 
 				 ccd_style_t *style);
 
+/**
+ * ccd_stylesheet_iter_t:
+ *
+ * Stack-allocatable iterator for walking a stylesheet.
+ **/
+typedef GHashTableIter ccd_stylesheet_iter_t;
+
+void ccd_stylesheet_iter_init (ccd_stylesheet_iter_t *self,
+			       ccd_stylesheet_t const *stylesheet);
+
+bool ccd_stylesheet_iter_next (ccd_stylesheet_iter_t *self,
+			       char const **type_name,
+			       ccd_selector_group_t const **group);
+
 #ifdef CCD_DEBUG
 void ccd_stylesheet_dump (ccd_stylesheet_t const *self);
 #endif

Modified: trunk/libccd/ccd/exports.sym
==============================================================================
--- trunk/libccd/ccd/exports.sym	(original)
+++ trunk/libccd/ccd/exports.sym	Thu Sep 25 13:27:00 2008
@@ -12,6 +12,8 @@
 ccd_stylesheet_query_type
 ccd_stylesheet_query_collect
 ccd_stylesheet_query_apply
+ccd_stylesheet_iter_init
+ccd_stylesheet_iter_next
 ccd_selector_group_new
 ccd_selector_group_free
 ccd_selector_group_apply

Modified: trunk/libccd/doc/ccd-sections.txt
==============================================================================
--- trunk/libccd/doc/ccd-sections.txt	(original)
+++ trunk/libccd/doc/ccd-sections.txt	Thu Sep 25 13:27:00 2008
@@ -42,6 +42,9 @@
 ccd_stylesheet_query_collect
 ccd_stylesheet_query_apply
 ccd_stylesheet_dump
+ccd_stylesheet_iter_t
+ccd_stylesheet_iter_init
+ccd_stylesheet_iter_next
 </SECTION>
 
 <SECTION>

Modified: trunk/libccd/doc/tmpl/stylesheet.sgml
==============================================================================
--- trunk/libccd/doc/tmpl/stylesheet.sgml	(original)
+++ trunk/libccd/doc/tmpl/stylesheet.sgml	Thu Sep 25 13:27:00 2008
@@ -91,3 +91,29 @@
 @self: 
 
 
+<!-- ##### TYPEDEF ccd_stylesheet_iter_t ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### FUNCTION ccd_stylesheet_iter_init ##### -->
+<para>
+
+</para>
+
+ self: 
+ stylesheet: 
+
+
+<!-- ##### FUNCTION ccd_stylesheet_iter_next ##### -->
+<para>
+
+</para>
+
+ self: 
+ type_name: 
+ group: 
+ Returns: 
+
+

Modified: trunk/src/gce-node.c
==============================================================================
--- trunk/src/gce-node.c	(original)
+++ trunk/src/gce-node.c	Thu Sep 25 13:27:00 2008
@@ -401,7 +401,7 @@
 	gce_node_cache_release_node (node);
 }
 
-static const ccd_node_class_t _node_class = {
+static const ccd_node_class_t const _node_class = {
 	.is_a			= (ccd_node_is_a_f) is_a,
 	.get_container		= (ccd_node_get_container_f) get_container,
 	.get_base_style		= (ccd_node_get_base_style_f) get_base_style,

Modified: trunk/src/gce-parser.c
==============================================================================
--- trunk/src/gce-parser.c	(original)
+++ trunk/src/gce-parser.c	Thu Sep 25 13:27:00 2008
@@ -20,84 +20,21 @@
 #include <libcroco/libcroco.h>
 #include "gce-parser.h"
 
-typedef struct {
-	ccd_stylesheet_t const *stylesheet;
-} gce_parser_info_t;
-
-#define HANDLER_GET_INFO(handler_) ((gce_parser_info_t *) handler->app_data)
-
-static void
-start_selector_cb (CRDocHandler	*handler,
-		   CRSelector	*cr_sel)
-{
-}
-
-static void
-property_cb (CRDocHandler	*handler,
-	     CRString		*name,
-	     CRTerm		*values,
-	     gboolean	 	 is_important)
-{
-#if 0
-	gce_parser_info_t	*info;
-	char const 		*property;
-
-	info = HANDLER_GET_INFO (handler);
-
-	g_assert (info);
-
-	/* TODO parse style properties. */
-#endif
-}
-
-static void
-end_selector_cb (CRDocHandler	*handler,
-		 CRSelector	*cr_sel)
-{
-	CRSimpleSel const *simple_sel;
-	char const *type_name;
-
-	/* TODO write a simple node implementation to query what we want. */
-
-	for (CRSelector const *iter = cr_sel; iter != NULL; iter = iter->next) {
-		simple_sel = iter->simple_sel;
-		if (TYPE_SELECTOR & simple_sel->type_mask &&
-		    NULL == simple_sel->next) {
-
-			type_name = cr_string_peek_raw_str (simple_sel->name);
-			// TODO
-		}
-	}
-}
 
 gboolean
-gce_parser_setup_gtkrc (ccd_stylesheet_t const	*stylesheet,
-			char const		*css_file)
+gce_parser_setup_gtkrc (ccd_stylesheet_t const	*stylesheet)
 {
+	ccd_stylesheet_iter_t		 iter;
+	char const			*type_name;
+	ccd_selector_group_t const	*group;
 
-	CRParser		*parser;
-	CRDocHandler		*handler;
-	gce_parser_info_t	 info;
-	enum CRStatus		 ret;
-
-	g_return_val_if_fail (stylesheet && css_file, FALSE);
+	ccd_stylesheet_iter_init (&iter, stylesheet);
 
-	parser = cr_parser_new_from_file ((guchar *) css_file, CR_UTF_8);
+	type_name = NULL;
+	group = NULL;
+	while (ccd_stylesheet_iter_next (&iter, &type_name, &group)) {
 
-	handler = cr_doc_handler_new ();
-	handler->app_data = (gpointer) &info;
-	info.stylesheet = stylesheet;
-
-	handler->start_selector = start_selector_cb;
-        handler->property = property_cb;
-	handler->end_selector = end_selector_cb;
-
-	cr_parser_set_sac_handler (parser, handler);
-	ret = cr_parser_parse (parser);
-
-	cr_doc_handler_destroy (handler);	
-	cr_parser_destroy (parser);
-
-	return CR_OK == ret;
+		printf ("%s\n", type_name);
+	}
 }
 

Modified: trunk/src/gce-parser.h
==============================================================================
--- trunk/src/gce-parser.h	(original)
+++ trunk/src/gce-parser.h	Thu Sep 25 13:27:00 2008
@@ -25,8 +25,7 @@
 
 G_BEGIN_DECLS
 
-gboolean gce_parser_setup_gtkrc (ccd_stylesheet_t const *stylesheet,
-				 char const *css_file);
+gboolean gce_parser_setup_gtkrc (ccd_stylesheet_t const *stylesheet);
 
 G_END_DECLS
 

Modified: trunk/src/gce-rc-style.c
==============================================================================
--- trunk/src/gce-rc-style.c	(original)
+++ trunk/src/gce-rc-style.c	Thu Sep 25 13:27:00 2008
@@ -19,6 +19,7 @@
 
 #include <gtk/gtk.h>
 #include <string.h>
+#include "gce-parser.h"
 #include "gce-rc-style.h"
 #include "gce-style.h"
 
@@ -85,6 +86,8 @@
 #ifdef DEBUG
 		ccd_stylesheet_dump (_stylesheet);
 #endif
+		gce_parser_setup_gtkrc (_stylesheet);
+
 		_stylesheet_owner = (gpointer) rc_style;
 		g_free (gce_file), gce_file = NULL;
 	}



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