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:
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "gtkcssmatcherprivate.h"
|
#include "gtkcssmatcherprivate.h"
|
||||||
|
|
||||||
|
#include "gtkcssnodedeclarationprivate.h"
|
||||||
#include "gtkwidgetpath.h"
|
#include "gtkwidgetpath.h"
|
||||||
|
|
||||||
/* GTK_CSS_MATCHER_WIDGET_PATH */
|
/* GTK_CSS_MATCHER_WIDGET_PATH */
|
||||||
@ -31,6 +32,7 @@ gtk_css_matcher_widget_path_get_parent (GtkCssMatcher *matcher,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
matcher->path.klass = child->path.klass;
|
matcher->path.klass = child->path.klass;
|
||||||
|
matcher->path.decl = NULL;
|
||||||
matcher->path.path = child->path.path;
|
matcher->path.path = child->path.path;
|
||||||
matcher->path.index = child->path.index - 1;
|
matcher->path.index = child->path.index - 1;
|
||||||
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index);
|
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;
|
return FALSE;
|
||||||
|
|
||||||
matcher->path.klass = next->path.klass;
|
matcher->path.klass = next->path.klass;
|
||||||
|
matcher->path.decl = NULL;
|
||||||
matcher->path.path = next->path.path;
|
matcher->path.path = next->path.path;
|
||||||
matcher->path.index = next->path.index;
|
matcher->path.index = next->path.index;
|
||||||
matcher->path.sibling_index = next->path.sibling_index - 1;
|
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;
|
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);
|
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))
|
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);
|
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;
|
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);
|
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))
|
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);
|
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;
|
GSList *regions;
|
||||||
gboolean result;
|
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
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
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))
|
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;
|
const GtkWidgetPath *siblings;
|
||||||
GtkRegionFlags region_flags;
|
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, ®ion_flags))
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
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))
|
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, ®ion_flags))
|
if (!gtk_widget_path_iter_has_region (matcher->path.path, matcher->path.index, region, ®ion_flags))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
|
|
||||||
|
found:
|
||||||
if ((flags & region_flags) != flags)
|
if ((flags & region_flags) != flags)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -195,13 +224,15 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_gtk_css_matcher_init (GtkCssMatcher *matcher,
|
_gtk_css_matcher_init (GtkCssMatcher *matcher,
|
||||||
const GtkWidgetPath *path)
|
const GtkWidgetPath *path,
|
||||||
|
const GtkCssNodeDeclaration *decl)
|
||||||
{
|
{
|
||||||
if (gtk_widget_path_length (path) == 0)
|
if (gtk_widget_path_length (path) == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
matcher->path.klass = >K_CSS_MATCHER_WIDGET_PATH;
|
matcher->path.klass = >K_CSS_MATCHER_WIDGET_PATH;
|
||||||
|
matcher->path.decl = decl;
|
||||||
matcher->path.path = path;
|
matcher->path.path = path;
|
||||||
matcher->path.index = gtk_widget_path_length (path) - 1;
|
matcher->path.index = gtk_widget_path_length (path) - 1;
|
||||||
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
|
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
|
||||||
|
|||||||
@ -54,6 +54,7 @@ struct _GtkCssMatcherClass {
|
|||||||
|
|
||||||
struct _GtkCssMatcherWidgetPath {
|
struct _GtkCssMatcherWidgetPath {
|
||||||
const GtkCssMatcherClass *klass;
|
const GtkCssMatcherClass *klass;
|
||||||
|
const GtkCssNodeDeclaration *decl;
|
||||||
const GtkWidgetPath *path;
|
const GtkWidgetPath *path;
|
||||||
guint index;
|
guint index;
|
||||||
guint sibling_index;
|
guint sibling_index;
|
||||||
@ -72,7 +73,8 @@ union _GtkCssMatcher {
|
|||||||
};
|
};
|
||||||
|
|
||||||
gboolean _gtk_css_matcher_init (GtkCssMatcher *matcher,
|
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_any_init (GtkCssMatcher *matcher);
|
||||||
void _gtk_css_matcher_superset_init (GtkCssMatcher *matcher,
|
void _gtk_css_matcher_superset_init (GtkCssMatcher *matcher,
|
||||||
const GtkCssMatcher *subset,
|
const GtkCssMatcher *subset,
|
||||||
|
|||||||
@ -305,7 +305,7 @@ gtk_css_node_real_init_matcher (GtkCssNode *cssnode,
|
|||||||
|
|
||||||
path = gtk_css_node_create_widget_path (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);
|
gtk_widget_path_free (path);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|||||||
@ -18,14 +18,12 @@
|
|||||||
#ifndef __GTK_CSS_NODE_DECLARATION_PRIVATE_H__
|
#ifndef __GTK_CSS_NODE_DECLARATION_PRIVATE_H__
|
||||||
#define __GTK_CSS_NODE_DECLARATION_PRIVATE_H__
|
#define __GTK_CSS_NODE_DECLARATION_PRIVATE_H__
|
||||||
|
|
||||||
|
#include "gtkcsstypesprivate.h"
|
||||||
#include "gtkenums.h"
|
#include "gtkenums.h"
|
||||||
#include "gtkwidgetpath.h"
|
#include "gtkwidgetpath.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct _GtkCssNodeDeclaration GtkCssNodeDeclaration;
|
|
||||||
|
|
||||||
|
|
||||||
GtkCssNodeDeclaration * gtk_css_node_declaration_new (void);
|
GtkCssNodeDeclaration * gtk_css_node_declaration_new (void);
|
||||||
GtkCssNodeDeclaration * gtk_css_node_declaration_ref (GtkCssNodeDeclaration *decl);
|
GtkCssNodeDeclaration * gtk_css_node_declaration_ref (GtkCssNodeDeclaration *decl);
|
||||||
void gtk_css_node_declaration_unref (GtkCssNodeDeclaration *decl);
|
void gtk_css_node_declaration_unref (GtkCssNodeDeclaration *decl);
|
||||||
|
|||||||
@ -1695,7 +1695,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
|
|||||||
gtk_widget_path_iter_set_state (path, -1, state);
|
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);
|
gtk_widget_path_unref (path);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|||||||
@ -25,6 +25,7 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
typedef union _GtkCssMatcher GtkCssMatcher;
|
typedef union _GtkCssMatcher GtkCssMatcher;
|
||||||
typedef struct _GtkCssNode GtkCssNode;
|
typedef struct _GtkCssNode GtkCssNode;
|
||||||
|
typedef struct _GtkCssNodeDeclaration GtkCssNodeDeclaration;
|
||||||
typedef struct _GtkCssStyle GtkCssStyle;
|
typedef struct _GtkCssStyle GtkCssStyle;
|
||||||
typedef struct _GtkStyleProviderPrivate GtkStyleProviderPrivate; /* dummy typedef */
|
typedef struct _GtkStyleProviderPrivate GtkStyleProviderPrivate; /* dummy typedef */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user