diff --git a/gtk/gtkcssimageradial.c b/gtk/gtkcssimageradial.c index f52fef10d8..8febdc4d39 100644 --- a/gtk/gtkcssimageradial.c +++ b/gtk/gtkcssimageradial.c @@ -337,7 +337,7 @@ gtk_css_image_radial_parse (GtkCssImage *image, return FALSE; } - if (radial->sizes[0] && _gtk_css_number_value_get_unit (radial->sizes[0]) == GTK_CSS_PERCENT) + if (radial->sizes[0] && gtk_css_number_value_has_percent (radial->sizes[0])) { _gtk_css_parser_error (parser, "Circular gradient cannot have percentage as size"); return FALSE; diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c index d32bff54e1..86b4c40dc8 100644 --- a/gtk/gtkcssnumbervalue.c +++ b/gtk/gtkcssnumbervalue.c @@ -265,12 +265,20 @@ _gtk_css_number_value_new (double value, return result; } -GtkCssUnit -_gtk_css_number_value_get_unit (const GtkCssValue *value) +GtkCssDimension +gtk_css_number_value_get_dimension (const GtkCssValue *value) { - g_return_val_if_fail (value->class == >K_CSS_VALUE_NUMBER, GTK_CSS_NUMBER); + g_return_val_if_fail (value->class == >K_CSS_VALUE_NUMBER, GTK_CSS_DIMENSION_PERCENTAGE); - return value->unit; + return gtk_css_unit_get_dimension (value->unit); +} + +gboolean +gtk_css_number_value_has_percent (const GtkCssValue *value) +{ + g_return_val_if_fail (value->class == >K_CSS_VALUE_NUMBER, FALSE); + + return gtk_css_unit_get_dimension (value->unit) == GTK_CSS_DIMENSION_PERCENTAGE; } double diff --git a/gtk/gtkcssnumbervalueprivate.h b/gtk/gtkcssnumbervalueprivate.h index b9bb6994e6..454374bffe 100644 --- a/gtk/gtkcssnumbervalueprivate.h +++ b/gtk/gtkcssnumbervalueprivate.h @@ -42,7 +42,9 @@ GtkCssValue * _gtk_css_number_value_new (double val GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *parser, GtkCssNumberParseFlags flags); -GtkCssUnit _gtk_css_number_value_get_unit (const GtkCssValue *value); +GtkCssDimension gtk_css_number_value_get_dimension (const GtkCssValue *value); +gboolean gtk_css_number_value_has_percent (const GtkCssValue *value); + double _gtk_css_number_value_get (const GtkCssValue *number, double one_hundred_percent); diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c index 4e5495fca9..f10a180d3a 100644 --- a/gtk/gtkcssshorthandpropertyimpl.c +++ b/gtk/gtkcssshorthandpropertyimpl.c @@ -736,7 +736,7 @@ parse_one_animation (GtkCssShorthandProperty *shorthand, if (value == NULL) return FALSE; - if (_gtk_css_number_value_get_unit (value) == GTK_CSS_NUMBER) + if (gtk_css_number_value_get_dimension (value) == GTK_CSS_DIMENSION_NUMBER) values[1] = value; else if (values[2] == NULL) values[2] = value; diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c index 2e93cbca56..45e6caf8ee 100644 --- a/gtk/gtkcsstypes.c +++ b/gtk/gtkcsstypes.c @@ -138,6 +138,44 @@ gtk_css_change_print (GtkCssChange change, } } +GtkCssDimension +gtk_css_unit_get_dimension (GtkCssUnit unit) +{ + switch (unit) + { + case GTK_CSS_NUMBER: + return GTK_CSS_DIMENSION_NUMBER; + + case GTK_CSS_PERCENT: + return GTK_CSS_DIMENSION_PERCENTAGE; + + case GTK_CSS_PX: + case GTK_CSS_PT: + case GTK_CSS_EM: + case GTK_CSS_EX: + case GTK_CSS_REM: + case GTK_CSS_PC: + case GTK_CSS_IN: + case GTK_CSS_CM: + case GTK_CSS_MM: + return GTK_CSS_DIMENSION_LENGTH; + + case GTK_CSS_RAD: + case GTK_CSS_DEG: + case GTK_CSS_GRAD: + case GTK_CSS_TURN: + return GTK_CSS_DIMENSION_ANGLE; + + case GTK_CSS_S: + case GTK_CSS_MS: + return GTK_CSS_DIMENSION_TIME; + + default: + g_assert_not_reached (); + return GTK_CSS_DIMENSION_PERCENTAGE; + } +} + char * gtk_css_change_to_string (GtkCssChange change) { diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h index b89ada1f7d..857c823860 100644 --- a/gtk/gtkcsstypesprivate.h +++ b/gtk/gtkcsstypesprivate.h @@ -341,6 +341,14 @@ typedef enum /*< skip >*/ { GTK_CSS_BOTTOM_LEFT } GtkCssCorner; +typedef enum /*< skip >*/ { + GTK_CSS_DIMENSION_PERCENTAGE, + GTK_CSS_DIMENSION_NUMBER, + GTK_CSS_DIMENSION_LENGTH, + GTK_CSS_DIMENSION_ANGLE, + GTK_CSS_DIMENSION_TIME +} GtkCssDimension; + typedef enum /*< skip >*/ { /* CSS term: */ GTK_CSS_NUMBER, @@ -369,6 +377,8 @@ typedef enum /*< skip >*/ { GtkCssChange _gtk_css_change_for_sibling (GtkCssChange match); GtkCssChange _gtk_css_change_for_child (GtkCssChange match); +GtkCssDimension gtk_css_unit_get_dimension (GtkCssUnit unit); + char * gtk_css_change_to_string (GtkCssChange change); void gtk_css_change_print (GtkCssChange change, GString *string); diff --git a/gtk/gtkrenderborder.c b/gtk/gtkrenderborder.c index 6940f6f6de..47fdba43d4 100644 --- a/gtk/gtkrenderborder.c +++ b/gtk/gtkrenderborder.c @@ -83,11 +83,11 @@ gtk_border_image_compute_border_size (GtkBorderImageSliceSize sizes[3], { double start, end; - if (_gtk_css_number_value_get_unit (start_border) == GTK_CSS_NUMBER) + if (gtk_css_number_value_get_dimension (start_border) == GTK_CSS_DIMENSION_NUMBER) start = start_border_width * _gtk_css_number_value_get (start_border, 100); else start = _gtk_css_number_value_get (start_border, area_size); - if (_gtk_css_number_value_get_unit (end_border) == GTK_CSS_NUMBER) + if (gtk_css_number_value_get_dimension (end_border) == GTK_CSS_DIMENSION_NUMBER) end = end_border_width * _gtk_css_number_value_get (end_border, 100); else end = _gtk_css_number_value_get (end_border, area_size);