Commit cce4acab authored by Timm Bäder's avatar Timm Bäder 👎

widget: Fix translate_coordinates for CSS values

As well as compute_bounds. In these cases, we need to consider the CSS
values (margin, border padding) specially.
parent 7c8b1fd6
......@@ -4394,30 +4394,6 @@ gtk_widget_common_ancestor (GtkWidget *widget_a,
return widget_a;
}
void
gtk_widget_get_origin_relative_to_parent (GtkWidget *widget,
int *origin_x,
int *origin_y)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GtkBorder margin, border, padding;
GtkCssStyle *style;
style = gtk_css_node_get_style (priv->cssnode);
get_box_margin (style, &margin);
get_box_border (style, &border);
get_box_padding (style, &padding);
/* allocation is relative to the parent's origin */
*origin_x = priv->allocation.x;
*origin_y = priv->allocation.y;
/* ... but points to the upper left, excluding widget margins
* but including all the css properties */
*origin_x += margin.left + border.left + padding.left;
*origin_y += margin.top + border.top + padding.top;
}
/**
* gtk_widget_translate_coordinates:
* @src_widget: a #GtkWidget
......@@ -4515,8 +4491,27 @@ gtk_widget_translate_coordinatesf (GtkWidget *src_widget,
{
graphene_vec4_t offset;
int origin_x, origin_y;
GtkBorder margin, border, padding;
GtkCssStyle *style;
gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
style = gtk_css_node_get_style (parent->priv->cssnode);
get_box_margin (style, &margin);
get_box_border (style, &border);
get_box_padding (style, &padding);
/* CSS Values */
{
graphene_vec4_t v;
graphene_vec4_init (&v,
margin.left + border.left + padding.left,
margin.top + border.top + padding.top,
0, 0);
graphene_vec4_add (&src_point, &v, &src_point);
}
origin_x = parent->priv->allocation.x;
origin_y = parent->priv->allocation.y;
graphene_matrix_transform_vec4 (&parent->priv->transform, &src_point, &src_point);
graphene_vec4_init (&offset, origin_x, origin_y, 0, 0);
......@@ -4532,10 +4527,18 @@ gtk_widget_translate_coordinatesf (GtkWidget *src_widget,
int origin_x, origin_y;
graphene_vec4_t offset;
graphene_matrix_t inv_transform;
GtkBorder margin, border, padding;
GtkCssStyle *style;
parent = dest_path[i];
gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
style = gtk_css_node_get_style (parent->priv->cssnode);
get_box_margin (style, &margin);
get_box_border (style, &border);
get_box_padding (style, &padding);
origin_x = parent->priv->allocation.x;
origin_y = parent->priv->allocation.y;
graphene_vec4_init (&offset, -origin_x, -origin_y, 0, 0);
graphene_vec4_add (&src_point, &offset, &src_point);
......@@ -4543,6 +4546,16 @@ gtk_widget_translate_coordinatesf (GtkWidget *src_widget,
/* TODO: inversion can fail */
graphene_matrix_inverse (&parent->priv->transform, &inv_transform);
graphene_matrix_transform_vec4 (&inv_transform, &src_point, &src_point);
/* CSS Values */
{
graphene_vec4_t v;
graphene_vec4_init (&v,
- margin.left - border.left - padding.left,
- margin.top - border.top - padding.top, 0, 0);
graphene_vec4_add (&src_point, &v, &src_point);
}
}
if (dest_x)
......@@ -11361,8 +11374,20 @@ gtk_widget_compute_bounds (GtkWidget *widget,
while (parent != ancestor)
{
int origin_x, origin_y;
GtkBorder margin, border, padding;
GtkCssStyle *style;
style = gtk_css_node_get_style (parent->priv->cssnode);
get_box_margin (style, &margin);
get_box_border (style, &border);
get_box_padding (style, &padding);
gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
graphene_rect_offset (&bounds,
margin.left + border.left + padding.left,
margin.top + border.top + padding.top);
origin_x = parent->priv->allocation.x;
origin_y = parent->priv->allocation.y;
graphene_matrix_transform_bounds (&parent->priv->transform, &bounds, &bounds);
graphene_rect_offset (&bounds, origin_x, origin_y);
......@@ -11376,16 +11401,28 @@ gtk_widget_compute_bounds (GtkWidget *widget,
{
int origin_x, origin_y;
graphene_matrix_t inv_transform;
GtkBorder margin, border, padding;
GtkCssStyle *style;
parent = dest_path[i];
gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
style = gtk_css_node_get_style (parent->priv->cssnode);
get_box_margin (style, &margin);
get_box_border (style, &border);
get_box_padding (style, &padding);
origin_x = parent->priv->allocation.x;
origin_y = parent->priv->allocation.y;
graphene_rect_offset (&bounds, -origin_x, -origin_y);
/* TODO: Inversion can fail */
graphene_matrix_inverse (&parent->priv->transform, &inv_transform);
graphene_matrix_transform_bounds (&inv_transform, &bounds, &bounds);
graphene_rect_offset (&bounds,
- margin.left - border.left - padding.left,
- margin.top - border.top - padding.top);
}
*out_bounds = bounds;
......
......@@ -331,6 +331,11 @@ void gtk_widget_get_origin_relative_to_parent (GtkWidget *wi
int *origin_x,
int *origin_y);
gboolean gtk_widget_emit_event_signals (GtkWidget *widget,
const GdkEvent *event);
void gtk_widget_init_legacy_controller (GtkWidget *widget);
void gtk_widget_cancel_event_sequence (GtkWidget *widget,
GtkGesture *gesture,
GdkEventSequence *sequence,
......
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