From 24a4ca0c6d6c65e753db1cde7b6f379d555c7589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 25 May 2010 20:07:53 +0200 Subject: [PATCH] [StThemeNode] Add a comparison function Add st_theme_node_equal() - two nodes are considered equal iff they refer to identical elements, so e.g. .example and .example:hover are not equal, even if no .example:hover rule exists in the CSS. https://bugzilla.gnome.org/show_bug.cgi?id=619025 --- src/st/st-theme-node.c | 43 ++++++++++++++++++++++++++++++++++++++++++ src/st/st-theme-node.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c index 24846ae0d..e2b0378c7 100644 --- a/src/st/st-theme-node.c +++ b/src/st/st-theme-node.c @@ -233,6 +233,49 @@ st_theme_node_get_pseudo_class (StThemeNode *node) return node->pseudo_class; } +/** + * st_theme_node_equal: + * @node_a: first #StThemeNode + * @node_b: second #StThemeNode + * + * Compare two #StThemeNodes. Two nodes which compare equal will match + * the same CSS rules and have the same style properties. However, two + * nodes that have ended up with identical style properties do not + * necessarily compare equal. + * In detail, @node_a and @node_b are considered equal iff + * + * + * they share the same #StTheme and #StThemeContext + * + * + * they have the same parent + * + * + * they have the same element type + * + * + * their id, class, pseudo-class and inline-style match + * + * + * + * Returns: %TRUE if @node_a equals @node_b + */ +gboolean +st_theme_node_equal (StThemeNode *node_a, StThemeNode *node_b) +{ + g_return_val_if_fail (ST_IS_THEME_NODE (node_a), FALSE); + g_return_val_if_fail (ST_IS_THEME_NODE (node_b), FALSE); + + return node_a->parent_node == node_b->parent_node && + node_a->context == node_b->context && + node_a->theme == node_b->theme && + node_a->element_type == node_b->element_type && + !g_strcmp0 (node_a->element_id, node_b->element_id) && + !g_strcmp0 (node_a->element_class, node_b->element_class) && + !g_strcmp0 (node_a->pseudo_class, node_b->pseudo_class) && + !g_strcmp0 (node_a->inline_style, node_b->inline_style); +} + static void ensure_properties (StThemeNode *node) { diff --git a/src/st/st-theme-node.h b/src/st/st-theme-node.h index 2bc5e7ab4..3fbeb810b 100644 --- a/src/st/st-theme-node.h +++ b/src/st/st-theme-node.h @@ -80,6 +80,8 @@ StThemeNode *st_theme_node_get_parent (StThemeNode *node); StTheme *st_theme_node_get_theme (StThemeNode *node); +gboolean st_theme_node_equal (StThemeNode *node_a, StThemeNode *node_b); + GType st_theme_node_get_element_type (StThemeNode *node); const char *st_theme_node_get_element_id (StThemeNode *node); const char *st_theme_node_get_element_class (StThemeNode *node);