[gtk+/wip/cssnode3: 36/101] cssmatcher: Allow widget path matcher to take a node declaration
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssnode3: 36/101] cssmatcher: Allow widget path matcher to take a node declaration
- Date: Wed, 11 Mar 2015 00:22:37 +0000 (UTC)
commit fe51ee45763a7f799d6d9cd02b4aab939efd2584
Author: Benjamin Otte <otte redhat com>
Date: Mon Feb 9 11:24:29 2015 +0100
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.
gtk/gtkcssmatcher.c | 37 +++++++++++++++++++++++++++++++++--
gtk/gtkcssmatcherprivate.h | 4 ++-
gtk/gtkcssnode.c | 2 +-
gtk/gtkcssnodedeclarationprivate.h | 4 +--
gtk/gtkcssprovider.c | 2 +-
gtk/gtkcsstypesprivate.h | 1 +
6 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index b734bfa..7d92ec8 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -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, ®ion_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, ®ion_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 = >K_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);
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index e37083e..e517501 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -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,
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 38640f6..377fb63 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -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;
diff --git a/gtk/gtkcssnodedeclarationprivate.h b/gtk/gtkcssnodedeclarationprivate.h
index f267974..9e715fe 100644
--- a/gtk/gtkcssnodedeclarationprivate.h
+++ b/gtk/gtkcssnodedeclarationprivate.h
@@ -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);
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index aa61771..eb582bf 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -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;
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 792a66e..0cb92b8 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]