summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Staudinger <robsta@gnome.org>2008-12-11 19:45:44 +0100
committerRobert Staudinger <robsta@gnome.org>2008-12-11 19:45:44 +0100
commitd3d7f4fdce94c7401f07d2d2c03359fc270b8554 (patch)
tree332bcfcd479d48b72de0d773057fb78cce1f3488
parent119d1b0fce29daba91bcd1abd828660906caaa81 (diff)
* ccss-doc/ccss-sections.txt:
* ccss-doc/tmpl/ccss-unused.sgml: * ccss-doc/tmpl/style.sgml: * ccss-doc/tmpl/stylesheet.sgml: * ccss-gtk/ccss-gtk-stylesheet.c (accumulate_state): * ccss/ccss-style-priv.h: * ccss/ccss-style.h: * ccss/ccss-stylesheet.c (ccss_stylesheet_query_type), (ccss_stylesheet_query): * ccss/ccss-stylesheet.h: * ccss/ccss.sym: * examples/example-1.c (main): * examples/example-2.c (main): * examples/example-3.c (main): * examples/example-4.c (main): * examples/example-5.c (main): Do not expose style constructor, return instance from stylesheet queries.
-rw-r--r--ChangeLog20
-rw-r--r--ccss-doc/ccss-sections.txt1
-rw-r--r--ccss-doc/tmpl/ccss-unused.sgml7
-rw-r--r--ccss-doc/tmpl/style.sgml8
-rw-r--r--ccss-doc/tmpl/stylesheet.sgml2
-rw-r--r--ccss-gtk/ccss-gtk-stylesheet.c6
-rw-r--r--ccss/ccss-style-priv.h3
-rw-r--r--ccss/ccss-style.h3
-rw-r--r--ccss/ccss-stylesheet.c68
-rw-r--r--ccss/ccss-stylesheet.h10
-rw-r--r--ccss/ccss.sym1
-rw-r--r--examples/example-1.c6
-rw-r--r--examples/example-2.c7
-rw-r--r--examples/example-3.c6
-rw-r--r--examples/example-4.c6
-rw-r--r--examples/example-5.c6
16 files changed, 82 insertions, 78 deletions
diff --git a/ChangeLog b/ChangeLog
index 2514313..b0cfdd8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
2008-12-11 Robert Staudinger <robsta@gnome.org>
+ * ccss-doc/ccss-sections.txt:
+ * ccss-doc/tmpl/ccss-unused.sgml:
+ * ccss-doc/tmpl/style.sgml:
+ * ccss-doc/tmpl/stylesheet.sgml:
+ * ccss-gtk/ccss-gtk-stylesheet.c (accumulate_state):
+ * ccss/ccss-style-priv.h:
+ * ccss/ccss-style.h:
+ * ccss/ccss-stylesheet.c (ccss_stylesheet_query_type),
+ (ccss_stylesheet_query):
+ * ccss/ccss-stylesheet.h:
+ * ccss/ccss.sym:
+ * examples/example-1.c (main):
+ * examples/example-2.c (main):
+ * examples/example-3.c (main):
+ * examples/example-4.c (main):
+ * examples/example-5.c (main):
+ Do not expose style constructor, return instance from stylesheet queries.
+
+2008-12-11 Robert Staudinger <robsta@gnome.org>
+
* ccss/ccss-grammar.c (ccss_grammar_add_properties): don't warn when the
default property handler is overwritten.
diff --git a/ccss-doc/ccss-sections.txt b/ccss-doc/ccss-sections.txt
index e352d1c..9354480 100644
--- a/ccss-doc/ccss-sections.txt
+++ b/ccss-doc/ccss-sections.txt
@@ -46,7 +46,6 @@ ccss_node_init
<TITLE>ccss_style_t</TITLE>
<FILE>style</FILE>
ccss_style_t
-ccss_style_create
ccss_style_destroy
ccss_style_get_double
ccss_style_get_property
diff --git a/ccss-doc/tmpl/ccss-unused.sgml b/ccss-doc/tmpl/ccss-unused.sgml
index f5b2322..e507b46 100644
--- a/ccss-doc/tmpl/ccss-unused.sgml
+++ b/ccss-doc/tmpl/ccss-unused.sgml
@@ -191,6 +191,13 @@ ccss_selector_group_t
</para>
+<!-- ##### FUNCTION ccss_style_create ##### -->
+<para>
+
+</para>
+
+@Returns:
+
<!-- ##### FUNCTION ccss_style_draw_gap ##### -->
<para>
diff --git a/ccss-doc/tmpl/style.sgml b/ccss-doc/tmpl/style.sgml
index 2c7ce52..fb1eb2c 100644
--- a/ccss-doc/tmpl/style.sgml
+++ b/ccss-doc/tmpl/style.sgml
@@ -23,14 +23,6 @@ ccss_style_t
</para>
-<!-- ##### FUNCTION ccss_style_create ##### -->
-<para>
-
-</para>
-
-@Returns:
-
-
<!-- ##### FUNCTION ccss_style_destroy ##### -->
<para>
diff --git a/ccss-doc/tmpl/stylesheet.sgml b/ccss-doc/tmpl/stylesheet.sgml
index df22794..e1bb61f 100644
--- a/ccss-doc/tmpl/stylesheet.sgml
+++ b/ccss-doc/tmpl/stylesheet.sgml
@@ -106,7 +106,6 @@ ccss_stylesheet_t
@self:
@type_name:
-@style:
@Returns:
@@ -117,7 +116,6 @@ ccss_stylesheet_t
@self:
@node:
-@style:
@Returns:
diff --git a/ccss-gtk/ccss-gtk-stylesheet.c b/ccss-gtk/ccss-gtk-stylesheet.c
index 87f2efe..4e747d3 100644
--- a/ccss-gtk/ccss-gtk-stylesheet.c
+++ b/ccss-gtk/ccss-gtk-stylesheet.c
@@ -213,10 +213,8 @@ accumulate_state (ccss_stylesheet_t *stylesheet,
node.id = NULL;
node.pseudo_class = state_name;
- style = ccss_style_create ();
- ret = ccss_stylesheet_query (stylesheet,
- (ccss_node_t const *) &node, style);
- if (!ret) {
+ style = ccss_stylesheet_query (stylesheet, (ccss_node_t const *) &node);
+ if (!style) {
return false;
}
diff --git a/ccss/ccss-style-priv.h b/ccss/ccss-style-priv.h
index 63c63e0..5cf8a68 100644
--- a/ccss/ccss-style-priv.h
+++ b/ccss/ccss-style-priv.h
@@ -38,6 +38,9 @@ struct ccss_style_ {
int32_t viewport_height;
};
+ccss_style_t *
+ccss_style_create (void);
+
CCSS_END_DECLS
#endif /* CCSS_STYLE_PRIV_H */
diff --git a/ccss/ccss-style.h b/ccss/ccss-style.h
index 3028c53..d10c37a 100644
--- a/ccss/ccss-style.h
+++ b/ccss/ccss-style.h
@@ -36,9 +36,6 @@ CCSS_BEGIN_DECLS
**/
typedef struct ccss_style_ ccss_style_t;
-ccss_style_t *
-ccss_style_create (void);
-
void
ccss_style_destroy (ccss_style_t *self);
diff --git a/ccss/ccss-stylesheet.c b/ccss/ccss-stylesheet.c
index 5e6b0a8..847fbba 100644
--- a/ccss/ccss-stylesheet.c
+++ b/ccss/ccss-stylesheet.c
@@ -180,35 +180,38 @@ ccss_stylesheet_get_reference_count (ccss_stylesheet_t const *self)
* ccss_stylesheet_query_type:
* @self: a #ccss_stylesheet_t.
* @type_name: the type to query for, e.g. `h1'.
- * @style: a #ccss_style_t that the results of the query are applied to.
*
* Query the stylesheet for styling information regarding a type.
*
- * Returns: a #ccss_selector_group_t containing the requested information of %NULL.
+ * Returns: a #ccss_style_t that the results of the query are applied to or
+ * %NULL if the query didn't yield results.
**/
-bool
+ccss_style_t *
ccss_stylesheet_query_type (ccss_stylesheet_t *self,
- char const *type_name,
- ccss_style_t *style)
+ char const *type_name)
{
- ccss_selector_group_t const *group;
+ ccss_selector_group_t const *group;
+ ccss_style_t *style;
+ bool ret;
- g_assert (self && type_name && self->groups);
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (type_name, NULL);
- if (style->stylesheet &&
- style->stylesheet != self) {
- g_warning ("style %p already associated to stylesheet %p",
- (void *) style, (void *) self);
- return false;
- } else if (NULL == style->stylesheet) {
- style->stylesheet = ccss_stylesheet_reference (self);
- }
+ style = ccss_style_create ();
+ style->stylesheet = ccss_stylesheet_reference (self);
group = (ccss_selector_group_t const *) g_hash_table_lookup (self->groups, type_name);
if (!group)
- return false;
+ goto bail;
- return ccss_selector_group_apply_type (group, type_name, style);
+ ret = ccss_selector_group_apply_type (group, type_name, style);
+ if (!ret)
+ goto bail;
+
+ return style;
+bail:
+ ccss_style_destroy (style);
+ return NULL;
}
/*
@@ -426,33 +429,28 @@ query_container_r (ccss_stylesheet_t const *self,
* ccss_stylesheet_query:
* @self: a #ccss_stylesheet_t.
* @node: a #ccss_node_t implementation that is used by libccss to retrieve information about the underlying document.
- * @style: a #ccss_style_t that the results of the query are applied to.
*
* Query the stylesheet for styling information regarding a document node and apply the results to a #ccss_style_t object.
*
- * Returns: %TRUE if styling information has been found.
+ * Returns: a #ccss_style_t that the results of the query are applied to or
+ * %NULL if the query didn't yield results.
**/
-bool
+ccss_style_t *
ccss_stylesheet_query (ccss_stylesheet_t *self,
- ccss_node_t const *node,
- ccss_style_t *style)
+ ccss_node_t const *node)
{
GHashTable *inherit;
GHashTableIter iter;
GQuark property_id;
ccss_property_base_t const *property;
+ ccss_style_t *style;
bool ret;
- g_assert (self && node && style);
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (node, NULL);
- if (style->stylesheet &&
- style->stylesheet != self) {
- g_warning ("style %p already associated to stylesheet %p",
- (void *) style, (void *) self);
- return false;
- } else if (NULL == style->stylesheet) {
- style->stylesheet = ccss_stylesheet_reference (self);
- }
+ style = ccss_style_create ();
+ style->stylesheet = ccss_stylesheet_reference (self);
/* Apply this node's styling. */
ret = query_node (self, node, style);
@@ -487,7 +485,13 @@ ccss_stylesheet_query (ccss_stylesheet_t *self,
}
g_hash_table_destroy (inherit), inherit = NULL;
- return ret;
+ if (!ret) {
+ /* No style matches. */
+ ccss_style_destroy (style);
+ style = NULL;
+ }
+
+ return style;
}
/**
diff --git a/ccss/ccss-stylesheet.h b/ccss/ccss-stylesheet.h
index e95ff7c..8247da2 100644
--- a/ccss/ccss-stylesheet.h
+++ b/ccss/ccss-stylesheet.h
@@ -58,15 +58,13 @@ ccss_stylesheet_add_from_file (ccss_stylesheet_t *self,
ccss_stylesheet_precedence_t precedence,
void *user_data);
-bool
+ccss_style_t *
ccss_stylesheet_query_type (ccss_stylesheet_t *self,
- char const *type_name,
- ccss_style_t *style);
+ char const *type_name);
-bool
+ccss_style_t *
ccss_stylesheet_query (ccss_stylesheet_t *self,
- ccss_node_t const *node,
- ccss_style_t *style);
+ ccss_node_t const *node);
void
ccss_stylesheet_invalidate_node (ccss_stylesheet_t const *self,
diff --git a/ccss/ccss.sym b/ccss/ccss.sym
index 1204245..2d87832 100644
--- a/ccss/ccss.sym
+++ b/ccss/ccss.sym
@@ -13,7 +13,6 @@ ccss_grammar_reference
ccss_node_init
ccss_property_init
ccss_property_parse_state
-ccss_style_create
ccss_style_destroy
ccss_style_dump
ccss_style_foreach
diff --git a/examples/example-1.c b/examples/example-1.c
index ce3f9a6..7401026 100644
--- a/examples/example-1.c
+++ b/examples/example-1.c
@@ -40,7 +40,6 @@ main (int argc,
ccss_stylesheet_t *stylesheet;
ccss_style_t *style;
GtkWidget *window;
- gboolean ret;
gtk_init (&argc, &argv);
@@ -49,9 +48,8 @@ main (int argc,
_css, sizeof (_css),
NULL);
- style = ccss_style_create ();
- ret = ccss_stylesheet_query_type (stylesheet, "box", style);
- g_assert (ret);
+ style = ccss_stylesheet_query_type (stylesheet, "box");
+ g_assert (style);
#ifdef CCSS_DEBUG
ccss_style_dump (style);
diff --git a/examples/example-2.c b/examples/example-2.c
index 1417985..fd70644 100644
--- a/examples/example-2.c
+++ b/examples/example-2.c
@@ -73,7 +73,6 @@ main (int argc,
ccss_style_t *style;
node_t node;
GtkWidget *window;
- gboolean ret;
gtk_init (&argc, &argv);
@@ -87,10 +86,8 @@ main (int argc,
node.instance = 0xdeadbeef;
node.inline_css = "background-color: yellow";
- style = ccss_style_create ();
- ret = ccss_stylesheet_query (stylesheet, (ccss_node_t const *) &node,
- style);
- g_assert (ret);
+ style = ccss_stylesheet_query (stylesheet, (ccss_node_t const *) &node);
+ g_assert (style);
#ifdef CCSS_DEBUG
ccss_style_dump (style);
diff --git a/examples/example-3.c b/examples/example-3.c
index 0bbab54..76fa1a6 100644
--- a/examples/example-3.c
+++ b/examples/example-3.c
@@ -63,7 +63,6 @@ main (int argc,
ccss_stylesheet_t *stylesheet;
ccss_style_t *style;
GtkWidget *window;
- gboolean ret;
gtk_init (&argc, &argv);
@@ -73,9 +72,8 @@ main (int argc,
_css, sizeof (_css),
NULL);
- style = ccss_style_create ();
- ret = ccss_stylesheet_query_type (stylesheet, "box", style);
- g_assert (ret);
+ style = ccss_stylesheet_query_type (stylesheet, "box");
+ g_assert (style);
#ifdef CCSS_DEBUG
ccss_style_dump (style);
diff --git a/examples/example-4.c b/examples/example-4.c
index 71a1538..25f0603 100644
--- a/examples/example-4.c
+++ b/examples/example-4.c
@@ -129,7 +129,6 @@ main (int argc,
ccss_stylesheet_t *stylesheet;
ccss_style_t *style;
GtkWidget *window;
- gboolean ret;
gtk_init (&argc, &argv);
@@ -139,9 +138,8 @@ main (int argc,
_css, sizeof (_css),
NULL);
- style = ccss_style_create ();
- ret = ccss_stylesheet_query_type (stylesheet, "box", style);
- g_assert (ret);
+ style = ccss_stylesheet_query_type (stylesheet, "box");
+ g_assert (style);
#ifdef CCSS_DEBUG
ccss_style_dump (style);
diff --git a/examples/example-5.c b/examples/example-5.c
index cb19dfd..06c794e 100644
--- a/examples/example-5.c
+++ b/examples/example-5.c
@@ -63,7 +63,6 @@ main (int argc,
ccss_stylesheet_t *stylesheet;
ccss_style_t *style;
GtkWidget *window;
- gboolean ret;
gtk_init (&argc, &argv);
@@ -73,9 +72,8 @@ main (int argc,
_css, sizeof (_css),
NULL);
- style = ccss_style_create ();
- ret = ccss_stylesheet_query_type (stylesheet, "box", style);
- g_assert (ret);
+ style = ccss_stylesheet_query_type (stylesheet, "box");
+ g_assert (style);
#ifdef CCSS_DEBUG
ccss_style_dump (style);