Commit e84af235 authored by Benjamin Otte's avatar Benjamin Otte

css: Implement padding as numbers

Also remove the now unused border parsing function for shorthands.
parent f2352a5f
......@@ -332,7 +332,7 @@ GtkLabel:selected:focused {
GtkCalendar.view {
border-width: 1px;
border-style: inset;
padding: 1;
padding: 1px;
}
GtkCalendar.view:inconsistent {
......@@ -360,5 +360,5 @@ GtkCalendar.button:hover {
.menu * {
border-width: 0;
padding: 2;
padding: 2px;
}
......@@ -607,7 +607,7 @@ GtkComboBox.combobox-entry .button:insensitive {
.notebook tab:active {
background-image: -gtk-win32-theme-part(tab, 1 3, margins(0 0 -1 0));
padding: 4;
padding: 4px;
}
.notebook tab:last-child {
......
......@@ -48,38 +48,6 @@ value_is_done_parsing (GtkCssParser *parser)
_gtk_css_parser_begins_with (parser, '}');
}
static gboolean
parse_border_width (GtkCssShorthandProperty *shorthand,
GValue *values,
GtkCssParser *parser,
GFile *base)
{
GValue temp = G_VALUE_INIT;
GtkBorder *border;
g_value_init (&temp, GTK_TYPE_BORDER);
if (!_gtk_css_style_parse_value (&temp, parser, base))
{
g_value_unset (&temp);
return FALSE;
}
border = g_value_get_boxed (&temp);
g_value_init (&values[0], G_TYPE_INT);
g_value_init (&values[1], G_TYPE_INT);
g_value_init (&values[2], G_TYPE_INT);
g_value_init (&values[3], G_TYPE_INT);
g_value_set_int (&values[0], border->top);
g_value_set_int (&values[1], border->right);
g_value_set_int (&values[2], border->bottom);
g_value_set_int (&values[3], border->left);
g_value_unset (&temp);
return TRUE;
}
static gboolean
parse_four_numbers (GtkCssShorthandProperty *shorthand,
GValue *values,
......@@ -134,10 +102,24 @@ parse_margin (GtkCssShorthandProperty *shorthand,
}
static gboolean
parse_border_width_really (GtkCssShorthandProperty *shorthand,
GValue *values,
GtkCssParser *parser,
GFile *base)
parse_padding (GtkCssShorthandProperty *shorthand,
GValue *values,
GtkCssParser *parser,
GFile *base)
{
return parse_four_numbers (shorthand,
values,
parser,
GTK_CSS_POSITIVE_ONLY
| GTK_CSS_NUMBER_AS_PIXELS
| GTK_CSS_PARSE_LENGTH);
}
static gboolean
parse_border_width (GtkCssShorthandProperty *shorthand,
GValue *values,
GtkCssParser *parser,
GFile *base)
{
return parse_four_numbers (shorthand,
values,
......@@ -923,13 +905,13 @@ _gtk_css_shorthand_property_init_properties (void)
_gtk_css_shorthand_property_register ("padding",
GTK_TYPE_BORDER,
padding_subproperties,
parse_border_width,
parse_padding,
unpack_border,
pack_border);
_gtk_css_shorthand_property_register ("border-width",
GTK_TYPE_BORDER,
border_width_subproperties,
parse_border_width_really,
parse_border_width,
unpack_border,
pack_border);
_gtk_css_shorthand_property_register ("border-radius",
......
......@@ -28,10 +28,16 @@
#include "gtkprivatetypebuiltins.h"
#include "gtkstylepropertiesprivate.h"
#include <math.h>
#include <cairo-gobject.h>
#include "gtkcssimagegradientprivate.h"
#include "gtkcssimageprivate.h"
/* 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"
enum {
PROP_0,
PROP_ID,
......@@ -165,6 +171,10 @@ _gtk_css_style_property_query (GtkStyleProperty *property,
g_value_take_boxed (value, pattern);
}
}
else if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_NUMBER)
{
g_value_set_int (value, round (_gtk_css_number_get (g_value_get_boxed (val), 100)));
}
else
g_value_copy (val, value);
}
......
......@@ -443,6 +443,39 @@ compute_margin (GtkCssStyleProperty *property,
g_value_set_boxed (computed, &number);
}
static gboolean
parse_padding (GtkCssStyleProperty *property,
GValue *value,
GtkCssParser *parser,
GFile *base)
{
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;
g_value_set_boxed (value, &number);
return TRUE;
}
static void
compute_padding (GtkCssStyleProperty *property,
GValue *computed,
GtkStyleContext *context,
const GValue *specified)
{
GtkCssNumber number;
_gtk_css_number_compute (&number,
g_value_get_boxed (specified),
context);
g_value_set_boxed (computed, &number);
}
static gboolean
parse_border_width (GtkCssStyleProperty *property,
GValue *value,
......@@ -815,41 +848,41 @@ _gtk_css_style_property_init_properties (void)
compute_margin,
&number);
gtk_css_style_property_register ("padding-top",
G_TYPE_INT,
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
0,
parse_padding,
NULL,
NULL,
NULL,
0);
compute_padding,
&number);
gtk_css_style_property_register ("padding-left",
G_TYPE_INT,
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
0,
parse_padding,
NULL,
NULL,
NULL,
0);
compute_padding,
&number);
gtk_css_style_property_register ("padding-bottom",
G_TYPE_INT,
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
0,
parse_padding,
NULL,
NULL,
NULL,
0);
compute_padding,
&number);
gtk_css_style_property_register ("padding-right",
G_TYPE_INT,
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
0,
parse_padding,
NULL,
NULL,
NULL,
0);
compute_padding,
&number);
/* IMPORTANT: compute_border_width() requires that the border-width
* properties be immeditaly followed by the border-style properties
*/
......
......@@ -15,7 +15,7 @@ GtkButton {
border-width: 5px;
border-style: solid;
border-color: rgba(255,0,0,0.6);
padding: 10;
padding: 10px;
background-color: rgb(0,0,255);
/* Make sure children of button are only offset by padding */
......
......@@ -16,7 +16,7 @@ GtkButton {
border-width: 5px;
border-style: solid;
border-color: rgba(255,0,0,0.5);
padding: 10;
padding: 10px;
background-color: rgb(0,0,255);
background-image: url("green-20x20.png");
......
......@@ -8,5 +8,5 @@
}
#reference {
padding: 20
padding: 20px
}
......@@ -9,7 +9,7 @@
GtkEntry #padded {
-GtkWidget-interior-focus: true;
padding: 10;
padding: 10px;
}
.progressbar {
......
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