[gtk+] cssnumbervalue: Remove gtk_css_number_value_get_unit()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssnumbervalue: Remove gtk_css_number_value_get_unit()
- Date: Sat, 13 Feb 2016 03:49:34 +0000 (UTC)
commit e2d966eda52ed8833ebdafdc7d6d43284a503453
Author: Benjamin Otte <otte redhat com>
Date: Fri Feb 12 04:40:35 2016 +0100
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.
gtk/gtkcssimageradial.c | 2 +-
gtk/gtkcssnumbervalue.c | 16 +++++++++++---
gtk/gtkcssnumbervalueprivate.h | 4 ++-
gtk/gtkcssshorthandpropertyimpl.c | 2 +-
gtk/gtkcsstypes.c | 38 +++++++++++++++++++++++++++++++++++++
gtk/gtkcsstypesprivate.h | 10 +++++++++
gtk/gtkrenderborder.c | 4 +-
7 files changed, 67 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcssimageradial.c b/gtk/gtkcssimageradial.c
index f52fef1..8febdc4 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 d32bff5..86b4c40 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 b9bb699..454374b 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 4e5495f..f10a180 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 2e93cbc..45e6caf 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 b89ada1..857c823 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -342,6 +342,14 @@ typedef enum /*< skip >*/ {
} 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,
/* CSS term: <percentage> */
@@ -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 6940f6f..47fdba4 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]