summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2012-10-01 18:21:30 +0200
committerBenjamin Otte <otte@redhat.com>2012-10-02 14:16:35 +0200
commit25271fe781df135b72c9e95a6551d6f4017d9c1b (patch)
tree63ec12628ca1f01d8c070ed7749870b82a829665
parent83c66c9c2cf6bf411f7d5ae3c89259203626173a (diff)
downloadgtk+-25271fe781df135b72c9e95a6551d6f4017d9c1b.tar.gz
css: Move special case code for border widths
We need to store the border widths independant of them being set to 0 by border styles, because otherwise we'd need to track that dependency and recompute on changes, and I don't want to add more entries to GtkCssDependencies just for this special case. By moving the code that does the setting to 0 from the compute stage to the query stage, we can achieve this. Now we need to just be aware that the actual value stored is not set to 0 when we use gtk_css_computed_values_get_value().
-rw-r--r--gtk/gtkcssnumbervalue.c34
-rw-r--r--gtk/gtkcssstyleproperty.c62
2 files changed, 62 insertions, 34 deletions
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index 58f4652511..8d7eaa96ee 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -42,40 +42,6 @@ gtk_css_value_number_compute (GtkCssValue *number,
GtkCssComputedValues *parent_values,
GtkCssDependencies *dependencies)
{
- GtkBorderStyle border_style;
-
- /* I don't like this special case being here in this generic code path, but no idea where else to put it. */
- switch (property_id)
- {
- case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
- border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
- if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
- return _gtk_css_number_value_new (0, GTK_CSS_PX);
- break;
- case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
- border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
- if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
- return _gtk_css_number_value_new (0, GTK_CSS_PX);
- break;
- case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
- border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
- if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
- return _gtk_css_number_value_new (0, GTK_CSS_PX);
- break;
- case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
- border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
- if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
- return _gtk_css_number_value_new (0, GTK_CSS_PX);
- break;
- case GTK_CSS_PROPERTY_OUTLINE_WIDTH:
- border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_OUTLINE_STYLE));
- if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
- return _gtk_css_number_value_new (0, GTK_CSS_PX);
- break;
- default:
- break;
- }
-
switch (number->unit)
{
default:
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 98e137d01d..7bb1e688e2 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -21,6 +21,7 @@
#include "gtkcssstylepropertyprivate.h"
+#include "gtkcssenumvalueprivate.h"
#include "gtkcssinheritvalueprivate.h"
#include "gtkcssinitialvalueprivate.h"
#include "gtkcssstylefuncsprivate.h"
@@ -129,6 +130,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,
@@ -138,6 +196,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);