mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-18 09:00:34 +00:00
cssvalue: Split number values into their own class
This commit is contained in:
parent
f7c0c7677b
commit
a33df2d1d6
@ -435,6 +435,7 @@ gtk_private_h_sources = \
|
||||
gtkcssinitialvalueprivate.h \
|
||||
gtkcsslookupprivate.h \
|
||||
gtkcssmatcherprivate.h \
|
||||
gtkcssnumbervalueprivate.h \
|
||||
gtkcssparserprivate.h \
|
||||
gtkcssproviderprivate.h \
|
||||
gtkcsssectionprivate.h \
|
||||
@ -635,6 +636,7 @@ gtk_base_c_sources = \
|
||||
gtkcssinitialvalue.c \
|
||||
gtkcsslookup.c \
|
||||
gtkcssmatcher.c \
|
||||
gtkcssnumbervalue.c \
|
||||
gtkcssparser.c \
|
||||
gtkcssprovider.c \
|
||||
gtkcsssection.c \
|
||||
|
194
gtk/gtkcssnumbervalue.c
Normal file
194
gtk/gtkcssnumbervalue.c
Normal file
@ -0,0 +1,194 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
|
||||
#include "gtkstylepropertyprivate.h"
|
||||
|
||||
struct _GtkCssValue {
|
||||
GTK_CSS_VALUE_BASE
|
||||
GtkCssUnit unit;
|
||||
double value;
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_css_value_number_free (GtkCssValue *value)
|
||||
{
|
||||
g_slice_free (GtkCssValue, value);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_value_number_equal (const GtkCssValue *number1,
|
||||
const GtkCssValue *number2)
|
||||
{
|
||||
return number1->unit == number2->unit &&
|
||||
number1->value == number2->value;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_value_number_print (const GtkCssValue *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_ascii_dtostr (buf, sizeof (buf), number->value);
|
||||
g_string_append (string, buf);
|
||||
if (number->value != 0.0)
|
||||
g_string_append (string, names[number->unit]);
|
||||
}
|
||||
|
||||
static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = {
|
||||
gtk_css_value_number_free,
|
||||
gtk_css_value_number_equal,
|
||||
gtk_css_value_number_print
|
||||
};
|
||||
|
||||
GtkCssValue *
|
||||
_gtk_css_number_value_new (double value,
|
||||
GtkCssUnit unit)
|
||||
{
|
||||
static GtkCssValue zero_singleton = { >K_CSS_VALUE_NUMBER, 1, GTK_CSS_NUMBER, 0 };
|
||||
static GtkCssValue px_singletons[] = {
|
||||
{ >K_CSS_VALUE_NUMBER, 1, GTK_CSS_PX, 0 },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, GTK_CSS_PX, 1 },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, GTK_CSS_PX, 2 },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, GTK_CSS_PX, 3 },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, GTK_CSS_PX, 4 },
|
||||
};
|
||||
GtkCssValue *result;
|
||||
|
||||
if (unit == GTK_CSS_NUMBER && value == 0)
|
||||
return _gtk_css_value_ref (&zero_singleton);
|
||||
|
||||
if (unit == GTK_CSS_PX &&
|
||||
(value == 0 ||
|
||||
value == 1 ||
|
||||
value == 2 ||
|
||||
value == 3 ||
|
||||
value == 4))
|
||||
{
|
||||
return _gtk_css_value_ref (&px_singletons[(int) value]);
|
||||
}
|
||||
|
||||
result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_NUMBER);
|
||||
result->unit = unit;
|
||||
result->value = 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);
|
||||
}
|
||||
|
||||
double
|
||||
_gtk_css_number_value_get (const GtkCssValue *number,
|
||||
double one_hundred_percent)
|
||||
{
|
||||
g_return_val_if_fail (number != NULL, 0.0);
|
||||
g_return_val_if_fail (number->class == >K_CSS_VALUE_NUMBER, 0.0);
|
||||
|
||||
if (number->unit == GTK_CSS_PERCENT)
|
||||
return number->value * one_hundred_percent / 100;
|
||||
else
|
||||
return number->value;
|
||||
}
|
||||
|
||||
GtkCssValue *
|
||||
_gtk_css_number_value_compute (GtkCssValue *number,
|
||||
GtkStyleContext *context)
|
||||
{
|
||||
g_return_val_if_fail (number->class == >K_CSS_VALUE_NUMBER, NULL);
|
||||
|
||||
switch (number->unit)
|
||||
{
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
/* fall through */
|
||||
case GTK_CSS_PERCENT:
|
||||
case GTK_CSS_NUMBER:
|
||||
case GTK_CSS_PX:
|
||||
case GTK_CSS_DEG:
|
||||
return _gtk_css_value_ref (number);
|
||||
case GTK_CSS_PT:
|
||||
return _gtk_css_number_value_new (number->value * 96.0 / 72.0,
|
||||
GTK_CSS_PX);
|
||||
case GTK_CSS_PC:
|
||||
return _gtk_css_number_value_new (number->value * 96.0 / 72.0 * 12.0,
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
case GTK_CSS_IN:
|
||||
return _gtk_css_number_value_new (number->value * 96.0,
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
case GTK_CSS_CM:
|
||||
return _gtk_css_number_value_new (number->value * 96.0 * 0.39370078740157477,
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
case GTK_CSS_MM:
|
||||
return _gtk_css_number_value_new (number->value * 96.0 * 0.039370078740157477,
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
case GTK_CSS_EM:
|
||||
return _gtk_css_number_value_new (number->value * _gtk_css_value_get_double (_gtk_style_context_peek_property (context, "font-size")),
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
case GTK_CSS_EX:
|
||||
/* for now we pretend ex is half of em */
|
||||
return _gtk_css_number_value_new (number->value * 0.5 * _gtk_css_value_get_double (_gtk_style_context_peek_property (context, "font-size")),
|
||||
GTK_CSS_PX);
|
||||
case GTK_CSS_RAD:
|
||||
return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI),
|
||||
GTK_CSS_DEG);
|
||||
case GTK_CSS_GRAD:
|
||||
return _gtk_css_number_value_new (number->value * 360.0 / 400.0,
|
||||
GTK_CSS_DEG);
|
||||
case GTK_CSS_TURN:
|
||||
return _gtk_css_number_value_new (number->value * 360.0,
|
||||
GTK_CSS_DEG);
|
||||
}
|
||||
}
|
||||
|
42
gtk/gtkcssnumbervalueprivate.h
Normal file
42
gtk/gtkcssnumbervalueprivate.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright © 2012 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Alexander Larsson <alexl@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_CSS_NUMBER_VALUE_PRIVATE_H__
|
||||
#define __GTK_CSS_NUMBER_VALUE_PRIVATE_H__
|
||||
|
||||
#include "gtkcssparserprivate.h"
|
||||
#include "gtkcsstypesprivate.h"
|
||||
#include "gtkcssvalueprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GtkCssValue * _gtk_css_number_value_new (double value,
|
||||
GtkCssUnit unit);
|
||||
GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *parser,
|
||||
GtkCssNumberParseFlags flags);
|
||||
|
||||
double _gtk_css_number_value_get (const GtkCssValue *number,
|
||||
double one_hundred_percent);
|
||||
GtkCssValue * _gtk_css_number_value_compute (GtkCssValue *number,
|
||||
GtkStyleContext *context);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CSS_NUMBER_VALUE_PRIVATE_H__ */
|
@ -25,13 +25,14 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "gtkcssimageprivate.h"
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtkcssstylefuncsprivate.h"
|
||||
#include "gtkcsstypesprivate.h"
|
||||
#include "gtkcssvalueprivate.h"
|
||||
#include "gtkprivatetypebuiltins.h"
|
||||
#include "gtkstylepropertiesprivate.h"
|
||||
#include "gtksymboliccolorprivate.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkcssvalueprivate.h"
|
||||
|
||||
/* this is in case round() is not provided by the compiler,
|
||||
* such as in the case of C89 compilers, like MSVC
|
||||
@ -54,7 +55,6 @@ parse_four_numbers (GtkCssShorthandProperty *shorthand,
|
||||
GtkCssParser *parser,
|
||||
GtkCssNumberParseFlags flags)
|
||||
{
|
||||
GtkCssNumber numbers[4];
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
@ -62,9 +62,8 @@ parse_four_numbers (GtkCssShorthandProperty *shorthand,
|
||||
if (!_gtk_css_parser_has_number (parser))
|
||||
break;
|
||||
|
||||
if (!_gtk_css_parser_read_number (parser,
|
||||
&numbers[i],
|
||||
flags))
|
||||
values[i] = _gtk_css_number_value_parse (parser, flags);
|
||||
if (values[i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -76,12 +75,7 @@ parse_four_numbers (GtkCssShorthandProperty *shorthand,
|
||||
|
||||
for (; i < 4; i++)
|
||||
{
|
||||
numbers[i] = numbers[(i - 1) >> 1];
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
values[i] = _gtk_css_value_new_from_number (&numbers[i]);
|
||||
values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -330,15 +324,12 @@ parse_border_side (GtkCssShorthandProperty *shorthand,
|
||||
if (values[0] == NULL &&
|
||||
_gtk_css_parser_has_number (parser))
|
||||
{
|
||||
GtkCssNumber number;
|
||||
if (!_gtk_css_parser_read_number (parser,
|
||||
&number,
|
||||
values[0] = _gtk_css_number_value_parse (parser,
|
||||
GTK_CSS_POSITIVE_ONLY
|
||||
| GTK_CSS_NUMBER_AS_PIXELS
|
||||
| GTK_CSS_PARSE_LENGTH))
|
||||
| GTK_CSS_PARSE_LENGTH);
|
||||
if (values[0] == NULL)
|
||||
return FALSE;
|
||||
|
||||
values[0] = _gtk_css_value_new_from_number (&number);
|
||||
}
|
||||
else if (values[1] == NULL &&
|
||||
_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, &style))
|
||||
@ -381,15 +372,12 @@ parse_border (GtkCssShorthandProperty *shorthand,
|
||||
if (values[0] == NULL &&
|
||||
_gtk_css_parser_has_number (parser))
|
||||
{
|
||||
GtkCssNumber number;
|
||||
if (!_gtk_css_parser_read_number (parser,
|
||||
&number,
|
||||
values[0] = _gtk_css_number_value_parse (parser,
|
||||
GTK_CSS_POSITIVE_ONLY
|
||||
| GTK_CSS_NUMBER_AS_PIXELS
|
||||
| GTK_CSS_PARSE_LENGTH))
|
||||
| GTK_CSS_PARSE_LENGTH);
|
||||
if (values[0] == NULL)
|
||||
return FALSE;
|
||||
|
||||
values[0] = _gtk_css_value_new_from_number (&number);
|
||||
values[1] = _gtk_css_value_ref (values[0]);
|
||||
values[2] = _gtk_css_value_ref (values[0]);
|
||||
values[3] = _gtk_css_value_ref (values[0]);
|
||||
|
@ -935,13 +935,6 @@ border_image_repeat_value_print (const GValue *value,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
css_number_print (const GValue *value,
|
||||
GString *string)
|
||||
{
|
||||
_gtk_css_number_print (g_value_get_boxed (value), string);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
enum_value_parse (GtkCssParser *parser,
|
||||
GFile *base,
|
||||
@ -1113,10 +1106,6 @@ gtk_css_style_funcs_init (void)
|
||||
border_image_repeat_value_parse,
|
||||
border_image_repeat_value_print,
|
||||
NULL);
|
||||
register_conversion_function (GTK_TYPE_CSS_NUMBER,
|
||||
NULL,
|
||||
css_number_print,
|
||||
NULL);
|
||||
register_conversion_function (G_TYPE_ENUM,
|
||||
enum_value_parse,
|
||||
enum_value_print,
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "gtkcssimagegradientprivate.h"
|
||||
#include "gtkcssimageprivate.h"
|
||||
#include "gtkcssimageprivate.h"
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtkgradient.h"
|
||||
#include "gtkshadowprivate.h"
|
||||
#include "gtksymboliccolorprivate.h"
|
||||
@ -143,7 +144,7 @@ query_length_as_int (GtkCssStyleProperty *property,
|
||||
GValue *value)
|
||||
{
|
||||
g_value_init (value, G_TYPE_INT);
|
||||
g_value_set_int (value, round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100)));
|
||||
g_value_set_int (value, round (_gtk_css_number_value_get (css_value, 100)));
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
@ -814,15 +815,9 @@ parse_margin (GtkCssStyleProperty *property,
|
||||
GtkCssParser *parser,
|
||||
GFile *base)
|
||||
{
|
||||
GtkCssNumber number;
|
||||
|
||||
if (!_gtk_css_parser_read_number (parser,
|
||||
&number,
|
||||
return _gtk_css_number_value_parse (parser,
|
||||
GTK_CSS_NUMBER_AS_PIXELS
|
||||
| GTK_CSS_PARSE_LENGTH))
|
||||
return NULL;
|
||||
|
||||
return _gtk_css_value_new_from_number (&number);
|
||||
| GTK_CSS_PARSE_LENGTH);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
@ -830,15 +825,7 @@ compute_margin (GtkCssStyleProperty *property,
|
||||
GtkStyleContext *context,
|
||||
GtkCssValue *specified)
|
||||
{
|
||||
GtkCssNumber number;
|
||||
|
||||
if (_gtk_css_number_compute (&number,
|
||||
_gtk_css_value_get_number (specified),
|
||||
context))
|
||||
{
|
||||
return _gtk_css_value_new_from_number (&number);
|
||||
}
|
||||
return _gtk_css_value_ref (specified);
|
||||
return _gtk_css_number_value_compute (specified, context);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
@ -846,16 +833,10 @@ parse_padding (GtkCssStyleProperty *property,
|
||||
GtkCssParser *parser,
|
||||
GFile *base)
|
||||
{
|
||||
GtkCssNumber number;
|
||||
|
||||
if (!_gtk_css_parser_read_number (parser,
|
||||
&number,
|
||||
return _gtk_css_number_value_parse (parser,
|
||||
GTK_CSS_POSITIVE_ONLY
|
||||
| GTK_CSS_NUMBER_AS_PIXELS
|
||||
| GTK_CSS_PARSE_LENGTH))
|
||||
return NULL;
|
||||
|
||||
return _gtk_css_value_new_from_number (&number);
|
||||
| GTK_CSS_PARSE_LENGTH);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
@ -863,13 +844,7 @@ compute_padding (GtkCssStyleProperty *property,
|
||||
GtkStyleContext *context,
|
||||
GtkCssValue *specified)
|
||||
{
|
||||
GtkCssNumber number;
|
||||
|
||||
if (_gtk_css_number_compute (&number,
|
||||
_gtk_css_value_get_number (specified),
|
||||
context))
|
||||
return _gtk_css_value_new_from_number (&number);
|
||||
return _gtk_css_value_ref (specified);
|
||||
return _gtk_css_number_value_compute (specified, context);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
@ -877,16 +852,10 @@ parse_border_width (GtkCssStyleProperty *property,
|
||||
GtkCssParser *parser,
|
||||
GFile *base)
|
||||
{
|
||||
GtkCssNumber number;
|
||||
|
||||
if (!_gtk_css_parser_read_number (parser,
|
||||
&number,
|
||||
return _gtk_css_number_value_parse (parser,
|
||||
GTK_CSS_POSITIVE_ONLY
|
||||
| GTK_CSS_NUMBER_AS_PIXELS
|
||||
| GTK_CSS_PARSE_LENGTH))
|
||||
return FALSE;
|
||||
|
||||
return _gtk_css_value_new_from_number (&number);
|
||||
| GTK_CSS_PARSE_LENGTH);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
@ -896,7 +865,6 @@ compute_border_width (GtkCssStyleProperty *property,
|
||||
{
|
||||
GtkCssStyleProperty *style;
|
||||
GtkBorderStyle border_style;
|
||||
GtkCssNumber number;
|
||||
|
||||
/* The -1 is magic that is only true because we register the style
|
||||
* properties directly after the width properties.
|
||||
@ -907,16 +875,9 @@ compute_border_width (GtkCssStyleProperty *property,
|
||||
|
||||
if (border_style == GTK_BORDER_STYLE_NONE ||
|
||||
border_style == GTK_BORDER_STYLE_HIDDEN)
|
||||
{
|
||||
_gtk_css_number_init (&number, 0, GTK_CSS_PX);
|
||||
}
|
||||
return _gtk_css_number_value_new (0, GTK_CSS_PX);
|
||||
else
|
||||
{
|
||||
_gtk_css_number_compute (&number,
|
||||
_gtk_css_value_get_number (specified),
|
||||
context);
|
||||
}
|
||||
return _gtk_css_value_new_from_number (&number);
|
||||
return _gtk_css_number_value_compute (specified, context);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
@ -1261,7 +1222,6 @@ void
|
||||
_gtk_css_style_property_init_properties (void)
|
||||
{
|
||||
char *default_font_family[] = { "Sans", NULL };
|
||||
GtkCssNumber number;
|
||||
GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE };
|
||||
GtkCssBackgroundPosition default_background_position = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT)};
|
||||
GtkCssBorderCornerRadius no_corner_radius = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX) };
|
||||
@ -1376,7 +1336,6 @@ _gtk_css_style_property_init_properties (void)
|
||||
NULL,
|
||||
_gtk_css_value_new_take_shadow (NULL));
|
||||
|
||||
_gtk_css_number_init (&number, 0, GTK_CSS_PX);
|
||||
gtk_css_style_property_register ("margin-top",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1385,7 +1344,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_margin,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("margin-left",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1394,7 +1353,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_margin,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("margin-bottom",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1403,7 +1362,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_margin,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("margin-right",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1412,7 +1371,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_margin,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("padding-top",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1421,7 +1380,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_padding,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("padding-left",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1430,7 +1389,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_padding,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("padding-bottom",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1439,7 +1398,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_padding,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("padding-right",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
@ -1448,7 +1407,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_padding,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
/* IMPORTANT: compute_border_width() requires that the border-width
|
||||
* properties be immeditaly followed by the border-style properties
|
||||
*/
|
||||
@ -1469,7 +1428,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_border_width,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("border-left-style",
|
||||
GTK_TYPE_BORDER_STYLE,
|
||||
0,
|
||||
@ -1487,7 +1446,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_border_width,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("border-bottom-style",
|
||||
GTK_TYPE_BORDER_STYLE,
|
||||
0,
|
||||
@ -1505,7 +1464,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_border_width,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("border-right-style",
|
||||
GTK_TYPE_BORDER_STYLE,
|
||||
0,
|
||||
@ -1523,7 +1482,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_border_width,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
|
||||
gtk_css_style_property_register ("border-top-left-radius",
|
||||
GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
|
||||
@ -1579,7 +1538,7 @@ _gtk_css_style_property_init_properties (void)
|
||||
compute_border_width,
|
||||
query_length_as_int,
|
||||
NULL,
|
||||
_gtk_css_value_new_from_number (&number));
|
||||
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
|
||||
gtk_css_style_property_register ("outline-offset",
|
||||
G_TYPE_INT,
|
||||
0,
|
||||
|
@ -34,7 +34,6 @@ DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBackgroundSize, _gtk_css_background_size
|
||||
DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBackgroundPosition, _gtk_css_background_position)
|
||||
DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBorderCornerRadius, _gtk_css_border_corner_radius)
|
||||
DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBorderImageRepeat, _gtk_css_border_image_repeat)
|
||||
DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssNumber, _gtk_css_number)
|
||||
|
||||
typedef struct _GtkCssChangeTranslation GtkCssChangeTranslation;
|
||||
struct _GtkCssChangeTranslation {
|
||||
|
@ -160,13 +160,11 @@ struct _GtkCssBorderImageRepeat {
|
||||
#define GTK_TYPE_CSS_BACKGROUND_POSITION _gtk_css_background_position_get_type ()
|
||||
#define GTK_TYPE_CSS_BORDER_CORNER_RADIUS _gtk_css_border_corner_radius_get_type ()
|
||||
#define GTK_TYPE_CSS_BORDER_IMAGE_REPEAT _gtk_css_border_image_repeat_get_type ()
|
||||
#define GTK_TYPE_CSS_NUMBER _gtk_css_number_get_type ()
|
||||
|
||||
GType _gtk_css_background_size_get_type (void);
|
||||
GType _gtk_css_background_position_get_type (void);
|
||||
GType _gtk_css_border_corner_radius_get_type (void);
|
||||
GType _gtk_css_border_image_repeat_get_type (void);
|
||||
GType _gtk_css_number_get_type (void);
|
||||
|
||||
GtkCssChange _gtk_css_change_for_sibling (GtkCssChange match);
|
||||
GtkCssChange _gtk_css_change_for_child (GtkCssChange match);
|
||||
|
@ -130,8 +130,6 @@ _gtk_css_value_new_from_gvalue (const GValue *g_value)
|
||||
/* Make sure we reuse the int/number singletons */
|
||||
if (type == G_TYPE_INT)
|
||||
value = _gtk_css_value_new_from_int (g_value_get_int (g_value));
|
||||
else if (type == GTK_TYPE_CSS_NUMBER)
|
||||
value = _gtk_css_value_new_from_number (g_value_get_boxed (g_value));
|
||||
else
|
||||
{
|
||||
value = gtk_css_value_new (type);
|
||||
@ -315,49 +313,6 @@ _gtk_css_value_new_take_binding_sets (GPtrArray *array)
|
||||
return value;
|
||||
}
|
||||
|
||||
GtkCssValue *
|
||||
_gtk_css_value_new_from_number (const GtkCssNumber *v)
|
||||
{
|
||||
GtkCssValue *value;
|
||||
static GtkCssValue *zero_singleton = NULL;
|
||||
static GtkCssValue *px_singletons[5] = {NULL};
|
||||
|
||||
if (v->unit == GTK_CSS_NUMBER &&
|
||||
v->value == 0)
|
||||
{
|
||||
if (zero_singleton == NULL)
|
||||
{
|
||||
value = gtk_css_value_new (GTK_TYPE_CSS_NUMBER);
|
||||
value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_NUMBER, v);
|
||||
zero_singleton = value;
|
||||
}
|
||||
return _gtk_css_value_ref (zero_singleton);
|
||||
}
|
||||
|
||||
if (v->unit == GTK_CSS_PX &&
|
||||
(v->value == 0 ||
|
||||
v->value == 1 ||
|
||||
v->value == 2 ||
|
||||
v->value == 3 ||
|
||||
v->value == 4))
|
||||
{
|
||||
int i = round (v->value);
|
||||
if (px_singletons[i] == NULL)
|
||||
{
|
||||
value = gtk_css_value_new (GTK_TYPE_CSS_NUMBER);
|
||||
value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_NUMBER, v);
|
||||
px_singletons[i] = value;
|
||||
}
|
||||
|
||||
return _gtk_css_value_ref (px_singletons[i]);
|
||||
}
|
||||
|
||||
value = gtk_css_value_new (GTK_TYPE_CSS_NUMBER);
|
||||
value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_NUMBER, v);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
GtkCssValue *
|
||||
_gtk_css_value_new_from_rgba (const GdkRGBA *v)
|
||||
{
|
||||
@ -560,13 +515,6 @@ _gtk_css_value_init_gvalue (const GtkCssValue *value,
|
||||
}
|
||||
}
|
||||
|
||||
const GtkCssNumber *
|
||||
_gtk_css_value_get_number (const GtkCssValue *value)
|
||||
{
|
||||
g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_NUMBER), NULL);
|
||||
return value->u.ptr;
|
||||
}
|
||||
|
||||
GtkSymbolicColor *
|
||||
_gtk_css_value_get_symbolic_color (const GtkCssValue *value)
|
||||
{
|
||||
|
@ -88,7 +88,6 @@ GtkCssValue *_gtk_css_value_new_take_pattern (cairo_pattern_t
|
||||
GtkCssValue *_gtk_css_value_new_take_shadow (GtkShadow *v);
|
||||
GtkCssValue *_gtk_css_value_new_take_image (GtkCssImage *v);
|
||||
GtkCssValue *_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v);
|
||||
GtkCssValue *_gtk_css_value_new_from_number (const GtkCssNumber *v);
|
||||
GtkCssValue *_gtk_css_value_new_take_binding_sets (GPtrArray *array);
|
||||
GtkCssValue *_gtk_css_value_new_from_background_size (const GtkCssBackgroundSize *v);
|
||||
GtkCssValue *_gtk_css_value_new_from_background_position (const GtkCssBackgroundPosition *v);
|
||||
@ -106,7 +105,6 @@ gpointer _gtk_css_value_dup_object (const
|
||||
gpointer _gtk_css_value_get_object (const GtkCssValue *value);
|
||||
gpointer _gtk_css_value_get_boxed (const GtkCssValue *value);
|
||||
const char ** _gtk_css_value_get_strv (const GtkCssValue *value);
|
||||
const GtkCssNumber *_gtk_css_value_get_number (const GtkCssValue *value);
|
||||
GtkSymbolicColor *_gtk_css_value_get_symbolic_color (const GtkCssValue *value);
|
||||
GtkCssImage *_gtk_css_value_get_image (const GtkCssValue *value);
|
||||
GtkBorderStyle _gtk_css_value_get_border_style (const GtkCssValue *value);
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "gtkprivate.h"
|
||||
#include "gtksymboliccolorprivate.h"
|
||||
#include "gtkanimationdescription.h"
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtktimeline.h"
|
||||
#include "gtkiconfactory.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
@ -2264,7 +2265,7 @@ _gtk_style_context_get_number (GtkStyleContext *context,
|
||||
GtkCssValue *value;
|
||||
|
||||
value = _gtk_style_context_peek_property (context, property_name);
|
||||
return _gtk_css_number_get (_gtk_css_value_get_number (value), one_hundred_percent);
|
||||
return _gtk_css_number_value_get (value, one_hundred_percent);
|
||||
}
|
||||
|
||||
const GValue *
|
||||
|
Loading…
Reference in New Issue
Block a user