[libcroco-list] New functions for statement/rule retrieval



Hi,

While coding on my dom implementation (which uses libcroco) I
found again a few areas where the libcroco API doesnt 100% map to
what the dom demands. So I have done a patch, rather like the one
for retrieving of declarations from a declaration list, but this time
for statements. I included functions to retrieve rules from a stylesheet
(using an index), from a list of rules and from a media rule. From my pov
these are very convenient functions. Please let me know what you think :)
Cheers,

Rob.
Index: src/cr-stylesheet.h
===================================================================
RCS file: /cvs/gnome/libcroco/src/cr-stylesheet.h,v
retrieving revision 1.5
diff -u -3 -p -p -u -b -r1.5 cr-stylesheet.h
--- src/cr-stylesheet.h	24 Jan 2004 19:24:02 -0000	1.5
+++ src/cr-stylesheet.h	24 Feb 2004 17:41:59 -0000
@@ -91,6 +91,12 @@ cr_stylesheet_new (CRStatement *a_stmts)
 void
 cr_stylesheet_dump (CRStyleSheet *a_this, FILE *a_fp) ;
 
+int
+cr_stylesheet_nr_rules (CRStyleSheet *a_this) ;
+
+CRStatement *
+cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr) ;
+
 void
 cr_stylesheet_ref (CRStyleSheet *a_this) ;
 
Index: src/cr-stylesheet.c
===================================================================
RCS file: /cvs/gnome/libcroco/src/cr-stylesheet.c,v
retrieving revision 1.6
diff -u -3 -p -p -u -b -r1.6 cr-stylesheet.c
--- src/cr-stylesheet.c	24 Jan 2004 19:24:02 -0000	1.6
+++ src/cr-stylesheet.c	24 Feb 2004 17:41:59 -0000
@@ -78,6 +78,34 @@ cr_stylesheet_dump (CRStyleSheet *a_this
 	}
 }
 
+/**
+ *Return the number of rules in the stylesheet.
+ * param a_this the current instance of #CRStyleSheet.
+ * return number of rules in the stylesheet.
+ */
+int
+cr_stylesheets_nr_rules (CRStyleSheet *a_this)
+{
+	g_return_val_if_fail (a_this, -1) ;
+
+	return cr_statement_nr_rules (a_this->statements);
+}
+
+/**
+ *Use an index to get a CRStatement from the rules in a given stylesheet.
+ * param a_this the current instance of #CRStatement.
+ * param itemnr the index into the rules.
+ * return CRStatement at position itemnr, if itemnr > number of rules - 1,
+ *it will return NULL.
+ */
+CRStatement *
+cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr)
+{
+	g_return_val_if_fail (a_this, NULL) ;
+
+	return cr_statement_get_from_list (a_this->statements, itemnr);
+}
+
 void
 cr_stylesheet_ref (CRStyleSheet *a_this)
 {
Index: src/cr-statement.h
===================================================================
RCS file: /cvs/gnome/libcroco/src/cr-statement.h,v
retrieving revision 1.6
diff -u -3 -p -p -u -b -r1.6 cr-statement.h
--- src/cr-statement.h	12 Feb 2004 22:49:12 -0000	1.6
+++ src/cr-statement.h	24 Feb 2004 17:41:59 -0000
@@ -350,6 +350,12 @@ enum CRStatus
 cr_statement_at_import_rule_get_url (CRStatement *a_this,
 				     GString **a_url) ;
 
+int
+cr_statement_at_media_nr_rules (CRStatement *a_this) ;
+
+CRStatement *
+cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) ;
+
 enum CRStatus
 cr_statement_at_page_rule_set_sel (CRStatement *a_this,
 				   CRSelector *a_sel) ;
@@ -390,6 +396,12 @@ cr_statement_at_font_face_rule_add_decl 
 void
 cr_statement_dump (CRStatement *a_this, FILE *a_fp, gulong a_indent) ;
 
+int
+cr_statement_nr_rules (CRStatement *a_this) ;
+
+CRStatement *
+cr_statement_get_from_list (CRStatement *a_this, int itemnr) ;
+
 void
 cr_statement_destroy (CRStatement *a_this) ;
 
Index: src/cr-statement.c
===================================================================
RCS file: /cvs/gnome/libcroco/src/cr-statement.c,v
retrieving revision 1.5
diff -u -3 -p -p -u -b -r1.5 cr-statement.c
--- src/cr-statement.c	24 Jan 2004 19:24:02 -0000	1.5
+++ src/cr-statement.c	24 Feb 2004 17:41:59 -0000
@@ -753,6 +753,45 @@ cr_statement_dump_page (CRStatement *a_t
 }
 
 /**
+ *Return the number of rules in the statement list;
+ * param a_this the current instance of #CRStatement.
+ * return number of rules in the statement list.
+ */
+int
+cr_statement_nr_rules (CRStatement *a_this)
+{
+	CRStatement *cur = NULL ;
+	int nr = 0;
+
+	g_return_val_if_fail (a_this, -1) ;
+
+	for (cur = a_this ; cur ; cur = cur->next)
+		nr ++;
+	return nr;
+}
+
+/**
+ *Use an index to get a CRStatement from the statement list.
+ * param a_this the current instance of #CRStatement.
+ * param itemnr the index into the statement list.
+ * return CRStatement at position itemnr, if itemnr > number of statements - 1,
+ *it will return NULL.
+ */
+CRStatement *
+cr_statement_get_from_list (CRStatement *a_this, int itemnr)
+{
+	CRStatement *cur = NULL ;
+	int nr = 0;
+
+	g_return_val_if_fail (a_this, NULL) ;
+
+	for (cur = a_this ; cur ; cur = cur->next)
+		if (nr++ == itemnr)
+			return cur;
+	return NULL;
+}
+
+/**
  *Dumps an @media rule statement to a file.
  * param a_this the statement to dump.
  * param a_fp the destination file pointer
@@ -2108,6 +2147,40 @@ cr_statement_at_import_rule_get_url (CRS
 }
 
 /**
+ *Return the number of rules in the media rule;
+ * param a_this the current instance of #CRStatement.
+ * return number of rules in the media rule.
+ */
+int
+cr_statement_at_media_nr_rules (CRStatement *a_this)
+{
+	g_return_val_if_fail (a_this 
+			      && a_this->type == AT_MEDIA_RULE_STMT
+			      && a_this->kind.media_rule,
+			      CR_BAD_PARAM_ERROR) ;
+
+	return cr_statement_nr_rules (a_this->kind.media_rule->rulesets);
+}
+
+/**
+ *Use an index to get a CRStatement from the media rule list of rules.
+ * param a_this the current instance of #CRStatement.
+ * param itemnr the index into the media rule list of rules.
+ * return CRStatement at position itemnr, if itemnr > number of rules - 1,
+ *it will return NULL.
+ */
+CRStatement *
+cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr)
+{
+	g_return_val_if_fail (a_this 
+			      && a_this->type == AT_MEDIA_RULE_STMT
+			      && a_this->kind.media_rule,
+			      NULL) ;
+
+	return cr_statement_get_from_list (a_this->kind.media_rule->rulesets, itemnr);
+}
+
+/**
  *Sets a declaration list to the current @page rule statement.
  * param a_this the current @page rule statement.
  * param a_decl_list the declaration list to add. Will be freed


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