#include "gtkcssstylepropertyprivate.h"
+#include "gtkcssenumvalueprivate.h"
+#include "gtkcssinheritvalueprivate.h"
+#include "gtkcssinitialvalueprivate.h"
#include "gtkcssstylefuncsprivate.h"
#include "gtkcsstypesprivate.h"
#include "gtkintl.h"
#include "gtkprivatetypebuiltins.h"
#include "gtkstylepropertiesprivate.h"
-#include <math.h>
-#include <cairo-gobject.h>
-#include "gtkcssimagegradientprivate.h"
-#include "gtkcssimageprivate.h"
-
/* this is in case round() is not provided by the compiler,
* such as in the case of C89 compilers, like MSVC
*/
enum {
PROP_0,
+ PROP_ANIMATED,
+ PROP_AFFECTS_SIZE,
+ PROP_AFFECTS_FONT,
PROP_ID,
- PROP_SPECIFIED_TYPE,
- PROP_COMPUTED_TYPE,
PROP_INHERIT,
PROP_INITIAL
};
G_DEFINE_TYPE (GtkCssStyleProperty, _gtk_css_style_property, GTK_TYPE_STYLE_PROPERTY)
+static GtkBitmask *_properties_affecting_size = NULL;
+static GtkBitmask *_properties_affecting_font = NULL;
+
+static GtkCssStylePropertyClass *gtk_css_style_property_class = NULL;
+
static void
gtk_css_style_property_constructed (GObject *object)
{
property->id = klass->style_properties->len;
g_ptr_array_add (klass->style_properties, property);
+ if (property->affects_size)
+ _properties_affecting_size = _gtk_bitmask_set (_properties_affecting_size, property->id, TRUE);
+
+ if (property->affects_font)
+ _properties_affecting_font = _gtk_bitmask_set (_properties_affecting_font, property->id, TRUE);
+
G_OBJECT_CLASS (_gtk_css_style_property_parent_class)->constructed (object);
}
switch (prop_id)
{
+ case PROP_ANIMATED:
+ property->animated = g_value_get_boolean (value);
+ break;
+ case PROP_AFFECTS_SIZE:
+ property->affects_size = g_value_get_boolean (value);
+ break;
+ case PROP_AFFECTS_FONT:
+ property->affects_font = g_value_get_boolean (value);
+ break;
case PROP_INHERIT:
property->inherit = g_value_get_boolean (value);
break;
property->initial_value = g_value_dup_boxed (value);
g_assert (property->initial_value != NULL);
break;
- case PROP_COMPUTED_TYPE:
- property->computed_type = g_value_get_gtype (value);
- g_assert (property->computed_type != G_TYPE_NONE);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id)
{
- case PROP_SPECIFIED_TYPE:
- g_value_set_gtype (value, G_VALUE_TYPE (&property->initial_value));
+ case PROP_ANIMATED:
+ g_value_set_boolean (value, property->animated);
+ break;
+ case PROP_AFFECTS_SIZE:
+ g_value_set_boolean (value, property->affects_size);
break;
- case PROP_COMPUTED_TYPE:
- g_value_set_gtype (value, property->computed_type);
+ case PROP_AFFECTS_FONT:
+ g_value_set_boolean (value, property->affects_font);
break;
case PROP_ID:
g_value_set_boolean (value, property->id);
GtkStateFlags state,
const GValue *value)
{
- GtkCssValue *css_value = _gtk_css_value_new_from_gvalue (value);
+ GtkCssStyleProperty *style;
+ GtkCssValue *css_value;
+
+ style = GTK_CSS_STYLE_PROPERTY (property);
+ css_value = style->assign_value (style, value);
+
_gtk_style_properties_set_property_by_property (props,
- GTK_CSS_STYLE_PROPERTY (property),
+ style,
state,
css_value);
_gtk_css_value_unref (css_value);
}
-static GtkCssValue *
+static gboolean
+_gtk_css_style_property_query_special_case (GtkCssStyleProperty *property,
+ GValue *value,
+ GtkStyleQueryFunc query_func,
+ gpointer query_data)
+{
+ GtkBorderStyle border_style;
+
+ switch (property->id)
+ {
+ case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_TOP_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_LEFT_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_OUTLINE_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_OUTLINE_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+static void
_gtk_css_style_property_query (GtkStyleProperty *property,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
+ GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
GtkCssValue *css_value;
+ /* I don't like this special case being here in this generic code path, but no idea where else to put it. */
+ if (_gtk_css_style_property_query_special_case (style_property, value, query_func, query_data))
+ return;
+
css_value = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data);
- if (css_value)
- {
- /* Somebody make this a vfunc */
- if (_gtk_css_value_holds (css_value, GTK_TYPE_CSS_IMAGE))
- {
- GtkCssImage *image = _gtk_css_value_get_image (css_value);
- cairo_pattern_t *pattern;
- cairo_surface_t *surface;
- cairo_matrix_t matrix;
-
- if (image == NULL)
- return _gtk_css_value_new_from_pattern (NULL);
- else if (GTK_IS_CSS_IMAGE_GRADIENT (image))
- return _gtk_css_value_new_from_pattern (GTK_CSS_IMAGE_GRADIENT (image)->pattern);
- else
- {
- double width, height;
-
- /* the 100, 100 is rather random */
- _gtk_css_image_get_concrete_size (image, 0, 0, 100, 100, &width, &height);
- surface = _gtk_css_image_get_surface (image, NULL, width, height);
- pattern = cairo_pattern_create_for_surface (surface);
- cairo_matrix_init_scale (&matrix, width, height);
- cairo_pattern_set_matrix (pattern, &matrix);
- cairo_surface_destroy (surface);
- return _gtk_css_value_new_take_pattern (pattern);
- }
- }
- else if (_gtk_css_value_holds (css_value, GTK_TYPE_CSS_NUMBER))
- {
- int v = round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100));
- return _gtk_css_value_new_from_int (v);
- }
- else
- return _gtk_css_value_ref (css_value);
- }
- else
- return _gtk_css_value_ref (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)));
+ if (css_value == NULL)
+ css_value =_gtk_css_style_property_get_initial_value (style_property);
+
+ style_property->query_value (style_property, css_value, value);
}
-static gboolean
+static GtkCssValue *
gtk_css_style_property_parse_value (GtkStyleProperty *property,
- GValue *value,
- GtkCssParser *parser,
- GFile *base)
+ GtkCssParser *parser)
{
GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
/* the initial value can be explicitly specified with the
* ‘initial’ keyword which all properties accept.
*/
- g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
- g_value_set_enum (value, GTK_CSS_INITIAL);
- return TRUE;
+ return _gtk_css_initial_value_new ();
}
else if (_gtk_css_parser_try (parser, "inherit", TRUE))
{
* strengthen inherited values in the cascade, and it can
* also be used on properties that are not normally inherited.
*/
- g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
- g_value_set_enum (value, GTK_CSS_INHERIT);
- return TRUE;
+ return _gtk_css_inherit_value_new ();
}
- g_value_init (value, _gtk_css_style_property_get_specified_type (style_property));
- if (!(* style_property->parse_value) (style_property, value, parser, base))
- {
- g_value_unset (value);
- return FALSE;
- }
-
- return TRUE;
+ return (* style_property->parse_value) (style_property, parser);
}
static void
object_class->set_property = gtk_css_style_property_set_property;
object_class->get_property = gtk_css_style_property_get_property;
+ g_object_class_install_property (object_class,
+ PROP_ANIMATED,
+ g_param_spec_boolean ("animated",
+ P_("Animated"),
+ P_("Set if the value can be animated"),
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_AFFECTS_SIZE,
+ g_param_spec_boolean ("affects-size",
+ P_("Affects size"),
+ P_("Set if the value affects the sizing of elements"),
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_AFFECTS_FONT,
+ g_param_spec_boolean ("affects-font",
+ P_("Affects font"),
+ P_("Set if the value affects the font"),
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_ID,
g_param_spec_uint ("id",
P_("The numeric id for quick access"),
0, G_MAXUINT, 0,
G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_SPECIFIED_TYPE,
- g_param_spec_gtype ("specified-type",
- P_("Specified type"),
- P_("The type of values after parsing"),
- G_TYPE_NONE,
- G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_COMPUTED_TYPE,
- g_param_spec_gtype ("computed-type",
- P_("Computed type"),
- P_("The type of values after style lookup"),
- G_TYPE_NONE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_INHERIT,
g_param_spec_boolean ("inherit",
property_class->parse_value = gtk_css_style_property_parse_value;
klass->style_properties = g_ptr_array_new ();
-}
-static gboolean
-gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property,
- GValue *value,
- GtkCssParser *parser,
- GFile *base)
-{
- return _gtk_css_style_parse_value (value, parser, base);
-}
+ _properties_affecting_size = _gtk_bitmask_new ();
+ _properties_affecting_font = _gtk_bitmask_new ();
-static void
-gtk_css_style_property_real_print_value (GtkCssStyleProperty *property,
- const GValue *value,
- GString *string)
-{
- _gtk_css_style_print_value (value, string);
+ gtk_css_style_property_class = klass;
}
static GtkCssValue *
-gtk_css_style_property_real_compute_value (GtkCssStyleProperty *property,
- GtkStyleContext *context,
- GtkCssValue *specified)
+gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property,
+ GtkCssParser *parser)
{
- return _gtk_css_style_compute_value (context, _gtk_css_style_property_get_computed_type (property), specified);
+ g_assert_not_reached ();
+ return NULL;
}
static void
_gtk_css_style_property_init (GtkCssStyleProperty *property)
{
property->parse_value = gtk_css_style_property_real_parse_value;
- property->print_value = gtk_css_style_property_real_print_value;
- property->compute_value = gtk_css_style_property_real_compute_value;
}
/**
guint
_gtk_css_style_property_get_n_properties (void)
{
- GtkCssStylePropertyClass *klass;
-
- klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
- if (G_UNLIKELY (klass == NULL))
+ if (G_UNLIKELY (gtk_css_style_property_class == NULL))
{
_gtk_style_property_init_properties ();
- klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
- g_assert (klass);
+ g_assert (gtk_css_style_property_class);
}
- return klass->style_properties->len;
+ return gtk_css_style_property_class->style_properties->len;
}
/**
GtkCssStyleProperty *
_gtk_css_style_property_lookup_by_id (guint id)
{
- GtkCssStylePropertyClass *klass;
- klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
- if (G_UNLIKELY (klass == NULL))
+ if (G_UNLIKELY (gtk_css_style_property_class == NULL))
{
_gtk_style_property_init_properties ();
- klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
- g_assert (klass);
+ g_assert (gtk_css_style_property_class);
}
- g_return_val_if_fail (id < klass->style_properties->len, NULL);
- return g_ptr_array_index (klass->style_properties, id);
+ g_return_val_if_fail (id < gtk_css_style_property_class->style_properties->len, NULL);
+
+ return g_ptr_array_index (gtk_css_style_property_class->style_properties, id);
}
/**
gboolean
_gtk_css_style_property_is_inherit (GtkCssStyleProperty *property)
{
- g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
return property->inherit;
}
/**
- * _gtk_css_style_property_get_id:
+ * _gtk_css_style_property_is_animated:
* @property: the property
*
- * Gets the id for the given property. IDs are used to allow using arrays
- * for style lookups.
+ * Queries if the given @property can be is animated. See
+ * <ulink url="http://www.w3.org/TR/css3-transitions/#animatable-css>
+ * the CSS documentation</ulink> for animatable properties.
*
- * Returns: The id of the property
+ * Returns: %TRUE if the property can be animated.
**/
-guint
-_gtk_css_style_property_get_id (GtkCssStyleProperty *property)
+gboolean
+_gtk_css_style_property_is_animated (GtkCssStyleProperty *property)
{
- g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
- return property->id;
+ return property->animated;
}
/**
- * _gtk_css_style_property_get_initial_value:
+ * _gtk_css_style_property_affects_size:
* @property: the property
*
- * Queries the initial value of the given @property. See
- * <ulink url="http://www.w3.org/TR/css3-cascade/#intial>
- * the CSS documentation</ulink> for an explanation of this concept.
+ * Queries if the given @property affects the size of elements. This is
+ * used for optimizations inside GTK, where a gtk_widget_queue_resize()
+ * can be avoided if the property does not affect size.
*
- * Returns: a reference to the initial value. The value will never change.
+ * Returns: %TRUE if the property affects sizing of elements.
**/
-GtkCssValue *
-_gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
+gboolean
+_gtk_css_style_property_affects_size (GtkCssStyleProperty *property)
{
- g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), NULL);
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
- return property->initial_value;
+ return property->affects_size;
}
/**
- * _gtk_css_style_property_get_computed_type:
- * @property: the property to query
+ * _gtk_css_style_property_affects_font:
+ * @property: the property
*
- * Gets the #GType used for values for this property after a CSS lookup has
- * happened. _gtk_css_style_property_compute_value() will convert values to
- * this type.
+ * Queries if the given @property affects the default font. This is
+ * used for optimizations inside GTK, where clearing pango
+ * layouts can be avoided if the font doesn't change.
*
- * Returns: the #GType used for computed values.
+ * Returns: %TRUE if the property affects the font.
**/
-GType
-_gtk_css_style_property_get_computed_type (GtkCssStyleProperty *property)
+gboolean
+_gtk_css_style_property_affects_font (GtkCssStyleProperty *property)
{
- g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), G_TYPE_NONE);
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
- return property->computed_type;
+ return property->affects_font;
}
/**
- * _gtk_css_style_property_get_specified_type:
- * @property: the property to query
- *
- * Gets the #GType used for values for this property after CSS parsing if
- * the value is not a special keyword. _gtk_css_style_property_compute_value()
- * will convert values of this type to the computed type.
+ * _gtk_css_style_property_get_id:
+ * @property: the property
*
- * The initial value returned by _gtk_css_style_property_get_initial_value()
- * will be of this type.
+ * Gets the id for the given property. IDs are used to allow using arrays
+ * for style lookups.
*
- * Returns: the #GType used for specified values.
+ * Returns: The id of the property
**/
-GType
-_gtk_css_style_property_get_specified_type (GtkCssStyleProperty *property)
-{
- g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), G_TYPE_NONE);
-
- return _gtk_css_value_get_content_type (property->initial_value);
-}
-
-gboolean
-_gtk_css_style_property_is_specified_type (GtkCssStyleProperty *property,
- GType type)
+guint
+_gtk_css_style_property_get_id (GtkCssStyleProperty *property)
{
- g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
-
- /* If it's our specified type, of course it's valid */
- if (type == _gtk_css_value_get_content_type (property->initial_value))
- return TRUE;
-
- /* The special values 'inherit' and 'initial' are always valid */
- if (type == GTK_TYPE_CSS_SPECIAL_VALUE)
- return TRUE;
-
- /* XXX: Someone needs to fix that legacy */
- if (_gtk_css_value_holds (property->initial_value, CAIRO_GOBJECT_TYPE_PATTERN) &&
- type == GTK_TYPE_GRADIENT)
- return TRUE;
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
- return FALSE;
+ return property->id;
}
/**
- * _gtk_css_style_property_compute_value:
+ * _gtk_css_style_property_get_initial_value:
* @property: the property
- * @computed: (out): an uninitialized value to be filled with the result
- * @context: the context to use for resolving
- * @specified: the value to compute from
*
- * Converts the @specified value into the @computed value 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>.
+ * Queries the initial value of the given @property. See
+ * <ulink url="http://www.w3.org/TR/css3-cascade/#intial>
+ * the CSS documentation</ulink> for an explanation of this concept.
+ *
+ * Returns: a reference to the initial value. The value will never change.
**/
GtkCssValue *
-_gtk_css_style_property_compute_value (GtkCssStyleProperty *property,
- GtkStyleContext *context,
- GtkCssValue *specified)
+_gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
{
g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), NULL);
- g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
- return property->compute_value (property, context, specified);
+ return property->initial_value;
}
-/**
- * _gtk_css_style_property_print_value:
- * @property: the property
- * @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().
- **/
-void
-_gtk_css_style_property_print_value (GtkCssStyleProperty *property,
- GtkCssValue *css_value,
- GString *string)
+gboolean
+_gtk_css_style_property_changes_affect_size (const GtkBitmask *changes)
{
- g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property));
- g_return_if_fail (css_value != NULL);
- g_return_if_fail (string != NULL);
-
- if (_gtk_css_value_is_special (css_value))
- {
- GEnumClass *enum_class;
- GEnumValue *enum_value;
-
- enum_class = g_type_class_ref (GTK_TYPE_CSS_SPECIAL_VALUE);
- enum_value = g_enum_get_value (enum_class, _gtk_css_value_get_special_kind (css_value));
-
- g_string_append (string, enum_value->value_nick);
-
- g_type_class_unref (enum_class);
- }
- else
- {
- GValue value = G_VALUE_INIT;
- _gtk_css_value_init_gvalue (css_value, &value);
- property->print_value (property, &value, string);
- g_value_unset (&value);
- }
+ return _gtk_bitmask_intersects (changes, _properties_affecting_size);
}
+gboolean
+_gtk_css_style_property_changes_affect_font (const GtkBitmask *changes)
+{
+ return _gtk_bitmask_intersects (changes, _properties_affecting_font);
+}