StThemeNode: Add border-radius support

Add support for parsing and caching the border-radius property.
Different radii for the 4 corners are supported; elliptical corners
are not supported.

https://bugzilla.gnome.org/show_bug.cgi?id=595993
This commit is contained in:
Owen W. Taylor
2009-09-20 09:08:08 -04:00
parent 1fd25573e5
commit 8c72623da3
4 changed files with 199 additions and 13 deletions

View File

@ -24,6 +24,7 @@ struct _StThemeNode {
ClutterColor foreground_color;
ClutterColor border_color[4];
double border_width[4];
double border_radius[4];
guint padding[4];
char *background_image;
@ -759,6 +760,88 @@ st_theme_node_get_length (StThemeNode *node,
return FALSE;
}
static void
do_border_radius_term (StThemeNode *node,
CRTerm *term,
gboolean topleft,
gboolean topright,
gboolean bottomright,
gboolean bottomleft)
{
gdouble value;
if (get_length_from_term (node, term, FALSE, &value) != VALUE_FOUND)
return;
if (topleft)
node->border_radius[ST_CORNER_TOPLEFT] = value;
if (topright)
node->border_radius[ST_CORNER_TOPRIGHT] = value;
if (bottomright)
node->border_radius[ST_CORNER_BOTTOMRIGHT] = value;
if (bottomleft)
node->border_radius[ST_CORNER_BOTTOMLEFT] = value;
}
static void
do_border_radius (StThemeNode *node,
CRDeclaration *decl)
{
const char *property_name = decl->property->stryng->str + 13; /* Skip 'border-radius' */
if (strcmp (property_name, "") == 0)
{
/* Slight deviation ... if we don't understand some of the terms and understand others,
* then we set the ones we understand and ignore the others instead of ignoring the
* whole thing
*/
if (decl->value == NULL) /* 0 values */
return;
else if (decl->value->next == NULL) /* 1 value */
{
do_border_radius_term (node, decl->value, TRUE, TRUE, TRUE, TRUE); /* all corners */
return;
}
else if (decl->value->next->next == NULL) /* 2 values */
{
do_border_radius_term (node, decl->value, TRUE, FALSE, TRUE, FALSE); /* topleft/bottomright */
do_border_radius_term (node, decl->value->next, FALSE, TRUE, FALSE, TRUE); /* topright/bottomleft */
}
else if (decl->value->next->next->next == NULL) /* 3 values */
{
do_border_radius_term (node, decl->value, TRUE, FALSE, FALSE, FALSE); /* topleft */
do_border_radius_term (node, decl->value->next, FALSE, TRUE, FALSE, TRUE); /* topright/bottomleft */
do_border_radius_term (node, decl->value->next->next, FALSE, FALSE, TRUE, FALSE); /* bottomright */
}
else if (decl->value->next->next->next->next == NULL) /* 4 values */
{
do_border_radius_term (node, decl->value, TRUE, FALSE, FALSE, FALSE); /* topleft */
do_border_radius_term (node, decl->value->next, FALSE, TRUE, FALSE, FALSE); /* topright */
do_border_radius_term (node, decl->value->next->next, FALSE, FALSE, TRUE, FALSE); /* bottomright */
do_border_radius_term (node, decl->value->next->next->next, FALSE, FALSE, FALSE, TRUE); /* bottomleft */
}
else
{
g_warning ("Too many values for border-radius property");
return;
}
}
else
{
if (decl->value == NULL || decl->value->next != NULL)
return;
if (strcmp (property_name, "-topleft") == 0)
do_border_radius_term (node, decl->value, TRUE, FALSE, FALSE, FALSE);
else if (strcmp (property_name, "-topright") == 0)
do_border_radius_term (node, decl->value, FALSE, TRUE, FALSE, FALSE);
else if (strcmp (property_name, "-bottomright") == 0)
do_border_radius_term (node, decl->value, FALSE, FALSE, TRUE, FALSE);
else if (strcmp (property_name, "-bottomleft") == 0)
do_border_radius_term (node, decl->value, FALSE, FALSE, FALSE, TRUE);
}
}
static void
do_border_property (StThemeNode *node,
CRDeclaration *decl)
@ -771,6 +854,12 @@ do_border_property (StThemeNode *node,
gboolean width_set = FALSE;
int j;
if (g_str_has_prefix (property_name, "-radius"))
{
do_border_radius (node, decl);
return;
}
if (g_str_has_prefix (property_name, "-left"))
{
side = ST_SIDE_LEFT;
@ -1004,13 +1093,25 @@ st_theme_node_get_border_width (StThemeNode *node,
StSide side)
{
g_return_val_if_fail (ST_IS_THEME_NODE (node), 0.);
g_return_val_if_fail (side >= ST_SIDE_LEFT && side <= ST_SIDE_BOTTOM, 0.);
g_return_val_if_fail (side >= ST_SIDE_TOP && side <= ST_SIDE_LEFT, 0.);
ensure_borders (node);
return node->border_width[side];
}
double
st_theme_node_get_border_radius (StThemeNode *node,
StCorner corner)
{
g_return_val_if_fail (ST_IS_THEME_NODE (node), 0.);
g_return_val_if_fail (corner >= ST_CORNER_TOPLEFT && corner <= ST_CORNER_BOTTOMLEFT, 0.);
ensure_borders (node);
return node->border_radius[corner];
}
static GetFromTermResult
get_background_color_from_term (StThemeNode *node,
CRTerm *term,
@ -1202,7 +1303,7 @@ st_theme_node_get_border_color (StThemeNode *node,
ClutterColor *color)
{
g_return_if_fail (ST_IS_THEME_NODE (node));
g_return_if_fail (side >= ST_SIDE_LEFT && side <= ST_SIDE_BOTTOM);
g_return_if_fail (side >= ST_SIDE_TOP && side <= ST_SIDE_LEFT);
ensure_borders (node);
@ -1214,7 +1315,7 @@ st_theme_node_get_padding (StThemeNode *node,
StSide side)
{
g_return_val_if_fail (ST_IS_THEME_NODE (node), 0.);
g_return_val_if_fail (side >= ST_SIDE_LEFT && side <= ST_SIDE_BOTTOM, 0.);
g_return_val_if_fail (side >= ST_SIDE_TOP && side <= ST_SIDE_LEFT, 0.);
ensure_borders (node);