gtk-css-engine r135 - in trunk: . libccss/ccss libccss/doc libccss/doc/tmpl src



Author: robsta
Date: Mon Sep 29 15:27:11 2008
New Revision: 135
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=135&view=rev

Log:
* libccss/ccss/ccss-node.c:
* libccss/ccss/ccss-node.h:
* libccss/ccss/ccss-selector-group.c:
* libccss/ccss/ccss-selector.c:
* libccss/ccss/ccss-stylesheet.c:
* libccss/ccss/ccss.c:
* libccss/ccss/ccss.h:
* libccss/ccss/exports.sym:
* libccss/doc/ccss-sections.txt:
* libccss/doc/tmpl/ccss.sgml:
* libccss/doc/tmpl/node.sgml:
* src/gce-node.c:
* src/gce-node.h:
* src/gce-serialize.c:
* src/gce-theme.c:
Merge changes after bzr repo problems (https://bugs.launchpad.net/bugs/275861):
  - Make implementation of ccss_node_class_t::is_a optional, fall back to
    ccss_node_class_t::get_type.
  - Attach node vtable to each node instance, simplifies the ccss API.



Modified:
   trunk/ChangeLog
   trunk/libccss/ccss/ccss-node.c
   trunk/libccss/ccss/ccss-node.h
   trunk/libccss/ccss/ccss-selector-group.c
   trunk/libccss/ccss/ccss-selector.c
   trunk/libccss/ccss/ccss-stylesheet.c
   trunk/libccss/ccss/ccss.c
   trunk/libccss/ccss/ccss.h
   trunk/libccss/ccss/exports.sym
   trunk/libccss/doc/ccss-sections.txt
   trunk/libccss/doc/tmpl/ccss.sgml
   trunk/libccss/doc/tmpl/node.sgml
   trunk/src/gce-node.c
   trunk/src/gce-node.h
   trunk/src/gce-serialize.c
   trunk/src/gce-theme.c

Modified: trunk/libccss/ccss/ccss-node.c
==============================================================================
--- trunk/libccss/ccss/ccss-node.c	(original)
+++ trunk/libccss/ccss/ccss-node.c	Mon Sep 29 15:27:11 2008
@@ -17,6 +17,7 @@
  * MA 02110-1301, USA.
  */
 
+#include <string.h>
 #include "ccss-node.h"
 
 static bool
@@ -87,69 +88,58 @@
 	.release		= release
 };
 
-static ccss_node_class_t _node_class = {
-	.is_a			= is_a,
-	.get_container		= get_container,
-	.get_base_style		= get_base_style,
-	.get_id			= get_id,
-	.get_type		= get_type,
-	.get_class		= get_class,
-	.get_pseudo_class	= get_pseudo_class,
-	.get_attribute		= get_attribute,
-	.release		= release
-};
-
 typedef void (*node_f) (void);
 #define N_ELEMENTS(vtable_) (sizeof (vtable_) / sizeof (node_f))
 
+/**
+ * ccss_node_init:
+ * @self:	a #ccss_node_t embedding structure.
+ * @node_class:	a #ccss_node_class_t vtable.
+ *
+ * Initializes @node_class by filling unset functions with the default
+ * implementations and attaches it to @self.
+ **/
 void
-ccss_node_fill_class (ccss_node_class_t *node_class)
+ccss_node_init (ccss_node_t		*self,
+		ccss_node_class_t	*node_class)
 {
-	node_f const	*node_vtable;
-	node_f		*new_node_vtable;
+	node_f const	*default_vtable;
+	node_f		*vtable;
 
-	g_return_if_fail (node_class);
+	g_return_if_fail (self && 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];
+	/* Initialize the node class.
+	 * FIXME: run only once per node class?  */
+	default_vtable = (node_f const *) &_default_node_class;
+	vtable = (node_f *) node_class;
+	for (unsigned int i = 0; i < N_ELEMENTS (_default_node_class); i++) {
+		if (NULL == vtable[i])
+			vtable[i] = default_vtable[i];
 	}
-}
 
