mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 14:30:15 +00:00
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().
This commit is contained in:
parent
83c66c9c2c
commit
25271fe781
@ -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:
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user