]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssstyleproperty.c
Rename property to be more neutral
[~andy/gtk] / gtk / gtkcssstyleproperty.c
index 05a80f08abdf5ed72a4d474b61b06a75ea6d7992..0b7491524e421174e64c9185dfbc85e64e601ffb 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "gtkcssstylepropertyprivate.h"
 
+#include "gtkcssenumvalueprivate.h"
 #include "gtkcssinheritvalueprivate.h"
 #include "gtkcssinitialvalueprivate.h"
 #include "gtkcssstylefuncsprivate.h"
@@ -36,6 +37,9 @@
 
 enum {
   PROP_0,
+  PROP_ANIMATED,
+  PROP_AFFECTS_SIZE,
+  PROP_AFFECTS_FONT,
   PROP_ID,
   PROP_INHERIT,
   PROP_INITIAL
@@ -43,6 +47,11 @@ enum {
 
 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)
 {
@@ -52,6 +61,12 @@ 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);
 }
 
@@ -65,6 +80,15 @@ gtk_css_style_property_set_property (GObject      *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;
@@ -88,6 +112,15 @@ gtk_css_style_property_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    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_AFFECTS_FONT:
+      g_value_set_boolean (value, property->affects_font);
+      break;
     case PROP_ID:
       g_value_set_boolean (value, property->id);
       break;
@@ -122,6 +155,63 @@ _gtk_css_style_property_assign (GtkStyleProperty   *property,
   _gtk_css_value_unref (css_value);
 }
 
+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,
@@ -131,6 +221,10 @@ _gtk_css_style_property_query (GtkStyleProperty   *property,
   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 == NULL)
     css_value =_gtk_css_style_property_get_initial_value (style_property);
@@ -140,8 +234,7 @@ _gtk_css_style_property_query (GtkStyleProperty   *property,
 
 static GtkCssValue *
 gtk_css_style_property_parse_value (GtkStyleProperty *property,
-                                    GtkCssParser     *parser,
-                                    GFile            *base)
+                                    GtkCssParser     *parser)
 {
   GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
 
@@ -163,7 +256,7 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
       return _gtk_css_inherit_value_new ();
     }
 
-  return (* style_property->parse_value) (style_property, parser, base);
+  return (* style_property->parse_value) (style_property, parser);
 }
 
 static void
@@ -176,6 +269,27 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
   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",
@@ -203,48 +317,25 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
   property_class->parse_value = gtk_css_style_property_parse_value;
 
   klass->style_properties = g_ptr_array_new ();
+
+  _properties_affecting_size = _gtk_bitmask_new ();
+  _properties_affecting_font = _gtk_bitmask_new ();
+
+  gtk_css_style_property_class = klass;
 }
 
 static GtkCssValue *
 gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property,
-                                         GtkCssParser        *parser,
-                                         GFile               *base)
+                                         GtkCssParser        *parser)
 {
   g_assert_not_reached ();
   return NULL;
 }
 
-static void
-gtk_css_style_property_real_print_value (GtkCssStyleProperty *property,
-                                         const GtkCssValue   *value,
-                                         GString             *string)
-{
-  _gtk_css_value_print (value, string);
-}
-
-static GtkCssValue *
-gtk_css_style_property_real_compute_value (GtkCssStyleProperty *property,
-                                           GtkStyleContext     *context,
-                                           GtkCssValue         *specified)
-{
-  return _gtk_css_value_ref (specified);
-}
-
-static gboolean
-gtk_css_style_property_real_equal (GtkCssStyleProperty *property,
-                                   GtkCssValue         *value1,
-                                   GtkCssValue         *value2)
-{
-  return _gtk_css_value_equal (value1, value2);
-}
-
 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;
-  property->equal_func = gtk_css_style_property_real_equal;
 }
 
 /**
@@ -258,17 +349,13 @@ _gtk_css_style_property_init (GtkCssStyleProperty *property)
 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;
 }
 
 /**
@@ -284,18 +371,16 @@ _gtk_css_style_property_get_n_properties (void)
 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);
 }
 
 /**
@@ -311,114 +396,108 @@ _gtk_css_style_property_lookup_by_id (guint 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_compute_value:
+ * _gtk_css_style_property_affects_font:
  * @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 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: %TRUE if the property affects the font.
  **/
-GtkCssValue *
-_gtk_css_style_property_compute_value (GtkCssStyleProperty *property,
-                                       GtkStyleContext     *context,
-                                       GtkCssValue         *specified)
+gboolean
+_gtk_css_style_property_affects_font (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);
+  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
 
-  return property->compute_value (property, context, specified);
+  return property->affects_font;
 }
 
 /**
- * _gtk_css_style_property_print_value:
+ * _gtk_css_style_property_get_id:
  * @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().
+ * Gets the id for the given property. IDs are used to allow using arrays
+ * for style lookups.
+ *
+ * Returns: The id of the property
  **/
-void
-_gtk_css_style_property_print_value (GtkCssStyleProperty    *property,
-                                     GtkCssValue            *value,
-                                     GString                *string)
+guint
+_gtk_css_style_property_get_id (GtkCssStyleProperty *property)
 {
-  g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property));
-  g_return_if_fail (value != NULL);
-  g_return_if_fail (string != NULL);
-
-  if (_gtk_css_value_is_inherit (value) ||
-      _gtk_css_value_is_initial (value))
-    _gtk_css_value_print (value, string);
-  else
-    property->print_value (property, value, string);
+  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
+
+  return property->id;
 }
 
 /**
- * _gtk_css_style_property_is_equal:
+ * _gtk_css_style_property_get_initial_value:
  * @property: the property
- * @value1: the first value to compare
- * @value2: the second value to compare
  *
- * Compares @value1 and @value2 for equality. Both values must be the
- * result of a call _gtk_css_style_property_compute_value().
+ * 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: %TRUE if @value1 and @value2 are equal
+ * Returns: a reference to the initial value. The value will never change.
  **/
+GtkCssValue *
+_gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
+{
+  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), NULL);
+
+  return property->initial_value;
+}
+
 gboolean
-_gtk_css_style_property_is_equal (GtkCssStyleProperty *property,
-                                  GtkCssValue         *value1,
-                                  GtkCssValue         *value2)
+_gtk_css_style_property_changes_affect_size (const GtkBitmask *changes)
 {
-  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
-  g_return_val_if_fail (value1 != NULL, FALSE);
-  g_return_val_if_fail (value2 != NULL, FALSE);
+  return _gtk_bitmask_intersects (changes, _properties_affecting_size);
+}
 
-  return property->equal_func (property, value1, value2);
+gboolean
+_gtk_css_style_property_changes_affect_font (const GtkBitmask *changes)
+{
+  return _gtk_bitmask_intersects (changes, _properties_affecting_font);
 }