[gtk/ebassi/new-a11y: 77/87] a11y: Update the accessible state for GtkRange



commit 9c3c6ca2b2f57689287753b72bc39c0d654f5b7a
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Jul 13 16:22:22 2020 +0100

    a11y: Update the accessible state for GtkRange

 gtk/gtkrange.c | 55 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 45 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index c47f90df95..7953cc9d82 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -27,8 +27,10 @@
 
 #include "gtkrangeprivate.h"
 
+#include "gtkaccessible.h"
 #include "gtkadjustmentprivate.h"
 #include "gtkcolorscaleprivate.h"
+#include "gtkenums.h"
 #include "gtkeventcontrollerkey.h"
 #include "gtkeventcontrollerscroll.h"
 #include "gtkgesturedrag.h"
@@ -240,6 +242,9 @@ static gboolean      gtk_range_scroll_controller_scroll (GtkEventControllerScrol
                                                          gdouble                   dy,
                                                          GtkRange                 *range);
 
+static void          gtk_range_set_orientation          (GtkRange       *range,
+                                                         GtkOrientation  orientation);
+
 G_DEFINE_TYPE_WITH_CODE (GtkRange, gtk_range, GTK_TYPE_WIDGET,
                          G_ADD_PRIVATE (GtkRange)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
@@ -437,18 +442,11 @@ gtk_range_set_property (GObject      *object,
                        GParamSpec   *pspec)
 {
   GtkRange *range = GTK_RANGE (object);
-  GtkRangePrivate *priv = gtk_range_get_instance_private (range);
 
   switch (prop_id)
     {
     case PROP_ORIENTATION:
-      if (priv->orientation != g_value_get_enum (value))
-        {
-          priv->orientation = g_value_get_enum (value);
-          gtk_widget_update_orientation (GTK_WIDGET (range), priv->orientation);
-          gtk_widget_queue_resize (GTK_WIDGET (range));
-          g_object_notify_by_pspec (object, pspec);
-        }
+      gtk_range_set_orientation (range, g_value_get_enum (value));
       break;
     case PROP_ADJUSTMENT:
       gtk_range_set_adjustment (range, g_value_get_object (value));
@@ -584,6 +582,27 @@ gtk_range_init (GtkRange *range)
   gtk_widget_add_controller (GTK_WIDGET (range), controller);
 }
 
+static void
+gtk_range_set_orientation (GtkRange       *range,
+                           GtkOrientation  orientation)
+{
+  GtkRangePrivate *priv = gtk_range_get_instance_private (range);
+
+  if (priv->orientation != orientation)
+    {
+      priv->orientation = orientation;
+
+      gtk_accessible_update_property (GTK_ACCESSIBLE (range),
+                                      GTK_ACCESSIBLE_PROPERTY_ORIENTATION, priv->orientation,
+                                      -1);
+
+      gtk_widget_update_orientation (GTK_WIDGET (range), priv->orientation);
+      gtk_widget_queue_resize (GTK_WIDGET (range));
+
+      g_object_notify (G_OBJECT (range), "orientation");
+    }
+}
+
 /**
  * gtk_range_get_adjustment:
  * @range: a #GtkRange
@@ -657,6 +676,12 @@ gtk_range_set_adjustment (GtkRange      *range,
                        G_CALLBACK (gtk_range_adjustment_value_changed),
                        range);
 
+      gtk_accessible_update_property (GTK_ACCESSIBLE (range),
+                                      GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, gtk_adjustment_get_upper 
(adjustment),
+                                      GTK_ACCESSIBLE_PROPERTY_VALUE_MIN, gtk_adjustment_get_lower 
(adjustment),
+                                      GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, gtk_adjustment_get_value 
(adjustment),
+                                      -1);
+
       gtk_range_adjustment_changed (adjustment, range);
       gtk_range_adjustment_value_changed (adjustment, range);
 
@@ -2281,15 +2306,21 @@ gtk_range_adjustment_changed (GtkAdjustment *adjustment,
 {
   GtkRange *range = GTK_RANGE (data);
   GtkRangePrivate *priv = gtk_range_get_instance_private (range);
+  double upper = gtk_adjustment_get_upper (priv->adjustment);
+  double lower = gtk_adjustment_get_lower (priv->adjustment);
 
-  if (gtk_adjustment_get_upper (priv->adjustment) == gtk_adjustment_get_lower (priv->adjustment) &&
-      GTK_IS_SCALE (range))
+  if (upper == lower && GTK_IS_SCALE (range))
     gtk_widget_hide (priv->slider_widget);
   else
     gtk_widget_show (priv->slider_widget);
 
   gtk_widget_queue_allocate (priv->trough_widget);
 
+  gtk_accessible_update_property (GTK_ACCESSIBLE (range),
+                                  GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, upper,
+                                  GTK_ACCESSIBLE_PROPERTY_VALUE_MIN, lower,
+                                  -1);
+
   /* Note that we don't round off to priv->round_digits here.
    * that's because it's really broken to change a value
    * in response to a change signal on that value; round_digits
@@ -2316,6 +2347,10 @@ gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
 
   g_signal_emit (range, signals[VALUE_CHANGED], 0);
 
+  gtk_accessible_update_property (GTK_ACCESSIBLE (range),
+                                  GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, gtk_adjustment_get_value (adjustment),
+                                  -1);
+
   gtk_widget_queue_allocate (priv->trough_widget);
 }
 


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