css: Make border-width a length property

This commit is contained in:
Benjamin Otte 2012-01-15 02:53:39 +01:00
parent a81ac3d5cd
commit 762ea4793f
5 changed files with 141 additions and 52 deletions

View File

@ -121,7 +121,7 @@ GtkTreeView.view.expander:selected:prelight {
background-color: alpha (@fg_color, 0.25);
border-color: @fg_color;
border-style: solid;
border-width: 1;
border-width: 1px;
}
.tooltip,
@ -129,14 +129,14 @@ GtkTreeView.view.expander:selected:prelight {
background-color: @tooltip_bg_color;
color: @tooltip_fg_color;
border-color: @tooltip_fg_color;
border-width: 1;
border-width: 1px;
border-style: solid;
}
.button,
.slider {
border-style: outset;
border-width: 2;
border-width: 2px;
}
.button:active {
@ -154,13 +154,13 @@ GtkTreeView.view.expander:selected:prelight {
.trough {
background-color: darker (@bg_color);
border-style: inset;
border-width: 1;
border-width: 1px;
padding: 0;
}
.entry {
border-style: inset;
border-width: 2;
border-width: 2px;
background-color: @base_color;
color: @text_color;
}
@ -181,7 +181,7 @@ GtkTreeView.view.expander:selected:prelight {
border-color: shade (@selected_bg_color, 0.7);
color: @selected_fg_color;
border-style: outset;
border-width: 1;
border-width: 1px;
}
GtkCheckButton:hover,
@ -195,7 +195,7 @@ GtkRadioButton:selected {
.cell.check, .cell.radio,
.cell.check:hover, .cell.radio:hover {
border-style: solid;
border-width: 1;
border-width: 1px;
background-color: @base_color;
border-color: @fg_color;
}
@ -225,22 +225,22 @@ GtkRadioButton:selected {
.popup {
border-style: outset;
border-width: 1;
border-width: 1px;
}
.viewport {
border-style: inset;
border-width: 2;
border-width: 2px;
}
.notebook {
border-style: outset;
border-width: 1;
border-width: 1px;
}
.frame {
border-style: inset;
border-width: 1;
border-width: 1px;
}
GtkScrolledWindow.frame {
@ -251,7 +251,7 @@ GtkScrolledWindow.frame {
.menubar,
.toolbar {
border-style: outset;
border-width: 1;
border-width: 1px;
}
.menu:hover,
@ -264,7 +264,7 @@ GtkScrolledWindow.frame {
}
GtkSpinButton.button {
border-width: 1;
border-width: 1px;
}
.scale.slider:hover,
@ -330,7 +330,7 @@ GtkLabel:selected:focused {
color: #fff;
}
GtkCalendar.view {
border-width: 1;
border-width: 1px;
border-style: inset;
padding: 1;
}
@ -342,7 +342,7 @@ GtkCalendar.view:inconsistent {
GtkCalendar.header {
background-color: @bg_color;
border-style: outset;
border-width: 2;
border-width: 2px;
}
GtkCalendar.highlight {

View File

@ -240,7 +240,7 @@
.spinbutton.button,
.spinbutton.button:focused {
background-color: transparent;
border-width: 1 1 0 0;
border-width: 1px 1px 0 0;
border-style: none;
background-image: -gtk-win32-theme-part(spin, 1 1);
color: rgba(0, 0, 0, 0);
@ -265,7 +265,7 @@
.spinbutton.button.bottom,
.spinbutton.button.bottom:focused {
border-width: 0 1 1 0;
border-width: 0 1px 1px 0;
background-image: -gtk-win32-theme-part(spin, 2 1);
color: rgba(0, 0, 0, 0);
}
@ -589,7 +589,7 @@ GtkComboBox.combobox-entry .button:insensitive {
.notebook {
background-color: transparent;
border-width: 1 3 2 2;
border-width: 1px 3px 2px 2px;
border-style: solid;
background-origin: padding-box;
background-clip: border-box;

View File

@ -2792,7 +2792,6 @@ gtk_css_provider_get_default (void)
if (G_UNLIKELY (!provider))
{
provider = gtk_css_provider_new ();
if (!_gtk_css_provider_load_from_resource (provider, "/org/gtk/libgtk/gtk-default.css"))
{

View File

@ -80,6 +80,48 @@ parse_border_width (GtkCssShorthandProperty *shorthand,
return TRUE;
}
static gboolean
parse_border_width_really (GtkCssShorthandProperty *shorthand,
GValue *values,
GtkCssParser *parser,
GFile *base)
{
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],
GTK_CSS_POSITIVE_ONLY
| GTK_CSS_NUMBER_AS_PIXELS
| GTK_CSS_PARSE_LENGTH))
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++)
{
g_value_init (&values[i], GTK_TYPE_CSS_NUMBER);
g_value_set_boxed (&values[i], &numbers[i]);
}
return TRUE;
}
static gboolean
parse_border_radius (GtkCssShorthandProperty *shorthand,
GValue *values,
@ -269,16 +311,23 @@ parse_border_side (GtkCssShorthandProperty *shorthand,
GtkCssParser *parser,
GFile *base)
{
int width;
int style;
do
{
if (!G_IS_VALUE (&values[0]) &&
_gtk_css_parser_try_length (parser, &width))
_gtk_css_parser_has_number (parser))
{
g_value_init (&values[0], G_TYPE_INT);
g_value_set_int (&values[0], width);
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_init (&values[0], GTK_TYPE_CSS_NUMBER);
g_value_set_boxed (&values[0], &number);
}
else if (!G_IS_VALUE (&values[1]) &&
_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, &style))
@ -316,22 +365,29 @@ parse_border (GtkCssShorthandProperty *shorthand,
GtkCssParser *parser,
GFile *base)
{
int width;
int style;
do
{
if (!G_IS_VALUE (&values[0]) &&
_gtk_css_parser_try_length (parser, &width))
_gtk_css_parser_has_number (parser))
{
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], width);
g_value_set_int (&values[1], width);
g_value_set_int (&values[2], width);
g_value_set_int (&values[3], width);
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_init (&values[0], GTK_TYPE_CSS_NUMBER);
g_value_init (&values[1], GTK_TYPE_CSS_NUMBER);
g_value_init (&values[2], GTK_TYPE_CSS_NUMBER);
g_value_init (&values[3], GTK_TYPE_CSS_NUMBER);
g_value_set_boxed (&values[0], &number);
g_value_set_boxed (&values[1], &number);
g_value_set_boxed (&values[2], &number);
g_value_set_boxed (&values[3], &number);
}
else if (!G_IS_VALUE (&values[4]) &&
_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, &style))
@ -843,7 +899,7 @@ _gtk_css_shorthand_property_init_properties (void)
_gtk_css_shorthand_property_register ("border-width",
GTK_TYPE_BORDER,
border_width_subproperties,
parse_border_width,
parse_border_width_really,
unpack_border,
pack_border);
_gtk_css_shorthand_property_register ("border-radius",

View File

@ -24,6 +24,7 @@
#include <gobject/gvaluecollector.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <cairo-gobject.h>
#include <math.h>
#include "gtkcssparserprivate.h"
#include "gtkcssstylefuncsprivate.h"
@ -33,6 +34,11 @@
#include "gtkprivatetypebuiltins.h"
#include "gtkstylepropertiesprivate.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"
/* the actual parsers we have */
#include "gtkanimationdescription.h"
#include "gtkbindings.h"
@ -419,6 +425,25 @@ css_image_value_compute (GtkCssStyleProperty *property,
g_value_take_object (computed, image);
}
static gboolean
parse_border_width (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_border_width (GtkCssStyleProperty *property,
GValue *computed,
@ -427,6 +452,7 @@ 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.
@ -436,9 +462,15 @@ compute_border_width (GtkCssStyleProperty *property,
if (border_style == GTK_BORDER_STYLE_NONE ||
border_style == GTK_BORDER_STYLE_HIDDEN)
{
g_value_set_int (computed, 0);
else
g_value_copy (specified, computed);
return;
}
_gtk_css_number_compute (&number,
g_value_get_boxed (specified),
context);
g_value_set_int (computed, round (number.value));
}
static gboolean
@ -524,6 +556,7 @@ void
_gtk_css_style_property_init_properties (void)
{
char *default_font_family[] = { "Sans", NULL };
GtkCssNumber number;
GtkSymbolicColor *symbolic;
GtkCssBorderCornerRadius no_corner_radius = { 0, };
GtkBorder border_of_ones = { 1, 1, 1, 1 };
@ -708,6 +741,7 @@ _gtk_css_style_property_init_properties (void)
NULL,
NULL,
0);
_gtk_css_number_init (&number, 0, GTK_CSS_PX);
/* IMPORTANT: compute_border_width() requires that the border-width
* properties be immeditaly followed by the border-style properties
*/
@ -721,14 +755,14 @@ _gtk_css_style_property_init_properties (void)
NULL,
GTK_BORDER_STYLE_NONE);
gtk_css_style_property_register ("border-top-width",
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
G_TYPE_INT,
0,
NULL,
parse_border_width,
NULL,
compute_border_width,
0);
&number);
gtk_css_style_property_register ("border-left-style",
GTK_TYPE_BORDER_STYLE,
GTK_TYPE_BORDER_STYLE,
@ -739,14 +773,14 @@ _gtk_css_style_property_init_properties (void)
NULL,
GTK_BORDER_STYLE_NONE);
gtk_css_style_property_register ("border-left-width",
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
G_TYPE_INT,
0,
NULL,
parse_border_width,
NULL,
compute_border_width,
0);
&number);
gtk_css_style_property_register ("border-bottom-style",
GTK_TYPE_BORDER_STYLE,
GTK_TYPE_BORDER_STYLE,
@ -757,14 +791,14 @@ _gtk_css_style_property_init_properties (void)
NULL,
GTK_BORDER_STYLE_NONE);
gtk_css_style_property_register ("border-bottom-width",
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
G_TYPE_INT,
0,
NULL,
parse_border_width,
NULL,
compute_border_width,
0);
&number);
gtk_css_style_property_register ("border-right-style",
GTK_TYPE_BORDER_STYLE,
GTK_TYPE_BORDER_STYLE,
@ -775,14 +809,14 @@ _gtk_css_style_property_init_properties (void)
NULL,
GTK_BORDER_STYLE_NONE);
gtk_css_style_property_register ("border-right-width",
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
G_TYPE_INT,
0,
NULL,
parse_border_width,
NULL,
compute_border_width,
0);
&number);
gtk_css_style_property_register ("border-top-left-radius",
GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
@ -831,14 +865,14 @@ _gtk_css_style_property_init_properties (void)
NULL,
GTK_BORDER_STYLE_NONE);
gtk_css_style_property_register ("outline-width",
G_TYPE_INT,
GTK_TYPE_CSS_NUMBER,
G_TYPE_INT,
G_TYPE_INT,
0,
NULL,
parse_border_width,
NULL,
compute_border_width,
0);
&number);
gtk_css_style_property_register ("outline-offset",
G_TYPE_INT,
G_TYPE_INT,