Commit e2d966ed authored by Benjamin Otte's avatar Benjamin Otte

cssnumbervalue: Remove gtk_css_number_value_get_unit()

This is in preparation for calc(), as calc(50% - 5px) is valid CSS
but has 2 units. Instead, add a function to query a value's dimension
(so we can differentiate lengths from numbers) and add a function to
query if the value contains percentages.
parent 7b301fce
......@@ -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;
......
......@@ -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 == &GTK_CSS_VALUE_NUMBER, GTK_CSS_NUMBER);
g_return_val_if_fail (value->class == &GTK_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 == &GTK_CSS_VALUE_NUMBER, FALSE);
return gtk_css_unit_get_dimension (value->unit) == GTK_CSS_DIMENSION_PERCENTAGE;
}
double
......
......@@ -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);
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -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: <number> */
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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment