style provider: Add a has_section api

Add gtk_style_provider_has_section and implement it for
GtkCssProvider. This will be used later to direct error
emissions to the right provider.
This commit is contained in:
Matthias Clasen 2024-05-09 21:28:05 -04:00 committed by Alice Mikhaylenko
parent f2ef5d85ea
commit b2fb624496
3 changed files with 32 additions and 1 deletions

View File

@ -137,6 +137,7 @@ struct _GtkCssProviderPrivate
GtkCssSelectorTree *tree;
GResource *resource;
char *path;
GBytes *bytes; /* *no* reference */
};
enum {
@ -565,6 +566,16 @@ gtk_css_style_provider_lookup (GtkStyleProvider *provider,
*change = gtk_css_selector_tree_get_change_all (priv->tree, filter, node);
}
static gboolean
gtk_css_style_provider_has_section (GtkStyleProvider *provider,
GtkCssSection *section)
{
GtkCssProvider *self = GTK_CSS_PROVIDER (provider);
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (self);
return priv->bytes == gtk_css_section_get_bytes (section);
}
static void
gtk_css_style_provider_iface_init (GtkStyleProviderInterface *iface)
{
@ -572,6 +583,7 @@ gtk_css_style_provider_iface_init (GtkStyleProviderInterface *iface)
iface->get_keyframes = gtk_css_style_provider_get_keyframes;
iface->lookup = gtk_css_style_provider_lookup;
iface->emit_error = gtk_css_style_provider_emit_error;
iface->has_section = gtk_css_style_provider_has_section;
}
static void
@ -1157,6 +1169,7 @@ gtk_css_provider_load_internal (GtkCssProvider *self,
GFile *file,
GBytes *bytes)
{
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (self);
gint64 before G_GNUC_UNUSED;
before = GDK_PROFILER_CURRENT_TIME;
@ -1191,6 +1204,8 @@ gtk_css_provider_load_internal (GtkCssProvider *self,
}
}
priv->bytes = bytes;
if (bytes)
{
GtkCssScanner *scanner;

View File

@ -170,6 +170,19 @@ gtk_style_provider_emit_error (GtkStyleProvider *provider,
iface->emit_error (provider, section, error);
}
gboolean
gtk_style_provider_has_section (GtkStyleProvider *provider,
GtkCssSection *section)
{
GtkStyleProviderInterface *iface;
iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
if (iface->has_section)
return iface->has_section (provider, section);
return FALSE;
}
/* These apis are misnamed, and the rest of GtkStyleContext is deprecated,
* so put them here for now
@ -230,4 +243,3 @@ gtk_style_context_remove_provider_for_display (GdkDisplay *display,
cascade = _gtk_settings_get_style_cascade (gtk_settings_get_for_display (display), 1);
_gtk_style_cascade_remove_provider (cascade, provider);
}

View File

@ -52,6 +52,8 @@ struct _GtkStyleProviderInterface
const GError *error);
/* signal */
void (* changed) (GtkStyleProvider *provider);
gboolean (* has_section) (GtkStyleProvider *provider,
GtkCssSection *section);
};
GtkSettings * gtk_style_provider_get_settings (GtkStyleProvider *provider);
@ -71,6 +73,8 @@ void gtk_style_provider_changed (GtkStyleProvid
void gtk_style_provider_emit_error (GtkStyleProvider *provider,
GtkCssSection *section,
GError *error);
gboolean gtk_style_provider_has_section (GtkStyleProvider *provider,
GtkCssSection *section);
G_END_DECLS