summaryrefslogtreecommitdiff
path: root/gtk/gtkcssmatcher.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2012-03-18 02:11:44 +0100
committerBenjamin Otte <otte@redhat.com>2012-04-17 08:59:08 +0200
commit3bdde54aaf92bca5c0511307b77b2c7afcbc4d3d (patch)
tree4a1d69c645d61bb9b3941910716a112275bd426a /gtk/gtkcssmatcher.c
parent8dbe8c83491c5877c9b19928f257ec7a671cb45e (diff)
downloadgtk+-3bdde54aaf92bca5c0511307b77b2c7afcbc4d3d.tar.gz
selector: Rewrite position tracking
We now track the position as a (type,a,b) tuple where the numbers make up the an + b formula from CSS3 nth-child. Also, the get_sibling() and get_sibling_index() vfuncs were replaced by a has_position() vfunc. This is mostly so that the matcher can always return TRUE. And I need that for the everything matcher.
Diffstat (limited to 'gtk/gtkcssmatcher.c')
-rw-r--r--gtk/gtkcssmatcher.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 053280fac7..cf9489eab4 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -146,22 +146,33 @@ gtk_css_matcher_widget_path_has_region (const GtkCssMatcher *matcher,
return TRUE;
}
-static guint
-gtk_css_matcher_widget_path_get_sibling_index (const GtkCssMatcher *matcher)
-{
- return matcher->path.sibling_index;
-}
-
-static guint
-gtk_css_matcher_widget_path_get_n_siblings (const GtkCssMatcher *matcher)
+static gboolean
+gtk_css_matcher_widget_path_has_position (const GtkCssMatcher *matcher,
+ gboolean forward,
+ int a,
+ int b)
{
const GtkWidgetPath *siblings;
+ int x;
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (!siblings)
- return 0;
+ return FALSE;
+
+ if (forward)
+ x = matcher->path.sibling_index + 1;
+ else
+ x = gtk_widget_path_length (siblings) - matcher->path.sibling_index;
+
+ x -= b;
+
+ if (a == 0)
+ return x == 0;
+
+ if (x % a)
+ return FALSE;
- return gtk_widget_path_length (siblings);
+ return x / a > 0;
}
static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
@@ -173,8 +184,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
gtk_css_matcher_widget_path_has_id,
gtk_css_matcher_widget_path_has_regions,
gtk_css_matcher_widget_path_has_region,
- gtk_css_matcher_widget_path_get_sibling_index,
- gtk_css_matcher_widget_path_get_n_siblings
+ gtk_css_matcher_widget_path_has_position,
};
void