-ccss_node_class_t const *
-ccss_node_peek_class (void)
-{
-	return &_node_class;
+	/* Initializse node. */
+	self->node_class = node_class;
 }
 
-void
-ccss_node_set_class (ccss_node_class_t const *node_class)
-{
-	node_f		*node_vtable;
-	node_f const	*new_node_vtable;
-
-	g_return_if_fail (node_class);
-
-	/* Reset if not resetting already, to allow for partial 
-	 * node class implementations. */
-	if (node_class != &_default_node_class) {
-		ccss_node_set_class (&_default_node_class);
+/**
+ * ccss_node_is_a:
+ *
+ * Wrapper implementation of #ccss_node_is_a_f. If the `is_a' function is not
+ * implemented `get_type' is used as a fallback.
+ **/
+bool
+ccss_node_is_a (ccss_node_t const	*self,
+		char const		*type_name)
+{
+	char const *node_type_name;
+
+	if (self->node_class->is_a != is_a) {
+		return self->node_class->is_a (self, type_name);
+	} else {
+		node_type_name = self->node_class->get_type (self);
+		return node_type_name ?
+			0 == strcmp (type_name, node_type_name) :
+			false;
 	}
-
-	node_vtable = (node_f *) &_node_class;
-	new_node_vtable = (node_f *) node_class;
-	for (unsigned int i = 0; i < N_ELEMENTS (_node_class); i++) {
-		/* Override only implemented methods. */
-		if (new_node_vtable[i]) {
-			node_vtable[i] = new_node_vtable[i];
-		}
-	}
-}
-
-void
-ccss_node_reset_class (void)
-{
-	ccss_node_set_class (&_default_node_class);
 }
 

Modified: trunk/libccss/ccss/ccss-node.h
==============================================================================
--- trunk/libccss/ccss/ccss-node.h	(original)
+++ trunk/libccss/ccss/ccss-node.h	Mon Sep 29 15:27:11 2008
@@ -26,6 +26,8 @@
 
 G_BEGIN_DECLS
 
+typedef struct ccss_node_class_ ccss_node_class_t;
+
 /**
  * ccss_node_t:
  * 
@@ -35,7 +37,10 @@
  * <emphasis>Memory management:</emphasis> Unless specified otherwise, objects 
  * of this kind are under the responsibility of the libccss consumer.
  **/
-typedef void * ccss_node_t;
+typedef struct {
+	/*< private >*/
+	ccss_node_class_t const *node_class;
+} ccss_node_t;
 
 /** 
  * ccss_node_is_a_f:
@@ -150,8 +155,8 @@
  *
  * The implemented dispatch table needs to be passed to #ccss_init.
  **/
-typedef struct {
-	ccss_node_is_a_f			is_a;
+struct ccss_node_class_ {
+	ccss_node_is_a_f		is_a;
 	ccss_node_get_container_f	get_container;
 	ccss_node_get_base_style_f	get_base_style;
 	ccss_node_get_id_f		get_id;
@@ -160,12 +165,11 @@
 	ccss_node_get_pseudo_class_f	get_pseudo_class;
 	ccss_node_get_attribute_f	get_attribute;
 	ccss_node_release_f		release;
-} ccss_node_class_t;
+};
+
+void ccss_node_init (ccss_node_t *self, ccss_node_class_t *node_class);
 
-void				ccss_node_fill_class	(ccss_node_class_t *node_class);
-ccss_node_class_t const *	ccss_node_peek_class	(void);
-void				ccss_node_set_class	(ccss_node_class_t const *node_class);
-void				ccss_node_reset_class	(void);
+bool ccss_node_is_a (ccss_node_t const *self, char const *type_name);
 
 G_END_DECLS
 

Modified: trunk/libccss/ccss/ccss-selector-group.c
==============================================================================
--- trunk/libccss/ccss/ccss-selector-group.c	(original)
+++ trunk/libccss/ccss/ccss-selector-group.c	Mon Sep 29 15:27:11 2008
@@ -116,7 +116,7 @@
 
 	g_assert (self->min_specificity_e >= 0);
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	specificity_e = self->min_specificity_e;
 	base = node_class->get_base_style (node);

Modified: trunk/libccss/ccss/ccss-selector.c
==============================================================================
--- trunk/libccss/ccss/ccss-selector.c	(original)
+++ trunk/libccss/ccss/ccss-selector.c	Mon Sep 29 15:27:11 2008
@@ -761,7 +761,7 @@
 	ccss_node_t		*container;
 	bool			 is_matching;
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	container = node_class->get_container (node);
 	if (container) {
@@ -792,7 +792,7 @@
 
 	g_return_val_if_fail (self && node, false);
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	is_matching = false;
 	switch (self->modality) {
@@ -800,7 +800,7 @@
 		is_matching = true;
 		break;
 	case CCSS_SELECTOR_MODALITY_TYPE:
-		is_matching = node_class->is_a (node, ((ccss_type_selector_t *) self)->type_name);
+		is_matching = ccss_node_is_a (node, ((ccss_type_selector_t *) self)->type_name);
 		break;
 	case CCSS_SELECTOR_MODALITY_BASE_TYPE:
 		/* HACK warning: let's just say it matches, because the base type selectors have

Modified: trunk/libccss/ccss/ccss-stylesheet.c
==============================================================================
--- trunk/libccss/ccss/ccss-stylesheet.c	(original)
+++ trunk/libccss/ccss/ccss-stylesheet.c	Mon Sep 29 15:27:11 2008
@@ -211,7 +211,7 @@
 	char const		*type_name;
 	bool			 ret;
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	if (!iter) {
 		iter = node;
@@ -263,7 +263,7 @@
 	ccss_selector_group_t const	*group;
 	bool				 ret;
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	g_return_val_if_fail (self && node && result_group, false);
 
@@ -304,7 +304,7 @@
 	char const		*type_name;
 	bool			 ret;
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	if (!iter) {
 		iter = node;
@@ -350,7 +350,7 @@
 	char const		*class_name;
 	bool			 ret;
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	ret = false;
 	class_name = node_class->get_class (node);
@@ -378,7 +378,7 @@
 	char const		*id;
 	bool			 ret;
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	ret = false;
 	id = node_class->get_id (node);
@@ -412,7 +412,7 @@
 	bool			 have_class;
 	bool			 have_id;
 
-	node_class = ccss_node_peek_class ();
+	node_class = node->node_class;
 
 	g_return_val_if_fail (self && node && style, false);
 

Modified: trunk/libccss/ccss/ccss.c
==============================================================================
--- trunk/libccss/ccss/ccss.c	(original)
+++ trunk/libccss/ccss/ccss.c	Mon Sep 29 15:27:11 2008
@@ -21,19 +21,13 @@
 
 /**
  * ccss_init:
- * @node_class: 	dispatch table as described at #ccss_node_class_t.
- * @functions:		table of functions that can be used in CSS.
- * @n_functions:	size of the function table.
+ * @functions:		table of functions that can be used in CSS or %NULL.
  * 
  * Initialize the CCSS library before making any calls to it.
  **/
 void
-ccss_init (ccss_node_class_t const	*node_class,
-	  ccss_function_t const		*vtable)
+ccss_init (ccss_function_t const *vtable)
 {
-	g_assert (node_class);
-
-	ccss_node_set_class (node_class);
 	ccss_function_set_vtable (vtable);
 }
 
@@ -45,6 +39,6 @@
 void
 ccss_shutdown (void)
 {
-	ccss_node_reset_class ();
+
 }
 

Modified: trunk/libccss/ccss/ccss.h
==============================================================================
--- trunk/libccss/ccss/ccss.h	(original)
+++ trunk/libccss/ccss/ccss.h	Mon Sep 29 15:27:11 2008
@@ -38,13 +38,7 @@
 #include <ccss/ccss-gtk-style.h>
 #endif /* CCSS_WITH_GTK */
 
-#define XH(n_) (n_)
-#define YH(n_) (n_ + 0.5)
-#define XV(n_) (n_ + 0.5)
-#define YV(n_) (n_)
-
-void 		ccss_init	(ccss_node_class_t const *node_class, 
-				 ccss_function_t const *vtable);
+void 		ccss_init	(ccss_function_t const *vtable);
 void 		ccss_shutdown	(void);
 
 G_END_DECLS

Modified: trunk/libccss/ccss/exports.sym
==============================================================================
--- trunk/libccss/ccss/exports.sym	(original)
+++ trunk/libccss/ccss/exports.sym	Mon Sep 29 15:27:11 2008
@@ -1,5 +1,6 @@
 ccss_init
 ccss_shutdown
+ccss_node_init
 ccss_style_init
 ccss_style_draw_line
 ccss_style_draw_outline

Modified: trunk/libccss/doc/ccss-sections.txt
==============================================================================
--- trunk/libccss/doc/ccss-sections.txt	(original)
+++ trunk/libccss/doc/ccss-sections.txt	Mon Sep 29 15:27:11 2008
@@ -18,6 +18,7 @@
 ccss_node_get_pseudo_class_f
 ccss_node_get_attribute_f
 ccss_node_release_f
+ccss_node_init
 </SECTION>
 
 <SECTION>

Modified: trunk/libccss/doc/tmpl/ccss.sgml
==============================================================================
--- trunk/libccss/doc/tmpl/ccss.sgml	(original)
+++ trunk/libccss/doc/tmpl/ccss.sgml	Mon Sep 29 15:27:11 2008
@@ -22,7 +22,6 @@
 
 </para>
 
- node_class: 
 @vtable: 
 
 

Modified: trunk/libccss/doc/tmpl/node.sgml
==============================================================================
--- trunk/libccss/doc/tmpl/node.sgml	(original)
+++ trunk/libccss/doc/tmpl/node.sgml	Mon Sep 29 15:27:11 2008
@@ -22,7 +22,6 @@
 
 </para>
 
- node_class: 
 @vtable: 
 
 
@@ -33,26 +32,17 @@
 
 
 
-<!-- ##### TYPEDEF ccss_node_t ##### -->
+<!-- ##### STRUCT ccss_node_t ##### -->
 <para>
 
 </para>
 
 
-<!-- ##### STRUCT ccss_node_class_t ##### -->
+<!-- ##### TYPEDEF ccss_node_class_t ##### -->
 <para>
 
 </para>
 
- is_a: 
- get_container: 
- get_base_style: 
- get_id: 
- get_type: 
- get_class: 
- get_pseudo_class: 
- get_attribute: 
- release: 
 
 <!-- ##### USER_FUNCTION ccss_node_get_container_f ##### -->
 <para>
@@ -126,3 +116,12 @@
 @self: 
 
 
+<!-- ##### FUNCTION ccss_node_init ##### -->
+<para>
+
+</para>
+
+ self: 
+ node_class: 
+
+

Modified: trunk/src/gce-node.c
==============================================================================
--- trunk/src/gce-node.c	(original)
+++ trunk/src/gce-node.c	Mon Sep 29 15:27:11 2008
@@ -53,6 +53,8 @@
 	.cursor = -1
 };
 
+static ccss_node_class_t * peek_node_class (void);
+
 GceNode *
 gce_node_cache_get_top_node (void)
 {
@@ -60,7 +62,7 @@
 }
 
 static GceNode *
-fetch_node ()
+fetch_node (void)
 {
 	GceNode *node;
 
@@ -70,6 +72,8 @@
 	node = &_node_cache.nodes[_node_cache.cursor];
 	memset (node, 0, sizeof (*node));
 
+	ccss_node_init ((ccss_node_t *) node, peek_node_class ());
+
 	return node;
 }
 
@@ -401,7 +405,7 @@
 	gce_node_cache_release_node (node);
 }
 
-static const ccss_node_class_t const _node_class = {
+static ccss_node_class_t _node_class = {
 	.is_a			= (ccss_node_is_a_f) is_a,
 	.get_container		= (ccss_node_get_container_f) get_container,
 	.get_base_style		= (ccss_node_get_base_style_f) get_base_style,
@@ -413,8 +417,8 @@
 	.release		= (ccss_node_release_f) release
 };
 
-ccss_node_class_t const *
-gce_node_get_class (void)
+static ccss_node_class_t *
+peek_node_class (void)
 {
 	return &_node_class;
 }

Modified: trunk/src/gce-node.h
==============================================================================
--- trunk/src/gce-node.h	(original)
+++ trunk/src/gce-node.h	Mon Sep 29 15:27:11 2008
@@ -50,8 +50,6 @@
 GceNode * gce_node_cache_get_top_node (void);
 void gce_node_cache_release_node (GceNode *node);
 
-ccss_node_class_t const * gce_node_get_class (void);
-
 GtkWidget *	gce_node_get_widget	(const GceNode *node);
 char const *	gce_node_get_primitive	(const GceNode *node);
 

Modified: trunk/src/gce-serialize.c
==============================================================================
--- trunk/src/gce-serialize.c	(original)
+++ trunk/src/gce-serialize.c	Mon Sep 29 15:27:11 2008
@@ -32,13 +32,6 @@
 	char const	*pseudo_class;
 } Node;
 
-static bool
-is_a (Node const *self,
-      char const *type_name)
-{
-	return 0 == g_ascii_strcasecmp (self->type_name, type_name);
-}
-
 static char const *
 get_type (Node const *self)
 {
@@ -57,8 +50,8 @@
 	return self->pseudo_class;
 }
 
-static const ccss_node_class_t const _node_class = {
-	.is_a			= (ccss_node_is_a_f) is_a,
+static ccss_node_class_t _node_class = {
+	.is_a			= NULL,
 	.get_container		= NULL,
 	.get_base_style		= NULL,
 	.get_id			= (ccss_node_get_id_f) get_id,
@@ -111,11 +104,12 @@
 	Node			 node;
 	gboolean		 ret;
 
-	ccss_style_init (&style);
+	ccss_node_init ((ccss_node_t *) &node, &_node_class);
 	node.type_name = type_name;
 	node.id = NULL;
 	node.pseudo_class = state_name;
 	
+	ccss_style_init (&style);
 	ret = ccss_stylesheet_query_apply (stylesheet,
 					  (ccss_node_t const *) &node, &style);
 	if (!ret) {
@@ -258,7 +252,6 @@
 gce_serialize (ccss_stylesheet_t const *stylesheet)
 {
 	ccss_stylesheet_iter_t		 iter;
-	ccss_node_class_t		 original_node_class;
 	char const			*type_name;
 	ccss_selector_group_t const	*group;
 	struct RcBlock			 block;
@@ -266,9 +259,6 @@
 	char				*str;
 	gboolean			 ret;
 
-	ccss_node_fill_class (&original_node_class);
-	ccss_node_set_class (&_node_class);
-
 	rc_string = g_string_new ("");
 
 	ccss_stylesheet_iter_init (&iter, stylesheet);
@@ -291,8 +281,6 @@
 		}
 	}
 
-	ccss_node_set_class (&original_node_class);
-
 	str = rc_string->str;
 	g_string_free (rc_string, FALSE), rc_string = NULL;
 	return str;

Modified: trunk/src/gce-theme.c
==============================================================================
--- trunk/src/gce-theme.c	(original)
+++ trunk/src/gce-theme.c	Mon Sep 29 15:27:11 2008
@@ -35,15 +35,13 @@
 G_MODULE_EXPORT void 
 theme_init (GTypeModule *module)
 {
-	ccss_node_class_t const	*node_class;
 	ccss_function_t const	*vtable;
 
 	gce_rc_style_register_type (module);
 	gce_style_register_type (module);
 
-	node_class = gce_node_get_class ();
 	vtable = gce_functions_get_vtable ();
-	ccss_init (node_class, vtable);
+	ccss_init (vtable);
 }
 
 G_MODULE_EXPORT void 



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