Actually use the AccessibleRange interface

This commit is contained in:
Lukáš Tyrychtr 2022-09-16 11:12:30 +02:00
parent ce761122b2
commit d517804acd
7 changed files with 27 additions and 37 deletions

View File

@ -24,14 +24,9 @@
#include "a11y/atspi/atspi-value.h"
#include "gtkaccessiblerange.h"
#include "gtkatcontextprivate.h"
#include "gtkdebug.h"
#include "gtklevelbar.h"
#include "gtkpaned.h"
#include "gtkprogressbar.h"
#include "gtkrange.h"
#include "gtkscalebutton.h"
#include "gtkspinbutton.h"
#include <gio/gio.h>
@ -69,7 +64,12 @@ handle_value_get_property (GDBusConnection *connection,
}
}
/* fall back for a) MinimumIncrement b) widgets that should have the
if (g_strcmp0 (property_name, "MinimumIncrement") == 0)
{
GtkAccessibleRange *range = GTK_ACCESSIBLE_RANGE (gtk_at_context_get_accessible (ctx));
return g_variant_new_double(gtk_accessible_range_get_minimum_increment (range));
}
/* fall back for widgets that should have the
* properties but don't
*/
return g_variant_new_double (0.0);
@ -86,22 +86,11 @@ handle_value_set_property (GDBusConnection *connection,
gpointer user_data)
{
GtkATContext *self = user_data;
GtkWidget *widget = GTK_WIDGET (gtk_at_context_get_accessible (self));
GtkAccessibleRange *range = GTK_ACCESSIBLE_RANGE (gtk_at_context_get_accessible (self));
if (g_strcmp0 (property_name, "CurrentValue") == 0)
{
/* we only allow setting values if that is part of the user-exposed
* functionality of the widget.
*/
if (GTK_IS_RANGE (widget))
gtk_range_set_value (GTK_RANGE (widget), g_variant_get_double (value));
else if (GTK_IS_PANED (widget))
gtk_paned_set_position (GTK_PANED (widget), (int)(g_variant_get_double (value) + 0.5));
else if (GTK_IS_SPIN_BUTTON (widget))
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), g_variant_get_double (value));
else if (GTK_IS_SCALE_BUTTON (widget))
gtk_scale_button_set_value (GTK_SCALE_BUTTON (widget), g_variant_get_double (value));
return TRUE;
return gtk_accessible_range_set_current_value (range, g_variant_get_double (value));
}
return FALSE;
@ -116,12 +105,7 @@ static const GDBusInterfaceVTable value_vtable = {
const GDBusInterfaceVTable *
gtk_atspi_get_value_vtable (GtkAccessible *accessible)
{
if (GTK_IS_LEVEL_BAR (accessible) ||
GTK_IS_PANED (accessible) ||
GTK_IS_PROGRESS_BAR (accessible) ||
GTK_IS_RANGE (accessible) ||
GTK_IS_SCALE_BUTTON (accessible) ||
GTK_IS_SPIN_BUTTON (accessible))
if (GTK_IS_ACCESSIBLE_RANGE (accessible))
return &value_vtable;
return NULL;

View File

@ -50,10 +50,10 @@ gtk_accessible_range_default_get_minimum_increment (GtkAccessibleRange *accessib
return 0.0;
}
static void
static gboolean
gtk_accessible_range_default_set_current_value (GtkAccessibleRange *accessible_range, double value)
{
/* By default, we do nothing */
return FALSE;
}
static void
@ -87,12 +87,13 @@ gtk_accessible_range_get_minimum_increment (GtkAccessibleRange *self)
* Note that for some widgets implementing this interface, setting a value
* through the accessibility API makes no sense, so calling this function may
* in some cases do nothing.
* @returns: %true if the call changed the value, %false otherwise
*/
void
gboolean
gtk_accessible_range_set_current_value (GtkAccessibleRange *self, double value)
{
g_return_if_fail (GTK_IS_ACCESSIBLE_RANGE (self));
g_return_val_if_fail (GTK_IS_ACCESSIBLE_RANGE (self), FALSE);
GtkAccessibleRangeInterface *iface = GTK_ACCESSIBLE_RANGE_GET_IFACE (self);
iface->set_current_value (self, value);
return iface->set_current_value (self, value);
}

View File

@ -54,14 +54,15 @@ struct _GtkAccessibleRangeInterface
*
* Sets the current value of @self to @value.
* This operation should behave similarly as if the user performed the action.
* @returns: %true if the operation was performed, %false otherwise
*/
void (* set_current_value) (GtkAccessibleRange *self, double value);
gboolean (* set_current_value) (GtkAccessibleRange *self, double value);
};
GDK_AVAILABLE_IN_ALL
double gtk_accessible_range_get_minimum_increment (GtkAccessibleRange *self);
GDK_AVAILABLE_IN_ALL
void gtk_accessible_range_set_current_value (GtkAccessibleRange *self, double value);
gboolean gtk_accessible_range_set_current_value (GtkAccessibleRange *self, double value);
G_END_DECLS

View File

@ -815,11 +815,12 @@ gtk_paned_accessible_range_get_minimum_increment (GtkAccessibleRange *accessible
return 1.0;
}
static void
static gboolean
gtk_paned_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
{
GtkPaned *paned = GTK_PANED (accessible_range);
gtk_paned_set_position (paned, (int) value + 0.5);
return TRUE;
}
static void

View File

@ -447,11 +447,12 @@ gtk_range_accessible_range_get_minimum_increment (GtkAccessibleRange *accessible
return gtk_adjustment_get_minimum_increment (gtk_range_get_adjustment (range));
}
static void
static gboolean
gtk_range_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
{
GtkRange *range = GTK_RANGE (accessible_range);
gtk_range_set_value (range, value);
return TRUE;
}
static void

View File

@ -177,11 +177,12 @@ gtk_scale_button_accessible_range_get_minimum_increment(GtkAccessibleRange *acce
return gtk_adjustment_get_minimum_increment (gtk_scale_button_get_adjustment (button));
}
static void
static gboolean
gtk_scale_button_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
{
GtkScaleButton *button = GTK_SCALE_BUTTON (accessible_range);
gtk_scale_button_set_value (button, value);
return TRUE;
}
static void

View File

@ -644,11 +644,12 @@ gtk_spin_button_accessible_range_get_minimum_increment (GtkAccessibleRange *acce
return gtk_adjustment_get_minimum_increment (gtk_spin_button_get_adjustment (button));
}
static void
static gboolean
gtk_spin_button_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
{
GtkSpinButton *button = GTK_SPIN_BUTTON (accessible_range);
gtk_spin_button_set_value (button, value);
return TRUE;
}
static void