a11y: Remove an overzealous optimisation
authorMatthias Clasen <mclasen@redhat.com>
Mon, 19 Jun 2023 10:45:28 +0000 (06:45 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 19 Jun 2023 11:22:32 +0000 (07:22 -0400)
The result of calling update_property needs
to be that the property is marked as set
afterward, even if the value we pass happens
to match the default value.

After this change, scrollbars have value-now
show up as zero in the accessiblity page of
the inspector, even when that matches the lower
bound.

Test included.

Fixes: #5886
gtk/gtkaccessibleattributeset.c
testsuite/a11y/meson.build
testsuite/a11y/value.c [new file with mode: 0644]

index fececf9bd1d3ddac597f6dd6dd65dcc73519b2ac..020602534679c9a0d3734d48d6069375361d036e 100644 (file)
@@ -121,7 +121,15 @@ gtk_accessible_attribute_set_add (GtkAccessibleAttributeSet *self,
   if (value != NULL)
     {
       if (gtk_accessible_value_equal (value, self->attribute_values[attribute]))
-        return FALSE;
+        {
+          if (!_gtk_bitmask_get (self->attributes_set, attribute))
+            {
+              self->attributes_set = _gtk_bitmask_set (self->attributes_set, attribute, TRUE);
+              return TRUE;
+            }
+          else
+            return FALSE;
+        }
     }
   else
     {
index b3baa13b40724aed850ef21c6bd1b6b0986fd7be..6d46647eefc3066046495e2d291c988b2efaff90 100644 (file)
@@ -29,6 +29,7 @@ tests = [
   { 'name': 'switch' },
   { 'name': 'textview' },
   { 'name': 'togglebutton' },
+  { 'name': 'value' },
   { 'name': 'window' },
 ]
 
diff --git a/testsuite/a11y/value.c b/testsuite/a11y/value.c
new file mode 100644 (file)
index 0000000..666dcb2
--- /dev/null
@@ -0,0 +1,32 @@
+#include <gtk/gtk.h>
+
+static void
+value_set_unset (void)
+{
+  GtkAdjustment *adjustment = gtk_adjustment_new (0, 0, 100, 1, 10, 10);
+  GtkWidget *scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, adjustment);
+
+  g_object_ref_sink (scrollbar);
+
+  gtk_test_accessible_assert_property (scrollbar, GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, 0.);
+
+  gtk_adjustment_set_value (adjustment, 10);
+
+  gtk_test_accessible_assert_property (scrollbar, GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, 10.);
+
+  gtk_adjustment_set_value (adjustment, 0);
+
+  gtk_test_accessible_assert_property (scrollbar, GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, 0.);
+
+  g_object_unref (scrollbar);
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/a11y/value/set-unset", value_set_unset);
+
+  return g_test_run ();
+}