2010-04-11 21:03:25 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2010 Carlos Garnacho <carlosg@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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-04-11 21:03:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2011-01-26 16:17:34 +00:00
|
|
|
#include "gtkcssproviderprivate.h"
|
|
|
|
|
2011-12-23 13:23:52 +00:00
|
|
|
#include "gtkbitmaskprivate.h"
|
2012-03-26 15:24:02 +00:00
|
|
|
#include "gtkcssarrayvalueprivate.h"
|
2012-11-25 01:28:59 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2012-04-19 01:41:41 +00:00
|
|
|
#include "gtkcsskeyframesprivate.h"
|
2011-04-14 02:47:18 +00:00
|
|
|
#include "gtkcssparserprivate.h"
|
2011-05-14 11:27:31 +00:00
|
|
|
#include "gtkcssselectorprivate.h"
|
2011-12-31 12:50:03 +00:00
|
|
|
#include "gtkcssshorthandpropertyprivate.h"
|
2014-01-24 13:04:04 +00:00
|
|
|
#include "gtksettingsprivate.h"
|
2011-01-23 23:29:07 +00:00
|
|
|
#include "gtkstyleprovider.h"
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2011-05-21 01:30:36 +00:00
|
|
|
#include "gtkstylepropertyprivate.h"
|
2011-12-28 21:59:55 +00:00
|
|
|
#include "gtkstyleproviderprivate.h"
|
2011-04-07 15:26:47 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2011-01-02 11:11:34 +00:00
|
|
|
#include "gtkprivate.h"
|
2011-04-07 15:26:47 +00:00
|
|
|
#include "gtkintl.h"
|
2014-11-13 00:22:55 +00:00
|
|
|
#include "gtkversion.h"
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2019-04-10 16:40:50 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2020-01-23 02:29:47 +00:00
|
|
|
#include "gdk/gdkprofilerprivate.h"
|
2019-04-10 16:40:50 +00:00
|
|
|
#include <cairo-gobject.h>
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkcssprovider
|
|
|
|
* @Short_description: CSS-like styling for widgets
|
|
|
|
* @Title: GtkCssProvider
|
|
|
|
* @See_also: #GtkStyleContext, #GtkStyleProvider
|
|
|
|
*
|
2010-11-26 01:39:53 +00:00
|
|
|
* GtkCssProvider is an object implementing the #GtkStyleProvider interface.
|
2015-12-24 23:10:04 +00:00
|
|
|
* It is able to parse [CSS-like][css-overview] input in order to style widgets.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2015-12-24 23:10:04 +00:00
|
|
|
* An application can make GTK+ parse a specific CSS style sheet by calling
|
2016-05-23 23:24:07 +00:00
|
|
|
* gtk_css_provider_load_from_file() or gtk_css_provider_load_from_resource()
|
2015-12-24 23:10:04 +00:00
|
|
|
* and adding the provider with gtk_style_context_add_provider() or
|
2017-10-31 01:35:21 +00:00
|
|
|
* gtk_style_context_add_provider_for_display().
|
2015-12-24 23:10:04 +00:00
|
|
|
|
|
|
|
* In addition, certain files will be read when GTK+ is initialized. First, the
|
2016-10-23 18:06:33 +00:00
|
|
|
* file `$XDG_CONFIG_HOME/gtk-4.0/gtk.css` is loaded if it exists. Then, GTK+
|
2016-03-17 04:32:53 +00:00
|
|
|
* loads the first existing file among
|
2019-05-08 14:47:08 +00:00
|
|
|
* `XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk-VARIANT.css`,
|
|
|
|
* `$HOME/.themes/THEME/gtk-VERSION/gtk-VARIANT.css`,
|
|
|
|
* `$XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk-VARIANT.css` and
|
|
|
|
* `DATADIR/share/themes/THEME/gtk-VERSION/gtk-VARIANT.css`, where `THEME` is the name of
|
|
|
|
* the current theme (see the #GtkSettings:gtk-theme-name setting),
|
|
|
|
* VARIANT is the variant to load (see the #GtkSettings:gtk-application-prefer-dark-theme setting), `DATADIR`
|
2016-03-17 04:32:53 +00:00
|
|
|
* is the prefix configured when GTK+ was compiled (unless overridden by the
|
2016-05-23 23:24:07 +00:00
|
|
|
* `GTK_DATA_PREFIX` environment variable), and `VERSION` is the GTK+ version number.
|
2015-12-20 05:54:47 +00:00
|
|
|
* If no file is found for the current version, GTK+ tries older versions all the
|
2017-11-08 06:51:32 +00:00
|
|
|
* way back to 4.0.
|
2010-10-19 08:59:46 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
#define MAX_SELECTOR_LIST_LENGTH 64
|
|
|
|
|
2019-05-19 18:41:33 +00:00
|
|
|
struct _GtkCssProviderClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
|
|
|
|
void (* parsing_error) (GtkCssProvider *provider,
|
|
|
|
GtkCssSection *section,
|
|
|
|
const GError * error);
|
|
|
|
};
|
2015-12-24 23:10:04 +00:00
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
typedef struct GtkCssRuleset GtkCssRuleset;
|
2011-04-14 02:47:18 +00:00
|
|
|
typedef struct _GtkCssScanner GtkCssScanner;
|
2012-02-15 16:06:30 +00:00
|
|
|
typedef struct _PropertyValue PropertyValue;
|
2010-04-11 21:03:25 +00:00
|
|
|
typedef enum ParserScope ParserScope;
|
2010-04-20 23:46:52 +00:00
|
|
|
typedef enum ParserSymbol ParserSymbol;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2012-03-01 05:40:15 +00:00
|
|
|
struct _PropertyValue {
|
|
|
|
GtkCssStyleProperty *property;
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *value;
|
2012-03-01 05:40:15 +00:00
|
|
|
GtkCssSection *section;
|
|
|
|
};
|
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
struct GtkCssRuleset
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
GtkCssSelector *selector;
|
2012-11-29 14:29:14 +00:00
|
|
|
GtkCssSelectorTree *selector_match;
|
2012-03-01 05:40:15 +00:00
|
|
|
PropertyValue *styles;
|
|
|
|
guint n_styles;
|
|
|
|
guint owns_styles : 1;
|
2010-04-11 21:03:25 +00:00
|
|
|
};
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
struct _GtkCssScanner
|
2011-04-10 01:39:52 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssProvider *provider;
|
|
|
|
GtkCssParser *parser;
|
|
|
|
GtkCssScanner *parent;
|
2011-04-10 01:39:52 +00:00
|
|
|
};
|
|
|
|
|
2011-04-06 14:10:25 +00:00
|
|
|
struct _GtkCssProviderPrivate
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
|
|
|
GScanner *scanner;
|
2010-12-03 20:56:39 +00:00
|
|
|
|
2010-06-25 18:27:15 +00:00
|
|
|
GHashTable *symbolic_colors;
|
2012-04-19 01:41:41 +00:00
|
|
|
GHashTable *keyframes;
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
GArray *rulesets;
|
2012-11-28 10:21:06 +00:00
|
|
|
GtkCssSelectorTree *tree;
|
2012-02-03 14:50:49 +00:00
|
|
|
GResource *resource;
|
2016-03-17 04:57:45 +00:00
|
|
|
gchar *path;
|
2010-04-11 21:03:25 +00:00
|
|
|
};
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
enum {
|
|
|
|
PARSING_ERROR,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2012-03-29 11:57:22 +00:00
|
|
|
static gboolean gtk_keep_css_sections = FALSE;
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
static guint css_provider_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
static void gtk_css_provider_finalize (GObject *object);
|
2017-10-31 03:31:46 +00:00
|
|
|
static void gtk_css_style_provider_iface_init (GtkStyleProviderInterface *iface);
|
|
|
|
static void gtk_css_style_provider_emit_error (GtkStyleProvider *provider,
|
|
|
|
GtkCssSection *section,
|
|
|
|
const GError *error);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2016-10-17 15:41:03 +00:00
|
|
|
static void
|
2011-04-11 23:10:13 +00:00
|
|
|
gtk_css_provider_load_internal (GtkCssProvider *css_provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner,
|
2011-04-11 23:10:13 +00:00
|
|
|
GFile *file,
|
2019-04-09 02:47:00 +00:00
|
|
|
GBytes *bytes);
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
G_DEFINE_TYPE_EXTENDED (GtkCssProvider, gtk_css_provider, G_TYPE_OBJECT, 0,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkCssProvider)
|
2010-04-11 21:03:25 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_style_provider_iface_init));
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_parsing_error (GtkCssProvider *provider,
|
2011-06-17 05:39:11 +00:00
|
|
|
GtkCssSection *section,
|
|
|
|
const GError *error)
|
2011-04-07 15:26:47 +00:00
|
|
|
{
|
2011-04-10 23:51:49 +00:00
|
|
|
/* Only emit a warning when we have no error handlers. This is our
|
|
|
|
* default handlers. And in this case erroneous CSS files are a bug
|
|
|
|
* and should be fixed.
|
|
|
|
* Note that these warnings can also be triggered by a broken theme
|
|
|
|
* that people installed from some weird location on the internets.
|
|
|
|
*/
|
|
|
|
if (!g_signal_has_handler_pending (provider,
|
|
|
|
css_provider_signals[PARSING_ERROR],
|
|
|
|
0,
|
|
|
|
TRUE))
|
|
|
|
{
|
2019-04-10 15:23:14 +00:00
|
|
|
char *s = gtk_css_section_to_string (section);
|
2011-06-17 05:39:11 +00:00
|
|
|
|
2012-09-27 13:10:52 +00:00
|
|
|
g_warning ("Theme parsing error: %s: %s",
|
|
|
|
s,
|
2011-06-17 05:39:11 +00:00
|
|
|
error->message);
|
|
|
|
|
2012-09-27 13:10:52 +00:00
|
|
|
g_free (s);
|
2011-04-10 23:51:49 +00:00
|
|
|
}
|
2011-04-07 15:26:47 +00:00
|
|
|
}
|
|
|
|
|
2014-07-06 16:16:26 +00:00
|
|
|
/* This is exported privately for use in GtkInspector.
|
|
|
|
* It is the callers responsibility to reparse the current theme.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_css_provider_set_keep_css_sections (void)
|
|
|
|
{
|
|
|
|
gtk_keep_css_sections = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_class_init (GtkCssProviderClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2012-03-29 11:57:22 +00:00
|
|
|
if (g_getenv ("GTK_CSS_DEBUG"))
|
2014-07-06 16:16:26 +00:00
|
|
|
gtk_css_provider_set_keep_css_sections ();
|
2012-03-29 11:57:22 +00:00
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
/**
|
|
|
|
* GtkCssProvider::parsing-error:
|
|
|
|
* @provider: the provider that had a parsing error
|
2011-06-17 05:39:11 +00:00
|
|
|
* @section: section the error happened in
|
2011-04-07 15:26:47 +00:00
|
|
|
* @error: The parsing error
|
|
|
|
*
|
2016-03-11 03:46:02 +00:00
|
|
|
* Signals that a parsing error occurred. the @path, @line and @position
|
2011-04-07 15:26:47 +00:00
|
|
|
* describe the actual location of the error as accurately as possible.
|
|
|
|
*
|
|
|
|
* Parsing errors are never fatal, so the parsing will resume after
|
|
|
|
* the error. Errors may however cause parts of the given
|
|
|
|
* data or even all of it to not be parsed at all. So it is a useful idea
|
|
|
|
* to check that the parsing succeeds by connecting to this signal.
|
|
|
|
*
|
|
|
|
* Note that this signal may be emitted at any time as the css provider
|
|
|
|
* may opt to defer parsing parts or all of the input to a later time
|
|
|
|
* than when a loading function was called.
|
|
|
|
*/
|
|
|
|
css_provider_signals[PARSING_ERROR] =
|
|
|
|
g_signal_new (I_("parsing-error"),
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkCssProviderClass, parsing_error),
|
|
|
|
NULL, NULL,
|
2011-06-17 05:39:11 +00:00
|
|
|
_gtk_marshal_VOID__BOXED_BOXED,
|
|
|
|
G_TYPE_NONE, 2, GTK_TYPE_CSS_SECTION, G_TYPE_ERROR);
|
2011-04-07 15:26:47 +00:00
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
object_class->finalize = gtk_css_provider_finalize;
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
klass->parsing_error = gtk_css_provider_parsing_error;
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
static void
|
|
|
|
gtk_css_ruleset_init_copy (GtkCssRuleset *new,
|
2012-02-15 16:06:30 +00:00
|
|
|
GtkCssRuleset *ruleset,
|
2011-05-18 02:20:05 +00:00
|
|
|
GtkCssSelector *selector)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-18 02:20:05 +00:00
|
|
|
memcpy (new, ruleset, sizeof (GtkCssRuleset));
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
new->selector = selector;
|
2012-02-15 16:06:30 +00:00
|
|
|
/* First copy takes over ownership */
|
2012-03-01 05:40:15 +00:00
|
|
|
if (ruleset->owns_styles)
|
|
|
|
ruleset->owns_styles = FALSE;
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-18 02:20:05 +00:00
|
|
|
gtk_css_ruleset_clear (GtkCssRuleset *ruleset)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2012-03-01 05:40:15 +00:00
|
|
|
if (ruleset->owns_styles)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < ruleset->n_styles; i++)
|
|
|
|
{
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (ruleset->styles[i].value);
|
|
|
|
ruleset->styles[i].value = NULL;
|
2012-03-29 11:57:22 +00:00
|
|
|
if (ruleset->styles[i].section)
|
|
|
|
gtk_css_section_unref (ruleset->styles[i].section);
|
2012-03-01 05:40:15 +00:00
|
|
|
}
|
|
|
|
g_free (ruleset->styles);
|
|
|
|
}
|
2011-05-17 20:04:40 +00:00
|
|
|
if (ruleset->selector)
|
|
|
|
_gtk_css_selector_free (ruleset->selector);
|
2011-01-16 11:52:43 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
memset (ruleset, 0, sizeof (GtkCssRuleset));
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 02:30:51 +00:00
|
|
|
static void
|
2012-03-01 04:28:41 +00:00
|
|
|
gtk_css_ruleset_add (GtkCssRuleset *ruleset,
|
2012-03-01 05:40:15 +00:00
|
|
|
GtkCssStyleProperty *property,
|
2012-03-26 15:24:02 +00:00
|
|
|
GtkCssValue *value,
|
2012-03-01 05:40:15 +00:00
|
|
|
GtkCssSection *section)
|
2011-05-18 02:30:51 +00:00
|
|
|
{
|
2012-03-01 05:40:15 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_if_fail (ruleset->owns_styles || ruleset->n_styles == 0);
|
2012-03-01 04:28:41 +00:00
|
|
|
|
2012-03-01 05:40:15 +00:00
|
|
|
ruleset->owns_styles = TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < ruleset->n_styles; i++)
|
|
|
|
{
|
|
|
|
if (ruleset->styles[i].property == property)
|
|
|
|
{
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (ruleset->styles[i].value);
|
|
|
|
ruleset->styles[i].value = NULL;
|
2012-03-29 11:57:22 +00:00
|
|
|
if (ruleset->styles[i].section)
|
|
|
|
gtk_css_section_unref (ruleset->styles[i].section);
|
2012-03-01 05:40:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == ruleset->n_styles)
|
|
|
|
{
|
|
|
|
ruleset->n_styles++;
|
|
|
|
ruleset->styles = g_realloc (ruleset->styles, ruleset->n_styles * sizeof (PropertyValue));
|
2012-03-06 13:16:32 +00:00
|
|
|
ruleset->styles[i].value = NULL;
|
2012-03-01 05:40:15 +00:00
|
|
|
ruleset->styles[i].property = property;
|
|
|
|
}
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
ruleset->styles[i].value = value;
|
2012-03-29 11:57:22 +00:00
|
|
|
if (gtk_keep_css_sections)
|
|
|
|
ruleset->styles[i].section = gtk_css_section_ref (section);
|
|
|
|
else
|
|
|
|
ruleset->styles[i].section = NULL;
|
2011-05-18 02:30:51 +00:00
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
|
|
|
gtk_css_scanner_destroy (GtkCssScanner *scanner)
|
|
|
|
{
|
|
|
|
g_object_unref (scanner->provider);
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_unref (scanner->parser);
|
2011-04-14 02:47:18 +00:00
|
|
|
|
|
|
|
g_slice_free (GtkCssScanner, scanner);
|
2011-04-10 01:51:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 03:45:21 +00:00
|
|
|
static void
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_style_provider_emit_error (GtkStyleProvider *provider,
|
|
|
|
GtkCssSection *section,
|
|
|
|
const GError *error)
|
2016-01-30 03:45:21 +00:00
|
|
|
{
|
|
|
|
g_signal_emit (provider, css_provider_signals[PARSING_ERROR], 0, section, error);
|
|
|
|
}
|
|
|
|
|
2011-04-10 01:35:19 +00:00
|
|
|
static void
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_scanner_parser_error (GtkCssParser *parser,
|
|
|
|
const GtkCssLocation *start,
|
|
|
|
const GtkCssLocation *end,
|
|
|
|
const GError *error,
|
|
|
|
gpointer user_data)
|
2011-04-10 01:35:19 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner = user_data;
|
2019-04-10 14:37:52 +00:00
|
|
|
GtkCssSection *section;
|
|
|
|
|
|
|
|
section = gtk_css_section_new (gtk_css_parser_get_file (parser),
|
|
|
|
start,
|
|
|
|
end);
|
|
|
|
|
|
|
|
gtk_css_style_provider_emit_error (GTK_STYLE_PROVIDER (scanner->provider), section, error);
|
2011-04-10 23:28:00 +00:00
|
|
|
|
2019-04-10 14:37:52 +00:00
|
|
|
gtk_css_section_unref (section);
|
2011-04-10 01:35:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static GtkCssScanner *
|
|
|
|
gtk_css_scanner_new (GtkCssProvider *provider,
|
|
|
|
GtkCssScanner *parent,
|
|
|
|
GFile *file,
|
2019-04-09 02:47:00 +00:00
|
|
|
GBytes *bytes)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
scanner = g_slice_new0 (GtkCssScanner);
|
2011-04-10 01:39:52 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
g_object_ref (provider);
|
|
|
|
scanner->provider = provider;
|
|
|
|
scanner->parent = parent;
|
2011-04-12 00:06:08 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
scanner->parser = gtk_css_parser_new_for_bytes (bytes,
|
|
|
|
file,
|
|
|
|
NULL,
|
|
|
|
gtk_css_scanner_parser_error,
|
|
|
|
scanner,
|
|
|
|
NULL);
|
2011-04-11 14:48:00 +00:00
|
|
|
|
2010-10-08 16:36:46 +00:00
|
|
|
return scanner;
|
|
|
|
}
|
|
|
|
|
2011-04-12 00:50:25 +00:00
|
|
|
static gboolean
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_scanner_would_recurse (GtkCssScanner *scanner,
|
|
|
|
GFile *file)
|
2011-04-12 00:50:25 +00:00
|
|
|
{
|
|
|
|
while (scanner)
|
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
GFile *parser_file = gtk_css_parser_get_file (scanner->parser);
|
2012-04-18 20:19:30 +00:00
|
|
|
if (parser_file && g_file_equal (parser_file, file))
|
2011-04-12 00:50:25 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
scanner = scanner->parent;
|
2011-04-12 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-10-08 16:36:46 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_init (GtkCssProvider *css_provider)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
priv->rulesets = g_array_new (FALSE, FALSE, sizeof (GtkCssRuleset));
|
2010-06-25 18:27:15 +00:00
|
|
|
|
|
|
|
priv->symbolic_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
(GDestroyNotify) g_free,
|
2012-11-25 01:28:59 +00:00
|
|
|
(GDestroyNotify) _gtk_css_value_unref);
|
2012-04-19 01:41:41 +00:00
|
|
|
priv->keyframes = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
(GDestroyNotify) g_free,
|
2015-07-27 18:54:13 +00:00
|
|
|
(GDestroyNotify) _gtk_css_keyframes_unref);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 13:40:10 +00:00
|
|
|
static void
|
|
|
|
verify_tree_match_results (GtkCssProvider *provider,
|
2020-04-29 08:46:53 +00:00
|
|
|
GtkCssNode *node,
|
|
|
|
GtkArray *tree_rules)
|
2012-11-29 13:40:10 +00:00
|
|
|
{
|
|
|
|
#ifdef VERIFY_TREE
|
2019-08-21 09:19:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
|
2012-11-29 13:40:10 +00:00
|
|
|
GtkCssRuleset *ruleset;
|
2012-11-29 16:23:36 +00:00
|
|
|
gboolean should_match;
|
2012-11-29 13:40:10 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
|
|
|
{
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
|
|
|
|
|
|
|
|
for (j = 0; j < tree_rules->len; j++)
|
|
|
|
{
|
2020-04-29 08:46:53 +00:00
|
|
|
if (ruleset == gtk_array_index (tree_rules, j))
|
2012-11-29 13:40:10 +00:00
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-01-28 02:53:48 +00:00
|
|
|
should_match = gtk_css_selector_matches (ruleset->selector, node);
|
2012-11-29 16:23:36 +00:00
|
|
|
if (found != !!should_match)
|
2012-11-29 13:40:10 +00:00
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
g_error ("expected rule '%s' to %s, but it %s",
|
2012-11-29 13:40:10 +00:00
|
|
|
_gtk_css_selector_to_string (ruleset->selector),
|
2012-11-29 16:23:36 +00:00
|
|
|
should_match ? "match" : "not match",
|
2012-11-29 13:40:10 +00:00
|
|
|
found ? "matched" : "didn't match");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-25 01:28:59 +00:00
|
|
|
static GtkCssValue *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_style_provider_get_color (GtkStyleProvider *provider,
|
|
|
|
const char *name)
|
2011-12-28 21:59:55 +00:00
|
|
|
{
|
|
|
|
GtkCssProvider *css_provider = GTK_CSS_PROVIDER (provider);
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2011-12-28 21:59:55 +00:00
|
|
|
|
2018-02-13 17:31:35 +00:00
|
|
|
return g_hash_table_lookup (priv->symbolic_colors, name);
|
2011-12-28 21:59:55 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 01:58:28 +00:00
|
|
|
static GtkCssKeyframes *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_style_provider_get_keyframes (GtkStyleProvider *provider,
|
|
|
|
const char *name)
|
2012-04-19 01:58:28 +00:00
|
|
|
{
|
|
|
|
GtkCssProvider *css_provider = GTK_CSS_PROVIDER (provider);
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2012-04-19 01:58:28 +00:00
|
|
|
|
2018-02-13 17:31:35 +00:00
|
|
|
return g_hash_table_lookup (priv->keyframes, name);
|
2012-04-19 01:58:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 21:59:55 +00:00
|
|
|
static void
|
2020-01-26 03:37:17 +00:00
|
|
|
gtk_css_style_provider_lookup (GtkStyleProvider *provider,
|
|
|
|
const GtkCountingBloomFilter *filter,
|
|
|
|
GtkCssNode *node,
|
|
|
|
GtkCssLookup *lookup,
|
|
|
|
GtkCssChange *change)
|
2011-12-28 21:59:55 +00:00
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProvider *css_provider = GTK_CSS_PROVIDER (provider);
|
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2012-11-09 09:06:55 +00:00
|
|
|
GtkCssRuleset *ruleset;
|
2012-03-01 05:40:15 +00:00
|
|
|
guint j;
|
2012-11-28 10:21:06 +00:00
|
|
|
int i;
|
2020-04-29 08:46:53 +00:00
|
|
|
GtkArray tree_rules_array;
|
|
|
|
GtkCssRuleset *rules_stack[32];
|
2011-12-28 21:59:55 +00:00
|
|
|
|
2019-08-24 08:35:53 +00:00
|
|
|
if (_gtk_css_selector_tree_is_empty (priv->tree))
|
|
|
|
return;
|
|
|
|
|
2020-04-29 08:46:53 +00:00
|
|
|
gtk_array_init (&tree_rules_array, (void**)rules_stack, 32);
|
|
|
|
_gtk_css_selector_tree_match_all (priv->tree, filter, node, &tree_rules_array);
|
|
|
|
|
|
|
|
if (tree_rules_array.len > 0)
|
2012-11-28 10:21:06 +00:00
|
|
|
{
|
2020-04-29 08:46:53 +00:00
|
|
|
verify_tree_match_results (css_provider, node, &tree_rules_array);
|
2011-12-28 21:59:55 +00:00
|
|
|
|
2020-04-29 08:46:53 +00:00
|
|
|
for (i = tree_rules_array.len - 1; i >= 0; i--)
|
2011-12-29 13:15:39 +00:00
|
|
|
{
|
2020-04-29 08:46:53 +00:00
|
|
|
ruleset = gtk_array_index (&tree_rules_array, i);
|
2011-12-28 21:59:55 +00:00
|
|
|
|
2015-09-09 14:55:31 +00:00
|
|
|
if (ruleset->styles == NULL)
|
2011-12-29 13:15:39 +00:00
|
|
|
continue;
|
2011-12-28 21:59:55 +00:00
|
|
|
|
2015-09-09 14:55:31 +00:00
|
|
|
for (j = 0; j < ruleset->n_styles; j++)
|
|
|
|
{
|
|
|
|
GtkCssStyleProperty *prop = ruleset->styles[j].property;
|
|
|
|
guint id = _gtk_css_style_property_get_id (prop);
|
|
|
|
|
|
|
|
if (!_gtk_css_lookup_is_missing (lookup, id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_gtk_css_lookup_set (lookup,
|
|
|
|
id,
|
|
|
|
ruleset->styles[j].section,
|
2019-08-22 16:00:37 +00:00
|
|
|
ruleset->styles[j].value);
|
2015-09-09 14:55:31 +00:00
|
|
|
}
|
2011-12-28 21:59:55 +00:00
|
|
|
}
|
2012-11-09 09:15:23 +00:00
|
|
|
|
2020-04-29 08:46:53 +00:00
|
|
|
gtk_array_free (&tree_rules_array, NULL);
|
2011-12-28 21:59:55 +00:00
|
|
|
}
|
2012-11-28 10:21:06 +00:00
|
|
|
|
2014-12-09 18:31:17 +00:00
|
|
|
if (change)
|
2020-01-27 02:26:39 +00:00
|
|
|
*change = gtk_css_selector_tree_get_change_all (priv->tree, filter, node);
|
2012-03-17 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 21:59:55 +00:00
|
|
|
static void
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_style_provider_iface_init (GtkStyleProviderInterface *iface)
|
2011-12-28 21:59:55 +00:00
|
|
|
{
|
|
|
|
iface->get_color = gtk_css_style_provider_get_color;
|
2012-04-19 01:58:28 +00:00
|
|
|
iface->get_keyframes = gtk_css_style_provider_get_keyframes;
|
2011-12-28 21:59:55 +00:00
|
|
|
iface->lookup = gtk_css_style_provider_lookup;
|
2016-01-30 03:45:21 +00:00
|
|
|
iface->emit_error = gtk_css_style_provider_emit_error;
|
2011-12-28 21:59:55 +00:00
|
|
|
}
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_finalize (GObject *object)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProvider *css_provider = GTK_CSS_PROVIDER (object);
|
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2011-05-30 17:26:28 +00:00
|
|
|
guint i;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-30 17:26:28 +00:00
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
|
|
|
gtk_css_ruleset_clear (&g_array_index (priv->rulesets, GtkCssRuleset, i));
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
g_array_free (priv->rulesets, TRUE);
|
2012-11-28 10:21:06 +00:00
|
|
|
_gtk_css_selector_tree_free (priv->tree);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2012-04-19 01:41:41 +00:00
|
|
|
g_hash_table_destroy (priv->symbolic_colors);
|
|
|
|
g_hash_table_destroy (priv->keyframes);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2012-02-03 14:50:49 +00:00
|
|
|
if (priv->resource)
|
|
|
|
{
|
|
|
|
g_resources_unregister (priv->resource);
|
|
|
|
g_resource_unref (priv->resource);
|
|
|
|
priv->resource = NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-17 04:57:45 +00:00
|
|
|
g_free (priv->path);
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_new:
|
|
|
|
*
|
|
|
|
* Returns a newly created #GtkCssProvider.
|
|
|
|
*
|
|
|
|
* Returns: A new #GtkCssProvider
|
|
|
|
**/
|
2010-04-11 21:03:25 +00:00
|
|
|
GtkCssProvider *
|
|
|
|
gtk_css_provider_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_CSS_PROVIDER, NULL);
|
|
|
|
}
|
|
|
|
|
2016-03-17 04:57:45 +00:00
|
|
|
static void
|
2020-01-25 07:33:51 +00:00
|
|
|
css_provider_commit (GtkCssProvider *css_provider,
|
|
|
|
GtkCssSelector **selectors,
|
|
|
|
guint n_selectors,
|
|
|
|
GtkCssRuleset *ruleset)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2020-01-25 07:33:51 +00:00
|
|
|
guint i;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2019-11-23 18:01:28 +00:00
|
|
|
if (ruleset->styles == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
for (i = 0; i < n_selectors; i ++)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2020-01-25 07:33:51 +00:00
|
|
|
GtkCssRuleset *new;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
g_array_set_size (priv->rulesets, priv->rulesets->len + 1);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
new = &g_array_index (priv->rulesets, GtkCssRuleset, priv->rulesets->len - 1);
|
|
|
|
gtk_css_ruleset_init_copy (new, ruleset, selectors[i]);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_reset (GtkCssProvider *css_provider)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2011-05-18 02:20:05 +00:00
|
|
|
guint i;
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2012-02-03 15:01:51 +00:00
|
|
|
if (priv->resource)
|
|
|
|
{
|
|
|
|
g_resources_unregister (priv->resource);
|
|
|
|
g_resource_unref (priv->resource);
|
|
|
|
priv->resource = NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-17 04:57:45 +00:00
|
|
|
if (priv->path)
|
|
|
|
{
|
|
|
|
g_free (priv->path);
|
|
|
|
priv->path = NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-27 23:01:42 +00:00
|
|
|
g_hash_table_remove_all (priv->symbolic_colors);
|
2012-04-19 01:41:41 +00:00
|
|
|
g_hash_table_remove_all (priv->keyframes);
|
2011-05-27 23:01:42 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
|
|
|
gtk_css_ruleset_clear (&g_array_index (priv->rulesets, GtkCssRuleset, i));
|
|
|
|
g_array_set_size (priv->rulesets, 0);
|
2012-11-28 10:21:06 +00:00
|
|
|
_gtk_css_selector_tree_free (priv->tree);
|
|
|
|
priv->tree = NULL;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
static gboolean
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_import (GtkCssScanner *scanner)
|
|
|
|
{
|
|
|
|
GFile *file;
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2019-04-01 22:21:02 +00:00
|
|
|
if (!gtk_css_parser_try_at_keyword (scanner->parser, "import"))
|
2019-04-10 14:37:52 +00:00
|
|
|
return FALSE;
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2019-03-23 17:21:59 +00:00
|
|
|
if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_STRING))
|
2012-01-13 23:08:12 +00:00
|
|
|
{
|
2019-04-09 00:15:12 +00:00
|
|
|
char *url;
|
2012-01-13 23:08:12 +00:00
|
|
|
|
2019-04-09 00:15:12 +00:00
|
|
|
url = gtk_css_parser_consume_string (scanner->parser);
|
2019-04-09 00:29:27 +00:00
|
|
|
if (url)
|
|
|
|
{
|
|
|
|
file = gtk_css_parser_resolve_url (scanner->parser, url);
|
2019-04-09 02:47:00 +00:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_import (scanner->parser,
|
|
|
|
"Could not resolve \"%s\" to a valid URL",
|
|
|
|
url);
|
2019-04-09 02:47:00 +00:00
|
|
|
}
|
2019-04-09 00:29:27 +00:00
|
|
|
g_free (url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file = NULL;
|
2012-01-13 23:08:12 +00:00
|
|
|
}
|
2011-07-19 23:19:59 +00:00
|
|
|
else
|
2012-01-13 23:08:12 +00:00
|
|
|
{
|
2019-05-12 13:18:46 +00:00
|
|
|
char *url = gtk_css_parser_consume_url (scanner->parser);
|
|
|
|
if (url)
|
|
|
|
{
|
|
|
|
file = gtk_css_parser_resolve_url (scanner->parser, url);
|
|
|
|
g_free (url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file = NULL;
|
2012-01-13 23:08:12 +00:00
|
|
|
}
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2012-01-13 23:08:12 +00:00
|
|
|
if (file == NULL)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
/* nothing to do */
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2019-04-09 02:47:00 +00:00
|
|
|
else if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
2012-01-15 18:20:34 +00:00
|
|
|
{
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_syntax (scanner->parser, "Expected ';'");
|
2012-01-15 18:20:34 +00:00
|
|
|
}
|
|
|
|
else if (gtk_css_scanner_would_recurse (scanner, file))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
|
|
|
char *path = g_file_get_path (file);
|
2019-04-11 04:10:52 +00:00
|
|
|
gtk_css_parser_error (scanner->parser,
|
|
|
|
GTK_CSS_PARSER_ERROR_IMPORT,
|
|
|
|
gtk_css_parser_get_block_location (scanner->parser),
|
|
|
|
gtk_css_parser_get_end_location (scanner->parser),
|
|
|
|
"Loading '%s' would recurse",
|
|
|
|
path);
|
2011-04-14 02:47:18 +00:00
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_provider_load_internal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
file,
|
|
|
|
NULL);
|
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
g_clear_object (&file);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-10-08 16:19:34 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
static gboolean
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_color_definition (GtkCssScanner *scanner)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (scanner->provider);
|
2012-11-25 01:28:59 +00:00
|
|
|
GtkCssValue *color;
|
2011-04-14 02:47:18 +00:00
|
|
|
char *name;
|
2010-10-08 16:19:34 +00:00
|
|
|
|
2019-04-01 22:21:02 +00:00
|
|
|
if (!gtk_css_parser_try_at_keyword (scanner->parser, "define-color"))
|
2019-04-10 14:37:52 +00:00
|
|
|
return FALSE;
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
name = gtk_css_parser_consume_ident (scanner->parser);
|
2011-04-14 02:47:18 +00:00
|
|
|
if (name == NULL)
|
2019-04-10 14:37:52 +00:00
|
|
|
return TRUE;
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2012-11-25 01:28:59 +00:00
|
|
|
color = _gtk_css_color_value_parse (scanner->parser);
|
|
|
|
if (color == NULL)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
|
|
|
g_free (name);
|
2011-06-17 00:02:24 +00:00
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
|
|
|
g_free (name);
|
2012-11-25 01:28:59 +00:00
|
|
|
_gtk_css_value_unref (color);
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_syntax (scanner->parser,
|
|
|
|
"Missing semicolon at end of color definition");
|
2011-06-17 00:02:24 +00:00
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-11-18 06:59:27 +00:00
|
|
|
|
2018-02-13 17:31:35 +00:00
|
|
|
g_hash_table_insert (priv->symbolic_colors, name, color);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2011-04-08 14:08:28 +00:00
|
|
|
|
2012-04-19 01:41:41 +00:00
|
|
|
static gboolean
|
|
|
|
parse_keyframes (GtkCssScanner *scanner)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (scanner->provider);
|
2012-04-19 01:41:41 +00:00
|
|
|
GtkCssKeyframes *keyframes;
|
|
|
|
char *name;
|
|
|
|
|
2019-04-01 22:21:02 +00:00
|
|
|
if (!gtk_css_parser_try_at_keyword (scanner->parser, "keyframes"))
|
2019-04-10 14:37:52 +00:00
|
|
|
return FALSE;
|
2012-04-19 01:41:41 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
name = gtk_css_parser_consume_ident (scanner->parser);
|
2012-04-19 01:41:41 +00:00
|
|
|
if (name == NULL)
|
2019-04-10 14:37:52 +00:00
|
|
|
return FALSE;
|
2012-04-19 01:41:41 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
2012-04-19 01:41:41 +00:00
|
|
|
{
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_syntax (scanner->parser, "Expected '{' for keyframes");
|
2019-04-09 02:47:00 +00:00
|
|
|
return FALSE;
|
2012-04-19 01:41:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_end_block_prelude (scanner->parser);
|
2012-04-19 01:41:41 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
keyframes = _gtk_css_keyframes_parse (scanner->parser);
|
|
|
|
if (keyframes != NULL)
|
|
|
|
g_hash_table_insert (priv->keyframes, name, keyframes);
|
2012-04-19 01:41:41 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_syntax (scanner->parser, "Expected '}' after declarations");
|
2012-04-19 01:41:41 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
|
|
|
parse_at_keyword (GtkCssScanner *scanner)
|
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_start_semicolon_block (scanner->parser, GTK_CSS_TOKEN_OPEN_CURLY);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (!parse_import (scanner) &&
|
|
|
|
!parse_color_definition (scanner) &&
|
|
|
|
!parse_keyframes (scanner))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_syntax (scanner->parser, "Unknown @ rule");
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2019-04-09 02:47:00 +00:00
|
|
|
|
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
static guint
|
|
|
|
parse_selector_list (GtkCssScanner *scanner,
|
|
|
|
GtkCssSelector *out_selectors[MAX_SELECTOR_LIST_LENGTH])
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2020-01-25 07:33:51 +00:00
|
|
|
guint n_selectors = 0;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
do {
|
2012-02-15 14:42:00 +00:00
|
|
|
GtkCssSelector *select = _gtk_css_selector_parse (scanner->parser);
|
2011-04-09 23:48:55 +00:00
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
if (select == NULL)
|
2020-01-25 07:33:51 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_selectors[n_selectors] = select;
|
|
|
|
n_selectors++;
|
2011-04-09 23:48:55 +00:00
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
if (G_UNLIKELY (n_selectors > MAX_SELECTOR_LIST_LENGTH))
|
|
|
|
{
|
|
|
|
gtk_css_parser_error_syntax (scanner->parser,
|
|
|
|
"Only %u selectors per ruleset allowed",
|
|
|
|
MAX_SELECTOR_LIST_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2019-04-09 02:47:00 +00:00
|
|
|
while (gtk_css_parser_try_token (scanner->parser, GTK_CSS_TOKEN_COMMA));
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
return n_selectors;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
2011-05-18 02:20:05 +00:00
|
|
|
parse_declaration (GtkCssScanner *scanner,
|
|
|
|
GtkCssRuleset *ruleset)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-12-31 15:08:23 +00:00
|
|
|
GtkStyleProperty *property;
|
2011-05-18 16:32:22 +00:00
|
|
|
char *name;
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2019-04-10 15:07:06 +00:00
|
|
|
/* advance the location over whitespace */
|
|
|
|
gtk_css_parser_get_token (scanner->parser);
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_start_semicolon_block (scanner->parser, GTK_CSS_TOKEN_EOF);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
|
|
|
{
|
|
|
|
gtk_css_parser_warn_syntax (scanner->parser, "Empty declaration");
|
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
name = gtk_css_parser_consume_ident (scanner->parser);
|
|
|
|
if (name == NULL)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
2011-04-14 02:47:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
property = _gtk_style_property_lookup (name);
|
|
|
|
|
2011-05-19 12:04:51 +00:00
|
|
|
if (property)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2019-04-10 14:37:52 +00:00
|
|
|
GtkCssSection *section;
|
2012-03-26 15:24:02 +00:00
|
|
|
GtkCssValue *value;
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (!gtk_css_parser_try_token (scanner->parser, GTK_CSS_TOKEN_COLON))
|
|
|
|
{
|
|
|
|
gtk_css_parser_error_syntax (scanner->parser, "Expected ':'");
|
|
|
|
g_free (name);
|
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
|
|
|
return;
|
|
|
|
}
|
2011-05-18 02:30:51 +00:00
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
value = _gtk_style_property_parse_value (property,
|
2012-04-18 20:04:44 +00:00
|
|
|
scanner->parser);
|
2012-03-26 15:24:02 +00:00
|
|
|
|
|
|
|
if (value == NULL)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
2012-03-26 15:24:02 +00:00
|
|
|
return;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_syntax (scanner->parser, "Junk at end of value for %s", property->name);
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
2011-05-25 23:25:00 +00:00
|
|
|
return;
|
2010-06-18 15:04:03 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
|
2019-04-10 14:37:52 +00:00
|
|
|
if (gtk_keep_css_sections)
|
|
|
|
{
|
|
|
|
section = gtk_css_section_new (gtk_css_parser_get_file (scanner->parser),
|
|
|
|
gtk_css_parser_get_block_location (scanner->parser),
|
|
|
|
gtk_css_parser_get_end_location (scanner->parser));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
section = NULL;
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
|
|
|
|
{
|
|
|
|
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
|
|
|
|
{
|
|
|
|
GtkCssStyleProperty *child = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
|
|
|
|
GtkCssValue *sub = _gtk_css_array_value_get_nth (value, i);
|
|
|
|
|
2019-04-10 14:37:52 +00:00
|
|
|
gtk_css_ruleset_add (ruleset, child, _gtk_css_value_ref (sub), section);
|
2012-03-26 15:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_gtk_css_value_unref (value);
|
|
|
|
}
|
|
|
|
else if (GTK_IS_CSS_STYLE_PROPERTY (property))
|
|
|
|
{
|
2019-04-10 14:37:52 +00:00
|
|
|
|
|
|
|
gtk_css_ruleset_add (ruleset, GTK_CSS_STYLE_PROPERTY (property), value, section);
|
2012-03-26 15:24:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
_gtk_css_value_unref (value);
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:37:52 +00:00
|
|
|
g_clear_pointer (§ion, gtk_css_section_unref);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_error_value (scanner->parser, "No property named \"%s\"", name);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
2019-04-09 02:47:00 +00:00
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
static void
|
|
|
|
parse_declarations (GtkCssScanner *scanner,
|
|
|
|
GtkCssRuleset *ruleset)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
while (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-05-18 02:20:05 +00:00
|
|
|
parse_declaration (scanner, ruleset);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-04-07 22:08:10 +00:00
|
|
|
static void
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_ruleset (GtkCssScanner *scanner)
|
2011-04-07 22:08:10 +00:00
|
|
|
{
|
2020-01-25 07:33:51 +00:00
|
|
|
GtkCssSelector *selectors[MAX_SELECTOR_LIST_LENGTH];
|
|
|
|
guint n_selectors;
|
2011-05-18 02:20:05 +00:00
|
|
|
GtkCssRuleset ruleset = { 0, };
|
2011-04-07 22:08:10 +00:00
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
n_selectors = parse_selector_list (scanner, selectors);
|
|
|
|
if (n_selectors == 0)
|
2011-06-17 00:02:24 +00:00
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_skip_until (scanner->parser, GTK_CSS_TOKEN_OPEN_CURLY);
|
|
|
|
gtk_css_parser_skip (scanner->parser);
|
2011-06-17 00:02:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-07 22:08:10 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_OPEN_CURLY))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2020-01-25 07:33:51 +00:00
|
|
|
guint i;
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_parser_error_syntax (scanner->parser, "Expected '{' after selectors");
|
2020-01-25 07:33:51 +00:00
|
|
|
for (i = 0; i < n_selectors; i ++)
|
|
|
|
_gtk_css_selector_free (selectors[i]);
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_skip_until (scanner->parser, GTK_CSS_TOKEN_OPEN_CURLY);
|
|
|
|
gtk_css_parser_skip (scanner->parser);
|
2011-04-14 02:47:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_start_block (scanner->parser);
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
parse_declarations (scanner, &ruleset);
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_parser_end_block (scanner->parser);
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2020-01-25 07:33:51 +00:00
|
|
|
css_provider_commit (scanner->provider, selectors, n_selectors, &ruleset);
|
2011-05-18 02:20:05 +00:00
|
|
|
gtk_css_ruleset_clear (&ruleset);
|
2011-04-07 22:08:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 00:32:26 +00:00
|
|
|
static void
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_statement (GtkCssScanner *scanner)
|
2011-04-11 00:32:26 +00:00
|
|
|
{
|
2019-03-24 02:56:31 +00:00
|
|
|
if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_AT_KEYWORD))
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_at_keyword (scanner);
|
|
|
|
else
|
|
|
|
parse_ruleset (scanner);
|
2011-04-11 00:32:26 +00:00
|
|
|
}
|
2011-04-08 00:57:33 +00:00
|
|
|
|
2011-04-11 17:57:42 +00:00
|
|
|
static void
|
2011-05-14 11:27:31 +00:00
|
|
|
parse_stylesheet (GtkCssScanner *scanner)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2019-03-31 21:22:18 +00:00
|
|
|
while (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_EOF))
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_CDO) ||
|
|
|
|
gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_CDC))
|
|
|
|
{
|
|
|
|
gtk_css_parser_consume_token (scanner->parser);
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_statement (scanner);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
static int
|
|
|
|
gtk_css_provider_compare_rule (gconstpointer a_,
|
|
|
|
gconstpointer b_)
|
|
|
|
{
|
2011-05-18 02:20:05 +00:00
|
|
|
const GtkCssRuleset *a = (const GtkCssRuleset *) a_;
|
|
|
|
const GtkCssRuleset *b = (const GtkCssRuleset *) b_;
|
2011-05-14 11:27:31 +00:00
|
|
|
int compare;
|
|
|
|
|
|
|
|
compare = _gtk_css_selector_compare (a->selector, b->selector);
|
|
|
|
if (compare != 0)
|
|
|
|
return compare;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_provider_postprocess (GtkCssProvider *css_provider)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (css_provider);
|
2012-11-28 10:21:06 +00:00
|
|
|
GtkCssSelectorTreeBuilder *builder;
|
|
|
|
guint i;
|
2020-01-23 15:29:22 +00:00
|
|
|
gint64 before = g_get_monotonic_time ();
|
2011-05-14 11:27:31 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
g_array_sort (priv->rulesets, gtk_css_provider_compare_rule);
|
2012-11-28 10:21:06 +00:00
|
|
|
|
|
|
|
builder = _gtk_css_selector_tree_builder_new ();
|
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
|
|
|
{
|
|
|
|
GtkCssRuleset *ruleset;
|
|
|
|
|
|
|
|
ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
|
|
|
|
|
|
|
|
_gtk_css_selector_tree_builder_add (builder,
|
|
|
|
ruleset->selector,
|
2012-11-29 14:29:14 +00:00
|
|
|
&ruleset->selector_match,
|
2012-11-28 10:21:06 +00:00
|
|
|
ruleset);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->tree = _gtk_css_selector_tree_builder_build (builder);
|
|
|
|
_gtk_css_selector_tree_builder_free (builder);
|
2020-01-18 22:55:58 +00:00
|
|
|
|
|
|
|
#ifndef VERIFY_TREE
|
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
|
|
|
{
|
|
|
|
GtkCssRuleset *ruleset;
|
|
|
|
|
|
|
|
ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
|
|
|
|
|
|
|
|
_gtk_css_selector_free (ruleset->selector);
|
|
|
|
ruleset->selector = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2020-01-23 15:29:22 +00:00
|
|
|
|
2020-02-12 10:05:01 +00:00
|
|
|
if (GDK_PROFILER_IS_RUNNING)
|
2020-02-12 10:25:34 +00:00
|
|
|
gdk_profiler_end_mark (before, "create selector tree", NULL);
|
2011-05-14 11:27:31 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 15:41:03 +00:00
|
|
|
static void
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_provider_load_internal (GtkCssProvider *self,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *parent,
|
2011-04-11 17:55:34 +00:00
|
|
|
GFile *file,
|
2019-04-09 02:47:00 +00:00
|
|
|
GBytes *bytes)
|
2011-04-11 17:55:34 +00:00
|
|
|
{
|
2020-01-23 02:29:47 +00:00
|
|
|
gint64 before = g_get_monotonic_time ();
|
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (bytes == NULL)
|
2011-04-11 18:08:57 +00:00
|
|
|
{
|
|
|
|
GError *load_error = NULL;
|
2011-04-11 17:55:34 +00:00
|
|
|
|
2018-02-05 16:20:17 +00:00
|
|
|
bytes = g_file_load_bytes (file, NULL, NULL, &load_error);
|
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (bytes == NULL)
|
2011-04-11 18:08:57 +00:00
|
|
|
{
|
2015-11-16 18:34:24 +00:00
|
|
|
if (parent == NULL)
|
|
|
|
{
|
2019-04-10 16:01:56 +00:00
|
|
|
GtkCssLocation empty = { 0, };
|
|
|
|
GtkCssSection *section = gtk_css_section_new (file, &empty, &empty);
|
|
|
|
|
|
|
|
gtk_css_style_provider_emit_error (GTK_STYLE_PROVIDER (self), section, load_error);
|
|
|
|
gtk_css_section_unref (section);
|
2015-11-16 18:34:24 +00:00
|
|
|
}
|
|
|
|
else
|
2019-04-10 16:01:56 +00:00
|
|
|
{
|
2019-04-11 04:10:52 +00:00
|
|
|
gtk_css_parser_error (parent->parser,
|
|
|
|
GTK_CSS_PARSER_ERROR_IMPORT,
|
|
|
|
gtk_css_parser_get_block_location (parent->parser),
|
|
|
|
gtk_css_parser_get_end_location (parent->parser),
|
|
|
|
"Failed to import: %s",
|
|
|
|
load_error->message);
|
2019-04-10 16:01:56 +00:00
|
|
|
}
|
2011-04-11 18:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 17:55:34 +00:00
|
|
|
|
2019-04-09 02:47:00 +00:00
|
|
|
if (bytes)
|
2011-04-11 18:08:57 +00:00
|
|
|
{
|
2019-04-10 16:01:56 +00:00
|
|
|
GtkCssScanner *scanner;
|
|
|
|
|
|
|
|
scanner = gtk_css_scanner_new (self,
|
2011-06-17 02:52:43 +00:00
|
|
|
parent,
|
|
|
|
file,
|
2019-04-09 02:47:00 +00:00
|
|
|
bytes);
|
2011-04-11 18:08:57 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_stylesheet (scanner);
|
2011-04-11 18:08:57 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_destroy (scanner);
|
2011-05-14 11:27:31 +00:00
|
|
|
|
|
|
|
if (parent == NULL)
|
2019-04-10 16:01:56 +00:00
|
|
|
gtk_css_provider_postprocess (self);
|
2019-07-06 07:50:07 +00:00
|
|
|
|
|
|
|
g_bytes_unref (bytes);
|
2011-04-11 18:08:57 +00:00
|
|
|
}
|
2020-01-23 02:29:47 +00:00
|
|
|
|
2020-02-12 10:05:01 +00:00
|
|
|
if (GDK_PROFILER_IS_RUNNING)
|
2020-01-23 02:29:47 +00:00
|
|
|
{
|
|
|
|
char *uri = g_file_get_uri (file);
|
2020-02-12 10:25:34 +00:00
|
|
|
gdk_profiler_end_mark (before, "theme load", uri);
|
2020-01-23 02:29:47 +00:00
|
|
|
g_free (uri);
|
|
|
|
}
|
2011-04-11 17:55:34 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_load_from_data:
|
|
|
|
* @css_provider: a #GtkCssProvider
|
2011-06-01 00:37:43 +00:00
|
|
|
* @data: (array length=length) (element-type guint8): CSS data loaded in memory
|
2011-06-17 03:15:48 +00:00
|
|
|
* @length: the length of @data in bytes, or -1 for NUL terminated strings. If
|
|
|
|
* @length is not -1, the code will assume it is not NUL terminated and will
|
|
|
|
* potentially do a copy.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2016-01-13 13:29:34 +00:00
|
|
|
* Loads @data into @css_provider, and by doing so clears any previously loaded
|
2010-10-19 08:59:46 +00:00
|
|
|
* information.
|
|
|
|
**/
|
2016-10-17 15:41:03 +00:00
|
|
|
void
|
2010-11-18 01:24:18 +00:00
|
|
|
gtk_css_provider_load_from_data (GtkCssProvider *css_provider,
|
|
|
|
const gchar *data,
|
2016-10-17 14:09:12 +00:00
|
|
|
gssize length)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2019-04-09 02:47:00 +00:00
|
|
|
GBytes *bytes;
|
2011-06-17 03:15:48 +00:00
|
|
|
|
2016-10-17 15:41:03 +00:00
|
|
|
g_return_if_fail (GTK_IS_CSS_PROVIDER (css_provider));
|
|
|
|
g_return_if_fail (data != NULL);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
|
|
|
if (length < 0)
|
2019-04-09 02:47:00 +00:00
|
|
|
length = strlen (data);
|
|
|
|
|
|
|
|
bytes = g_bytes_new_static (data, length);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-07 22:08:10 +00:00
|
|
|
gtk_css_provider_reset (css_provider);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2019-07-06 07:50:07 +00:00
|
|
|
g_bytes_ref (bytes);
|
2019-04-09 02:47:00 +00:00
|
|
|
gtk_css_provider_load_internal (css_provider, NULL, NULL, bytes);
|
|
|
|
g_bytes_unref (bytes);
|
2011-06-17 03:15:48 +00:00
|
|
|
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_provider_changed (GTK_STYLE_PROVIDER (css_provider));
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_load_from_file:
|
|
|
|
* @css_provider: a #GtkCssProvider
|
|
|
|
* @file: #GFile pointing to a file to load
|
|
|
|
*
|
|
|
|
* Loads the data contained in @file into @css_provider, making it
|
|
|
|
* clear any previously loaded information.
|
|
|
|
**/
|
2016-10-17 15:41:03 +00:00
|
|
|
void
|
2010-04-11 21:03:25 +00:00
|
|
|
gtk_css_provider_load_from_file (GtkCssProvider *css_provider,
|
2016-10-17 14:09:12 +00:00
|
|
|
GFile *file)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2016-10-17 15:41:03 +00:00
|
|
|
g_return_if_fail (GTK_IS_CSS_PROVIDER (css_provider));
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-07 22:08:10 +00:00
|
|
|
gtk_css_provider_reset (css_provider);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2016-10-17 15:41:03 +00:00
|
|
|
gtk_css_provider_load_internal (css_provider, NULL, file, NULL);
|
2012-04-08 15:35:24 +00:00
|
|
|
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_provider_changed (GTK_STYLE_PROVIDER (css_provider));
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_load_from_path:
|
|
|
|
* @css_provider: a #GtkCssProvider
|
|
|
|
* @path: the path of a filename to load, in the GLib filename encoding
|
|
|
|
*
|
|
|
|
* Loads the data contained in @path into @css_provider, making it clear
|
|
|
|
* any previously loaded information.
|
|
|
|
**/
|
2016-10-17 15:41:03 +00:00
|
|
|
void
|
2010-10-08 16:36:46 +00:00
|
|
|
gtk_css_provider_load_from_path (GtkCssProvider *css_provider,
|
2016-10-17 14:09:12 +00:00
|
|
|
const gchar *path)
|
2010-10-08 16:36:46 +00:00
|
|
|
{
|
2011-04-11 23:22:16 +00:00
|
|
|
GFile *file;
|
|
|
|
|
2016-10-17 15:41:03 +00:00
|
|
|
g_return_if_fail (GTK_IS_CSS_PROVIDER (css_provider));
|
|
|
|
g_return_if_fail (path != NULL);
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2011-04-11 23:22:16 +00:00
|
|
|
file = g_file_new_for_path (path);
|
|
|
|
|
2016-10-17 15:41:03 +00:00
|
|
|
gtk_css_provider_load_from_file (css_provider, file);
|
2011-04-11 23:22:16 +00:00
|
|
|
|
|
|
|
g_object_unref (file);
|
2010-10-08 16:36:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-04 19:52:02 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_load_from_resource:
|
|
|
|
* @css_provider: a #GtkCssProvider
|
|
|
|
* @resource_path: a #GResource resource path
|
|
|
|
*
|
|
|
|
* Loads the data contained in the resource at @resource_path into
|
|
|
|
* the #GtkCssProvider, clearing any previously loaded information.
|
|
|
|
*
|
2014-10-04 20:06:30 +00:00
|
|
|
* To track errors while loading CSS, connect to the
|
|
|
|
* #GtkCssProvider::parsing-error signal.
|
2014-10-04 19:52:02 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_css_provider_load_from_resource (GtkCssProvider *css_provider,
|
|
|
|
const gchar *resource_path)
|
2012-01-12 18:14:33 +00:00
|
|
|
{
|
|
|
|
GFile *file;
|
2014-10-04 19:52:02 +00:00
|
|
|
gchar *uri, *escaped;
|
2012-01-12 18:14:33 +00:00
|
|
|
|
2012-09-19 13:18:19 +00:00
|
|
|
g_return_if_fail (GTK_IS_CSS_PROVIDER (css_provider));
|
|
|
|
g_return_if_fail (resource_path != NULL);
|
2012-01-12 18:14:33 +00:00
|
|
|
|
|
|
|
escaped = g_uri_escape_string (resource_path,
|
|
|
|
G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
|
|
|
|
uri = g_strconcat ("resource://", escaped, NULL);
|
|
|
|
g_free (escaped);
|
|
|
|
|
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
g_free (uri);
|
|
|
|
|
2016-10-17 14:09:12 +00:00
|
|
|
gtk_css_provider_load_from_file (css_provider, file);
|
2012-01-12 18:14:33 +00:00
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
|
2012-09-18 02:10:59 +00:00
|
|
|
gchar *
|
2016-03-17 04:57:45 +00:00
|
|
|
_gtk_get_theme_dir (void)
|
2012-09-18 02:10:59 +00:00
|
|
|
{
|
|
|
|
const gchar *var;
|
|
|
|
|
|
|
|
var = g_getenv ("GTK_DATA_PREFIX");
|
2016-03-17 04:57:45 +00:00
|
|
|
if (var == NULL)
|
|
|
|
var = _gtk_get_data_prefix ();
|
|
|
|
return g_build_filename (var, "share", "themes", NULL);
|
|
|
|
}
|
2012-09-18 02:10:59 +00:00
|
|
|
|
2016-03-17 04:57:45 +00:00
|
|
|
/* Return the path that this providers gtk.css was loaded from,
|
|
|
|
* if it is part of a theme, otherwise NULL.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
_gtk_css_provider_get_theme_dir (GtkCssProvider *provider)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
|
|
|
|
|
|
|
|
return priv->path;
|
2012-09-18 02:10:59 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 00:22:55 +00:00
|
|
|
#if (GTK_MINOR_VERSION % 2)
|
|
|
|
#define MINOR (GTK_MINOR_VERSION + 1)
|
|
|
|
#else
|
|
|
|
#define MINOR GTK_MINOR_VERSION
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for
|
2016-10-23 18:06:33 +00:00
|
|
|
* $dir/$subdir/gtk-4.16/gtk-$variant.css
|
|
|
|
* $dir/$subdir/gtk-4.14/gtk-$variant.css
|
2014-11-13 00:22:55 +00:00
|
|
|
* ...
|
2016-10-23 18:06:33 +00:00
|
|
|
* $dir/$subdir/gtk-4.0/gtk-$variant.css
|
2014-11-13 00:22:55 +00:00
|
|
|
* and return the first found file.
|
|
|
|
*/
|
2014-11-12 23:20:35 +00:00
|
|
|
static gchar *
|
2014-11-13 00:22:55 +00:00
|
|
|
_gtk_css_find_theme_dir (const gchar *dir,
|
|
|
|
const gchar *subdir,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *variant)
|
|
|
|
{
|
|
|
|
gchar *file;
|
|
|
|
gchar *base;
|
|
|
|
gchar *subsubdir;
|
|
|
|
gint i;
|
2014-11-12 23:20:35 +00:00
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
if (variant)
|
2014-11-13 00:22:55 +00:00
|
|
|
file = g_strconcat ("gtk-", variant, ".css", NULL);
|
2014-11-12 23:20:35 +00:00
|
|
|
else
|
2014-11-13 00:22:55 +00:00
|
|
|
file = g_strdup ("gtk.css");
|
2014-11-12 23:20:35 +00:00
|
|
|
|
2014-11-13 00:22:55 +00:00
|
|
|
if (subdir)
|
|
|
|
base = g_build_filename (dir, subdir, name, NULL);
|
|
|
|
else
|
|
|
|
base = g_build_filename (dir, name, NULL);
|
|
|
|
|
|
|
|
for (i = MINOR; i >= 0; i = i - 2)
|
2014-11-12 23:20:35 +00:00
|
|
|
{
|
2016-10-23 18:06:33 +00:00
|
|
|
subsubdir = g_strdup_printf ("gtk-4.%d", i);
|
2014-11-13 00:22:55 +00:00
|
|
|
path = g_build_filename (base, subsubdir, file, NULL);
|
|
|
|
g_free (subsubdir);
|
2014-11-12 23:20:35 +00:00
|
|
|
|
2014-11-13 00:22:55 +00:00
|
|
|
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
|
|
|
break;
|
2014-11-12 23:20:35 +00:00
|
|
|
|
2014-11-13 00:22:55 +00:00
|
|
|
g_free (path);
|
|
|
|
path = NULL;
|
2014-11-12 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 00:22:55 +00:00
|
|
|
g_free (file);
|
|
|
|
g_free (base);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef MINOR
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
_gtk_css_find_theme (const gchar *name,
|
|
|
|
const gchar *variant)
|
|
|
|
{
|
|
|
|
gchar *path;
|
2016-03-17 04:32:53 +00:00
|
|
|
const char *const *dirs;
|
|
|
|
int i;
|
2016-03-17 04:57:45 +00:00
|
|
|
char *dir;
|
2014-11-13 00:22:55 +00:00
|
|
|
|
2016-03-17 04:32:53 +00:00
|
|
|
/* First look in the user's data directory */
|
2014-11-13 00:22:55 +00:00
|
|
|
path = _gtk_css_find_theme_dir (g_get_user_data_dir (), "themes", name, variant);
|
|
|
|
if (path)
|
|
|
|
return path;
|
|
|
|
|
|
|
|
/* Next look in the user's home directory */
|
|
|
|
path = _gtk_css_find_theme_dir (g_get_home_dir (), ".themes", name, variant);
|
|
|
|
if (path)
|
|
|
|
return path;
|
|
|
|
|
2016-03-17 04:32:53 +00:00
|
|
|
/* Look in system data directories */
|
|
|
|
dirs = g_get_system_data_dirs ();
|
|
|
|
for (i = 0; dirs[i]; i++)
|
|
|
|
{
|
|
|
|
path = _gtk_css_find_theme_dir (dirs[i], "themes", name, variant);
|
|
|
|
if (path)
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2014-11-13 00:22:55 +00:00
|
|
|
/* Finally, try in the default theme directory */
|
2016-03-17 04:57:45 +00:00
|
|
|
dir = _gtk_get_theme_dir ();
|
|
|
|
path = _gtk_css_find_theme_dir (dir, NULL, name, variant);
|
|
|
|
g_free (dir);
|
2014-11-12 23:20:35 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2012-09-19 14:15:05 +00:00
|
|
|
/**
|
2019-04-18 00:05:58 +00:00
|
|
|
* gtk_css_provider_load_named:
|
2012-09-19 14:15:05 +00:00
|
|
|
* @provider: a #GtkCssProvider
|
|
|
|
* @name: A theme name
|
|
|
|
* @variant: (allow-none): variant to load, for example, "dark", or
|
|
|
|
* %NULL for the default
|
|
|
|
*
|
|
|
|
* Loads a theme from the usual theme paths. The actual process of
|
|
|
|
* finding the theme might change between releases, but it is
|
|
|
|
* guaranteed that this function uses the same mechanism to load the
|
2019-04-18 00:05:58 +00:00
|
|
|
* theme that GTK uses for loading its own theme.
|
2012-09-19 14:15:05 +00:00
|
|
|
**/
|
|
|
|
void
|
2019-04-18 00:05:58 +00:00
|
|
|
gtk_css_provider_load_named (GtkCssProvider *provider,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *variant)
|
2012-09-18 02:10:59 +00:00
|
|
|
{
|
2014-11-13 00:22:55 +00:00
|
|
|
gchar *path;
|
2012-09-19 14:07:39 +00:00
|
|
|
gchar *resource_path;
|
2012-09-18 02:10:59 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
g_return_if_fail (GTK_IS_CSS_PROVIDER (provider));
|
|
|
|
g_return_if_fail (name != NULL);
|
2012-09-18 02:10:59 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
gtk_css_provider_reset (provider);
|
2012-02-09 22:16:03 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
/* try loading the resource for the theme. This is mostly meant for built-in
|
|
|
|
* themes.
|
|
|
|
*/
|
|
|
|
if (variant)
|
2016-02-04 12:28:21 +00:00
|
|
|
resource_path = g_strdup_printf ("/org/gtk/libgtk/theme/%s/gtk-%s.css", name, variant);
|
2012-09-19 14:07:39 +00:00
|
|
|
else
|
2016-02-04 12:28:21 +00:00
|
|
|
resource_path = g_strdup_printf ("/org/gtk/libgtk/theme/%s/gtk.css", name);
|
2012-02-09 22:16:03 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
if (g_resources_get_info (resource_path, 0, NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
gtk_css_provider_load_from_resource (provider, resource_path);
|
2012-09-18 02:10:59 +00:00
|
|
|
g_free (resource_path);
|
2012-09-19 14:07:39 +00:00
|
|
|
return;
|
2012-02-09 22:16:03 +00:00
|
|
|
}
|
2012-09-19 14:07:39 +00:00
|
|
|
g_free (resource_path);
|
2012-02-09 22:16:03 +00:00
|
|
|
|
2014-11-12 23:20:35 +00:00
|
|
|
/* Next try looking for files in the various theme directories. */
|
|
|
|
path = _gtk_css_find_theme (name, variant);
|
2012-09-19 14:07:39 +00:00
|
|
|
if (path)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
|
2012-09-19 14:07:39 +00:00
|
|
|
char *dir, *resource_file;
|
|
|
|
GResource *resource;
|
2012-09-18 02:10:59 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
dir = g_path_get_dirname (path);
|
|
|
|
resource_file = g_build_filename (dir, "gtk.gresource", NULL);
|
|
|
|
resource = g_resource_load (resource_file, NULL);
|
|
|
|
g_free (resource_file);
|
2012-03-04 16:51:07 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
if (resource != NULL)
|
|
|
|
g_resources_register (resource);
|
2012-02-03 14:50:49 +00:00
|
|
|
|
2016-10-17 14:09:12 +00:00
|
|
|
gtk_css_provider_load_from_path (provider, path);
|
2012-09-19 13:32:38 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
/* Only set this after load, as load_from_path will clear it */
|
2018-02-13 17:31:35 +00:00
|
|
|
priv->resource = resource;
|
|
|
|
priv->path = dir;
|
2011-02-05 02:13:56 +00:00
|
|
|
|
2012-09-19 14:07:39 +00:00
|
|
|
g_free (path);
|
2010-08-20 09:50:39 +00:00
|
|
|
}
|
2012-09-19 14:30:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Things failed! Fall back! Fall back! */
|
|
|
|
|
|
|
|
if (variant)
|
|
|
|
{
|
|
|
|
/* If there was a variant, try without */
|
2019-04-18 00:05:58 +00:00
|
|
|
gtk_css_provider_load_named (provider, name, NULL);
|
2012-09-19 14:30:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-24 13:04:04 +00:00
|
|
|
/* Worst case, fall back to the default */
|
|
|
|
g_return_if_fail (!g_str_equal (name, DEFAULT_THEME_NAME)); /* infloop protection */
|
2019-04-18 00:05:58 +00:00
|
|
|
gtk_css_provider_load_named (provider, DEFAULT_THEME_NAME, NULL);
|
2012-09-19 14:30:27 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-19 14:07:39 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
static int
|
2012-03-01 05:40:15 +00:00
|
|
|
compare_properties (gconstpointer a, gconstpointer b, gpointer style)
|
2011-05-18 02:36:43 +00:00
|
|
|
{
|
2012-03-01 05:40:15 +00:00
|
|
|
const guint *ua = a;
|
|
|
|
const guint *ub = b;
|
|
|
|
PropertyValue *styles = style;
|
|
|
|
|
|
|
|
return strcmp (_gtk_style_property_get_name (GTK_STYLE_PROPERTY (styles[*ua].property)),
|
|
|
|
_gtk_style_property_get_name (GTK_STYLE_PROPERTY (styles[*ub].property)));
|
2012-02-15 16:06:30 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 20:03:35 +00:00
|
|
|
static void
|
2011-05-17 20:04:40 +00:00
|
|
|
gtk_css_ruleset_print (const GtkCssRuleset *ruleset,
|
|
|
|
GString *str)
|
2011-04-06 20:03:35 +00:00
|
|
|
{
|
2012-03-01 05:40:15 +00:00
|
|
|
guint i;
|
2011-04-06 20:03:35 +00:00
|
|
|
|
2012-11-29 15:00:01 +00:00
|
|
|
_gtk_css_selector_tree_match_print (ruleset->selector_match, str);
|
2011-04-06 20:03:35 +00:00
|
|
|
|
|
|
|
g_string_append (str, " {\n");
|
|
|
|
|
2012-03-01 05:40:15 +00:00
|
|
|
if (ruleset->styles)
|
2011-04-06 20:03:35 +00:00
|
|
|
{
|
2012-03-01 05:40:15 +00:00
|
|
|
guint *sorted = g_new (guint, ruleset->n_styles);
|
|
|
|
|
|
|
|
for (i = 0; i < ruleset->n_styles; i++)
|
|
|
|
sorted[i] = i;
|
2012-02-15 16:06:30 +00:00
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
/* so the output is identical for identical selector styles */
|
2012-03-01 05:40:15 +00:00
|
|
|
g_qsort_with_data (sorted, ruleset->n_styles, sizeof (guint), compare_properties, ruleset->styles);
|
2011-04-06 20:03:35 +00:00
|
|
|
|
2012-03-01 05:40:15 +00:00
|
|
|
for (i = 0; i < ruleset->n_styles; i++)
|
2011-05-18 02:36:43 +00:00
|
|
|
{
|
2012-03-01 05:40:15 +00:00
|
|
|
PropertyValue *prop = &ruleset->styles[sorted[i]];
|
2011-05-18 02:36:43 +00:00
|
|
|
g_string_append (str, " ");
|
2012-03-01 05:40:15 +00:00
|
|
|
g_string_append (str, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop->property)));
|
2011-05-18 02:36:43 +00:00
|
|
|
g_string_append (str, ": ");
|
2012-07-16 12:28:58 +00:00
|
|
|
_gtk_css_value_print (prop->value, str);
|
2011-05-18 02:36:43 +00:00
|
|
|
g_string_append (str, ";\n");
|
|
|
|
}
|
|
|
|
|
2012-03-01 05:40:15 +00:00
|
|
|
g_free (sorted);
|
2011-04-06 20:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append (str, "}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_provider_print_colors (GHashTable *colors,
|
|
|
|
GString *str)
|
|
|
|
{
|
|
|
|
GList *keys, *walk;
|
|
|
|
|
|
|
|
keys = g_hash_table_get_keys (colors);
|
|
|
|
/* so the output is identical for identical styles */
|
|
|
|
keys = g_list_sort (keys, (GCompareFunc) strcmp);
|
|
|
|
|
|
|
|
for (walk = keys; walk; walk = walk->next)
|
|
|
|
{
|
|
|
|
const char *name = walk->data;
|
2012-11-25 01:28:59 +00:00
|
|
|
GtkCssValue *color = g_hash_table_lookup (colors, (gpointer) name);
|
2011-04-06 20:03:35 +00:00
|
|
|
|
|
|
|
g_string_append (str, "@define-color ");
|
|
|
|
g_string_append (str, name);
|
|
|
|
g_string_append (str, " ");
|
2012-11-25 01:28:59 +00:00
|
|
|
_gtk_css_value_print (color, str);
|
2011-04-06 20:03:35 +00:00
|
|
|
g_string_append (str, ";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (keys);
|
|
|
|
}
|
|
|
|
|
2012-04-19 01:41:41 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_print_keyframes (GHashTable *keyframes,
|
|
|
|
GString *str)
|
|
|
|
{
|
|
|
|
GList *keys, *walk;
|
|
|
|
|
|
|
|
keys = g_hash_table_get_keys (keyframes);
|
|
|
|
/* so the output is identical for identical styles */
|
|
|
|
keys = g_list_sort (keys, (GCompareFunc) strcmp);
|
|
|
|
|
|
|
|
for (walk = keys; walk; walk = walk->next)
|
|
|
|
{
|
|
|
|
const char *name = walk->data;
|
|
|
|
GtkCssKeyframes *keyframe = g_hash_table_lookup (keyframes, (gpointer) name);
|
|
|
|
|
|
|
|
if (str->len > 0)
|
|
|
|
g_string_append (str, "\n");
|
|
|
|
g_string_append (str, "@keyframes ");
|
|
|
|
g_string_append (str, name);
|
|
|
|
g_string_append (str, " {\n");
|
|
|
|
_gtk_css_keyframes_print (keyframe, str);
|
|
|
|
g_string_append (str, "}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (keys);
|
|
|
|
}
|
|
|
|
|
2011-04-06 20:03:35 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_to_string:
|
|
|
|
* @provider: the provider to write to a string
|
|
|
|
*
|
2014-03-02 08:47:31 +00:00
|
|
|
* Converts the @provider into a string representation in CSS
|
2011-04-06 20:03:35 +00:00
|
|
|
* format.
|
2014-03-02 08:47:31 +00:00
|
|
|
*
|
2011-04-06 20:03:35 +00:00
|
|
|
* Using gtk_css_provider_load_from_data() with the return value
|
|
|
|
* from this function on a new provider created with
|
2014-03-02 11:09:48 +00:00
|
|
|
* gtk_css_provider_new() will basically create a duplicate of
|
2011-04-06 20:03:35 +00:00
|
|
|
* this @provider.
|
|
|
|
*
|
|
|
|
* Returns: a new string representing the @provider.
|
|
|
|
**/
|
|
|
|
char *
|
|
|
|
gtk_css_provider_to_string (GtkCssProvider *provider)
|
|
|
|
{
|
2018-02-13 17:31:35 +00:00
|
|
|
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
|
2011-04-06 20:03:35 +00:00
|
|
|
GString *str;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_PROVIDER (provider), NULL);
|
|
|
|
|
|
|
|
str = g_string_new ("");
|
|
|
|
|
|
|
|
gtk_css_provider_print_colors (priv->symbolic_colors, str);
|
2012-04-19 01:41:41 +00:00
|
|
|
gtk_css_provider_print_keyframes (priv->keyframes, str);
|
2011-04-06 20:03:35 +00:00
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
2011-04-06 20:03:35 +00:00
|
|
|
{
|
2012-04-05 20:28:21 +00:00
|
|
|
if (str->len != 0)
|
2011-04-06 20:03:35 +00:00
|
|
|
g_string_append (str, "\n");
|
2011-05-18 02:20:05 +00:00
|
|
|
gtk_css_ruleset_print (&g_array_index (priv->rulesets, GtkCssRuleset, i), str);
|
2011-04-06 20:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
}
|
|
|
|
|