[gtk/wip/baedert/transforms6: 26/31] widget: Don't save position in allocations



commit 4f3180e8e92e39a3e734b59bd8b33bdaa4f414f2
Author: Timm Bäder <mail baedert org>
Date:   Sat Aug 18 09:38:47 2018 +0200

    widget: Don't save position in allocations
    
    The position we save in those is always 0 now, so let's just remove it.
    Also remove the allocated_transform since the difference between that
    and the one we save as priv->transform is always just a translation and
    we only look at priv->allocated_transform in
    gtk_widget_get_allocated_size().

 demos/gtk-demo/popover.c       |   9 +--
 examples/drawing.c             |   9 +--
 gtk/a11y/gtkpanedaccessible.c  |   3 +-
 gtk/a11y/gtkwidgetaccessible.c |   4 +-
 gtk/gtkwidget.c                | 132 ++++++++++++++++++++---------------------
 gtk/gtkwidgetprivate.h         |  21 +++++--
 gtk/gtkwindow.c                |   4 +-
 tests/testoverlaystyleclass.c  |   3 +-
 8 files changed, 97 insertions(+), 88 deletions(-)
---
diff --git a/demos/gtk-demo/popover.c b/demos/gtk-demo/popover.c
index 2feb48ac70..3aa201c2d3 100644
--- a/demos/gtk-demo/popover.c
+++ b/demos/gtk-demo/popover.c
@@ -55,10 +55,11 @@ create_complex_popover (GtkWidget       *parent,
 }
 
 static void
