[libcroco-list] Possible API additions



Hi,

While trying to match css2 DOM methods like CSSStyleDeclaration::item()
and CSSStyleDeclaration::length() with the libcroco API, it looks to me
there is no close matching. I am reluctant to touch the libcroco internals
to much, out of fear it may change in the future. So I have done a small
patch with functions I can call, so I dont have to mess too much with
libcroco structures from outside libcroco :)
I am posting it here because Dodji asked me to and since I dont know
if these method are useful outside dom wrapping?
Cheers,

Rob.
Index: src/cr-declaration.c
===================================================================
RCS file: /cvs/gnome/libcroco/src/cr-declaration.c,v
retrieving revision 1.6
diff -u -3 -p -p -u -b -r1.6 cr-declaration.c
--- src/cr-declaration.c	12 Feb 2004 22:49:12 -0000	1.6
+++ src/cr-declaration.c	13 Feb 2004 22:02:37 -0000
@@ -597,6 +597,65 @@ cr_declaration_to_string (CRDeclaration 
 }
 
 /**
+ *Return the number of properties in the declaration;
+ * param a_this the current instance of #CRDeclaration.
+ * return number of properties in the declaration list.
+ */
+int
+cr_declaration_nr_props (CRDeclaration *a_this)
+{
+	CRDeclaration *cur = NULL ;
+	int nr = 0;
+
+	g_return_if_fail (a_this) ;
+
+	for (cur = a_this ; cur ; cur = cur->next)
+		nr ++;
+	return nr;
+}
+
+/**
+ *Use an index to get a CRDeclaration from the declaration list.
+ * param a_this the current instance of #CRDeclaration.
+ * param itemnr the index into the declaration list.
+ * return CRDeclaration at position itemnr, if itemnr > number of declarations - 1,
+ *it will return NULL.
+ */
+CRDeclaration *
+cr_declaration_get_from_list (CRDeclaration *a_this, int itemnr)
+{
+	CRDeclaration *cur = NULL ;
+	int nr = 0;
+
+	g_return_if_fail (a_this) ;
+
+	for (cur = a_this ; cur ; cur = cur->next)
+		if (nr++ == itemnr)
+			return cur;
+	return NULL;
+}
+
+/**
+ *Use property name to get a CRDeclaration from the declaration list.
+ * param a_this the current instance of #CRDeclaration.
+ * param a_prop the property name to search for.
+ * return CRDeclaration with property name a_prop, or NULL if not found.
+ */
+CRDeclaration *
+cr_declaration_get_by_prop_name (CRDeclaration *a_this, const guchar *a_prop)
+{
+	CRDeclaration *cur = NULL ;
+
+	g_return_if_fail (a_this) ;
+	g_return_if_fail (a_prop) ;
+
+	for (cur = a_this ; cur ; cur = cur->next)
+		if (!strcmp (cur->property->str, a_prop))
+			return cur;
+	return NULL;
+}
+
+/**
  *Increases the ref count of the current instance of #CRDeclaration.
  * param a_this the current instance of #CRDeclaration.
  */
Index: src/cr-declaration.h
===================================================================
RCS file: /cvs/gnome/libcroco/src/cr-declaration.h,v
retrieving revision 1.5
diff -u -3 -p -p -u -b -r1.5 cr-declaration.h
--- src/cr-declaration.h	12 Feb 2004 22:49:12 -0000	1.5
+++ src/cr-declaration.h	13 Feb 2004 22:02:37 -0000
@@ -100,6 +100,15 @@ void
 cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent,
 		     gboolean a_one_per_line) ;
 
+int
+cr_declaration_nr_props (CRDeclaration *a_this) ;
+
+CRDeclaration *
+cr_declaration_get_from_list (CRDeclaration *a_this, int itemnr) ;
+
+CRDeclaration *
+cr_declaration_get_by_prop_name (CRDeclaration *a_this, const guchar *a_str) ;
+
 guchar *
 cr_declaration_to_string (CRDeclaration *a_this,
 			  gulong a_indent) ;


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