[gtk+] css: Add _gtk_css_style_property_affects_font



commit 6dfee46cdb6c720d19489f39d802e1d46c598a51
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Dec 6 21:14:02 2012 +0100

    css: Add _gtk_css_style_property_affects_font
    
    This checks if a style_update affects the font.

 gtk/gtkcssstyleproperty.c        |   44 ++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssstylepropertyimpl.c    |   14 +++++++-----
 gtk/gtkcssstylepropertyprivate.h |    2 +
 3 files changed, 54 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index bd7d5a0..c3016ab 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -39,6 +39,7 @@ enum {
   PROP_0,
   PROP_ANIMATED,
   PROP_AFFECTS_SIZE,
+  PROP_AFFECTS_FONT,
   PROP_ID,
   PROP_INHERIT,
   PROP_INITIAL
@@ -47,6 +48,7 @@ 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 void
 gtk_css_style_property_constructed (GObject *object)
@@ -60,6 +62,9 @@ gtk_css_style_property_constructed (GObject *object)
   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);
 }
 
@@ -79,6 +84,9 @@ gtk_css_style_property_set_property (GObject      *object,
     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;
@@ -108,6 +116,9 @@ gtk_css_style_property_get_property (GObject    *object,
     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;
@@ -271,6 +282,13 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
                                                          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_("ID"),
@@ -299,6 +317,7 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
   klass->style_properties = g_ptr_array_new ();
 
   _properties_affecting_size = _gtk_bitmask_new ();
+  _properties_affecting_font = _gtk_bitmask_new ();
 }
 
 static GtkCssValue *
@@ -419,6 +438,25 @@ _gtk_css_style_property_affects_size (GtkCssStyleProperty *property)
 
   return property->affects_size;
 }
+
+/**
+ * _gtk_css_style_property_affects_font:
+ * @property: the property
+ *
+ * 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.
+ **/
+gboolean
+_gtk_css_style_property_affects_font (GtkCssStyleProperty *property)
+{
+  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
+
+  return property->affects_font;
+}
+
 /**
  * _gtk_css_style_property_get_id:
  * @property: the property
@@ -459,3 +497,9 @@ _gtk_css_style_property_changes_affect_size (const GtkBitmask *changes)
 {
   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);
+}
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 3d8eb21..c58edd8 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -66,7 +66,8 @@
 typedef enum {
   GTK_STYLE_PROPERTY_INHERIT = (1 << 0),
   GTK_STYLE_PROPERTY_ANIMATED = (1 << 1),
-  GTK_STYLE_PROPERTY_NO_RESIZE = (1 << 2)
+  GTK_STYLE_PROPERTY_NO_RESIZE = (1 << 2),
+  GTK_STYLE_PROPERTY_AFFECTS_FONT = (1 << 3)
 } GtkStylePropertyFlags;
 
 static void
@@ -89,6 +90,7 @@ gtk_css_style_property_register (const char *                   name,
   node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
                        "value-type", value_type,
                        "affects-size", (flags & GTK_STYLE_PROPERTY_NO_RESIZE) ? FALSE : TRUE,
+                       "affects-font", (flags & GTK_STYLE_PROPERTY_AFFECTS_FONT) ? TRUE : FALSE,
                        "animated", (flags & GTK_STYLE_PROPERTY_ANIMATED) ? TRUE : FALSE,
                        "inherit", (flags & GTK_STYLE_PROPERTY_INHERIT) ? TRUE : FALSE,
                        "initial-value", initial_value,
@@ -876,7 +878,7 @@ _gtk_css_style_property_init_properties (void)
   gtk_css_style_property_register        ("font-size",
                                           GTK_CSS_PROPERTY_FONT_SIZE,
                                           G_TYPE_DOUBLE,
-                                          GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
+                                          GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED | GTK_STYLE_PROPERTY_AFFECTS_FONT,
                                           font_size_parse,
                                           query_length_as_double,
                                           assign_length_from_double,
@@ -896,7 +898,7 @@ _gtk_css_style_property_init_properties (void)
   gtk_css_style_property_register        ("font-family",
                                           GTK_CSS_PROPERTY_FONT_FAMILY,
                                           G_TYPE_STRV,
-                                          GTK_STYLE_PROPERTY_INHERIT,
+                                          GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_AFFECTS_FONT,
                                           font_family_parse,
                                           font_family_query,
                                           font_family_assign,
@@ -904,7 +906,7 @@ _gtk_css_style_property_init_properties (void)
   gtk_css_style_property_register        ("font-style",
                                           GTK_CSS_PROPERTY_FONT_STYLE,
                                           PANGO_TYPE_STYLE,
-                                          GTK_STYLE_PROPERTY_INHERIT,
+                                          GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_AFFECTS_FONT,
                                           parse_pango_style,
                                           query_pango_style,
                                           assign_pango_style,
@@ -912,7 +914,7 @@ _gtk_css_style_property_init_properties (void)
   gtk_css_style_property_register        ("font-variant",
                                           GTK_CSS_PROPERTY_FONT_VARIANT,
                                           PANGO_TYPE_VARIANT,
-                                          GTK_STYLE_PROPERTY_INHERIT,
+                                          GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_AFFECTS_FONT,
                                           parse_pango_variant,
                                           query_pango_variant,
                                           assign_pango_variant,
@@ -920,7 +922,7 @@ _gtk_css_style_property_init_properties (void)
   gtk_css_style_property_register        ("font-weight",
                                           GTK_CSS_PROPERTY_FONT_WEIGHT,
                                           PANGO_TYPE_WEIGHT,
-                                          GTK_STYLE_PROPERTY_INHERIT,
+                                          GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_AFFECTS_FONT,
                                           parse_pango_weight,
                                           query_pango_weight,
                                           assign_pango_weight,
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index 00d8437..342cdb7 100644
--- a/gtk/gtkcssstylepropertyprivate.h
+++ b/gtk/gtkcssstylepropertyprivate.h
@@ -50,6 +50,7 @@ struct _GtkCssStyleProperty
   guint inherit :1;
   guint animated :1;
   guint affects_size :1;
+  guint affects_font :1;
 
   GtkCssStylePropertyParseFunc parse_value;
   GtkCssStylePropertyQueryFunc query_value;
@@ -73,6 +74,7 @@ GtkCssStyleProperty *   _gtk_css_style_property_lookup_by_id    (guint
 gboolean                _gtk_css_style_property_is_inherit      (GtkCssStyleProperty    *property);
 gboolean                _gtk_css_style_property_is_animated     (GtkCssStyleProperty    *property);
 gboolean                _gtk_css_style_property_affects_size    (GtkCssStyleProperty    *property);
+gboolean                _gtk_css_style_property_affects_font    (GtkCssStyleProperty    *property);
 guint                   _gtk_css_style_property_get_id          (GtkCssStyleProperty    *property);
 GtkCssValue  *          _gtk_css_style_property_get_initial_value
                                                                 (GtkCssStyleProperty    *property);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]