-entry_size_allocate_cb (GtkEntry            *entry,
-                        const GtkAllocation *allocation,
-                        int                  baseline,
-                        gpointer             user_data)
+entry_size_allocate_cb (GtkEntry *entry,
+                        int       width,
+                        int       height,
+                        int       baseline,
+                        gpointer  user_data)
 {
   GtkEntryIconPosition popover_pos;
   GtkPopover *popover = user_data;
diff --git a/examples/drawing.c b/examples/drawing.c
index 08f2872105..264a71e7a5 100644
--- a/examples/drawing.c
+++ b/examples/drawing.c
@@ -19,7 +19,8 @@ clear_surface (void)
 /* Create a new surface of the appropriate size to store our scribbles */
 static void
 size_allocate_cb (GtkWidget     *widget,
-                  GtkAllocation *alloc,
+                  int            width,
+                  int            height,
                   int            baseline,
                   gpointer       data)
 {
@@ -32,9 +33,9 @@ size_allocate_cb (GtkWidget     *widget,
   if (gtk_widget_get_surface (widget))
     {
       surface = gdk_surface_create_similar_surface (gtk_widget_get_surface (widget),
-                                                   CAIRO_CONTENT_COLOR,
-                                                   gtk_widget_get_width (widget),
-                                                   gtk_widget_get_height (widget));
+                                                    CAIRO_CONTENT_COLOR,
+                                                    width,
+                                                    height);
 
       /* Initialize the surface to white */
       clear_surface ();
diff --git a/gtk/a11y/gtkpanedaccessible.c b/gtk/a11y/gtkpanedaccessible.c
index 48dc9e454a..71f6857ef8 100644
--- a/gtk/a11y/gtkpanedaccessible.c
+++ b/gtk/a11y/gtkpanedaccessible.c
@@ -27,8 +27,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkPanedAccessible, gtk_paned_accessible, GTK_TYPE_CONT
                          G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
 
 static void
-gtk_paned_accessible_size_allocate_gtk (GtkWidget     *widget,
-                                        GtkAllocation *allocation)
+gtk_paned_accessible_size_allocate_gtk (GtkWidget *widget)
 {
   AtkObject *obj = gtk_widget_get_accessible (widget);
 
diff --git a/gtk/a11y/gtkwidgetaccessible.c b/gtk/a11y/gtkwidgetaccessible.c
index 69a205f508..103851e0e2 100644
--- a/gtk/a11y/gtkwidgetaccessible.c
+++ b/gtk/a11y/gtkwidgetaccessible.c
@@ -59,9 +59,7 @@ notify_cb (GObject    *obj,
 
 /* Translate GtkWidget::size-allocate to AtkComponent::bounds-changed */
 static void
-size_allocate_cb (GtkWidget *widget,
-                  int        width,
-                  int        height)
+size_allocate_cb (GtkWidget *widget)
 {
   AtkObject* accessible;
   AtkRectangle rect;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 114751d780..856507beab 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -853,8 +853,8 @@ gtk_widget_real_contains (GtkWidget *widget,
   graphene_rect_init (&bounds,
                       - border.left - padding.left,
                       - border.top - padding.top,
-                      priv->allocation.width - margin.left - margin.right,
-                      priv->allocation.height - margin.top - margin.bottom);
+                      priv->width - margin.left - margin.right,
+                      priv->height - margin.top - margin.bottom);
 
   /* XXX: This misses rounded rects */
   return graphene_rect_contains_point (&bounds,
@@ -2849,10 +2849,8 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   priv->visible = gtk_widget_class_get_visible_by_default (g_class);
   priv->child_visible = TRUE;
   priv->name = NULL;
-  priv->allocation.x = -1;
-  priv->allocation.y = -1;
-  priv->allocation.width = 0;
-  priv->allocation.height = 0;
+  priv->width = 0;
+  priv->height = 0;
   priv->user_alpha = 255;
   priv->alpha = 255;
   priv->surface = NULL;
@@ -3085,8 +3083,8 @@ gtk_widget_unparent (GtkWidget *widget)
   /* Reset the width and height here, to force reallocation if we
    * get added back to a new parent.
    */
-  priv->allocation.width = 0;
-  priv->allocation.height = 0;
+  priv->width = 0;
+  priv->height = 0;
 
   if (_gtk_widget_get_realized (widget))
     gtk_widget_unrealize (widget);
@@ -4112,7 +4110,7 @@ effective_align (GtkAlign         align,
 static void
 adjust_for_align (GtkAlign           align,
                   GtkOrientation     orientation,
-                  graphene_matrix_t *transform,
+                  int               *offset,
                   int                min_size,
                   int               *allocated_size)
 {
@@ -4128,23 +4126,11 @@ adjust_for_align (GtkAlign           align,
       *allocated_size = MIN (*allocated_size, min_size);
       break;
     case GTK_ALIGN_END:
-      if (orientation == GTK_ORIENTATION_HORIZONTAL)
-        graphene_matrix_translate (transform,
-                                   &GRAPHENE_POINT3D_INIT (*allocated_size - min_size, 0, 0));
-      else
-        graphene_matrix_translate (transform,
-                                   &GRAPHENE_POINT3D_INIT (0, *allocated_size - min_size, 0));
-
+      *offset += *allocated_size - min_size;
       *allocated_size = min_size;
       break;
     case GTK_ALIGN_CENTER:
-      if (orientation == GTK_ORIENTATION_HORIZONTAL)
-        graphene_matrix_translate (transform,
-                                   &GRAPHENE_POINT3D_INIT ((*allocated_size - min_size) / 2, 0, 0));
-      else
-        graphene_matrix_translate (transform,
-                                   &GRAPHENE_POINT3D_INIT (0, (*allocated_size - min_size) / 2, 0));
-
+      *offset += (*allocated_size - min_size) / 2;
       *allocated_size = min_size;
       break;
     }
@@ -4169,6 +4155,8 @@ gtk_widget_size_allocate_transformed (GtkWidget               *widget,
   GtkCssStyle *style;
   GtkBorder margin, border, padding;
   GdkDisplay *display;
+  int allocated_offset_x;
+  int allocated_offset_y;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (baseline >= -1);
@@ -4202,8 +4190,9 @@ gtk_widget_size_allocate_transformed (GtkWidget               *widget,
 
   real_allocation = (GtkAllocation) {0, 0, width, height};
 
-  priv->allocated_transform = *transform;
-  priv->allocated_size = real_allocation;
+  /*priv->allocated_transform = *transform;*/
+  priv->allocated_width = real_allocation.width;
+  priv->allocated_height = real_allocation.height;
   priv->allocated_size_baseline = baseline;
 
   adjusted_allocation = real_allocation;
@@ -4246,23 +4235,28 @@ gtk_widget_size_allocate_transformed (GtkWidget               *widget,
 
   final_transform = *transform;
   /* Remove widget margins from the allocated size */
-  graphene_matrix_translate (&final_transform,
-                             &GRAPHENE_POINT3D_INIT (priv->margin.left,
-                                                     priv->margin.top, 0));
+  allocated_offset_x = priv->margin.left;
+  allocated_offset_y = priv->margin.top;
   adjusted_allocation.width  -= priv->margin.left + priv->margin.right;
   adjusted_allocation.height -= priv->margin.top  + priv->margin.bottom;
 
   adjust_for_align (effective_align (priv->halign, _gtk_widget_get_direction (widget)),
                     GTK_ORIENTATION_HORIZONTAL,
-                    &final_transform,
+                    &allocated_offset_x,
                     min_width,
                     &adjusted_allocation.width);
   adjust_for_align (effective_align (priv->valign, GTK_TEXT_DIR_NONE),
                     GTK_ORIENTATION_VERTICAL,
-                    &final_transform,
+                    &allocated_offset_y,
                     min_height,
                     &adjusted_allocation.height);
 
+  priv->allocated_offset_x = allocated_offset_x;
+  priv->allocated_offset_y = allocated_offset_y;
+
+  graphene_matrix_translate (&final_transform,
+                             &GRAPHENE_POINT3D_INIT (allocated_offset_x, allocated_offset_y, 0));
+
   if (baseline >= 0)
     baseline -= priv->margin.top;
 
@@ -4286,14 +4280,15 @@ gtk_widget_size_allocate_transformed (GtkWidget               *widget,
     }
 
   baseline_changed = priv->allocated_baseline != baseline;
-  size_changed = (priv->allocation.width != real_allocation.width ||
-                  priv->allocation.height != real_allocation.height);
+  size_changed = (priv->width != real_allocation.width ||
+                  priv->height != real_allocation.height);
   transform_changed = memcmp (&final_transform,
                               &priv->transform,
                               sizeof (graphene_matrix_t)) != 0;
 
   /* Set the widget allocation to real_allocation now, pass the smaller allocation to the vfunc */
-  priv->allocation = real_allocation;
+  priv->width = real_allocation.width;
+  priv->height = real_allocation.height;
   priv->allocated_baseline = baseline;
   priv->transform = final_transform;
 
@@ -4545,8 +4540,8 @@ gtk_widget_translate_coordinatesf (GtkWidget  *src_widget,
         graphene_vec4_add (&src_point, &v, &src_point);
       }
 
-      origin_x = parent->priv->allocation.x;
-      origin_y = parent->priv->allocation.y;
+      origin_x = 0;
+      origin_y = 0;
 
       graphene_matrix_transform_vec4 (&parent->priv->transform, &src_point, &src_point);
       graphene_vec4_init (&offset, origin_x, origin_y, 0, 0);
@@ -4572,8 +4567,8 @@ gtk_widget_translate_coordinatesf (GtkWidget  *src_widget,
       get_box_border (style, &border);
       get_box_padding (style, &padding);
 
-      origin_x = parent->priv->allocation.x;
-      origin_y = parent->priv->allocation.y;
+      origin_x = 0;
+      origin_y = 0;
 
       graphene_vec4_init (&offset, -origin_x, -origin_y, 0, 0);
       graphene_vec4_add (&src_point, &offset, &src_point);
@@ -5294,7 +5289,7 @@ gtk_widget_intersect (GtkWidget            *widget,
                      const GdkRectangle *area,
                      GdkRectangle       *intersection)
 {
-  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+  GtkAllocation allocation;
   GdkRectangle *dest;
   GdkRectangle tmp;
   gint return_val;
@@ -5307,12 +5302,14 @@ gtk_widget_intersect (GtkWidget          *widget,
   else
     dest = &tmp;
 
-  return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
+  gtk_widget_get_allocation (widget, &allocation);
+
+  return_val = gdk_rectangle_intersect (&allocation, area, dest);
 
   if (return_val && intersection && _gtk_widget_get_has_surface (widget))
     {
-      intersection->x -= priv->allocation.x;
-      intersection->y -= priv->allocation.y;
+      intersection->x -= allocation.x;
+      intersection->y -= allocation.y;
     }
 
   return return_val;
@@ -6236,11 +6233,10 @@ _gtk_widget_set_visible_flag (GtkWidget *widget,
 
   if (!visible)
     {
-      priv->allocation.x = -1;
-      priv->allocation.y = -1;
-      priv->allocation.width = 0;
-      priv->allocation.height = 0;
-      memset (&priv->allocated_size, 0, sizeof (priv->allocated_size));
+      priv->width = 0;
+      priv->height = 0;
+      priv->allocated_width = 0;
+      priv->allocated_height = 0;
       priv->allocated_size_baseline = 0;
       gtk_widget_update_paintables (widget);
     }
@@ -6329,8 +6325,8 @@ gtk_widget_set_has_surface (GtkWidget *widget,
   priv->no_surface_set = TRUE;
 
   /* GdkSurface has a min size of 1×1 */
-  priv->allocation.width = 1;
-  priv->allocation.height = 1;
+  priv->width = 1;
+  priv->height = 1;
 }
 
 /**
@@ -11184,10 +11180,10 @@ gtk_widget_get_allocated_size (GtkWidget     *widget,
   g_return_if_fail (allocation != NULL);
 
   *allocation = (GtkAllocation) {
-    (int)graphene_matrix_get_value (&priv->allocated_transform, 3, 0),
-    (int)graphene_matrix_get_value (&priv->allocated_transform, 3, 1),
-    priv->allocated_size.width,
-    priv->allocated_size.height
+    (int)graphene_matrix_get_value (&priv->transform, 3, 0) - priv->allocated_offset_x,
+    (int)graphene_matrix_get_value (&priv->transform, 3, 1) - priv->allocated_offset_y,
+    priv->allocated_width,
+    priv->allocated_height
   };
 
   if (baseline)
@@ -11223,10 +11219,10 @@ gtk_widget_get_allocation (GtkWidget     *widget,
   g_return_if_fail (allocation != NULL);
 
   *allocation = (GtkAllocation) {
-    (int)graphene_matrix_get_value (&priv->transform, 0, 3),
-    (int)graphene_matrix_get_value (&priv->transform, 1, 3),
-    priv->allocation.width,
-    priv->allocation.height
+    (int)graphene_matrix_get_value (&priv->transform, 3, 0),
+    (int)graphene_matrix_get_value (&priv->transform, 3, 1),
+    priv->width,
+    priv->height
   };
 }
 
@@ -11369,8 +11365,8 @@ gtk_widget_compute_bounds (GtkWidget       *widget,
   graphene_rect_init (&bounds,
                       - border.left - padding.left,
                       - border.top - padding.top,
-                      priv->allocation.width - margin.left - margin.right,
-                      priv->allocation.height - margin.top - margin.bottom);
+                      priv->width - margin.left - margin.right,
+                      priv->height - margin.top - margin.bottom);
 
   parent = widget;
   while (parent != ancestor)
@@ -11388,8 +11384,8 @@ gtk_widget_compute_bounds (GtkWidget       *widget,
                             margin.left + border.left + padding.left,
                             margin.top  + border.top  + padding.top);
 
-      origin_x = parent->priv->allocation.x;
-      origin_y = parent->priv->allocation.y;
+      origin_x = 0;
+      origin_y = 0;
 
       graphene_matrix_transform_bounds (&parent->priv->transform, &bounds, &bounds);
       graphene_rect_offset (&bounds, origin_x, origin_y);
@@ -11413,8 +11409,8 @@ gtk_widget_compute_bounds (GtkWidget       *widget,
       get_box_border (style, &border);
       get_box_padding (style, &padding);
 
-      origin_x = parent->priv->allocation.x;
-      origin_y = parent->priv->allocation.y;
+      origin_x = 0;
+      origin_y = 0;
 
       graphene_rect_offset (&bounds, -origin_x, -origin_y);
 
@@ -11447,7 +11443,7 @@ gtk_widget_get_allocated_width (GtkWidget *widget)
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
 
-  return priv->allocation.width;
+  return priv->width;
 }
 
 /**
@@ -11465,7 +11461,7 @@ gtk_widget_get_allocated_height (GtkWidget *widget)
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
 
-  return priv->allocation.height;
+  return priv->width;
 }
 
 /**
@@ -13063,7 +13059,7 @@ gtk_widget_maybe_add_debug_render_nodes (GtkWidget             *widget,
           graphene_rect_init (&bounds,
                               0,
                               margin.top + border.top + padding.top + baseline,
-                              priv->allocation.width, 1);
+                              priv->width, 1);
           gtk_snapshot_append_color (snapshot,
                                      &red,
                                      &bounds);
@@ -13078,7 +13074,7 @@ gtk_widget_maybe_add_debug_render_nodes (GtkWidget             *widget,
 
       graphene_rect_init (&bounds,
                           0, 0,
-                          priv->allocation.width, priv->allocation.height);
+                          priv->width, priv->height);
 
       gtk_snapshot_append_color (snapshot,
                                  &blue,
@@ -13736,7 +13732,7 @@ gtk_widget_get_width (GtkWidget *widget)
   get_box_border (style, &border);
   get_box_padding (style, &padding);
 
-  return priv->allocation.width -
+  return priv->width -
          margin.left  - margin.right -
          border.left  - border.right -
          padding.left - padding.right;
@@ -13766,7 +13762,7 @@ gtk_widget_get_height (GtkWidget *widget)
   get_box_border (style, &border);
   get_box_padding (style, &padding);
 
-  return priv->allocation.height -
+  return priv->height -
          margin.top  - margin.bottom -
          border.top  - border.bottom -
          padding.top - padding.bottom;
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index ec45b27205..847c66672a 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -138,12 +138,18 @@ struct _GtkWidgetPrivate
   GtkStyleContext *context;
 
   /* The widget's allocated size */
-  GtkAllocation allocated_size;
+  int allocated_width;
+  int allocated_height;
   gint allocated_size_baseline;
-  GtkAllocation allocation;
+  /* Size with widget margins and alignment applied */
+  int width;
+  int height;
   gint allocated_baseline;
 
-  graphene_matrix_t allocated_transform;
+  /* Align and widget margin offset the position by this
+   * amount. */
+  int allocated_offset_x;
+  int allocated_offset_y;
   graphene_matrix_t transform;
 
   /* The widget's requested sizes */
@@ -456,7 +462,14 @@ static inline void
 _gtk_widget_get_allocation (GtkWidget     *widget,
                             GtkAllocation *allocation)
 {
-  *allocation = widget->priv->allocation;
+  GtkWidgetPrivate *priv = widget->priv;
+
+  *allocation = (GtkAllocation) {
+    (int)graphene_matrix_get_value (&priv->transform, 3, 0),
+    (int)graphene_matrix_get_value (&priv->transform, 3, 1),
+    priv->width,
+    priv->height
+  };
 }
 
 static inline GtkWidget *
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index f1e99e5792..51a4c77440 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6853,8 +6853,8 @@ gtk_window_realize (GtkWidget *widget)
   _gtk_widget_get_allocation (widget, &allocation);
 
   /* ensure widget tree is properly size allocated */
-  if (allocation.x == -1 &&
-      allocation.y == -1 &&
+  if (allocation.x == 0 &&
+      allocation.y == 0 &&
       allocation.width == 1 &&
       allocation.height == 1)
     {
diff --git a/tests/testoverlaystyleclass.c b/tests/testoverlaystyleclass.c
index 37a857d265..3ed77cee3c 100644
--- a/tests/testoverlaystyleclass.c
+++ b/tests/testoverlaystyleclass.c
@@ -2,7 +2,8 @@
 
 static void
 child_size_allocate (GtkWidget    *child,
-                     GdkRectangle *allocation,
+                     int           width,
+                     int           height,
                      gint          baseline,
                      gpointer      user_data)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]