widget: Don't forget margins when adjusting
authorBenjamin Otte <otte@redhat.com>
Fri, 19 Nov 2021 22:19:14 +0000 (23:19 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 19 Nov 2021 22:46:59 +0000 (23:46 +0100)
This could lead to the wrong values being passed and computing invalid
sizes which would then lead to very unhappy code.

Test included.

gtk/gtkwidget.c
testsuite/reftests/meson.build
testsuite/reftests/wrap-margin-align-critical.ref.ui [new file with mode: 0644]
testsuite/reftests/wrap-margin-align-critical.ui [new file with mode: 0644]

index 788cfb6650af0b2d22c1e170d37e0ddb704cf2fb..73dc6b20be848f82bb83232fc3df5836fd34e065 100644 (file)
@@ -3846,7 +3846,7 @@ gtk_widget_adjust_size_allocation (GtkWidget     *widget,
                         &allocation->x,
                         &allocation->width);
       gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
-                          allocation->width,
+                          allocation->width + priv->margin.left + priv->margin.right,
                           &min_height, &natural_height, NULL, NULL);
       adjust_for_align (priv->valign,
                         natural_height - priv->margin.top - priv->margin.bottom,
@@ -3867,7 +3867,7 @@ gtk_widget_adjust_size_allocation (GtkWidget     *widget,
                         &allocation->y,
                         &allocation->height);
       gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
-                          allocation->height,
+                          allocation->height + priv->margin.top + priv->margin.bottom,
                           &min_width, &natural_width, NULL, NULL);
       adjust_for_align (effective_align (priv->halign, _gtk_widget_get_direction (widget)),
                         natural_width - priv->margin.left - priv->margin.right,
index eb277d8bf742a881952ba3678525c99347c967e6..01f813bee561130ee467115f68cb8a70bb396a8b 100644 (file)
@@ -527,6 +527,8 @@ testdata = [
   # it is not in xfail since it succeeds on some platforms
   #'window-show-contents-on-map.ref.ui',
   #'window-show-contents-on-map.ui',
+  'wrap-margin-align-critical.ref.ui',
+  'wrap-margin-align-critical.ui',
 ]
 
 # These need to be fixed but the issue hasn't been tracked down.
diff --git a/testsuite/reftests/wrap-margin-align-critical.ref.ui b/testsuite/reftests/wrap-margin-align-critical.ref.ui
new file mode 100644 (file)
index 0000000..04d550c
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+  <object class="GtkWindow">
+    <property name="default-width">300</property>
+    <property name="default-height">300</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkBox">
+        <property name="halign">center</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="halign">center</property>
+            <property name="label">Hello World</property>
+            <property name="wrap">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/wrap-margin-align-critical.ui b/testsuite/reftests/wrap-margin-align-critical.ui
new file mode 100644 (file)
index 0000000..b69c770
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+  <object class="GtkWindow">
+    <property name="default-width">300</property>
+    <property name="default-height">300</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkBox">
+        <property name="halign">center</property>
+        <property name="margin-start">50</property>
+        <property name="margin-end">50</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="label">Hello World</property>
+            <property name="wrap">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>