summaryrefslogtreecommitdiff
path: root/gtk/gtkcssboxesimplprivate.h
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/gtkcssboxesimplprivate.h')
-rw-r--r--gtk/gtkcssboxesimplprivate.h184
1 files changed, 47 insertions, 137 deletions
diff --git a/gtk/gtkcssboxesimplprivate.h b/gtk/gtkcssboxesimplprivate.h
index 01b046ee4e..d5c8361602 100644
--- a/gtk/gtkcssboxesimplprivate.h
+++ b/gtk/gtkcssboxesimplprivate.h
@@ -44,10 +44,10 @@ gtk_css_boxes_init (GtkCssBoxes *boxes,
static inline void
gtk_css_boxes_init_content_box (GtkCssBoxes *boxes,
GtkCssStyle *style,
- double x,
- double y,
- double width,
- double height)
+ float x,
+ float y,
+ float width,
+ float height)
{
memset (boxes, 0, sizeof (GtkCssBoxes));
@@ -59,10 +59,10 @@ gtk_css_boxes_init_content_box (GtkCssBoxes *boxes,
static inline void
gtk_css_boxes_init_border_box (GtkCssBoxes *boxes,
GtkCssStyle *style,
- double x,
- double y,
- double width,
- double height)
+ float x,
+ float y,
+ float width,
+ float height)
{
memset (boxes, 0, sizeof (GtkCssBoxes));
@@ -74,70 +74,24 @@ gtk_css_boxes_init_border_box (GtkCssBoxes *boxes,
static inline void
gtk_css_boxes_rect_grow (GskRoundedRect *dest,
GskRoundedRect *src,
- GtkCssValue *top,
- GtkCssValue *right,
- GtkCssValue *bottom,
- GtkCssValue *left)
+ const float width[4])
{
- if (gtk_css_dimension_value_is_zero (left))
- {
- dest->bounds.origin.x = src->bounds.origin.x;
- if (gtk_css_dimension_value_is_zero (right))
- dest->bounds.size.width = src->bounds.size.width;
- else
- dest->bounds.size.width = src->bounds.size.width + _gtk_css_number_value_get (right, 100);
- }
- else
- {
- const double left_value = _gtk_css_number_value_get (left, 100);
-
- dest->bounds.origin.x = src->bounds.origin.x - left_value;
- if (gtk_css_dimension_value_is_zero (right))
- dest->bounds.size.width = src->bounds.size.width + left_value;
- else
- dest->bounds.size.width = src->bounds.size.width + left_value + _gtk_css_number_value_get (right, 100);
-
- }
-
-
- if (gtk_css_dimension_value_is_zero (top))
- {
- dest->bounds.origin.y = src->bounds.origin.y;
- if (gtk_css_dimension_value_is_zero (bottom))
- dest->bounds.size.height = src->bounds.size.height;
- else
- dest->bounds.size.height = src->bounds.size.height + _gtk_css_number_value_get (bottom, 100);
- }
- else
- {
- const double top_value = _gtk_css_number_value_get (top, 100);
-
- dest->bounds.origin.y = src->bounds.origin.y - top_value;
- if (gtk_css_dimension_value_is_zero (bottom))
- dest->bounds.size.height = src->bounds.size.height + top_value;
- else
- dest->bounds.size.height = src->bounds.size.height + top_value + _gtk_css_number_value_get (bottom, 100);
- }
+ dest->bounds.origin.x = src->bounds.origin.x - width[GTK_CSS_LEFT];
+ dest->bounds.origin.y = src->bounds.origin.y - width[GTK_CSS_TOP];
+ dest->bounds.size.width = src->bounds.size.width + width[GTK_CSS_LEFT] + width[GTK_CSS_RIGHT];
+ dest->bounds.size.height = src->bounds.size.height + width[GTK_CSS_TOP] + width[GTK_CSS_BOTTOM];
}
static inline void
gtk_css_boxes_rect_shrink (GskRoundedRect *dest,
GskRoundedRect *src,
- GtkCssValue *top_value,
- GtkCssValue *right_value,
- GtkCssValue *bottom_value,
- GtkCssValue *left_value)
+ const float width[4])
{
- double top = _gtk_css_number_value_get (top_value, 100);
- double right = _gtk_css_number_value_get (right_value, 100);
- double bottom = _gtk_css_number_value_get (bottom_value, 100);
- double left = _gtk_css_number_value_get (left_value, 100);
-
/* FIXME: Do we need underflow checks here? */
- dest->bounds.origin.x = src->bounds.origin.x + left;
- dest->bounds.origin.y = src->bounds.origin.y + top;
- dest->bounds.size.width = src->bounds.size.width - left - right;
- dest->bounds.size.height = src->bounds.size.height - top - bottom;
+ dest->bounds.origin.x = src->bounds.origin.x + width[GTK_CSS_LEFT];
+ dest->bounds.origin.y = src->bounds.origin.y + width[GTK_CSS_TOP];
+ dest->bounds.size.width = src->bounds.size.width - width[GTK_CSS_LEFT] - width[GTK_CSS_RIGHT];
+ dest->bounds.size.height = src->bounds.size.height - width[GTK_CSS_TOP] - width[GTK_CSS_BOTTOM];
}
static inline void gtk_css_boxes_compute_padding_rect (GtkCssBoxes *boxes);
@@ -170,10 +124,7 @@ gtk_css_boxes_compute_border_rect (GtkCssBoxes *boxes)
gtk_css_boxes_rect_grow (&boxes->box[GTK_CSS_AREA_BORDER_BOX],
&boxes->box[GTK_CSS_AREA_PADDING_BOX],
- boxes->style->border->border_top_width,
- boxes->style->border->border_right_width,
- boxes->style->border->border_bottom_width,
- boxes->style->border->border_left_width);
+ boxes->style->border->_border_width);
boxes->has_rect[GTK_CSS_AREA_BORDER_BOX] = TRUE;
}
@@ -188,19 +139,13 @@ gtk_css_boxes_compute_padding_rect (GtkCssBoxes *boxes)
{
gtk_css_boxes_rect_shrink (&boxes->box[GTK_CSS_AREA_PADDING_BOX],
&boxes->box[GTK_CSS_AREA_BORDER_BOX],
- boxes->style->border->border_top_width,
- boxes->style->border->border_right_width,
- boxes->style->border->border_bottom_width,
- boxes->style->border->border_left_width);
+ boxes->style->border->_border_width);
}
else
{
gtk_css_boxes_rect_grow (&boxes->box[GTK_CSS_AREA_PADDING_BOX],
&boxes->box[GTK_CSS_AREA_CONTENT_BOX],
- boxes->style->size->padding_top,
- boxes->style->size->padding_right,
- boxes->style->size->padding_bottom,
- boxes->style->size->padding_left);
+ boxes->style->size->_padding);
}
boxes->has_rect[GTK_CSS_AREA_PADDING_BOX] = TRUE;
@@ -216,10 +161,7 @@ gtk_css_boxes_compute_content_rect (GtkCssBoxes *boxes)
gtk_css_boxes_rect_shrink (&boxes->box[GTK_CSS_AREA_CONTENT_BOX],
&boxes->box[GTK_CSS_AREA_PADDING_BOX],
- boxes->style->size->padding_top,
- boxes->style->size->padding_right,
- boxes->style->size->padding_bottom,
- boxes->style->size->padding_left);
+ boxes->style->size->_padding);
boxes->has_rect[GTK_CSS_AREA_CONTENT_BOX] = TRUE;
}
@@ -234,10 +176,7 @@ gtk_css_boxes_compute_margin_rect (GtkCssBoxes *boxes)
gtk_css_boxes_rect_grow (&boxes->box[GTK_CSS_AREA_MARGIN_BOX],
&boxes->box[GTK_CSS_AREA_BORDER_BOX],
- boxes->style->size->margin_top,
- boxes->style->size->margin_right,
- boxes->style->size->margin_bottom,
- boxes->style->size->margin_left);
+ boxes->style->size->_margin);
boxes->has_rect[GTK_CSS_AREA_MARGIN_BOX] = TRUE;
}
@@ -246,7 +185,7 @@ static inline void
gtk_css_boxes_compute_outline_rect (GtkCssBoxes *boxes)
{
graphene_rect_t *dest, *src;
- double d;
+ float d;
if (boxes->has_rect[GTK_CSS_AREA_OUTLINE_BOX])
return;
@@ -256,8 +195,8 @@ gtk_css_boxes_compute_outline_rect (GtkCssBoxes *boxes)
dest = &boxes->box[GTK_CSS_AREA_OUTLINE_BOX].bounds;
src = &boxes->box[GTK_CSS_AREA_BORDER_BOX].bounds;
- d = _gtk_css_number_value_get (boxes->style->outline->outline_offset, 100) +
- _gtk_css_number_value_get (boxes->style->outline->outline_width, 100);
+ d = boxes->style->outline->_outline_offset +
+ boxes->style->outline->_outline_width;
dest->origin.x = src->origin.x - d;
dest->origin.y = src->origin.y - d;
@@ -311,8 +250,8 @@ gtk_css_boxes_get_outline_rect (GtkCssBoxes *boxes)
static inline void
gtk_css_boxes_clamp_border_radius (GskRoundedRect *box)
{
- double factor = 1.0;
- double corners;
+ float factor = 1.0;
+ float corners;
corners = box->corner[GSK_CORNER_TOP_LEFT].width + box->corner[GSK_CORNER_TOP_RIGHT].width;
if (corners != 0)
@@ -341,52 +280,26 @@ gtk_css_boxes_clamp_border_radius (GskRoundedRect *box)
}
static inline void
-gtk_css_boxes_apply_border_radius (GskRoundedRect *box,
- const GtkCssValue *top_left,
- const GtkCssValue *top_right,
- const GtkCssValue *bottom_right,
- const GtkCssValue *bottom_left)
+gtk_css_boxes_apply_border_radius (GskRoundedRect *box,
+ const graphene_size_t corner[4])
{
- gboolean has_border_radius = FALSE;
-
- if (!gtk_css_corner_value_is_zero (top_left))
- {
- box->corner[GSK_CORNER_TOP_LEFT].width = _gtk_css_corner_value_get_x (top_left, box->bounds.size.width);
- box->corner[GSK_CORNER_TOP_LEFT].height = _gtk_css_corner_value_get_y (top_left, box->bounds.size.height);
- has_border_radius = TRUE;
- }
-
- if (!gtk_css_corner_value_is_zero (top_right))
- {
- box->corner[GSK_CORNER_TOP_RIGHT].width = _gtk_css_corner_value_get_x (top_right, box->bounds.size.width);
- box->corner[GSK_CORNER_TOP_RIGHT].height = _gtk_css_corner_value_get_y (top_right, box->bounds.size.height);
- has_border_radius = TRUE;
- }
-
- if (!gtk_css_corner_value_is_zero (bottom_right))
- {
- box->corner[GSK_CORNER_BOTTOM_RIGHT].width = _gtk_css_corner_value_get_x (bottom_right, box->bounds.size.width);
- box->corner[GSK_CORNER_BOTTOM_RIGHT].height = _gtk_css_corner_value_get_y (bottom_right, box->bounds.size.height);
- has_border_radius = TRUE;
- }
-
- if (!gtk_css_corner_value_is_zero (bottom_left))
+ memcpy (box->corner, corner, sizeof (graphene_size_t) * 4);
+ for (int i = 0; i < 4; i++)
{
- box->corner[GSK_CORNER_BOTTOM_LEFT].width = _gtk_css_corner_value_get_x (bottom_left, box->bounds.size.width);
- box->corner[GSK_CORNER_BOTTOM_LEFT].height = _gtk_css_corner_value_get_y (bottom_left, box->bounds.size.height);
- has_border_radius = TRUE;
+ if (corner[i].width != 0 || corner[i].height != 0)
+ {
+ gtk_css_boxes_clamp_border_radius (box);
+ break;
+ }
}
-
- if (has_border_radius)
- gtk_css_boxes_clamp_border_radius (box);
}
/* NB: width and height must be >= 0 */
static inline void
gtk_css_boxes_shrink_border_radius (graphene_size_t *dest,
const graphene_size_t *src,
- double width,
- double height)
+ float width,
+ float height)
{
dest->width = src->width - width;
dest->height = src->height - height;
@@ -402,10 +315,10 @@ static inline void
gtk_css_boxes_shrink_corners (GskRoundedRect *dest,
const GskRoundedRect *src)
{
- double top = dest->bounds.origin.y - src->bounds.origin.y;
- double right = src->bounds.origin.x + src->bounds.size.width - dest->bounds.origin.x - dest->bounds.size.width;
- double bottom = src->bounds.origin.y + src->bounds.size.height - dest->bounds.origin.y - dest->bounds.size.height;
- double left = dest->bounds.origin.x - src->bounds.origin.x;
+ float top = dest->bounds.origin.y - src->bounds.origin.y;
+ float right = src->bounds.origin.x + src->bounds.size.width - dest->bounds.origin.x - dest->bounds.size.width;
+ float bottom = src->bounds.origin.y + src->bounds.size.height - dest->bounds.origin.y - dest->bounds.size.height;
+ float left = dest->bounds.origin.x - src->bounds.origin.x;
gtk_css_boxes_shrink_border_radius (&dest->corner[GSK_CORNER_TOP_LEFT],
&src->corner[GSK_CORNER_TOP_LEFT],
@@ -430,10 +343,7 @@ gtk_css_boxes_compute_border_box (GtkCssBoxes *boxes)
gtk_css_boxes_compute_border_rect (boxes);
gtk_css_boxes_apply_border_radius (&boxes->box[GTK_CSS_AREA_BORDER_BOX],
- boxes->style->border->border_top_left_radius,
- boxes->style->border->border_top_right_radius,
- boxes->style->border->border_bottom_right_radius,
- boxes->style->border->border_bottom_left_radius);
+ boxes->style->border->_border_radius);
boxes->has_box[GTK_CSS_AREA_BORDER_BOX] = TRUE;
}
@@ -473,7 +383,7 @@ gtk_css_boxes_compute_outline_box (GtkCssBoxes *boxes)
{
const GskRoundedRect *src;
GskRoundedRect *dest;
- double d;
+ float d;
int i;
if (boxes->has_box[GTK_CSS_AREA_OUTLINE_BOX])
@@ -484,8 +394,8 @@ gtk_css_boxes_compute_outline_box (GtkCssBoxes *boxes)
src = &boxes->box[GTK_CSS_AREA_BORDER_BOX];
dest = &boxes->box[GTK_CSS_AREA_OUTLINE_BOX];
- d = _gtk_css_number_value_get (boxes->style->outline->outline_offset, 100) +
- _gtk_css_number_value_get (boxes->style->outline->outline_width, 100);
+ d = boxes->style->outline->_outline_offset +
+ boxes->style->outline->_outline_width;
/* Grow border rect into outline rect */
dest->bounds.origin.x = src->bounds.origin.x - d;