2012-03-06 13:16:08 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2012-12-03 12:26:16 +00:00
|
|
|
#include "gtkprivate.h"
|
2012-03-06 13:16:08 +00:00
|
|
|
#include "gtkcssvalueprivate.h"
|
|
|
|
|
2014-10-22 21:41:50 +00:00
|
|
|
#include "gtkcssstyleprivate.h"
|
2012-09-28 16:02:46 +00:00
|
|
|
#include "gtkstyleproviderprivate.h"
|
|
|
|
|
2012-04-07 05:40:36 +00:00
|
|
|
struct _GtkCssValue {
|
2012-03-26 04:13:57 +00:00
|
|
|
GTK_CSS_VALUE_BASE
|
|
|
|
};
|
|
|
|
|
2012-03-06 13:16:08 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GtkCssValue, _gtk_css_value, _gtk_css_value_ref, _gtk_css_value_unref)
|
|
|
|
|
2020-01-18 17:10:26 +00:00
|
|
|
#undef CSS_VALUE_ACCOUNTING
|
|
|
|
|
|
|
|
#ifdef CSS_VALUE_ACCOUNTING
|
2020-01-10 04:48:30 +00:00
|
|
|
static GHashTable *counters;
|
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
guint all;
|
|
|
|
guint alive;
|
|
|
|
guint computed;
|
|
|
|
guint transitioned;
|
|
|
|
} ValueAccounting;
|
|
|
|
|
2020-01-10 04:48:30 +00:00
|
|
|
static void
|
|
|
|
dump_value_counts (void)
|
|
|
|
{
|
2020-01-13 09:19:56 +00:00
|
|
|
int col_widths[5] = { 0, strlen ("all"), strlen ("alive"), strlen ("computed"), strlen("transitioned") };
|
2020-01-10 04:48:30 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key;
|
|
|
|
gpointer value;
|
2020-01-13 09:19:56 +00:00
|
|
|
int sum_all = 0, sum_alive = 0, sum_computed = 0, sum_transitioned = 0;
|
2020-01-10 04:48:30 +00:00
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, counters);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
const char *class = key;
|
2020-01-13 09:19:56 +00:00
|
|
|
const ValueAccounting *c = value;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
sum_all += c->all;
|
|
|
|
sum_alive += c->alive;
|
|
|
|
sum_computed += c->computed;
|
|
|
|
sum_transitioned += c->transitioned;
|
|
|
|
|
|
|
|
col_widths[0] = MAX (col_widths[0], strlen (class));
|
|
|
|
|
|
|
|
str = g_strdup_printf ("%'d", sum_all);
|
|
|
|
col_widths[1] = MAX (col_widths[1], strlen (str));
|
|
|
|
g_free (str);
|
2020-01-10 04:48:30 +00:00
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
str = g_strdup_printf ("%'d", sum_alive);
|
|
|
|
col_widths[2] = MAX (col_widths[2], strlen (str));
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
str = g_strdup_printf ("%'d", sum_computed);
|
|
|
|
col_widths[3] = MAX (col_widths[3], strlen (str));
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
str = g_strdup_printf ("%'d", sum_transitioned);
|
|
|
|
col_widths[4] = MAX (col_widths[4], strlen (str));
|
|
|
|
g_free (str);
|
2020-01-10 04:48:30 +00:00
|
|
|
}
|
2020-01-13 09:19:56 +00:00
|
|
|
/* Some spacing */
|
|
|
|
col_widths[0] += 4;
|
|
|
|
col_widths[1] += 4;
|
|
|
|
col_widths[2] += 4;
|
|
|
|
col_widths[3] += 4;
|
|
|
|
col_widths[4] += 4;
|
|
|
|
|
|
|
|
g_print("%*s%*s%*s%*s%*s\n", col_widths[0] + 1, " ",
|
|
|
|
col_widths[1] + 1, "All",
|
|
|
|
col_widths[2] + 1, "Alive",
|
|
|
|
col_widths[3] + 1, "Computed",
|
|
|
|
col_widths[4] + 1, "Transitioned");
|
2020-01-10 04:48:30 +00:00
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
g_hash_table_iter_init (&iter, counters);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
const char *class = key;
|
|
|
|
const ValueAccounting *c = value;
|
|
|
|
|
|
|
|
g_print ("%*s:", col_widths[0], class);
|
|
|
|
g_print (" %'*d", col_widths[1], c->all);
|
|
|
|
g_print (" %'*d", col_widths[2], c->alive);
|
|
|
|
g_print (" %'*d", col_widths[3], c->computed);
|
|
|
|
g_print (" %'*d", col_widths[4], c->transitioned);
|
|
|
|
g_print("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_print("%*s%'*d%'*d%'*d%'*d\n", col_widths[0] + 1, " ",
|
|
|
|
col_widths[1] + 1, sum_all,
|
|
|
|
col_widths[2] + 1, sum_alive,
|
|
|
|
col_widths[3] + 1, sum_computed,
|
|
|
|
col_widths[4] + 1, sum_transitioned);
|
2020-01-10 04:48:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
static ValueAccounting *
|
|
|
|
get_accounting_data (const char *class)
|
2020-01-10 04:48:30 +00:00
|
|
|
{
|
2020-01-13 09:19:56 +00:00
|
|
|
ValueAccounting *c;
|
2020-01-10 04:48:30 +00:00
|
|
|
|
|
|
|
if (!counters)
|
|
|
|
{
|
|
|
|
counters = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
atexit (dump_value_counts);
|
|
|
|
}
|
|
|
|
c = g_hash_table_lookup (counters, class);
|
|
|
|
if (!c)
|
|
|
|
{
|
2020-01-13 09:19:56 +00:00
|
|
|
c = g_malloc0 (sizeof (ValueAccounting));
|
2020-01-10 04:48:30 +00:00
|
|
|
g_hash_table_insert (counters, (gpointer)class, c);
|
|
|
|
}
|
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
return c;
|
2020-01-10 04:48:30 +00:00
|
|
|
}
|
2020-01-18 17:10:26 +00:00
|
|
|
#endif
|
2020-01-10 04:48:30 +00:00
|
|
|
|
2012-03-26 04:13:57 +00:00
|
|
|
GtkCssValue *
|
|
|
|
_gtk_css_value_alloc (const GtkCssValueClass *klass,
|
|
|
|
gsize size)
|
|
|
|
{
|
|
|
|
GtkCssValue *value;
|
|
|
|
|
|
|
|
value = g_slice_alloc0 (size);
|
|
|
|
|
|
|
|
value->class = klass;
|
|
|
|
value->ref_count = 1;
|
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
#ifdef CSS_VALUE_ACCOUNTING
|
2020-01-18 17:10:26 +00:00
|
|
|
{
|
|
|
|
ValueAccounting *c;
|
|
|
|
|
|
|
|
c = get_accounting_data (klass->type_name);
|
|
|
|
c->all++;
|
|
|
|
c->alive++;
|
|
|
|
}
|
2020-01-13 09:19:56 +00:00
|
|
|
#endif
|
2020-01-10 04:48:30 +00:00
|
|
|
|
2012-03-26 04:13:57 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:08 +00:00
|
|
|
GtkCssValue *
|
2018-02-13 04:55:33 +00:00
|
|
|
gtk_css_value_ref (GtkCssValue *value)
|
2012-03-06 13:16:08 +00:00
|
|
|
{
|
2012-12-03 12:26:16 +00:00
|
|
|
gtk_internal_return_val_if_fail (value != NULL, NULL);
|
2012-03-06 13:16:08 +00:00
|
|
|
|
2015-09-11 23:04:54 +00:00
|
|
|
value->ref_count += 1;
|
2012-03-06 13:16:08 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-02-13 04:55:33 +00:00
|
|
|
gtk_css_value_unref (GtkCssValue *value)
|
2012-03-06 13:16:08 +00:00
|
|
|
{
|
|
|
|
if (value == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-09-11 23:04:54 +00:00
|
|
|
value->ref_count -= 1;
|
|
|
|
if (value->ref_count > 0)
|
2012-03-06 13:16:08 +00:00
|
|
|
return;
|
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
#ifdef CSS_VALUE_ACCOUNTING
|
2020-01-18 17:10:26 +00:00
|
|
|
{
|
|
|
|
ValueAccounting *c;
|
|
|
|
|
|
|
|
c = get_accounting_data (value->class->type_name);
|
|
|
|
c->alive--;
|
|
|
|
}
|
2020-01-13 09:19:56 +00:00
|
|
|
#endif
|
2020-01-10 04:48:30 +00:00
|
|
|
|
2012-03-26 04:13:57 +00:00
|
|
|
value->class->free (value);
|
2012-03-06 13:16:08 +00:00
|
|
|
}
|
|
|
|
|
2012-07-16 12:28:58 +00:00
|
|
|
/**
|
|
|
|
* _gtk_css_value_compute:
|
|
|
|
* @value: the value to compute from
|
|
|
|
* @property_id: the ID of the property to compute
|
2012-09-28 16:02:46 +00:00
|
|
|
* @provider: Style provider for looking up extra information
|
2015-12-29 03:36:29 +00:00
|
|
|
* @style: Style to compute for
|
|
|
|
* @parent_style: parent style to use for inherited values
|
2012-07-16 12:28:58 +00:00
|
|
|
*
|
|
|
|
* Converts the specified @value into the computed value for the CSS
|
|
|
|
* property given by @property_id using the information in @context.
|
2014-02-04 23:53:51 +00:00
|
|
|
* This step is explained in detail in the
|
|
|
|
* [CSS Documentation](http://www.w3.org/TR/css3-cascade/#computed).
|
2012-07-16 12:28:58 +00:00
|
|
|
*
|
2012-07-16 12:48:43 +00:00
|
|
|
* Returns: the computed value
|
2012-07-16 12:28:58 +00:00
|
|
|
**/
|
2012-07-11 04:56:07 +00:00
|
|
|
GtkCssValue *
|
2017-10-31 03:31:46 +00:00
|
|
|
_gtk_css_value_compute (GtkCssValue *value,
|
|
|
|
guint property_id,
|
|
|
|
GtkStyleProvider *provider,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkCssStyle *parent_style)
|
2012-07-11 04:56:07 +00:00
|
|
|
{
|
2020-01-11 11:56:40 +00:00
|
|
|
if (gtk_css_value_is_computed (value))
|
|
|
|
return _gtk_css_value_ref (value);
|
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
#ifdef CSS_VALUE_ACCOUNTING
|
|
|
|
get_accounting_data (value->class->type_name)->computed++;
|
|
|
|
#endif
|
|
|
|
|
2015-02-14 01:27:39 +00:00
|
|
|
return value->class->compute (value, property_id, provider, style, parent_style);
|
2012-07-11 04:56:07 +00:00
|
|
|
}
|
|
|
|
|
cssvalue: Add _gtk_css_value_equal()
For now, we return FALSE for all default css values, so this is not very
useful.
I also think of this as an optimization equal, not a guaranteed equal,
because we don't even have a notion of what "equal" means.
For example, for background-repeat, "repeat, repeat" and "repeat"
are functionally equivalent. But the cssvalue has no idea that it's used
for background-repeat.
As a more complicated example, "repeat, no-repeat" and "repeat" are
equal to what one sees as long as there's only one image listed
background-image-source. But once you start transition'ing to an image
with 2 sources, it's different...
2012-03-26 23:43:12 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_css_value_equal (const GtkCssValue *value1,
|
|
|
|
const GtkCssValue *value2)
|
|
|
|
{
|
2012-12-03 12:26:16 +00:00
|
|
|
gtk_internal_return_val_if_fail (value1 != NULL, FALSE);
|
|
|
|
gtk_internal_return_val_if_fail (value2 != NULL, FALSE);
|
cssvalue: Add _gtk_css_value_equal()
For now, we return FALSE for all default css values, so this is not very
useful.
I also think of this as an optimization equal, not a guaranteed equal,
because we don't even have a notion of what "equal" means.
For example, for background-repeat, "repeat, repeat" and "repeat"
are functionally equivalent. But the cssvalue has no idea that it's used
for background-repeat.
As a more complicated example, "repeat, no-repeat" and "repeat" are
equal to what one sees as long as there's only one image listed
background-image-source. But once you start transition'ing to an image
with 2 sources, it's different...
2012-03-26 23:43:12 +00:00
|
|
|
|
2012-09-16 16:42:25 +00:00
|
|
|
if (value1 == value2)
|
|
|
|
return TRUE;
|
|
|
|
|
cssvalue: Add _gtk_css_value_equal()
For now, we return FALSE for all default css values, so this is not very
useful.
I also think of this as an optimization equal, not a guaranteed equal,
because we don't even have a notion of what "equal" means.
For example, for background-repeat, "repeat, repeat" and "repeat"
are functionally equivalent. But the cssvalue has no idea that it's used
for background-repeat.
As a more complicated example, "repeat, no-repeat" and "repeat" are
equal to what one sees as long as there's only one image listed
background-image-source. But once you start transition'ing to an image
with 2 sources, it's different...
2012-03-26 23:43:12 +00:00
|
|
|
if (value1->class != value2->class)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return value1->class->equal (value1, value2);
|
|
|
|
}
|
|
|
|
|
2012-04-04 14:15:41 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_css_value_equal0 (const GtkCssValue *value1,
|
|
|
|
const GtkCssValue *value2)
|
|
|
|
{
|
2012-09-16 16:42:25 +00:00
|
|
|
/* Inclues both values being NULL */
|
|
|
|
if (value1 == value2)
|
2012-04-04 14:15:41 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (value1 == NULL || value2 == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return _gtk_css_value_equal (value1, value2);
|
|
|
|
}
|
|
|
|
|
2012-03-30 15:47:26 +00:00
|
|
|
GtkCssValue *
|
|
|
|
_gtk_css_value_transition (GtkCssValue *start,
|
|
|
|
GtkCssValue *end,
|
2012-08-30 13:51:29 +00:00
|
|
|
guint property_id,
|
2012-03-30 15:47:26 +00:00
|
|
|
double progress)
|
|
|
|
{
|
2012-12-03 12:26:16 +00:00
|
|
|
gtk_internal_return_val_if_fail (start != NULL, FALSE);
|
|
|
|
gtk_internal_return_val_if_fail (end != NULL, FALSE);
|
2012-03-30 15:47:26 +00:00
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
if (progress == 0)
|
|
|
|
return _gtk_css_value_ref (start);
|
|
|
|
|
|
|
|
if (progress == 1)
|
|
|
|
return _gtk_css_value_ref (end);
|
|
|
|
|
2020-01-14 14:37:30 +00:00
|
|
|
if (start == end)
|
|
|
|
return _gtk_css_value_ref (start);
|
|
|
|
|
2020-01-13 09:19:56 +00:00
|
|
|
#ifdef CSS_VALUE_ACCOUNTING
|
|
|
|
get_accounting_data (start->class->type_name)->transitioned++;
|
|
|
|
#endif
|
|
|
|
|
2012-08-30 13:51:29 +00:00
|
|
|
return start->class->transition (start, end, property_id, progress);
|
2012-03-30 15:47:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 05:28:35 +00:00
|
|
|
char *
|
|
|
|
_gtk_css_value_to_string (const GtkCssValue *value)
|
|
|
|
{
|
|
|
|
GString *string;
|
|
|
|
|
2012-12-03 12:26:16 +00:00
|
|
|
gtk_internal_return_val_if_fail (value != NULL, NULL);
|
2012-04-01 05:28:35 +00:00
|
|
|
|
|
|
|
string = g_string_new (NULL);
|
|
|
|
_gtk_css_value_print (value, string);
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
2012-07-16 12:28:58 +00:00
|
|
|
/**
|
|
|
|
* _gtk_css_value_print:
|
|
|
|
* @value: the value to print
|
|
|
|
* @string: the string to print to
|
|
|
|
*
|
|
|
|
* Prints @value to the given @string in CSS format. The @value must be a
|
|
|
|
* valid specified value as parsed using the parse functions or as assigned
|
|
|
|
* via _gtk_style_property_assign().
|
|
|
|
**/
|
2012-03-26 04:46:29 +00:00
|
|
|
void
|
|
|
|
_gtk_css_value_print (const GtkCssValue *value,
|
|
|
|
GString *string)
|
|
|
|
{
|
2012-12-03 12:26:16 +00:00
|
|
|
gtk_internal_return_if_fail (value != NULL);
|
|
|
|
gtk_internal_return_if_fail (string != NULL);
|
2012-03-26 04:46:29 +00:00
|
|
|
|
|
|
|
value->class->print (value, string);
|
|
|
|
}
|
|
|
|
|
2018-02-13 04:55:33 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_value_is_dynamic:
|
|
|
|
* @value: a #GtkCssValue
|
|
|
|
*
|
|
|
|
* A "dynamic" value has a different value at different times. This means that
|
|
|
|
* the value needs to be animated when time is progressing.
|
|
|
|
*
|
|
|
|
* Examples of dynamic values are animated images, such as videos or dynamic shaders.
|
|
|
|
*
|
|
|
|
* Use gtk_css_value_get_dynamic_value() to get the value for a given timestamp.
|
|
|
|
*
|
|
|
|
* Returns %TRUE if the value is dynamic
|
|
|
|
*/
|
|
|
|
gboolean
|
2020-01-24 12:17:09 +00:00
|
|
|
gtk_css_value_is_dynamic (const GtkCssValue *value)
|
2018-02-13 04:55:33 +00:00
|
|
|
{
|
|
|
|
gtk_internal_return_val_if_fail (value != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!value->class->is_dynamic)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return value->class->is_dynamic (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_css_value_get_dynamic_value:
|
|
|
|
* @value: a #GtkCssValue
|
|
|
|
* @monotonic_time: the timestamp for which to get the dynamic value
|
|
|
|
*
|
|
|
|
* Gets the dynamic value for a given timestamp. If @monotonic_time is 0,
|
|
|
|
* the default value is returned.
|
|
|
|
*
|
|
|
|
* See gtk_css_value_is_dynamic() for details about dynamic values.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): The dynamic value for @value at the given
|
|
|
|
* timestamp
|
|
|
|
**/
|
|
|
|
GtkCssValue *
|
|
|
|
gtk_css_value_get_dynamic_value (GtkCssValue *value,
|
|
|
|
gint64 monotonic_time)
|
|
|
|
{
|
|
|
|
gtk_internal_return_val_if_fail (value != NULL, NULL);
|
|
|
|
|
|
|
|
if (!value->class->get_dynamic_value)
|
|
|
|
return gtk_css_value_ref (value);
|
|
|
|
|
|
|
|
return value->class->get_dynamic_value (value, monotonic_time);
|
|
|
|
}
|
2020-01-11 11:53:23 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_css_value_is_computed (const GtkCssValue *value)
|
|
|
|
{
|
|
|
|
return value->is_computed;
|
|
|
|
}
|