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"
|
|
|
|
|
|
|
|
#include "gtkcssvalueprivate.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)
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:08 +00:00
|
|
|
GtkCssValue *
|
|
|
|
_gtk_css_value_ref (GtkCssValue *value)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (value != NULL, NULL);
|
|
|
|
|
|
|
|
g_atomic_int_add (&value->ref_count, 1);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_css_value_unref (GtkCssValue *value)
|
|
|
|
{
|
|
|
|
if (value == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_atomic_int_dec_and_test (&value->ref_count))
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
* @context: the context to use for resolving
|
2012-07-16 12:48:43 +00:00
|
|
|
* @dependencies: (out) (allow-none): Set to the dependencies of the
|
|
|
|
* computed values that indicate when this value needs to be
|
|
|
|
* recomputed and how.
|
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.
|
|
|
|
* This step is explained in detail in
|
|
|
|
* <ulink url="http://www.w3.org/TR/css3-cascade/#computed>
|
|
|
|
* the CSS documentation</ulink>.
|
|
|
|
*
|
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 *
|
2012-07-16 12:48:43 +00:00
|
|
|
_gtk_css_value_compute (GtkCssValue *value,
|
|
|
|
guint property_id,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GtkCssDependencies *dependencies)
|
2012-07-11 04:56:07 +00:00
|
|
|
{
|
2012-07-16 12:48:43 +00:00
|
|
|
GtkCssDependencies fallback;
|
|
|
|
|
2012-07-11 04:56:07 +00:00
|
|
|
g_return_val_if_fail (value != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
|
|
|
|
|
2012-07-16 12:48:43 +00:00
|
|
|
if (dependencies == NULL)
|
|
|
|
dependencies = &fallback;
|
|
|
|
*dependencies = 0;
|
|
|
|
|
|
|
|
return value->class->compute (value, property_id, context, dependencies);
|
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)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (value1 != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value2 != NULL, FALSE);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (value1 == NULL && value2 == NULL)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (start != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (end != NULL, FALSE);
|
|
|
|
|
|
|
|
if (start->class != end->class)
|
|
|
|
return NULL;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
g_return_val_if_fail (value != NULL, NULL);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
g_return_if_fail (string != NULL);
|
|
|
|
|
|
|
|
value->class->print (value, string);
|
|
|
|
}
|
|
|
|
|