[gtk+/wip/cssdep: 3/21] css: Fold color value computation into gtksymboliccolor.c
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssdep: 3/21] css: Fold color value computation into gtksymboliccolor.c
- Date: Sat, 25 Aug 2012 08:36:11 +0000 (UTC)
commit 1fcb46569a0ec44748a90d0ef4559690afd02dae
Author: Benjamin Otte <otte redhat com>
Date: Sat Jul 14 20:24:46 2012 +0200
css: Fold color value computation into gtksymboliccolor.c
This gets rid of the public function
_gtk_css_rgba_value_compute_from_symbolic().
The fallback is now handled using a switch statement instead of letting
the caller pass the function.
gtk/gtkcssimagelinear.c | 10 +------
gtk/gtkcssrgbavalue.c | 38 ------------------------
gtk/gtkcssrgbavalueprivate.h | 6 ----
gtk/gtkcssshadowvalue.c | 12 +-------
gtk/gtkcssstylepropertyimpl.c | 14 +--------
gtk/gtksymboliccolor.c | 63 ++++++++++++++++++++++++++++++++++++++--
6 files changed, 63 insertions(+), 80 deletions(-)
---
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index e644023..10977e8 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -413,10 +413,8 @@ gtk_css_image_linear_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
{
- static const GdkRGBA transparent = { 0, 0, 0, 0 };
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
GtkCssImageLinear *copy;
- GtkCssValue *fallback;
guint i;
copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
@@ -424,7 +422,6 @@ gtk_css_image_linear_compute (GtkCssImage *image,
copy->angle = _gtk_css_value_compute (linear->angle, property_id, context);
- fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
g_array_set_size (copy->stops, linear->stops->len);
for (i = 0; i < linear->stops->len; i++)
{
@@ -433,10 +430,7 @@ gtk_css_image_linear_compute (GtkCssImage *image,
stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i);
- scopy->color = _gtk_css_rgba_value_compute_from_symbolic (stop->color,
- fallback,
- context,
- FALSE);
+ scopy->color = _gtk_css_value_compute (stop->color, property_id, context);
if (stop->offset)
scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context);
@@ -444,8 +438,6 @@ gtk_css_image_linear_compute (GtkCssImage *image,
scopy->offset = NULL;
}
- _gtk_css_value_unref (fallback);
-
return GTK_CSS_IMAGE (copy);
}
diff --git a/gtk/gtkcssrgbavalue.c b/gtk/gtkcssrgbavalue.c
index fc1642c..7a641a3 100644
--- a/gtk/gtkcssrgbavalue.c
+++ b/gtk/gtkcssrgbavalue.c
@@ -102,41 +102,3 @@ _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
return &rgba->rgba;
}
-
-GtkCssValue *
-_gtk_css_rgba_value_compute_from_symbolic (GtkCssValue *symbolic,
- GtkCssValue *fallback,
- GtkStyleContext *context,
- gboolean for_color_property)
-{
- GtkCssValue *resolved, *current;
-
- g_return_val_if_fail (symbolic != NULL, NULL);
-
- /* The computed value of the âcurrentColorâ keyword is the computed
- * value of the âcolorâ property. If the âcurrentColorâ keyword is
- * set on the âcolorâ property itself, it is treated as âcolor: inheritâ.
- */
- if (for_color_property)
- {
- GtkStyleContext *parent = gtk_style_context_get_parent (context);
-
- if (parent)
- current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
- else
- current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
- }
- else
- {
- current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
- }
-
- resolved = _gtk_style_context_resolve_color_value (context, current, symbolic);
-
- if (resolved == NULL)
- return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, for_color_property);
-
- g_assert (resolved->class == >K_CSS_VALUE_RGBA);
- return resolved;
-}
-
diff --git a/gtk/gtkcssrgbavalueprivate.h b/gtk/gtkcssrgbavalueprivate.h
index 539473f..4a2909d 100644
--- a/gtk/gtkcssrgbavalueprivate.h
+++ b/gtk/gtkcssrgbavalueprivate.h
@@ -28,12 +28,6 @@ G_BEGIN_DECLS
GtkCssValue * _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba);
-GtkCssValue * _gtk_css_rgba_value_compute_from_symbolic
- (GtkCssValue *symbolic,
- GtkCssValue *fallback,
- GtkStyleContext *context,
- gboolean for_color_property);
-
const GdkRGBA * _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba);
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index dfd3b1c..3351d6f 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -64,22 +64,12 @@ gtk_css_value_shadow_compute (GtkCssValue *shadow,
guint property_id,
GtkStyleContext *context)
{
- GdkRGBA transparent = { 0, 0, 0, 0 };
- GtkCssValue *color, *fallback;
-
- fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
- color = _gtk_css_rgba_value_compute_from_symbolic (shadow->color,
- fallback,
- context,
- FALSE);
- _gtk_css_value_unref (fallback);
-
return gtk_css_shadow_value_new (_gtk_css_value_compute (shadow->hoffset, property_id, context),
_gtk_css_value_compute (shadow->voffset, property_id, context),
_gtk_css_value_compute (shadow->radius, property_id, context),
_gtk_css_value_compute (shadow->spread, property_id, context),
shadow->inset,
- color);
+ _gtk_css_value_compute (shadow->color, property_id, context));
}
static gboolean
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 162ab3a..bf7fa99 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -185,10 +185,7 @@ color_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
- return _gtk_css_rgba_value_compute_from_symbolic (specified,
- _gtk_css_style_property_get_initial_value (property),
- context,
- FALSE);
+ return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@@ -196,14 +193,7 @@ color_property_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
- GtkCssValue *value;
-
- value = _gtk_css_rgba_value_compute_from_symbolic (specified,
- _gtk_css_style_property_get_initial_value (property),
- context,
- TRUE);
- _gtk_css_rgba_value_get_rgba (value);
- return value;
+ return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static void
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index fe8656d..8429bbc 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -17,6 +17,8 @@
#include "config.h"
#include "gtkcssrgbavalueprivate.h"
+#include "gtkcssstylepropertyprivate.h"
+#include "gtkstylepropertyprivate.h"
#include "gtksymboliccolorprivate.h"
#include "gtkstyleproperties.h"
#include "gtkintl.h"
@@ -118,15 +120,68 @@ gtk_css_value_symbolic_free (GtkCssValue *value)
}
static GtkCssValue *
+gtk_css_value_symbolic_get_fallback (guint property_id,
+ GtkStyleContext *context)
+{
+ static const GdkRGBA transparent = { 0, 0, 0, 0 };
+
+ switch (property_id)
+ {
+ case GTK_CSS_PROPERTY_BACKGROUND_IMAGE:
+ case GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE:
+ case GTK_CSS_PROPERTY_TEXT_SHADOW:
+ case GTK_CSS_PROPERTY_ICON_SHADOW:
+ case GTK_CSS_PROPERTY_BOX_SHADOW:
+ return _gtk_css_rgba_value_new_from_rgba (&transparent);
+ case GTK_CSS_PROPERTY_COLOR:
+ case GTK_CSS_PROPERTY_BACKGROUND_COLOR:
+ case GTK_CSS_PROPERTY_BORDER_TOP_COLOR:
+ case GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR:
+ case GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR:
+ case GTK_CSS_PROPERTY_BORDER_LEFT_COLOR:
+ case GTK_CSS_PROPERTY_OUTLINE_COLOR:
+ return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
+ property_id,
+ context);
+ default:
+ if (property_id < GTK_CSS_PROPERTY_N_PROPERTIES)
+ g_warning ("No fallback color defined for property '%s'",
+ _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (property_id))));
+ return _gtk_css_rgba_value_new_from_rgba (&transparent);
+ }
+}
+
+static GtkCssValue *
gtk_css_value_symbolic_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
- /* for now we expect this to never be called
- * because all cases are handled via
- * _gtk_css_rgba_value_compute_from_symbolic()
+ GtkCssValue *resolved, *current;
+
+ /* The computed value of the âcurrentColorâ keyword is the computed
+ * value of the âcolorâ property. If the âcurrentColorâ keyword is
+ * set on the âcolorâ property itself, it is treated as âcolor: inheritâ.
*/
- g_return_val_if_reached (_gtk_css_value_ref (value));
+ if (property_id == GTK_CSS_PROPERTY_COLOR)
+ {
+ GtkStyleContext *parent = gtk_style_context_get_parent (context);
+
+ if (parent)
+ current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
+ else
+ current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
+ }
+ else
+ {
+ current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
+ }
+
+ resolved = _gtk_style_context_resolve_color_value (context, current, value);
+
+ if (resolved == NULL)
+ return gtk_css_value_symbolic_get_fallback (property_id, context);
+
+ return resolved;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]