[gtk+/wip/cssvalue: 89/165] stylecontext: Convert _gtk_style_context_peek_property()



commit c2c24b084d10db68549c4945ccf04279fe6e2dff
Author: Benjamin Otte <otte redhat com>
Date:   Sat Mar 31 05:42:28 2012 +0200

    stylecontext: Convert _gtk_style_context_peek_property()
    
    Take the property id instead of the name.

 gtk/gtkborderimage.c          |    8 ++++----
 gtk/gtkcsscomputedvalues.c    |    3 +--
 gtk/gtkcssnumbervalue.c       |    4 ++--
 gtk/gtkcssrgbavalue.c         |    4 ++--
 gtk/gtkcssstylefuncs.c        |    2 +-
 gtk/gtkcssstylepropertyimpl.c |    5 +----
 gtk/gtkcsstypes.c             |    4 ++--
 gtk/gtkstylecontext.c         |    8 ++++----
 gtk/gtkstylecontextprivate.h  |    4 ++--
 gtk/gtkthemingbackground.c    |   12 ++++++------
 gtk/gtkthemingengine.c        |   24 +++++++++++-------------
 gtk/gtkthemingengineprivate.h |    4 ++--
 12 files changed, 38 insertions(+), 44 deletions(-)
---
diff --git a/gtk/gtkborderimage.c b/gtk/gtkborderimage.c
index 399e869..f13cc86 100644
--- a/gtk/gtkborderimage.c
+++ b/gtk/gtkborderimage.c
@@ -40,12 +40,12 @@ _gtk_border_image_init (GtkBorderImage   *image,
 {
   GtkBorder *width;
 
-  image->source = _gtk_css_image_value_get_image (_gtk_theming_engine_peek_property (engine, "border-image-source"));
+  image->source = _gtk_css_image_value_get_image (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE));
   if (image->source == NULL)
     return FALSE;
 
-  image->slice = *(GtkBorder *) _gtk_css_value_get_boxed (_gtk_theming_engine_peek_property (engine, "border-image-slice"));
-  width = _gtk_css_value_get_boxed (_gtk_theming_engine_peek_property (engine, "border-image-width"));
+  image->slice = *(GtkBorder *) _gtk_css_value_get_boxed (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_SLICE));
+  width = _gtk_css_value_get_boxed (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_WIDTH));
   if (width)
     {
       image->width = *width;
@@ -54,7 +54,7 @@ _gtk_border_image_init (GtkBorderImage   *image,
   else
     image->has_width = FALSE;
 
-  image->repeat = *_gtk_css_value_get_border_image_repeat (_gtk_theming_engine_peek_property (engine, "border-image-repeat"));
+  image->repeat = *_gtk_css_value_get_border_image_repeat (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_REPEAT));
 
   return TRUE;
 }
diff --git a/gtk/gtkcsscomputedvalues.c b/gtk/gtkcsscomputedvalues.c
index 6b2ca8e..44a7f97 100644
--- a/gtk/gtkcsscomputedvalues.c
+++ b/gtk/gtkcsscomputedvalues.c
@@ -157,8 +157,7 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values,
     {
       GtkCssValue *parent_value;
       /* Set NULL here and do the inheritance upon lookup? */
-      parent_value = _gtk_style_context_peek_property (parent,
-                                                       _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop)));
+      parent_value = _gtk_style_context_peek_property (parent, id);
 
       g_ptr_array_index (values->values, id) = _gtk_css_value_ref (parent_value);
     }
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index 106fd76..fded8c7 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -189,13 +189,13 @@ _gtk_css_number_value_compute (GtkCssValue     *number,
       break;
     case GTK_CSS_EM:
       return _gtk_css_number_value_new (number->value *
-                                        _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100),
+                                        _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
                                         GTK_CSS_PX);
       break;
     case GTK_CSS_EX:
       /* for now we pretend ex is half of em */
       return _gtk_css_number_value_new (number->value * 0.5 * 
-                                        _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100),
+                                        _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
                                         GTK_CSS_PX);
     case GTK_CSS_RAD:
       return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI),
diff --git a/gtk/gtkcssrgbavalue.c b/gtk/gtkcssrgbavalue.c
index 61d8b1f..490ca35 100644
--- a/gtk/gtkcssrgbavalue.c
+++ b/gtk/gtkcssrgbavalue.c
@@ -117,13 +117,13 @@ _gtk_css_rgba_value_compute_from_symbolic (GtkCssValue     *rgba,
           GtkStyleContext *parent = gtk_style_context_get_parent (context);
 
           if (parent)
-            return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, "color"));
+            return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR));
           else
             return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, TRUE);
         }
       else
         {
-          return _gtk_css_value_ref (_gtk_style_context_peek_property (context, "color"));
+          return _gtk_css_value_ref (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
         }
     }
   
