Commit dcd54e20 authored by Benjamin Otte's avatar Benjamin Otte

css: Remove GtkCssNumber

It's completely replaced by GtkCssNumberValue now.
parent 1b69f1d7
......@@ -21,6 +21,7 @@
#define __GTK_CSS_BORDER_VALUE_PRIVATE_H__
#include "gtkcssparserprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssvalueprivate.h"
G_BEGIN_DECLS
......
......@@ -127,20 +127,6 @@ _gtk_css_number_value_new (double value,
return result;
}
GtkCssValue *
_gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags)
{
GtkCssNumber number;
g_return_val_if_fail (parser != NULL, NULL);
if (!_gtk_css_parser_read_number (parser, &number, flags))
return NULL;
return _gtk_css_number_value_new (number.value, number.unit);
}
GtkCssUnit
_gtk_css_number_value_get_unit (const GtkCssValue *value)
{
......
......@@ -26,8 +26,19 @@
G_BEGIN_DECLS
typedef enum /*< skip >*/ {
GTK_CSS_POSITIVE_ONLY = (1 << 0),
GTK_CSS_PARSE_PERCENT = (1 << 1),
GTK_CSS_PARSE_NUMBER = (1 << 2),
GTK_CSS_NUMBER_AS_PIXELS = (1 << 3),
GTK_CSS_PARSE_LENGTH = (1 << 4),
GTK_CSS_PARSE_ANGLE = (1 << 5),
GTK_CSS_PARSE_TIME = (1 << 6)
} GtkCssNumberParseFlags;
GtkCssValue * _gtk_css_number_value_new (double value,
GtkCssUnit unit);
/* This function implemented in gtkcssparser.c */
GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags);
......
......@@ -18,6 +18,8 @@
#include "config.h"
#include "gtkcssparserprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkwin32themeprivate.h"
#include <errno.h>
......@@ -551,9 +553,8 @@ _gtk_css_parser_has_number (GtkCssParser *parser)
return strchr ("+-0123456789.", parser->data[0]) != NULL;
}
gboolean
_gtk_css_parser_read_number (GtkCssParser *parser,
GtkCssNumber *number,
GtkCssValue *
_gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags)
{
static const struct {
......@@ -576,94 +577,98 @@ _gtk_css_parser_read_number (GtkCssParser *parser,
{ "s", GTK_CSS_S, GTK_CSS_PARSE_TIME },
{ "ms", GTK_CSS_MS, GTK_CSS_PARSE_TIME }
};
char *end, *unit;
char *end, *unit_name;
double value;
GtkCssUnit unit;
g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
g_return_val_if_fail (number != NULL, FALSE);
g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), NULL);
errno = 0;
number->unit = GTK_CSS_NUMBER;
number->value = g_ascii_strtod (parser->data, &end);
value = g_ascii_strtod (parser->data, &end);
if (errno)
{
_gtk_css_parser_error (parser, "not a number: %s", g_strerror (errno));
return FALSE;
return NULL;
}
if (parser->data == end)
{
_gtk_css_parser_error (parser, "not a number");
return FALSE;
return NULL;
}
parser->data = end;
if (flags & GTK_CSS_POSITIVE_ONLY &&
number->value < 0)
value < 0)
{
_gtk_css_parser_error (parser, "negative values are not allowed.");
return FALSE;
return NULL;
}
unit = _gtk_css_parser_try_ident (parser, FALSE);
unit_name = _gtk_css_parser_try_ident (parser, FALSE);
if (unit)
if (unit_name)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (units); i++)
{
if (flags & units[i].required_flags &&
g_ascii_strcasecmp (unit, units[i].name) == 0)
g_ascii_strcasecmp (unit_name, units[i].name) == 0)
break;
}
g_free (unit_name);
if (i >= G_N_ELEMENTS (units))
{
_gtk_css_parser_error (parser, "`%s' is not a valid unit.", unit);
g_free (unit);
return FALSE;
_gtk_css_parser_error (parser, "`%s' is not a valid unit.", unit_name);
return NULL;
}
number->unit = units[i].unit;
g_free (unit);
unit = units[i].unit;
}
else
{
if ((flags & GTK_CSS_PARSE_PERCENT) &&
_gtk_css_parser_try (parser, "%", FALSE))
{
number->unit = GTK_CSS_PERCENT;
unit = GTK_CSS_PERCENT;
}
else if (number->value == 0.0)
else if (value == 0.0)
{
if (flags & GTK_CSS_PARSE_NUMBER)
number->unit = GTK_CSS_NUMBER;
unit = GTK_CSS_NUMBER;
else if (flags & GTK_CSS_PARSE_LENGTH)
number->unit = GTK_CSS_PX;
unit = GTK_CSS_PX;
else if (flags & GTK_CSS_PARSE_ANGLE)
unit = GTK_CSS_DEG;
else if (flags & GTK_CSS_PARSE_TIME)
unit = GTK_CSS_S;
else
number->unit = GTK_CSS_PERCENT;
unit = GTK_CSS_PERCENT;
}
else if (flags & GTK_CSS_NUMBER_AS_PIXELS)
{
_gtk_css_parser_error_full (parser,
GTK_CSS_PROVIDER_ERROR_DEPRECATED,
"Not using units is deprecated. Assuming 'px'.");
number->unit = GTK_CSS_PX;
unit = GTK_CSS_PX;
}
else if (flags & GTK_CSS_PARSE_NUMBER)
{
number->unit = GTK_CSS_NUMBER;
unit = GTK_CSS_NUMBER;
}
else
{
_gtk_css_parser_error (parser, "Unit is missing.");
return FALSE;
return NULL;
}
}
_gtk_css_parser_skip_whitespace (parser);
return TRUE;
return _gtk_css_number_value_new (value, unit);
}
/* XXX: we should introduce GtkCssLenght that deals with
......
......@@ -24,16 +24,6 @@
G_BEGIN_DECLS
typedef enum /*< skip >*/ {
GTK_CSS_POSITIVE_ONLY = (1 << 0),
GTK_CSS_PARSE_PERCENT = (1 << 1),
GTK_CSS_PARSE_NUMBER = (1 << 2),
GTK_CSS_NUMBER_AS_PIXELS = (1 << 3),
GTK_CSS_PARSE_LENGTH = (1 << 4),
GTK_CSS_PARSE_ANGLE = (1 << 5),
GTK_CSS_PARSE_TIME = (1 << 6)
} GtkCssNumberParseFlags;
typedef struct _GtkCssParser GtkCssParser;
typedef void (* GtkCssParserErrorFunc) (GtkCssParser *parser,
......@@ -93,9 +83,6 @@ gboolean _gtk_css_parser_try_enum (GtkCssParser *parser
int *value);
gboolean _gtk_css_parser_has_number (GtkCssParser *parser);
gboolean _gtk_css_parser_read_number (GtkCssParser *parser,
GtkCssNumber *number,
GtkCssNumberParseFlags flags);
char * _gtk_css_parser_read_string (GtkCssParser *parser);
char * _gtk_css_parser_read_value (GtkCssParser *parser);
GtkSymbolicColor *_gtk_css_parser_read_symbolic_color
......
......@@ -78,124 +78,3 @@ _gtk_css_change_for_child (GtkCssChange match)
return gtk_css_change_translate (match, table, G_N_ELEMENTS (table));
}
void
_gtk_css_number_init (GtkCssNumber *number,
double value,
GtkCssUnit unit)
{
number->value = value;
number->unit = unit;
}
gboolean
_gtk_css_number_equal (const GtkCssNumber *one,
const GtkCssNumber *two)
{
return one->unit == two->unit &&
one->value == two->value;
}
double
_gtk_css_number_get (const GtkCssNumber *number,
double one_hundred_percent)
{
if (number->unit == GTK_CSS_PERCENT)
return number->value * one_hundred_percent * 0.01;
else
return number->value;
}
gboolean
_gtk_css_number_compute (GtkCssNumber *dest,
const GtkCssNumber *src,
GtkStyleContext *context)
{
switch (src->unit)
{
default:
g_assert_not_reached();
/* fall through */
case GTK_CSS_PERCENT:
case GTK_CSS_NUMBER:
case GTK_CSS_PX:
case GTK_CSS_DEG:
dest->value = src->value;
dest->unit = src->unit;
break;
case GTK_CSS_PT:
dest->value = src->value * 96.0 / 72.0;
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_PC:
dest->value = src->value * 96.0 / 72.0 * 12.0;
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_IN:
dest->value = src->value * 96.0;
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_CM:
dest->value = src->value * 96.0 * 0.39370078740157477;
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_MM:
dest->value = src->value * 96.0 * 0.039370078740157477;
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_EM:
dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100);
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_EX:
/* for now we pretend ex is half of em */
dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100);
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_RAD:
dest->value = 360 * src->value / (2 * G_PI);
dest->unit = GTK_CSS_DEG;
break;
case GTK_CSS_GRAD:
dest->value = 360 * src->value / 400.0;
dest->unit = GTK_CSS_DEG;
break;
case GTK_CSS_TURN:
dest->value = 360 * src->value;
dest->unit = GTK_CSS_DEG;
break;
}
return !_gtk_css_number_equal (src, dest);
}
void
_gtk_css_number_print (const GtkCssNumber *number,
GString *string)
{
char buf[G_ASCII_DTOSTR_BUF_SIZE];
const char *names[] = {
/* [GTK_CSS_NUMBER] = */ "",
/* [GTK_CSS_PERCENT] = */ "%",
/* [GTK_CSS_PX] = */ "px",
/* [GTK_CSS_PT] = */ "pt",
/* [GTK_CSS_EM] = */ "em",
/* [GTK_CSS_EX] = */ "ex",
/* [GTK_CSS_PC] = */ "pc",
/* [GTK_CSS_IN] = */ "in",
/* [GTK_CSS_CM] = */ "cm",
/* [GTK_CSS_MM] = */ "mm",
/* [GTK_CSS_RAD] = */ "rad",
/* [GTK_CSS_DEG] = */ "deg",
/* [GTK_CSS_GRAD] = */ "grad",
/* [GTK_CSS_TURN] = */ "turn",
};
g_return_if_fail (number != NULL);
g_return_if_fail (string != NULL);
g_ascii_dtostr (buf, sizeof (buf), number->value);
g_string_append (string, buf);
if (number->value != 0.0)
g_string_append (string, names[number->unit]);
}
......@@ -159,30 +159,9 @@ typedef enum /*< skip >*/ {
GTK_CSS_MS,
} GtkCssUnit;
typedef struct _GtkCssNumber GtkCssNumber;
struct _GtkCssNumber {
gdouble value;
GtkCssUnit unit;
};
GtkCssChange _gtk_css_change_for_sibling (GtkCssChange match);
GtkCssChange _gtk_css_change_for_child (GtkCssChange match);
#define GTK_CSS_NUMBER_INIT(_value,_unit) { (_value), (_unit) }
void _gtk_css_number_init (GtkCssNumber *number,
double value,
GtkCssUnit unit);
gboolean _gtk_css_number_equal (const GtkCssNumber *one,
const GtkCssNumber *two);
double _gtk_css_number_get (const GtkCssNumber *number,
double one_hundred_percent);
gboolean _gtk_css_number_compute (GtkCssNumber *dest,
const GtkCssNumber *src,
GtkStyleContext *context);
void _gtk_css_number_print (const GtkCssNumber *number,
GString *string);
G_END_DECLS
......
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