2011-12-31 14:05:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 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.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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-12-31 14:05:09 +00:00
|
|
|
*
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcssshorthandpropertyprivate.h"
|
|
|
|
|
|
|
|
#include <cairo-gobject.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2012-01-04 03:04:59 +00:00
|
|
|
#include "gtkcssimageprivate.h"
|
2012-01-01 23:14:23 +00:00
|
|
|
#include "gtkcssstylefuncsprivate.h"
|
2011-12-31 14:05:09 +00:00
|
|
|
#include "gtkcsstypesprivate.h"
|
2012-01-04 18:15:00 +00:00
|
|
|
#include "gtkprivatetypebuiltins.h"
|
2012-01-10 22:36:10 +00:00
|
|
|
#include "gtkstylepropertiesprivate.h"
|
2012-01-14 01:38:42 +00:00
|
|
|
#include "gtksymboliccolorprivate.h"
|
2012-01-05 15:53:43 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2012-03-06 13:16:32 +00:00
|
|
|
#include "gtkcssvalueprivate.h"
|
2011-12-31 14:05:09 +00:00
|
|
|
|
|
|
|
/* this is in case round() is not provided by the compiler,
|
|
|
|
* such as in the case of C89 compilers, like MSVC
|
|
|
|
*/
|
|
|
|
#include "fallback-c89.c"
|
|
|
|
|
|
|
|
/*** PARSING ***/
|
|
|
|
|
2012-01-02 03:12:41 +00:00
|
|
|
static gboolean
|
|
|
|
value_is_done_parsing (GtkCssParser *parser)
|
|
|
|
{
|
|
|
|
return _gtk_css_parser_is_eof (parser) ||
|
|
|
|
_gtk_css_parser_begins_with (parser, ';') ||
|
|
|
|
_gtk_css_parser_begins_with (parser, '}');
|
|
|
|
}
|
|
|
|
|
2012-01-15 01:53:39 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_four_numbers (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GtkCssNumberParseFlags flags)
|
2012-01-15 01:53:39 +00:00
|
|
|
{
|
|
|
|
GtkCssNumber numbers[4];
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (!_gtk_css_parser_has_number (parser))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!_gtk_css_parser_read_number (parser,
|
|
|
|
&numbers[i],
|
2012-01-17 15:41:14 +00:00
|
|
|
flags))
|
2012-01-15 01:53:39 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Expected a length");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < 4; i++)
|
|
|
|
{
|
|
|
|
numbers[i] = numbers[(i - 1) >> 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[i] = _gtk_css_value_new_from_number (&numbers[i]);
|
2012-01-15 01:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:41:14 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_margin (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-17 15:41:14 +00:00
|
|
|
{
|
|
|
|
return parse_four_numbers (shorthand,
|
|
|
|
values,
|
|
|
|
parser,
|
|
|
|
GTK_CSS_NUMBER_AS_PIXELS
|
|
|
|
| GTK_CSS_PARSE_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_padding (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-24 16:49:29 +00:00
|
|
|
{
|
|
|
|
return parse_four_numbers (shorthand,
|
|
|
|
values,
|
|
|
|
parser,
|
|
|
|
GTK_CSS_POSITIVE_ONLY
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS
|
|
|
|
| GTK_CSS_PARSE_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_border_width (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-17 15:41:14 +00:00
|
|
|
{
|
|
|
|
return parse_four_numbers (shorthand,
|
|
|
|
values,
|
|
|
|
parser,
|
|
|
|
GTK_CSS_POSITIVE_ONLY
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS
|
|
|
|
| GTK_CSS_PARSE_LENGTH);
|
|
|
|
}
|
|
|
|
|
2012-01-02 02:05:49 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_border_radius (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-02 02:05:49 +00:00
|
|
|
{
|
|
|
|
GtkCssBorderCornerRadius borders[4];
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (borders); i++)
|
|
|
|
{
|
2012-01-15 05:26:08 +00:00
|
|
|
if (!_gtk_css_parser_has_number (parser))
|
2012-01-02 02:05:49 +00:00
|
|
|
break;
|
2012-01-15 05:26:08 +00:00
|
|
|
if (!_gtk_css_parser_read_number (parser,
|
|
|
|
&borders[i].horizontal,
|
|
|
|
GTK_CSS_POSITIVE_ONLY
|
|
|
|
| GTK_CSS_PARSE_PERCENT
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS
|
|
|
|
| GTK_CSS_PARSE_LENGTH))
|
|
|
|
return FALSE;
|
2012-01-02 02:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Expected a number");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The magic (i - 1) >> 1 below makes it take the correct value
|
|
|
|
* according to spec. Feel free to check the 4 cases */
|
|
|
|
for (; i < G_N_ELEMENTS (borders); i++)
|
|
|
|
borders[i].horizontal = borders[(i - 1) >> 1].horizontal;
|
|
|
|
|
|
|
|
if (_gtk_css_parser_try (parser, "/", TRUE))
|
|
|
|
{
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (borders); i++)
|
|
|
|
{
|
2012-01-15 05:26:08 +00:00
|
|
|
if (!_gtk_css_parser_has_number (parser))
|
2012-01-02 02:05:49 +00:00
|
|
|
break;
|
2012-01-15 05:26:08 +00:00
|
|
|
if (!_gtk_css_parser_read_number (parser,
|
|
|
|
&borders[i].vertical,
|
|
|
|
GTK_CSS_POSITIVE_ONLY
|
|
|
|
| GTK_CSS_PARSE_PERCENT
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS
|
|
|
|
| GTK_CSS_PARSE_LENGTH))
|
|
|
|
return FALSE;
|
2012-01-02 02:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Expected a number");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < G_N_ELEMENTS (borders); i++)
|
|
|
|
borders[i].vertical = borders[(i - 1) >> 1].vertical;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (borders); i++)
|
|
|
|
borders[i].vertical = borders[i].horizontal;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (borders); i++)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[i] = _gtk_css_value_new_from_border_corner_radius (&borders[i]);
|
2012-01-02 02:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-02 02:43:48 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_border_color (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-02 02:43:48 +00:00
|
|
|
{
|
|
|
|
GtkSymbolicColor *symbolic;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2012-01-11 22:35:59 +00:00
|
|
|
if (_gtk_css_parser_try (parser, "currentcolor", TRUE))
|
|
|
|
{
|
2012-01-14 01:38:42 +00:00
|
|
|
symbolic = gtk_symbolic_color_ref (_gtk_symbolic_color_get_current_color ());
|
2012-01-11 22:35:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
symbolic = _gtk_css_parser_read_symbolic_color (parser);
|
|
|
|
if (symbolic == NULL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-02 02:43:48 +00:00
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
values[i] = _gtk_css_value_new_take_symbolic_color (symbolic);
|
2012-01-14 01:38:42 +00:00
|
|
|
|
2012-01-02 03:12:41 +00:00
|
|
|
if (value_is_done_parsing (parser))
|
2012-01-02 02:43:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i++; i < 4; i++)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
|
2012-01-02 02:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-05 15:53:43 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_border_style (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-05 15:53:43 +00:00
|
|
|
{
|
|
|
|
GtkBorderStyle styles[4];
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, (int *)&styles[i]))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Expected a border style");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < G_N_ELEMENTS (styles); i++)
|
|
|
|
styles[i] = styles[(i - 1) >> 1];
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (styles); i++)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[i] = _gtk_css_value_new_from_enum (GTK_TYPE_BORDER_STYLE, styles[i]);
|
2012-01-05 15:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-31 14:05:09 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_border_image (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
GValue value = G_VALUE_INIT;
|
2011-12-21 16:43:31 +00:00
|
|
|
GtkCssImage *image;
|
|
|
|
|
|
|
|
if (_gtk_css_parser_try (parser, "none", TRUE))
|
|
|
|
image = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = _gtk_css_image_new_parse (parser, base);
|
|
|
|
if (!image)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
values[0] = _gtk_css_value_new_take_image (image);
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-02 03:12:41 +00:00
|
|
|
if (value_is_done_parsing (parser))
|
|
|
|
return TRUE;
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
g_value_init (&value, GTK_TYPE_BORDER);
|
|
|
|
if (!_gtk_css_style_parse_value (&value, parser, base))
|
2012-01-02 03:12:41 +00:00
|
|
|
return FALSE;
|
2012-03-26 15:24:02 +00:00
|
|
|
values[1] = _gtk_css_value_new_from_gvalue (&value);
|
|
|
|
g_value_unset (&value);
|
2011-12-31 14:05:09 +00:00
|
|
|
|
|
|
|
if (_gtk_css_parser_try (parser, "/", TRUE))
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
g_value_init (&value, GTK_TYPE_BORDER);
|
|
|
|
if (!_gtk_css_style_parse_value (&value, parser, base))
|
2012-01-02 03:12:41 +00:00
|
|
|
return FALSE;
|
2012-03-26 15:24:02 +00:00
|
|
|
values[2] = _gtk_css_value_new_from_gvalue (&value);
|
|
|
|
g_value_unset (&value);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 03:12:41 +00:00
|
|
|
if (value_is_done_parsing (parser))
|
|
|
|
return TRUE;
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
g_value_init (&value, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
|
|
|
|
if (!_gtk_css_style_parse_value (&value, parser, base))
|
2012-01-02 03:12:41 +00:00
|
|
|
return FALSE;
|
2012-03-26 15:24:02 +00:00
|
|
|
values[3] = _gtk_css_value_new_from_gvalue (&value);
|
|
|
|
g_value_unset (&value);
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-02 03:12:41 +00:00
|
|
|
return TRUE;
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-07 02:04:10 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_border_side (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-07 02:04:10 +00:00
|
|
|
{
|
|
|
|
int style;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
if (values[0] == NULL &&
|
2012-01-15 01:53:39 +00:00
|
|
|
_gtk_css_parser_has_number (parser))
|
2012-01-07 02:04:10 +00:00
|
|
|
{
|
2012-01-15 01:53:39 +00:00
|
|
|
GtkCssNumber number;
|
|
|
|
if (!_gtk_css_parser_read_number (parser,
|
|
|
|
&number,
|
|
|
|
GTK_CSS_POSITIVE_ONLY
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS
|
|
|
|
| GTK_CSS_PARSE_LENGTH))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
values[0] = _gtk_css_value_new_from_number (&number);
|
2012-01-07 02:04:10 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
else if (values[1] == NULL &&
|
2012-01-07 02:04:10 +00:00
|
|
|
_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, &style))
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[1] = _gtk_css_value_new_from_enum (GTK_TYPE_BORDER_STYLE, style);
|
2012-01-07 02:04:10 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
else if (values[2] == NULL)
|
2012-01-07 02:04:10 +00:00
|
|
|
{
|
|
|
|
GtkSymbolicColor *symbolic;
|
|
|
|
|
|
|
|
symbolic = _gtk_css_parser_read_symbolic_color (parser);
|
|
|
|
if (symbolic == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
values[2] = _gtk_css_value_new_take_symbolic_color (symbolic);
|
2012-01-07 02:04:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We parsed everything and there's still stuff left?
|
|
|
|
* Pretend we didn't notice and let the normal code produce
|
|
|
|
* a 'junk at end of value' error */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!value_is_done_parsing (parser));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-04 23:04:12 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_border (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-04 23:04:12 +00:00
|
|
|
{
|
|
|
|
int style;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
if (values[0] == NULL &&
|
2012-01-15 01:53:39 +00:00
|
|
|
_gtk_css_parser_has_number (parser))
|
2012-01-04 23:04:12 +00:00
|
|
|
{
|
2012-01-15 01:53:39 +00:00
|
|
|
GtkCssNumber number;
|
|
|
|
if (!_gtk_css_parser_read_number (parser,
|
|
|
|
&number,
|
|
|
|
GTK_CSS_POSITIVE_ONLY
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS
|
|
|
|
| GTK_CSS_PARSE_LENGTH))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
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]);
|
2012-01-04 23:04:12 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
else if (values[4] == NULL &&
|
2012-01-04 23:04:12 +00:00
|
|
|
_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, &style))
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[4] = _gtk_css_value_new_from_enum (GTK_TYPE_BORDER_STYLE, style);
|
|
|
|
values[5] = _gtk_css_value_ref (values[4]);
|
|
|
|
values[6] = _gtk_css_value_ref (values[4]);
|
|
|
|
values[7] = _gtk_css_value_ref (values[4]);
|
2012-01-04 23:04:12 +00:00
|
|
|
}
|
|
|
|
else if (!G_IS_VALUE (&values[8]))
|
|
|
|
{
|
|
|
|
GtkSymbolicColor *symbolic;
|
|
|
|
|
|
|
|
symbolic = _gtk_css_parser_read_symbolic_color (parser);
|
|
|
|
if (symbolic == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
values[8] = _gtk_css_value_new_take_symbolic_color (symbolic);
|
|
|
|
values[9] = _gtk_css_value_ref (values[8]);
|
|
|
|
values[10] = _gtk_css_value_ref (values[8]);
|
|
|
|
values[11] = _gtk_css_value_ref (values[8]);
|
2012-01-04 23:04:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We parsed everything and there's still stuff left?
|
|
|
|
* Pretend we didn't notice and let the normal code produce
|
|
|
|
* a 'junk at end of value' error */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!value_is_done_parsing (parser));
|
|
|
|
|
|
|
|
/* Note that border-image values are not set: according to the spec
|
|
|
|
they just need to be reset when using the border shorthand */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-02 08:19:27 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_font (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-02 08:19:27 +00:00
|
|
|
{
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
guint mask;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = _gtk_css_parser_read_value (parser);
|
|
|
|
if (str == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
desc = pango_font_description_from_string (str);
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
mask = pango_font_description_get_set_fields (desc);
|
|
|
|
|
|
|
|
if (mask & PANGO_FONT_MASK_FAMILY)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
char **strv = g_new0 (char *, 2);
|
2012-01-02 08:19:27 +00:00
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
strv[0] = g_strdup (pango_font_description_get_family (desc));
|
|
|
|
values[0] = _gtk_css_value_new_take_strv (strv);
|
2012-01-02 08:19:27 +00:00
|
|
|
}
|
|
|
|
if (mask & PANGO_FONT_MASK_STYLE)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[1] = _gtk_css_value_new_from_enum (PANGO_TYPE_STYLE,
|
|
|
|
pango_font_description_get_style (desc));
|
2012-01-02 08:19:27 +00:00
|
|
|
}
|
|
|
|
if (mask & PANGO_FONT_MASK_VARIANT)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[2] = _gtk_css_value_new_from_enum (PANGO_TYPE_VARIANT,
|
|
|
|
pango_font_description_get_variant (desc));
|
2012-01-02 08:19:27 +00:00
|
|
|
}
|
|
|
|
if (mask & PANGO_FONT_MASK_WEIGHT)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[3] = _gtk_css_value_new_from_enum (PANGO_TYPE_WEIGHT,
|
|
|
|
pango_font_description_get_weight (desc));
|
2012-01-02 08:19:27 +00:00
|
|
|
}
|
|
|
|
if (mask & PANGO_FONT_MASK_SIZE)
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
values[4] = _gtk_css_value_new_from_double ((double) pango_font_description_get_size (desc) / PANGO_SCALE);
|
2012-01-02 08:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-04 18:15:00 +00:00
|
|
|
static gboolean
|
2012-03-26 15:24:02 +00:00
|
|
|
parse_background (GtkCssShorthandProperty *shorthand,
|
|
|
|
GtkCssValue **values,
|
|
|
|
GtkCssParser *parser,
|
|
|
|
GFile *base)
|
2012-01-04 18:15:00 +00:00
|
|
|
{
|
|
|
|
int enum_value;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* the image part */
|
2012-03-26 15:24:02 +00:00
|
|
|
if (values[0] == NULL &&
|
2012-01-04 18:15:00 +00:00
|
|
|
(_gtk_css_parser_has_prefix (parser, "none") ||
|
|
|
|
_gtk_css_image_can_parse (parser)))
|
|
|
|
{
|
|
|
|
GtkCssImage *image;
|
|
|
|
|
|
|
|
if (_gtk_css_parser_try (parser, "none", TRUE))
|
|
|
|
image = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = _gtk_css_image_new_parse (parser, base);
|
|
|
|
if (image == NULL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
values[0] = _gtk_css_value_new_take_image (image);
|
2012-01-04 18:15:00 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
else if (values[1] == NULL &&
|
2012-01-04 18:15:00 +00:00
|
|
|
_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &enum_value))
|
|
|
|
{
|
2012-01-05 01:48:32 +00:00
|
|
|
if (enum_value <= GTK_CSS_BACKGROUND_REPEAT_MASK)
|
|
|
|
{
|
|
|
|
int vertical;
|
|
|
|
|
|
|
|
if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &vertical))
|
|
|
|
{
|
|
|
|
if (vertical >= GTK_CSS_BACKGROUND_REPEAT_MASK)
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Not a valid 2nd value for border-repeat");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
enum_value |= vertical << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
enum_value |= enum_value << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
|
|
|
|
}
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
values[1] = _gtk_css_value_new_from_enum (GTK_TYPE_CSS_BACKGROUND_REPEAT, enum_value);
|
2012-01-04 18:15:00 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
else if ((values[2] == NULL || values[3] == NULL) &&
|
2012-01-04 18:15:00 +00:00
|
|
|
_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_AREA, &enum_value))
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
guint idx = values[2] == NULL ? 2 : 3;
|
|
|
|
values[idx] = _gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, enum_value);
|
2012-01-04 18:15:00 +00:00
|
|
|
}
|
2012-03-26 15:24:02 +00:00
|
|
|
else if (values[4] == NULL)
|
2012-01-04 18:15:00 +00:00
|
|
|
{
|
|
|
|
GtkSymbolicColor *symbolic;
|
|
|
|
|
|
|
|
symbolic = _gtk_css_parser_read_symbolic_color (parser);
|
|
|
|
if (symbolic == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
values[4] = _gtk_css_value_new_take_symbolic_color (symbolic);
|
2012-01-04 18:15:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We parsed everything and there's still stuff left?
|
|
|
|
* Pretend we didn't notice and let the normal code produce
|
|
|
|
* a 'junk at end of value' error */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!value_is_done_parsing (parser));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-31 14:05:09 +00:00
|
|
|
/*** PACKING ***/
|
|
|
|
|
2012-01-11 00:11:58 +00:00
|
|
|
static void
|
2012-01-10 23:42:29 +00:00
|
|
|
unpack_border (GtkCssShorthandProperty *shorthand,
|
2012-01-11 00:11:58 +00:00
|
|
|
GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GValue *value)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-01-11 00:11:58 +00:00
|
|
|
GValue v = G_VALUE_INIT;
|
2011-12-31 14:05:09 +00:00
|
|
|
GtkBorder *border = g_value_get_boxed (value);
|
|
|
|
|
2012-01-11 00:11:58 +00:00
|
|
|
g_value_init (&v, G_TYPE_INT);
|
|
|
|
|
|
|
|
g_value_set_int (&v, border->top);
|
|
|
|
_gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 0)), props, state, &v);
|
|
|
|
g_value_set_int (&v, border->right);
|
|
|
|
_gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 1)), props, state, &v);
|
|
|
|
g_value_set_int (&v, border->bottom);
|
|
|
|
_gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 2)), props, state, &v);
|
|
|
|
g_value_set_int (&v, border->left);
|
|
|
|
_gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 3)), props, state, &v);
|
|
|
|
|
|
|
|
g_value_unset (&v);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
static void
|
2012-01-10 22:36:10 +00:00
|
|
|
pack_border (GtkCssShorthandProperty *shorthand,
|
2012-03-26 05:08:24 +00:00
|
|
|
GValue *value,
|
2012-01-11 01:43:16 +00:00
|
|
|
GtkStyleQueryFunc query_func,
|
|
|
|
gpointer query_data)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-01-10 22:36:10 +00:00
|
|
|
GtkCssStyleProperty *prop;
|
2011-12-31 14:05:09 +00:00
|
|
|
GtkBorder border;
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *v;
|
2012-01-10 22:36:10 +00:00
|
|
|
|
|
|
|
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
|
2012-01-11 01:43:16 +00:00
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
|
2012-01-10 22:36:10 +00:00
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
border.top = _gtk_css_value_get_int (v);
|
2012-01-10 22:36:10 +00:00
|
|
|
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 1);
|
2012-01-11 01:43:16 +00:00
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
|
2012-01-10 22:36:10 +00:00
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
border.right = _gtk_css_value_get_int (v);
|
2012-01-10 22:36:10 +00:00
|
|
|
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 2);
|
2012-01-11 01:43:16 +00:00
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
|
2012-01-10 22:36:10 +00:00
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
border.bottom = _gtk_css_value_get_int (v);
|
2012-01-10 22:36:10 +00:00
|
|
|
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 3);
|
2012-01-11 01:43:16 +00:00
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
|
2012-01-10 22:36:10 +00:00
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
border.left = _gtk_css_value_get_int (v);
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
g_value_init (value, GTK_TYPE_BORDER);
|
|
|
|
g_value_set_boxed (value, &border);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 00:11:58 +00:00
|
|
|
static void
|
2012-01-10 18:02:42 +00:00
|
|
|
unpack_border_radius (GtkCssShorthandProperty *shorthand,
|
2012-01-11 00:11:58 +00:00
|
|
|
GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GValue *value)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-01-02 02:05:49 +00:00
|
|
|
GtkCssBorderCornerRadius border;
|
2012-01-11 00:11:58 +00:00
|
|
|
GValue v = G_VALUE_INIT;
|
|
|
|
guint i;
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-15 05:26:08 +00:00
|
|
|
_gtk_css_number_init (&border.horizontal, g_value_get_int (value), GTK_CSS_PX);
|
|
|
|
border.vertical = border.horizontal;
|
2012-01-11 00:11:58 +00:00
|
|
|
g_value_init (&v, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
|
|
|
|
g_value_set_boxed (&v, &border);
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-11 00:11:58 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
_gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, i)), props, state, &v);
|
|
|
|
|
|
|
|
g_value_unset (&v);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
static void
|
2012-01-10 18:02:42 +00:00
|
|
|
pack_border_radius (GtkCssShorthandProperty *shorthand,
|
2012-03-26 05:08:24 +00:00
|
|
|
GValue *value,
|
2012-01-11 01:43:16 +00:00
|
|
|
GtkStyleQueryFunc query_func,
|
|
|
|
gpointer query_data)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-03-23 22:23:30 +00:00
|
|
|
const GtkCssBorderCornerRadius *top_left;
|
2012-01-11 01:43:16 +00:00
|
|
|
GtkCssStyleProperty *prop;
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *v;
|
2012-03-26 05:08:24 +00:00
|
|
|
int i = 0;
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-11 01:43:16 +00:00
|
|
|
prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius"));
|
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
|
|
|
|
if (v)
|
|
|
|
{
|
2012-03-06 13:16:32 +00:00
|
|
|
top_left = _gtk_css_value_get_border_corner_radius (v);
|
2012-01-11 01:43:16 +00:00
|
|
|
if (top_left)
|
2012-03-26 05:08:24 +00:00
|
|
|
i = top_left->horizontal.value;
|
2012-01-11 01:43:16 +00:00
|
|
|
}
|
2012-03-06 13:16:32 +00:00
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
g_value_init (value, G_TYPE_INT);
|
|
|
|
g_value_set_int (value, i);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 00:11:58 +00:00
|
|
|
static void
|
2012-01-10 18:02:42 +00:00
|
|
|
unpack_font_description (GtkCssShorthandProperty *shorthand,
|
2012-01-11 00:11:58 +00:00
|
|
|
GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GValue *value)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-01-11 00:11:58 +00:00
|
|
|
GtkStyleProperty *prop;
|
2011-12-31 14:05:09 +00:00
|
|
|
PangoFontDescription *description;
|
|
|
|
PangoFontMask mask;
|
2012-01-11 00:11:58 +00:00
|
|
|
GValue v = G_VALUE_INIT;
|
2011-12-31 14:05:09 +00:00
|
|
|
|
|
|
|
/* For backwards compat, we only unpack values that are indeed set.
|
|
|
|
* For strict CSS conformance we need to unpack all of them.
|
|
|
|
* Note that we do set all of them in the parse function, so it
|
|
|
|
* will not have effects when parsing CSS files. It will though
|
|
|
|
* for custom style providers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
description = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
if (description)
|
|
|
|
mask = pango_font_description_get_set_fields (description);
|
|
|
|
else
|
|
|
|
mask = 0;
|
|
|
|
|
|
|
|
if (mask & PANGO_FONT_MASK_FAMILY)
|
|
|
|
{
|
|
|
|
GPtrArray *strv = g_ptr_array_new ();
|
|
|
|
|
|
|
|
g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
|
|
|
|
g_ptr_array_add (strv, NULL);
|
2012-01-11 00:11:58 +00:00
|
|
|
g_value_init (&v, G_TYPE_STRV);
|
|
|
|
g_value_take_boxed (&v, g_ptr_array_free (strv, FALSE));
|
|
|
|
|
|
|
|
prop = _gtk_style_property_lookup ("font-family");
|
|
|
|
_gtk_style_property_assign (prop, props, state, &v);
|
|
|
|
g_value_unset (&v);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & PANGO_FONT_MASK_STYLE)
|
|
|
|
{
|
2012-01-11 00:11:58 +00:00
|
|
|
g_value_init (&v, PANGO_TYPE_STYLE);
|
|
|
|
g_value_set_enum (&v, pango_font_description_get_style (description));
|
|
|
|
|
|
|
|
prop = _gtk_style_property_lookup ("font-style");
|
|
|
|
_gtk_style_property_assign (prop, props, state, &v);
|
|
|
|
g_value_unset (&v);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & PANGO_FONT_MASK_VARIANT)
|
|
|
|
{
|
2012-01-11 00:11:58 +00:00
|
|
|
g_value_init (&v, PANGO_TYPE_VARIANT);
|
|
|
|
g_value_set_enum (&v, pango_font_description_get_variant (description));
|
|
|
|
|
|
|
|
prop = _gtk_style_property_lookup ("font-variant");
|
|
|
|
_gtk_style_property_assign (prop, props, state, &v);
|
|
|
|
g_value_unset (&v);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & PANGO_FONT_MASK_WEIGHT)
|
|
|
|
{
|
2012-01-11 00:11:58 +00:00
|
|
|
g_value_init (&v, PANGO_TYPE_WEIGHT);
|
|
|
|
g_value_set_enum (&v, pango_font_description_get_weight (description));
|
|
|
|
|
|
|
|
prop = _gtk_style_property_lookup ("font-weight");
|
|
|
|
_gtk_style_property_assign (prop, props, state, &v);
|
|
|
|
g_value_unset (&v);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & PANGO_FONT_MASK_SIZE)
|
|
|
|
{
|
2012-01-11 00:11:58 +00:00
|
|
|
g_value_init (&v, G_TYPE_DOUBLE);
|
|
|
|
g_value_set_double (&v, (double) pango_font_description_get_size (description) / PANGO_SCALE);
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-11 00:11:58 +00:00
|
|
|
prop = _gtk_style_property_lookup ("font-size");
|
|
|
|
_gtk_style_property_assign (prop, props, state, &v);
|
|
|
|
g_value_unset (&v);
|
|
|
|
}
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
static void
|
2012-01-10 18:02:42 +00:00
|
|
|
pack_font_description (GtkCssShorthandProperty *shorthand,
|
2012-03-26 05:08:24 +00:00
|
|
|
GValue *value,
|
2012-01-11 01:43:16 +00:00
|
|
|
GtkStyleQueryFunc query_func,
|
|
|
|
gpointer query_data)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
|
|
|
PangoFontDescription *description;
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *v;
|
2011-12-31 14:05:09 +00:00
|
|
|
|
|
|
|
description = pango_font_description_new ();
|
|
|
|
|
2012-01-11 01:43:16 +00:00
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data);
|
|
|
|
if (v)
|
|
|
|
{
|
2012-03-06 13:16:32 +00:00
|
|
|
const char **families = _gtk_css_value_get_strv (v);
|
2012-01-11 01:43:16 +00:00
|
|
|
/* xxx: Can we set all the families here somehow? */
|
|
|
|
if (families)
|
|
|
|
pango_font_description_set_family (description, families[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
|
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
pango_font_description_set_size (description, round (_gtk_css_value_get_double (v) * PANGO_SCALE));
|
2012-01-11 01:43:16 +00:00
|
|
|
|
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
|
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
pango_font_description_set_style (description, _gtk_css_value_get_pango_style (v));
|
2012-01-11 01:43:16 +00:00
|
|
|
|
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data);
|
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
pango_font_description_set_variant (description, _gtk_css_value_get_pango_variant (v));
|
2012-01-11 01:43:16 +00:00
|
|
|
|
|
|
|
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data);
|
|
|
|
if (v)
|
2012-03-06 13:16:32 +00:00
|
|
|
pango_font_description_set_weight (description, _gtk_css_value_get_pango_weight (v));
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
g_value_init (value, PANGO_TYPE_FONT_DESCRIPTION);
|
|
|
|
g_value_take_boxed (value, description);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 00:11:58 +00:00
|
|
|
static void
|
2012-01-10 23:08:15 +00:00
|
|
|
unpack_to_everything (GtkCssShorthandProperty *shorthand,
|
2012-01-11 00:11:58 +00:00
|
|
|
GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GValue *value)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-01-10 23:08:15 +00:00
|
|
|
GtkCssStyleProperty *prop;
|
|
|
|
guint i, n;
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-10 23:08:15 +00:00
|
|
|
n = _gtk_css_shorthand_property_get_n_subproperties (shorthand);
|
2011-12-31 14:05:09 +00:00
|
|
|
|
2012-01-10 23:08:15 +00:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
|
2012-01-11 00:11:58 +00:00
|
|
|
_gtk_style_property_assign (GTK_STYLE_PROPERTY (prop), props, state, value);
|
2012-01-10 23:08:15 +00:00
|
|
|
}
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
static void
|
2012-01-10 22:49:21 +00:00
|
|
|
pack_first_element (GtkCssShorthandProperty *shorthand,
|
2012-03-26 05:08:24 +00:00
|
|
|
GValue *value,
|
2012-01-11 01:43:16 +00:00
|
|
|
GtkStyleQueryFunc query_func,
|
|
|
|
gpointer query_data)
|
2011-12-31 14:05:09 +00:00
|
|
|
{
|
2012-01-10 22:49:21 +00:00
|
|
|
GtkCssStyleProperty *prop;
|
|
|
|
|
|
|
|
/* NB: This is a fallback for properties that originally were
|
|
|
|
* not used as shorthand. We just pick the first subproperty
|
|
|
|
* as a representative.
|
|
|
|
* Lesson learned: Don't query the shorthand, query the
|
2011-12-31 14:05:09 +00:00
|
|
|
* real properties instead. */
|
2012-03-26 05:08:24 +00:00
|
|
|
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
|
|
|
|
_gtk_style_property_query (GTK_STYLE_PROPERTY (prop),
|
|
|
|
value,
|
|
|
|
query_func,
|
|
|
|
query_data);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 14:43:13 +00:00
|
|
|
static void
|
2012-01-02 01:23:54 +00:00
|
|
|
_gtk_css_shorthand_property_register (const char *name,
|
|
|
|
GType value_type,
|
|
|
|
const char **subproperties,
|
|
|
|
GtkCssShorthandPropertyParseFunc parse_func,
|
2012-01-10 18:02:42 +00:00
|
|
|
GtkCssShorthandPropertyAssignFunc assign_func,
|
|
|
|
GtkCssShorthandPropertyQueryFunc query_func)
|
2011-12-31 14:43:13 +00:00
|
|
|
{
|
2012-01-10 18:02:42 +00:00
|
|
|
GtkCssShorthandProperty *node;
|
2011-12-31 14:43:13 +00:00
|
|
|
|
|
|
|
node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
|
2012-01-01 22:16:35 +00:00
|
|
|
"name", name,
|
|
|
|
"value-type", value_type,
|
2011-12-31 15:31:25 +00:00
|
|
|
"subproperties", subproperties,
|
2011-12-31 14:43:13 +00:00
|
|
|
NULL);
|
|
|
|
|
2012-01-10 18:02:42 +00:00
|
|
|
node->parse = parse_func;
|
|
|
|
node->assign = assign_func;
|
|
|
|
node->query = query_func;
|
2011-12-31 14:43:13 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 14:05:09 +00:00
|
|
|
void
|
|
|
|
_gtk_css_shorthand_property_init_properties (void)
|
|
|
|
{
|
2012-01-02 01:33:56 +00:00
|
|
|
/* The order is important here, be careful when changing it */
|
2011-12-31 15:31:25 +00:00
|
|
|
const char *font_subproperties[] = { "font-family", "font-style", "font-variant", "font-weight", "font-size", NULL };
|
|
|
|
const char *margin_subproperties[] = { "margin-top", "margin-right", "margin-bottom", "margin-left", NULL };
|
|
|
|
const char *padding_subproperties[] = { "padding-top", "padding-right", "padding-bottom", "padding-left", NULL };
|
|
|
|
const char *border_width_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width", NULL };
|
|
|
|
const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
|
|
|
|
"border-bottom-right-radius", "border-bottom-left-radius", NULL };
|
|
|
|
const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
|
2012-01-05 15:53:43 +00:00
|
|
|
const char *border_style_subproperties[] = { "border-top-style", "border-right-style", "border-bottom-style", "border-left-style", NULL };
|
2011-12-31 15:31:25 +00:00
|
|
|
const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
|
2012-01-07 02:04:10 +00:00
|
|
|
const char *border_top_subproperties[] = { "border-top-width", "border-top-style", "border-top-color", NULL };
|
|
|
|
const char *border_right_subproperties[] = { "border-right-width", "border-right-style", "border-right-color", NULL };
|
|
|
|
const char *border_bottom_subproperties[] = { "border-bottom-width", "border-bottom-style", "border-bottom-color", NULL };
|
|
|
|
const char *border_left_subproperties[] = { "border-left-width", "border-left-style", "border-left-color", NULL };
|
2012-01-04 23:04:12 +00:00
|
|
|
const char *border_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width",
|
|
|
|
"border-top-style", "border-right-style", "border-bottom-style", "border-left-style",
|
|
|
|
"border-top-color", "border-right-color", "border-bottom-color", "border-left-color",
|
|
|
|
"border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
|
2012-01-08 01:10:35 +00:00
|
|
|
const char *outline_subproperties[] = { "outline-width", "outline-style", "outline-color", NULL };
|
2012-01-04 18:15:00 +00:00
|
|
|
const char *background_subproperties[] = { "background-image", "background-repeat", "background-clip", "background-origin",
|
|
|
|
"background-color", NULL };
|
2011-12-31 15:31:25 +00:00
|
|
|
|
2012-01-01 22:16:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("font",
|
|
|
|
PANGO_TYPE_FONT_DESCRIPTION,
|
2011-12-31 15:31:25 +00:00
|
|
|
font_subproperties,
|
2012-01-02 08:19:27 +00:00
|
|
|
parse_font,
|
2011-12-31 14:05:09 +00:00
|
|
|
unpack_font_description,
|
2012-01-02 08:22:35 +00:00
|
|
|
pack_font_description);
|
2012-01-01 22:16:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("margin",
|
|
|
|
GTK_TYPE_BORDER,
|
2011-12-31 15:31:25 +00:00
|
|
|
margin_subproperties,
|
2012-01-17 15:41:14 +00:00
|
|
|
parse_margin,
|
2012-01-10 23:42:29 +00:00
|
|
|
unpack_border,
|
2012-01-10 22:36:10 +00:00
|
|
|
pack_border);
|
2012-01-01 22:16:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("padding",
|
|
|
|
GTK_TYPE_BORDER,
|
2011-12-31 15:31:25 +00:00
|
|
|
padding_subproperties,
|
2012-01-24 16:49:29 +00:00
|
|
|
parse_padding,
|
2012-01-10 23:42:29 +00:00
|
|
|
unpack_border,
|
2012-01-10 22:36:10 +00:00
|
|
|
pack_border);
|
2012-01-01 22:16:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("border-width",
|
|
|
|
GTK_TYPE_BORDER,
|
2011-12-31 15:31:25 +00:00
|
|
|
border_width_subproperties,
|
2012-01-24 16:49:29 +00:00
|
|
|
parse_border_width,
|
2012-01-10 23:42:29 +00:00
|
|
|
unpack_border,
|
2012-01-10 22:36:10 +00:00
|
|
|
pack_border);
|
2012-01-01 22:16:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("border-radius",
|
|
|
|
G_TYPE_INT,
|
2011-12-31 15:31:25 +00:00
|
|
|
border_radius_subproperties,
|
2012-01-02 02:05:49 +00:00
|
|
|
parse_border_radius,
|
2011-12-31 14:05:09 +00:00
|
|
|
unpack_border_radius,
|
2012-01-02 08:22:35 +00:00
|
|
|
pack_border_radius);
|
2012-01-01 22:16:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("border-color",
|
|
|
|
GDK_TYPE_RGBA,
|
2011-12-31 15:31:25 +00:00
|
|
|
border_color_subproperties,
|
2012-01-02 02:43:48 +00:00
|
|
|
parse_border_color,
|
2012-01-10 23:08:15 +00:00
|
|
|
unpack_to_everything,
|
2012-01-10 22:49:21 +00:00
|
|
|
pack_first_element);
|
2012-01-05 15:53:43 +00:00
|
|
|
_gtk_css_shorthand_property_register ("border-style",
|
|
|
|
GTK_TYPE_BORDER_STYLE,
|
|
|
|
border_style_subproperties,
|
|
|
|
parse_border_style,
|
2012-01-10 23:08:15 +00:00
|
|
|
unpack_to_everything,
|
2012-01-10 22:49:21 +00:00
|
|
|
pack_first_element);
|
2012-01-01 22:16:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("border-image",
|
2012-01-04 03:04:59 +00:00
|
|
|
G_TYPE_NONE,
|
2011-12-31 15:31:25 +00:00
|
|
|
border_image_subproperties,
|
2012-01-02 03:12:41 +00:00
|
|
|
parse_border_image,
|
2012-01-04 03:04:59 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
2012-01-07 02:04:10 +00:00
|
|
|
_gtk_css_shorthand_property_register ("border-top",
|
|
|
|
G_TYPE_NONE,
|
|
|
|
border_top_subproperties,
|
|
|
|
parse_border_side,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
_gtk_css_shorthand_property_register ("border-right",
|
|
|
|
G_TYPE_NONE,
|
|
|
|
border_right_subproperties,
|
|
|
|
parse_border_side,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
_gtk_css_shorthand_property_register ("border-bottom",
|
|
|
|
G_TYPE_NONE,
|
|
|
|
border_bottom_subproperties,
|
|
|
|
parse_border_side,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
_gtk_css_shorthand_property_register ("border-left",
|
|
|
|
G_TYPE_NONE,
|
|
|
|
border_left_subproperties,
|
|
|
|
parse_border_side,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2012-01-04 23:04:12 +00:00
|
|
|
_gtk_css_shorthand_property_register ("border",
|
|
|
|
G_TYPE_NONE,
|
|
|
|
border_subproperties,
|
|
|
|
parse_border,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2012-01-08 01:10:35 +00:00
|
|
|
_gtk_css_shorthand_property_register ("outline",
|
|
|
|
G_TYPE_NONE,
|
|
|
|
outline_subproperties,
|
|
|
|
parse_border_side,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2012-01-04 18:15:00 +00:00
|
|
|
_gtk_css_shorthand_property_register ("background",
|
|
|
|
G_TYPE_NONE,
|
|
|
|
background_subproperties,
|
|
|
|
parse_background,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2011-12-31 14:05:09 +00:00
|
|
|
}
|