2012-03-17 01:17:23 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2012 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcssmatcherprivate.h"
|
|
|
|
|
2015-02-09 10:24:29 +00:00
|
|
|
#include "gtkcssnodedeclarationprivate.h"
|
2015-02-09 15:41:06 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
2012-03-17 01:17:23 +00:00
|
|
|
#include "gtkwidgetpath.h"
|
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
/* GTK_CSS_MATCHER_WIDGET_PATH */
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_widget_path_get_parent (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *child)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
2012-03-17 13:32:52 +00:00
|
|
|
if (child->path.index == 0)
|
2012-03-17 01:17:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
matcher->path.klass = child->path.klass;
|
2015-02-09 10:24:29 +00:00
|
|
|
matcher->path.decl = NULL;
|
2012-03-17 13:32:52 +00:00
|
|
|
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);
|
2012-03-17 01:17:23 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_widget_path_get_previous (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *next)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
2012-03-17 13:32:52 +00:00
|
|
|
if (next->path.sibling_index == 0)
|
2012-03-17 01:17:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
matcher->path.klass = next->path.klass;
|
2015-02-09 10:24:29 +00:00
|
|
|
matcher->path.decl = NULL;
|
2012-03-17 13:32:52 +00:00
|
|
|
matcher->path.path = next->path.path;
|
|
|
|
matcher->path.index = next->path.index;
|
|
|
|
matcher->path.sibling_index = next->path.sibling_index - 1;
|
2012-03-17 01:17:23 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static GtkStateFlags
|
|
|
|
gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
2014-08-13 14:18:39 +00:00
|
|
|
const GtkWidgetPath *siblings;
|
|
|
|
|
2015-02-09 10:24:29 +00:00
|
|
|
if (matcher->path.decl)
|
|
|
|
return gtk_css_node_declaration_get_state (matcher->path.decl);
|
|
|
|
|
2014-08-13 14:18:39 +00:00
|
|
|
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);
|
|
|
|
else
|
|
|
|
return gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
|
2012-03-17 01:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static gboolean
|
2012-12-10 11:57:10 +00:00
|
|
|
gtk_css_matcher_widget_path_has_type (const GtkCssMatcher *matcher,
|
|
|
|
GType type)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
|
|
|
const GtkWidgetPath *siblings;
|
2012-12-10 11:57:10 +00:00
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
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 g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), type);
|
2012-03-17 01:17:23 +00:00
|
|
|
else
|
2012-03-17 13:32:52 +00:00
|
|
|
return g_type_is_a (gtk_widget_path_iter_get_object_type (matcher->path.path, matcher->path.index), type);
|
2012-03-17 01:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_widget_path_has_class (const GtkCssMatcher *matcher,
|
2012-03-24 00:13:50 +00:00
|
|
|
GQuark class_name)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
|
|
|
const GtkWidgetPath *siblings;
|
|
|
|
|
2015-02-09 10:24:29 +00:00
|
|
|
if (matcher->path.decl &&
|
|
|
|
gtk_css_node_declaration_has_class (matcher->path.decl, class_name))
|
|
|
|
return TRUE;
|
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
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))
|
2012-03-24 00:13:50 +00:00
|
|
|
return gtk_widget_path_iter_has_qclass (siblings, matcher->path.sibling_index, class_name);
|
2012-03-17 01:17:23 +00:00
|
|
|
else
|
2012-03-24 00:13:50 +00:00
|
|
|
return gtk_widget_path_iter_has_qclass (matcher->path.path, matcher->path.index, class_name);
|
2012-03-17 01:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_widget_path_has_id (const GtkCssMatcher *matcher,
|
|
|
|
const char *id)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
|
|
|
const GtkWidgetPath *siblings;
|
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
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_name (siblings, matcher->path.sibling_index, id);
|
2012-03-17 01:17:23 +00:00
|
|
|
else
|
2012-03-17 13:32:52 +00:00
|
|
|
return gtk_widget_path_iter_has_name (matcher->path.path, matcher->path.index, id);
|
2012-03-17 01:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_widget_path_has_regions (const GtkCssMatcher *matcher)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
|
|
|
const GtkWidgetPath *siblings;
|
|
|
|
GSList *regions;
|
|
|
|
gboolean result;
|
2014-06-24 12:21:29 +00:00
|
|
|
|
2015-02-09 10:24:29 +00:00
|
|
|
if (matcher->path.decl)
|
|
|
|
{
|
|
|
|
GList *list = gtk_css_node_declaration_list_regions (matcher->path.decl);
|
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
g_list_free (list);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 12:21:29 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2012-03-17 13:32:52 +00:00
|
|
|
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))
|
|
|
|
regions = gtk_widget_path_iter_list_regions (siblings, matcher->path.sibling_index);
|
2012-03-17 01:17:23 +00:00
|
|
|
else
|
2012-03-17 13:32:52 +00:00
|
|
|
regions = gtk_widget_path_iter_list_regions (matcher->path.path, matcher->path.index);
|
2012-03-17 01:17:23 +00:00
|
|
|
result = regions != NULL;
|
|
|
|
g_slist_free (regions);
|
|
|
|
|
|
|
|
return result;
|
2014-06-24 12:21:29 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2012-03-17 01:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_widget_path_has_region (const GtkCssMatcher *matcher,
|
|
|
|
const char *region,
|
|
|
|
GtkRegionFlags flags)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
|
|
|
const GtkWidgetPath *siblings;
|
|
|
|
GtkRegionFlags region_flags;
|
|
|
|
|
2015-02-09 10:24:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-24 12:21:29 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2012-03-17 13:32:52 +00:00
|
|
|
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))
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
2012-03-17 13:32:52 +00:00
|
|
|
if (!gtk_widget_path_iter_has_region (siblings, matcher->path.sibling_index, region, ®ion_flags))
|
2012-03-17 01:17:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 13:32:52 +00:00
|
|
|
if (!gtk_widget_path_iter_has_region (matcher->path.path, matcher->path.index, region, ®ion_flags))
|
2012-03-17 01:17:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-09 10:24:29 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2012-03-17 01:17:23 +00:00
|
|
|
|
2015-02-09 10:24:29 +00:00
|
|
|
found:
|
2012-03-17 01:17:23 +00:00
|
|
|
if ((flags & region_flags) != flags)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-18 01:11:44 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_widget_path_has_position (const GtkCssMatcher *matcher,
|
|
|
|
gboolean forward,
|
|
|
|
int a,
|
|
|
|
int b)
|
2012-03-17 01:17:23 +00:00
|
|
|
{
|
|
|
|
const GtkWidgetPath *siblings;
|
2012-03-18 01:11:44 +00:00
|
|
|
int x;
|
2012-03-17 01:17:23 +00:00
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
2012-03-17 01:17:23 +00:00
|
|
|
if (!siblings)
|
2012-03-18 01:11:44 +00:00
|
|
|
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;
|
2012-03-17 01:17:23 +00:00
|
|
|
|
2012-03-18 01:11:44 +00:00
|
|
|
return x / a > 0;
|
2012-03-17 01:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 13:28:07 +00:00
|
|
|
static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
|
|
|
|
gtk_css_matcher_widget_path_get_parent,
|
|
|
|
gtk_css_matcher_widget_path_get_previous,
|
|
|
|
gtk_css_matcher_widget_path_get_state,
|
2012-12-10 11:57:10 +00:00
|
|
|
gtk_css_matcher_widget_path_has_type,
|
2012-03-17 13:28:07 +00:00
|
|
|
gtk_css_matcher_widget_path_has_class,
|
|
|
|
gtk_css_matcher_widget_path_has_id,
|
|
|
|
gtk_css_matcher_widget_path_has_regions,
|
|
|
|
gtk_css_matcher_widget_path_has_region,
|
2012-03-18 01:11:44 +00:00
|
|
|
gtk_css_matcher_widget_path_has_position,
|
2012-11-28 10:07:52 +00:00
|
|
|
FALSE
|
2012-03-17 13:28:07 +00:00
|
|
|
};
|
|
|
|
|
2012-04-30 19:28:57 +00:00
|
|
|
gboolean
|
2015-02-09 10:24:29 +00:00
|
|
|
_gtk_css_matcher_init (GtkCssMatcher *matcher,
|
|
|
|
const GtkWidgetPath *path,
|
|
|
|
const GtkCssNodeDeclaration *decl)
|
2012-03-17 13:28:07 +00:00
|
|
|
{
|
2012-04-30 19:28:57 +00:00
|
|
|
if (gtk_widget_path_length (path) == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-17 13:32:52 +00:00
|
|
|
matcher->path.klass = >K_CSS_MATCHER_WIDGET_PATH;
|
2015-02-09 10:24:29 +00:00
|
|
|
matcher->path.decl = decl;
|
2012-03-17 13:32:52 +00:00
|
|
|
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);
|
2012-04-30 19:28:57 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2012-03-17 13:28:07 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 15:41:06 +00:00
|
|
|
/* GTK_CSS_MATCHER_NODE */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_get_parent (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *child)
|
|
|
|
{
|
|
|
|
GtkCssNode *node;
|
|
|
|
|
|
|
|
node = gtk_css_node_get_parent (child->node.node);
|
|
|
|
if (node == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-09 16:26:07 +00:00
|
|
|
return gtk_css_node_init_matcher (node, matcher);
|
2015-02-09 15:41:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-10 01:50:57 +00:00
|
|
|
static GtkCssNode *
|
|
|
|
get_previous_visible_sibling (GtkCssNode *node)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
node = gtk_css_node_get_previous_sibling (node);
|
|
|
|
} while (node && !gtk_css_node_get_visible (node));
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCssNode *
|
|
|
|
get_next_visible_sibling (GtkCssNode *node)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
node = gtk_css_node_get_next_sibling (node);
|
|
|
|
} while (node && !gtk_css_node_get_visible (node));
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:41:06 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_get_previous (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *next)
|
|
|
|
{
|
|
|
|
GtkCssNode *node;
|
|
|
|
|
2015-02-10 01:50:57 +00:00
|
|
|
node = get_previous_visible_sibling (next->node.node);
|
2015-02-09 15:41:06 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-09 16:26:07 +00:00
|
|
|
return gtk_css_node_init_matcher (node, matcher);
|
2015-02-09 15:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkStateFlags
|
|
|
|
gtk_css_matcher_node_get_state (const GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
return gtk_css_node_get_state (matcher->node.node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_has_type (const GtkCssMatcher *matcher,
|
|
|
|
GType type)
|
|
|
|
{
|
|
|
|
return g_type_is_a (gtk_css_node_get_widget_type (matcher->node.node), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_has_class (const GtkCssMatcher *matcher,
|
|
|
|
GQuark class_name)
|
|
|
|
{
|
|
|
|
return gtk_css_node_has_class (matcher->node.node, class_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_has_id (const GtkCssMatcher *matcher,
|
|
|
|
const char *id)
|
|
|
|
{
|
|
|
|
return gtk_css_node_get_id (matcher->node.node) == g_intern_string (id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_has_regions (const GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
GList *regions;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
regions = gtk_css_node_list_regions (matcher->node.node);
|
|
|
|
result = regions != NULL;
|
|
|
|
g_list_free (regions);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_has_region (const GtkCssMatcher *matcher,
|
|
|
|
const char *region,
|
|
|
|
GtkRegionFlags flags)
|
|
|
|
{
|
|
|
|
GtkRegionFlags region_flags;
|
|
|
|
GQuark region_quark;
|
|
|
|
|
|
|
|
region_quark = g_quark_try_string (region);
|
|
|
|
if (!region_quark)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gtk_css_node_has_region (matcher->node.node, region_quark, ®ion_flags))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((flags & region_flags) != flags)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_nth_child (GtkCssNode *node,
|
|
|
|
int a,
|
|
|
|
int b)
|
|
|
|
{
|
|
|
|
while (b-- > 0)
|
|
|
|
{
|
|
|
|
if (node == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-10 01:50:57 +00:00
|
|
|
node = get_previous_visible_sibling (node);
|
2015-02-09 15:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (a == 0)
|
|
|
|
return node == NULL;
|
|
|
|
else if (a == 1)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
b = 0;
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
b++;
|
2015-02-10 01:50:57 +00:00
|
|
|
node = get_previous_visible_sibling (node);
|
2015-02-09 15:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b % a == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_nth_last_child (GtkCssNode *node,
|
|
|
|
int a,
|
|
|
|
int b)
|
|
|
|
{
|
|
|
|
while (b-- > 0)
|
|
|
|
{
|
|
|
|
if (node == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-10 01:50:57 +00:00
|
|
|
node = get_next_visible_sibling (node);
|
2015-02-09 15:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (a == 0)
|
|
|
|
return node == NULL;
|
|
|
|
else if (a == 1)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
b = 0;
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
b++;
|
2015-02-10 01:50:57 +00:00
|
|
|
node = get_next_visible_sibling (node);
|
2015-02-09 15:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b % a == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_node_has_position (const GtkCssMatcher *matcher,
|
|
|
|
gboolean forward,
|
|
|
|
int a,
|
|
|
|
int b)
|
|
|
|
{
|
|
|
|
if (forward)
|
|
|
|
return gtk_css_matcher_node_nth_child (matcher->node.node, a, b);
|
|
|
|
else
|
|
|
|
return gtk_css_matcher_node_nth_last_child (matcher->node.node, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
|
|
|
|
gtk_css_matcher_node_get_parent,
|
|
|
|
gtk_css_matcher_node_get_previous,
|
|
|
|
gtk_css_matcher_node_get_state,
|
|
|
|
gtk_css_matcher_node_has_type,
|
|
|
|
gtk_css_matcher_node_has_class,
|
|
|
|
gtk_css_matcher_node_has_id,
|
|
|
|
gtk_css_matcher_node_has_regions,
|
|
|
|
gtk_css_matcher_node_has_region,
|
|
|
|
gtk_css_matcher_node_has_position,
|
|
|
|
FALSE
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_css_matcher_node_init (GtkCssMatcher *matcher,
|
|
|
|
GtkCssNode *node)
|
|
|
|
{
|
|
|
|
matcher->node.klass = >K_CSS_MATCHER_NODE;
|
|
|
|
matcher->node.node = node;
|
|
|
|
}
|
|
|
|
|
2012-03-18 13:42:50 +00:00
|
|
|
/* GTK_CSS_MATCHER_WIDGET_ANY */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_any_get_parent (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *child)
|
|
|
|
{
|
|
|
|
_gtk_css_matcher_any_init (matcher);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_any_get_previous (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *next)
|
|
|
|
{
|
|
|
|
_gtk_css_matcher_any_init (matcher);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkStateFlags
|
|
|
|
gtk_css_matcher_any_get_state (const GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
/* XXX: This gets tricky when we implement :not() */
|
|
|
|
|
|
|
|
return GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
|
|
|
|
| GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT
|
2013-10-08 09:27:53 +00:00
|
|
|
| GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_BACKDROP | GTK_STATE_FLAG_LINK
|
|
|
|
| GTK_STATE_FLAG_VISITED;
|
2012-03-18 13:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-10 11:57:10 +00:00
|
|
|
gtk_css_matcher_any_has_type (const GtkCssMatcher *matcher,
|
|
|
|
GType type)
|
2012-03-18 13:42:50 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_any_has_class (const GtkCssMatcher *matcher,
|
2012-03-24 00:13:50 +00:00
|
|
|
GQuark class_name)
|
2012-03-18 13:42:50 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_any_has_id (const GtkCssMatcher *matcher,
|
|
|
|
const char *id)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_any_has_regions (const GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_any_has_region (const GtkCssMatcher *matcher,
|
|
|
|
const char *region,
|
|
|
|
GtkRegionFlags flags)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_any_has_position (const GtkCssMatcher *matcher,
|
|
|
|
gboolean forward,
|
|
|
|
int a,
|
|
|
|
int b)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GtkCssMatcherClass GTK_CSS_MATCHER_ANY = {
|
|
|
|
gtk_css_matcher_any_get_parent,
|
|
|
|
gtk_css_matcher_any_get_previous,
|
|
|
|
gtk_css_matcher_any_get_state,
|
2012-12-10 11:57:10 +00:00
|
|
|
gtk_css_matcher_any_has_type,
|
2012-03-18 13:42:50 +00:00
|
|
|
gtk_css_matcher_any_has_class,
|
|
|
|
gtk_css_matcher_any_has_id,
|
|
|
|
gtk_css_matcher_any_has_regions,
|
|
|
|
gtk_css_matcher_any_has_region,
|
|
|
|
gtk_css_matcher_any_has_position,
|
2012-11-28 10:07:52 +00:00
|
|
|
TRUE
|
2012-03-18 13:42:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_css_matcher_any_init (GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
matcher->klass = >K_CSS_MATCHER_ANY;
|
|
|
|
}
|
|
|
|
|
2012-03-18 15:13:09 +00:00
|
|
|
/* GTK_CSS_MATCHER_WIDGET_SUPERSET */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_superset_get_parent (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *child)
|
|
|
|
{
|
|
|
|
_gtk_css_matcher_any_init (matcher);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_superset_get_previous (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *next)
|
|
|
|
{
|
|
|
|
_gtk_css_matcher_any_init (matcher);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkStateFlags
|
|
|
|
gtk_css_matcher_superset_get_state (const GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
/* XXX: This gets tricky when we implement :not() */
|
|
|
|
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_STATE)
|
|
|
|
return _gtk_css_matcher_get_state (matcher->superset.subset);
|
|
|
|
else
|
|
|
|
return GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
|
|
|
|
| GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT
|
2013-10-08 09:27:53 +00:00
|
|
|
| GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_BACKDROP | GTK_STATE_FLAG_LINK
|
|
|
|
| GTK_STATE_FLAG_VISITED;
|
2012-03-18 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-10 11:57:10 +00:00
|
|
|
gtk_css_matcher_superset_has_type (const GtkCssMatcher *matcher,
|
|
|
|
GType type)
|
2012-03-18 15:13:09 +00:00
|
|
|
{
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_NAME)
|
2012-12-10 11:57:10 +00:00
|
|
|
return _gtk_css_matcher_has_type (matcher->superset.subset, type);
|
2012-03-18 15:13:09 +00:00
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_superset_has_class (const GtkCssMatcher *matcher,
|
2012-03-24 00:13:50 +00:00
|
|
|
GQuark class_name)
|
2012-03-18 15:13:09 +00:00
|
|
|
{
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_CLASS)
|
|
|
|
return _gtk_css_matcher_has_class (matcher->superset.subset, class_name);
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_superset_has_id (const GtkCssMatcher *matcher,
|
|
|
|
const char *id)
|
|
|
|
{
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_NAME)
|
|
|
|
return _gtk_css_matcher_has_id (matcher->superset.subset, id);
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_superset_has_regions (const GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_NAME)
|
|
|
|
return _gtk_css_matcher_has_regions (matcher->superset.subset);
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_superset_has_region (const GtkCssMatcher *matcher,
|
|
|
|
const char *region,
|
|
|
|
GtkRegionFlags flags)
|
|
|
|
{
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_NAME)
|
|
|
|
{
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_POSITION)
|
|
|
|
return _gtk_css_matcher_has_region (matcher->superset.subset, region, flags);
|
|
|
|
else
|
|
|
|
return _gtk_css_matcher_has_region (matcher->superset.subset, region, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_matcher_superset_has_position (const GtkCssMatcher *matcher,
|
|
|
|
gboolean forward,
|
|
|
|
int a,
|
|
|
|
int b)
|
|
|
|
{
|
|
|
|
if (matcher->superset.relevant & GTK_CSS_CHANGE_POSITION)
|
|
|
|
return _gtk_css_matcher_has_position (matcher->superset.subset, forward, a, b);
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET = {
|
|
|
|
gtk_css_matcher_superset_get_parent,
|
|
|
|
gtk_css_matcher_superset_get_previous,
|
|
|
|
gtk_css_matcher_superset_get_state,
|
2012-12-10 11:57:10 +00:00
|
|
|
gtk_css_matcher_superset_has_type,
|
2012-03-18 15:13:09 +00:00
|
|
|
gtk_css_matcher_superset_has_class,
|
|
|
|
gtk_css_matcher_superset_has_id,
|
|
|
|
gtk_css_matcher_superset_has_regions,
|
|
|
|
gtk_css_matcher_superset_has_region,
|
|
|
|
gtk_css_matcher_superset_has_position,
|
2012-11-28 10:07:52 +00:00
|
|
|
FALSE
|
2012-03-18 15:13:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_css_matcher_superset_init (GtkCssMatcher *matcher,
|
|
|
|
const GtkCssMatcher *subset,
|
|
|
|
GtkCssChange relevant)
|
|
|
|
{
|
|
|
|
g_return_if_fail (subset != NULL);
|
|
|
|
g_return_if_fail ((relevant & ~(GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_STATE)) == 0);
|
|
|
|
|
|
|
|
matcher->superset.klass = >K_CSS_MATCHER_SUPERSET;
|
|
|
|
matcher->superset.subset = subset;
|
|
|
|
matcher->superset.relevant = relevant;
|
|
|
|
}
|
|
|
|
|