cssmatcher: Allow widget path matcher to take a node declaration

The node declaration has the same functionality as
gtk_css_node_declaration_add_to_widget_path(). So instead of using that
function on a path, you can use the original path and the declaration in
a matcher.
This commit is contained in:
Benjamin Otte 2015-02-09 11:24:29 +01:00
parent 630f0f199e
commit 2bf7bdd651
6 changed files with 41 additions and 9 deletions

View File

@ -19,6 +19,7 @@
#include "gtkcssmatcherprivate.h"
#include "gtkcssnodedeclarationprivate.h"
#include "gtkwidgetpath.h"
/* GTK_CSS_MATCHER_WIDGET_PATH */
@ -31,6 +32,7 @@ gtk_css_matcher_widget_path_get_parent (GtkCssMatcher *matcher,
return FALSE;
matcher->path.klass = child->path.klass;
matcher->path.decl = NULL;
matcher->path.path = child->path.path;
matcher->path.index = child->path.index - 1;
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index);
@ -46,6 +48,7 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher *matcher,
return FALSE;
matcher->path.klass = next->path.klass;
matcher->path.decl = NULL;
matcher->path.path = next->path.path;
matcher->path.index = next->path.index;
matcher->path.sibling_index = next->path.sibling_index - 1;
@ -58,6 +61,9 @@ gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
{
const GtkWidgetPath *siblings;
if (matcher->path.decl)
return gtk_css_node_declaration_get_state (matcher->path.decl);
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
return gtk_widget_path_iter_get_state (siblings, matcher->path.sibling_index);
@ -84,6 +90,10 @@ gtk_css_matcher_widget_path_has_class (const GtkCssMatcher *matcher,
{
const GtkWidgetPath *siblings;
if (matcher->path.decl &&
gtk_css_node_declaration_has_class (matcher->path.decl, class_name))
return TRUE;
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
return gtk_widget_path_iter_has_qclass (siblings, matcher->path.sibling_index, class_name);
@ -111,6 +121,16 @@ gtk_css_matcher_widget_path_has_regions (const GtkCssMatcher *matcher)
GSList *regions;
gboolean result;
if (matcher->path.decl)
{
GList *list = gtk_css_node_declaration_list_regions (matcher->path.decl);
if (list)
{
g_list_free (list);
return TRUE;
}
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
@ -132,6 +152,14 @@ gtk_css_matcher_widget_path_has_region (const GtkCssMatcher *matcher,
const GtkWidgetPath *siblings;
GtkRegionFlags region_flags;
if (matcher->path.decl)
{
GQuark q = g_quark_try_string (region);
if (q && gtk_css_node_declaration_has_region (matcher->path.decl, q, &region_flags))
goto found;
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
@ -144,12 +172,13 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (!gtk_widget_path_iter_has_region (matcher->path.path, matcher->path.index, region, &region_flags))
return FALSE;
}
G_GNUC_END_IGNORE_DEPRECATIONS
found:
if ((flags & region_flags) != flags)
return FALSE;
return TRUE;
G_GNUC_END_IGNORE_DEPRECATIONS
}
static gboolean
@ -195,13 +224,15 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
};
gboolean
_gtk_css_matcher_init (GtkCssMatcher *matcher,
const GtkWidgetPath *path)
_gtk_css_matcher_init (GtkCssMatcher *matcher,
const GtkWidgetPath *path,
const GtkCssNodeDeclaration *decl)
{
if (gtk_widget_path_length (path) == 0)
return FALSE;
matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
matcher->path.decl = decl;
matcher->path.path = path;
matcher->path.index = gtk_widget_path_length (path) - 1;
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);

View File

@ -54,6 +54,7 @@ struct _GtkCssMatcherClass {
struct _GtkCssMatcherWidgetPath {
const GtkCssMatcherClass *klass;
const GtkCssNodeDeclaration *decl;
const GtkWidgetPath *path;
guint index;
guint sibling_index;
@ -72,7 +73,8 @@ union _GtkCssMatcher {
};
gboolean _gtk_css_matcher_init (GtkCssMatcher *matcher,
const GtkWidgetPath *path) G_GNUC_WARN_UNUSED_RESULT;
const GtkWidgetPath *path,
const GtkCssNodeDeclaration *decl) G_GNUC_WARN_UNUSED_RESULT;
void _gtk_css_matcher_any_init (GtkCssMatcher *matcher);
void _gtk_css_matcher_superset_init (GtkCssMatcher *matcher,
const GtkCssMatcher *subset,

View File

@ -305,7 +305,7 @@ gtk_css_node_real_init_matcher (GtkCssNode *cssnode,
path = gtk_css_node_create_widget_path (cssnode);
if (!_gtk_css_matcher_init (matcher, path))
if (!_gtk_css_matcher_init (matcher, path, NULL))
{
gtk_widget_path_free (path);
return FALSE;

View File

@ -18,14 +18,12 @@
#ifndef __GTK_CSS_NODE_DECLARATION_PRIVATE_H__
#define __GTK_CSS_NODE_DECLARATION_PRIVATE_H__
#include "gtkcsstypesprivate.h"
#include "gtkenums.h"
#include "gtkwidgetpath.h"
G_BEGIN_DECLS
typedef struct _GtkCssNodeDeclaration GtkCssNodeDeclaration;
GtkCssNodeDeclaration * gtk_css_node_declaration_new (void);
GtkCssNodeDeclaration * gtk_css_node_declaration_ref (GtkCssNodeDeclaration *decl);
void gtk_css_node_declaration_unref (GtkCssNodeDeclaration *decl);

View File

@ -1695,7 +1695,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
gtk_widget_path_iter_set_state (path, -1, state);
}
if (!_gtk_css_matcher_init (&matcher, path))
if (!_gtk_css_matcher_init (&matcher, path, NULL))
{
gtk_widget_path_unref (path);
return FALSE;

View File

@ -25,6 +25,7 @@ G_BEGIN_DECLS
typedef union _GtkCssMatcher GtkCssMatcher;
typedef struct _GtkCssNode GtkCssNode;
typedef struct _GtkCssNodeDeclaration GtkCssNodeDeclaration;
typedef struct _GtkCssStyle GtkCssStyle;
typedef struct _GtkStyleProviderPrivate GtkStyleProviderPrivate; /* dummy typedef */