[gtk/wip/baedert/transforms6: 21/31] widget: Fix translate_coordinates for CSS values
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/transforms6: 21/31] widget: Fix translate_coordinates for CSS values
- Date: Thu, 29 Nov 2018 08:10:10 +0000 (UTC)
commit 1baf46017547d0c47360ca810368e622d9b165a3
Author: Timm Bäder <mail baedert org>
Date: Sun Aug 12 13:32:20 2018 +0200
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.
gtk/gtkwidget.c | 93 +++++++++++++++++++++++++++++++++++---------------
gtk/gtkwidgetprivate.h | 5 +++
2 files changed, 70 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 4b13b08eb7..eb8f58d523 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4374,30 +4374,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
@@ -4495,8 +4471,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);
@@ -4512,10 +4507,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);
@@ -4523,6 +4526,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)
@@ -11395,8 +11408,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);
@@ -11410,16 +11435,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;
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 0585eb5284..69622e9821 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -330,6 +330,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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]