diff --git a/gtk/gtkcssstylefuncs.c b/gtk/gtkcssstylefuncs.c
index eaade29..518a327 100644
--- a/gtk/gtkcssstylefuncs.c
+++ b/gtk/gtkcssstylefuncs.c
@@ -224,7 +224,7 @@ rgba_value_compute (GtkStyleContext *context,
       GdkRGBA rgba;
 
       if (symbolic == _gtk_symbolic_color_get_current_color ())
-        rgba = *_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, "color"));
+        rgba = *_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
       else if (!gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
         rgba = white;
 
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index e3abc7c..b2ee619 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -834,15 +834,12 @@ compute_border_width (GtkCssStyleProperty    *property,
                       GtkStyleContext        *context,
                       GtkCssValue            *specified)
 {
-  GtkCssStyleProperty *style;
   GtkBorderStyle border_style;
   
   /* The -1 is magic that is only true because we register the style
    * properties directly after the width properties.
    */
-  style = _gtk_css_style_property_lookup_by_id (_gtk_css_style_property_get_id (property) - 1);
-  
-  border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (style))));
+  border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, _gtk_css_style_property_get_id (property) - 1));
 
   if (border_style == GTK_BORDER_STYLE_NONE ||
       border_style == GTK_BORDER_STYLE_HIDDEN)
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index 411f401..640ab31 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -158,12 +158,12 @@ _gtk_css_number_compute (GtkCssNumber       *dest,
       dest->unit = GTK_CSS_PX;
       break;
     case GTK_CSS_EM:
-      dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100);
+      dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100);
       dest->unit = GTK_CSS_PX;
       break;
     case GTK_CSS_EX:
       /* for now we pretend ex is half of em */
-      dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100);
+      dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100);
       dest->unit = GTK_CSS_PX;
       break;
     case GTK_CSS_RAD:
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 218df50..9b86904 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -2241,21 +2241,21 @@ style_property_values_cmp (gconstpointer bsearch_node1,
 
 GtkCssValue *
 _gtk_style_context_peek_property (GtkStyleContext *context,
-                                  const char      *property_name)
+                                  guint            property_id)
 {
   StyleData *data = style_data_lookup (context);
 
-  return _gtk_css_computed_values_get_value_by_name (data->store, property_name);
+  return _gtk_css_computed_values_get_value (data->store, property_id);
 }
 
 double
 _gtk_style_context_get_number (GtkStyleContext *context,
-                               const char      *property_name,
+                               guint            property_id,
                                double           one_hundred_percent)
 {
   GtkCssValue *value;
   
-  value = _gtk_style_context_peek_property (context, property_name);
+  value = _gtk_style_context_peek_property (context, property_id);
   return _gtk_css_number_value_get (value, one_hundred_percent);
 }
 
diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h
index 759929e..9feaf78 100644
--- a/gtk/gtkstylecontextprivate.h
+++ b/gtk/gtkstylecontextprivate.h
@@ -27,9 +27,9 @@ G_BEGIN_DECLS
 void            _gtk_style_context_set_widget                (GtkStyleContext *context,
                                                               GtkWidget       *widget);
 GtkCssValue   * _gtk_style_context_peek_property             (GtkStyleContext *context,
-                                                              const char      *property_name);
+                                                              guint            property_id);
 double         _gtk_style_context_get_number                 (GtkStyleContext *context,
-                                                              const char      *property_name,
+                                                              guint            property_id,
                                                               double           one_hundred_percent);
 const GValue * _gtk_style_context_peek_style_property        (GtkStyleContext *context,
                                                               GType            widget_type,
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index 882e496..f6ae1d5 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -55,7 +55,7 @@ _gtk_theming_background_apply_origin (GtkThemingBackground *bg)
   GtkCssArea origin;
   cairo_rectangle_t image_rect;
 
-  origin = _gtk_css_area_value_get (_gtk_style_context_peek_property (bg->context, "background-clip"));
+  origin = _gtk_css_area_value_get (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_CLIP));
 
   /* The default size of the background image depends on the
      background-origin value as this affects the top left
@@ -90,7 +90,7 @@ _gtk_theming_background_apply_origin (GtkThemingBackground *bg)
 static void
 _gtk_theming_background_apply_clip (GtkThemingBackground *bg)
 {
-  GtkCssArea clip = _gtk_css_area_value_get (_gtk_style_context_peek_property (bg->context, "background-clip"));
+  GtkCssArea clip = _gtk_css_area_value_get (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_CLIP));
 
   if (clip == GTK_CSS_AREA_PADDING_BOX)
     {
@@ -163,8 +163,8 @@ _gtk_theming_background_paint (GtkThemingBackground *bg,
       double image_width, image_height;
       double width, height;
 
-      size = _gtk_css_value_get_background_size (_gtk_style_context_peek_property (bg->context, "background-size"));
-      pos = _gtk_css_value_get_background_position (_gtk_style_context_peek_property (bg->context, "background-position"));
+      size = _gtk_css_value_get_background_size (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_SIZE));
+      pos = _gtk_css_value_get_background_position (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_POSITION));
       gtk_style_context_get (bg->context, bg->flags,
                              "background-repeat", &hrepeat,
                              NULL);
@@ -298,7 +298,7 @@ static void
 _gtk_theming_background_apply_shadow (GtkThemingBackground *bg,
                                       cairo_t              *cr)
 {
-  _gtk_css_shadow_value_paint_box (_gtk_style_context_peek_property (bg->context, "box-shadow"),
+  _gtk_css_shadow_value_paint_box (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BOX_SHADOW),
                                    cr,
                                    &bg->padding_box);
 }
@@ -332,7 +332,7 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg)
   _gtk_theming_background_apply_clip (bg);
   _gtk_theming_background_apply_origin (bg);
 
-  bg->image = _gtk_css_image_value_get_image (_gtk_style_context_peek_property (bg->context, "background-image"));
+  bg->image = _gtk_css_image_value_get_image (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE));
 }
 
 void
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index aad10ac..8ce1727 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -342,23 +342,21 @@ _gtk_theming_engine_get_context (GtkThemingEngine *engine)
 
 GtkCssValue *
 _gtk_theming_engine_peek_property (GtkThemingEngine *engine,
-                                   const char       *property_name)
+                                   guint             property_id)
 {
   g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
-  g_return_val_if_fail (property_name != NULL, NULL);
 
-  return _gtk_style_context_peek_property (engine->priv->context, property_name);
+  return _gtk_style_context_peek_property (engine->priv->context, property_id);
 }
 
 double
 _gtk_theming_engine_get_number (GtkThemingEngine *engine,
-                                const char       *property_name,
+                                guint             property_id,
                                 double            one_hundred_percent)
 {
   g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0.0);
-  g_return_val_if_fail (property_name != NULL, 0.0);
 
-  return _gtk_style_context_get_number (engine->priv->context, property_name, one_hundred_percent);
+  return _gtk_style_context_get_number (engine->priv->context, property_id, one_hundred_percent);
 }
 
 /**
@@ -1822,17 +1820,17 @@ render_frame_internal (GtkThemingEngine *engine,
       render_border (cr, &border_box, &border, hidden_side, colors, border_style);
     }
 
-  border_style[0] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine, "outline-style"));
+  border_style[0] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_STYLE));
   if (border_style[0] != GTK_BORDER_STYLE_NONE)
     {
       int offset;
 
       border_style[1] = border_style[2] = border_style[3] = border_style[0];
-      border.top = _gtk_css_value_get_int (_gtk_theming_engine_peek_property (engine, "outline-width"));
+      border.top = _gtk_css_value_get_int (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_WIDTH));
       border.left = border.right = border.bottom = border.top;
-      colors[0] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine, "outline-color"));
+      colors[0] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_COLOR));
       colors[3] = colors[2] = colors[1] = colors[0];
-      offset = _gtk_css_value_get_int (_gtk_theming_engine_peek_property (engine, "outline-offset"));
+      offset = _gtk_css_value_get_int (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_OFFSET));
       
       /* reinit box here - outlines don't have a border radius */
       _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
@@ -2134,7 +2132,7 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
       fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
     }
 
-  text_shadow = _gtk_theming_engine_peek_property (engine, "text-shadow");
+  text_shadow = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_TEXT_SHADOW);
 
   prepare_context_for_layout (cr, x, y, layout);
 
@@ -2765,7 +2763,7 @@ render_spinner (GtkThemingEngine *engine,
   radius = MIN (width / 2, height / 2);
 
   gtk_theming_engine_get_color (engine, state, &color);
-  shadow = _gtk_theming_engine_peek_property (engine, "icon-shadow");
+  shadow = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_ICON_SHADOW);
 
   cairo_save (cr);
   cairo_translate (cr, x + width / 2, y + height / 2);
@@ -2943,7 +2941,7 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine,
 
   gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
 
-  _gtk_css_shadow_value_paint_icon (_gtk_theming_engine_peek_property (engine, "icon-shadow"), cr);
+  _gtk_css_shadow_value_paint_icon (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_ICON_SHADOW), cr);
 
   cairo_paint (cr);
 
diff --git a/gtk/gtkthemingengineprivate.h b/gtk/gtkthemingengineprivate.h
index 63d0cfa..63079ee 100644
--- a/gtk/gtkthemingengineprivate.h
+++ b/gtk/gtkthemingengineprivate.h
@@ -28,9 +28,9 @@ void _gtk_theming_engine_paint_spinner (cairo_t *cr,
                                         GdkRGBA *color);
 
 GtkCssValue  *_gtk_theming_engine_peek_property (GtkThemingEngine *engine,
-                                                 const char       *property_name);
+                                                 guint             property_id);
 double        _gtk_theming_engine_get_number    (GtkThemingEngine *engine,
-                                                 const char       *property_name,
+                                                 guint             property_id,
                                                  double            one_hundred_percent);
 void          _gtk_theming_engine_set_context   (GtkThemingEngine *engine,
                                                  GtkStyleContext  *context);



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