a11y: Drop GtkAccessibleRange.get_minimum_increment()

MinimumIncrement is an AT-SPI-ism that has no counterpart in the ARIA
specification, so it should not live inside public API. Additionally,
it's not really a useful method because it collapses two values on the
adjustment API.

The only method in the GtkAccessibleRange interface should be the
set_current_value(), which allows ATs to control the current position in
a ranged widget.

The AT-SPI implementation can now use all the accessible properties,
including the VALUE_TEXT one, mapped to the Text property on the
AtSpi.Value interface.
This commit is contained in:
Emmanuele Bassi 2022-09-30 18:31:55 +01:00
parent 5dd7e24806
commit 31fea11255
9 changed files with 92 additions and 133 deletions

View File

@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/node">
<interface name="org.a11y.atspi.Value">
<property name="MinimumValue" type="d" access="read"/>
<property name="MaximumValue" type="d" access="read"/>
<property name="MinimumIncrement" type="d" access="read"/>
<property name="CurrentValue" type="d" access="readwrite"/>
</interface>
<interface name="org.a11y.atspi.Value">
<property name="MinimumValue" type="d" access="read"/>
<property name="MaximumValue" type="d" access="read"/>
<property name="MinimumIncrement" type="d" access="read"/>
<property name="CurrentValue" type="d" access="readwrite"/>
<property name="Text" type="s" access="read"/>
</interface>
</node>

View File

@ -24,7 +24,7 @@
#include "a11y/atspi/atspi-value.h"
#include "gtkaccessiblerange.h"
#include "gtkaccessiblerangeprivate.h"
#include "gtkatcontextprivate.h"
#include "gtkdebug.h"
@ -40,35 +40,57 @@ handle_value_get_property (GDBusConnection *connection,
gpointer user_data)
{
GtkATContext *ctx = GTK_AT_CONTEXT (user_data);
/* Numeric attributes */
struct {
const char *name;
GtkAccessibleProperty property;
} properties[] = {
} num_properties[] = {
{ "MinimumValue", GTK_ACCESSIBLE_PROPERTY_VALUE_MIN },
{ "MaximumValue", GTK_ACCESSIBLE_PROPERTY_VALUE_MAX },
{ "CurrentValue", GTK_ACCESSIBLE_PROPERTY_VALUE_NOW },
};
int i;
for (i = 0; i < G_N_ELEMENTS (properties); i++)
/* String attributes */
struct {
const char *name;
GtkAccessibleProperty property;
} str_properties[] = {
{ "Text", GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT },
};
for (int i = 0; i < G_N_ELEMENTS (num_properties); i++)
{
if (g_strcmp0 (property_name, properties[i].name) == 0)
if (g_strcmp0 (property_name, num_properties[i].name) == 0)
{
if (gtk_at_context_has_accessible_property (ctx, properties[i].property))
if (gtk_at_context_has_accessible_property (ctx, num_properties[i].property))
{
GtkAccessibleValue *value;
GtkAccessibleValue *value =
gtk_at_context_get_accessible_property (ctx, num_properties[i].property);
value = gtk_at_context_get_accessible_property (ctx, properties[i].property);
return g_variant_new_double (gtk_number_accessible_value_get (value));
}
}
}
if (g_strcmp0 (property_name, "MinimumIncrement") == 0)
for (int i = 0; i < G_N_ELEMENTS (str_properties); i++)
{
GtkAccessibleRange *range = GTK_ACCESSIBLE_RANGE (gtk_at_context_get_accessible (ctx));
return g_variant_new_double(gtk_accessible_range_get_minimum_increment (range));
}
if (g_strcmp0 (property_name, str_properties[i].name) == 0)
{
if (gtk_at_context_has_accessible_property (ctx, str_properties[i].property))
{
GtkAccessibleValue *value =
gtk_at_context_get_accessible_property (ctx, str_properties[i].property);
return g_variant_new_string (gtk_string_accessible_value_get (value));
}
}
}
/* Special-case MinimumIncrement as it does not have an ARIA counterpart */
if (g_strcmp0 (property_name, "MinimumIncrement") == 0)
return g_variant_new_double (0.0);
/* fall back for widgets that should have the
* properties but don't
*/
@ -89,9 +111,7 @@ handle_value_set_property (GDBusConnection *connection,
GtkAccessibleRange *range = GTK_ACCESSIBLE_RANGE (gtk_at_context_get_accessible (self));
if (g_strcmp0 (property_name, "CurrentValue") == 0)
{
return gtk_accessible_range_set_current_value (range, g_variant_get_double (value));
}
return gtk_accessible_range_set_current_value (range, g_variant_get_double (value));
return FALSE;
}
@ -110,4 +130,3 @@ gtk_atspi_get_value_vtable (GtkAccessible *accessible)
return NULL;
}

View File

@ -29,27 +29,22 @@
* - `GTK_ACCESSIBLE_PROPERTY_VALUE_NOW`
* - `GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT`
*
* For controls where a minimum increment makes no sense and which do not allow
* setting the current value from the user, the default implementation of this
* interface suffices.
*
* Since: 4.10
*/
#include "config.h"
#include "gtkaccessiblerange.h"
#include "gtkaccessiblerangeprivate.h"
#include "gtkaccessibleprivate.h"
#include "gtkatcontextprivate.h"
#include "gtkaccessiblevalueprivate.h"
G_DEFINE_INTERFACE (GtkAccessibleRange, gtk_accessible_range, GTK_TYPE_ACCESSIBLE)
static double
gtk_accessible_range_default_get_minimum_increment (GtkAccessibleRange *accessible_range)
{
return 0.0;
}
static gboolean
gtk_accessible_range_default_set_current_value (GtkAccessibleRange *accessible_range, double value)
gtk_accessible_range_default_set_current_value (GtkAccessibleRange *accessible_range,
double value)
{
return FALSE;
}
@ -57,29 +52,10 @@ gtk_accessible_range_default_set_current_value (GtkAccessibleRange *accessible_r
static void
gtk_accessible_range_default_init (GtkAccessibleRangeInterface *iface)
{
iface->get_minimum_increment = gtk_accessible_range_default_get_minimum_increment;
iface->set_current_value = gtk_accessible_range_default_set_current_value;
}
/**
* gtk_accessible_range_get_minimum_increment:
* @self: a `GtkAccessibleRange`
*
* Returns the minimum increment which this `GtkAccessibleRange` supports.
*
* Returns: the minimum increment, or 0.0 if not overridden
*
* Since: 4.10
*/
double
gtk_accessible_range_get_minimum_increment (GtkAccessibleRange *self)
{
g_return_val_if_fail (GTK_IS_ACCESSIBLE_RANGE (self), .0);
return GTK_ACCESSIBLE_RANGE_GET_IFACE (self)->get_minimum_increment (self);
}
/**
/*< private >
* gtk_accessible_range_set_current_value:
* @self: a `GtkAccessibleRange`
*
@ -90,8 +66,6 @@ gtk_accessible_range_get_minimum_increment (GtkAccessibleRange *self)
* may in some cases do nothing
*
* Returns: true if the call changed the value, and false otherwise
*
* Since: 4.10
*/
gboolean
gtk_accessible_range_set_current_value (GtkAccessibleRange *self, double value)

View File

@ -10,7 +10,6 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <glib-object.h>
#include <gtk/gtkaccessible.h>
G_BEGIN_DECLS
@ -23,24 +22,12 @@ struct _GtkAccessibleRangeInterface
{
GTypeInterface g_iface;
/**
* GtkAccessibleRangeInterface::get_minimum_increment:
* @self: a `GtkAccessibleRange`
*
* Returns the minimum increment for this `GtkAccessibleRange`.
* The default implementation returns 0.0, which indicates that a minimum
* increment does not make sense for this implementation.
* Returns: the minimum increment
*
* Since: 4.10
*/
double (* get_minimum_increment) (GtkAccessibleRange *self);
/**
* GtkAccessibleRangeInterface::set_current_value:
* @self: a `GtkAccessibleRange`
* @value: the value to set
*
* Sets the current value of @self to @value.
* Sets the current value of the accessible range.
*
* This operation should behave similarly as if the user performed the
* action.
@ -53,11 +40,4 @@ struct _GtkAccessibleRangeInterface
double value);
};
GDK_AVAILABLE_IN_4_10
double gtk_accessible_range_get_minimum_increment (GtkAccessibleRange *self);
GDK_AVAILABLE_IN_4_10
gboolean gtk_accessible_range_set_current_value (GtkAccessibleRange *self,
double value);
G_END_DECLS

View File

@ -0,0 +1,18 @@
/* gtkaccessiblerangeprivate.h: Accessible range private API
*
* SPDX-FileCopyrightText: 2022 Emmanuele Bassi
* SPDX-FileCopyrightText: 2022 Red Hat Inc
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#include "gtkaccessiblerange.h"
G_BEGIN_DECLS
gboolean
gtk_accessible_range_set_current_value (GtkAccessibleRange *self,
double value);
G_END_DECLS

View File

@ -809,25 +809,18 @@ gtk_paned_buildable_iface_init (GtkBuildableIface *iface)
iface->add_child = gtk_paned_buildable_add_child;
}
static double
gtk_paned_accessible_range_get_minimum_increment (GtkAccessibleRange *accessible_range)
{
return 1.0;
}
static gboolean
gtk_paned_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
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);
gtk_paned_set_position (GTK_PANED (accessible_range), (int) value + 0.5);
return TRUE;
}
static void
gtk_paned_accessible_range_init (GtkAccessibleRangeInterface *iface)
{
iface->get_minimum_increment = gtk_paned_accessible_range_get_minimum_increment;
iface->set_current_value = gtk_paned_accessible_range_set_current_value;
iface->set_current_value = accessible_range_set_current_value;
}
static gboolean

View File

@ -440,26 +440,19 @@ gtk_range_class_init (GtkRangeClass *class)
gtk_widget_class_set_css_name (widget_class, I_("range"));
}
static double
gtk_range_accessible_range_get_minimum_increment (GtkAccessibleRange *accessible_range)
{
GtkRange *range = GTK_RANGE (accessible_range);
return gtk_adjustment_get_minimum_increment (gtk_range_get_adjustment (range));
}
static gboolean
gtk_range_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
accessible_range_set_current_value (GtkAccessibleRange *accessible_range,
double value)
{
GtkRange *range = GTK_RANGE (accessible_range);
gtk_range_set_value (range, value);
gtk_range_set_value (GTK_RANGE (accessible_range), value);
return TRUE;
}
static void
gtk_range_accessible_range_init (GtkAccessibleRangeInterface *iface)
{
iface->get_minimum_increment = gtk_range_accessible_range_get_minimum_increment;
iface->set_current_value = gtk_range_accessible_range_set_current_value;
iface->set_current_value = accessible_range_set_current_value;
}
static void

View File

@ -159,7 +159,8 @@ static gboolean gtk_scale_button_scroll_controller_scroll (GtkEventControllerScr
double dx,
double dy,
GtkScaleButton *button);
static void gtk_scale_button_accessible_range_init(GtkAccessibleRangeInterface *iface);
static void gtk_scale_button_accessible_range_init (GtkAccessibleRangeInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkScaleButton, gtk_scale_button, GTK_TYPE_WIDGET,
@ -170,26 +171,19 @@ G_DEFINE_TYPE_WITH_CODE (GtkScaleButton, gtk_scale_button, GTK_TYPE_WIDGET,
static guint signals[LAST_SIGNAL] = { 0, };
static double
gtk_scale_button_accessible_range_get_minimum_increment(GtkAccessibleRange *accessible_range)
{
GtkScaleButton *button = GTK_SCALE_BUTTON (accessible_range);
return gtk_adjustment_get_minimum_increment (gtk_scale_button_get_adjustment (button));
}
static gboolean
gtk_scale_button_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
accessible_range_set_current_value (GtkAccessibleRange *accessible_range,
double value)
{
GtkScaleButton *button = GTK_SCALE_BUTTON (accessible_range);
gtk_scale_button_set_value (button, value);
gtk_scale_button_set_value (GTK_SCALE_BUTTON (accessible_range), value);
return TRUE;
}
static void
gtk_scale_button_accessible_range_init(GtkAccessibleRangeInterface *iface)
gtk_scale_button_accessible_range_init (GtkAccessibleRangeInterface *iface)
{
iface->get_minimum_increment = gtk_scale_button_accessible_range_get_minimum_increment;
iface->set_current_value = gtk_scale_button_accessible_range_set_current_value;
iface->set_current_value = accessible_range_set_current_value;
}
static void

View File

@ -318,8 +318,8 @@ G_DEFINE_TYPE_WITH_CODE (GtkSpinButton, gtk_spin_button, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE,
gtk_spin_button_accessible_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE_RANGE,
gtk_spin_button_accessible_range_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE_RANGE,
gtk_spin_button_accessible_range_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
gtk_spin_button_editable_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
@ -637,26 +637,18 @@ gtk_spin_button_accessible_init (GtkAccessibleInterface *iface)
iface->get_platform_state = gtk_spin_button_accessible_get_platform_state;
}
static double
gtk_spin_button_accessible_range_get_minimum_increment (GtkAccessibleRange *accessible_range)
{
GtkSpinButton *button = GTK_SPIN_BUTTON (accessible_range);
return gtk_adjustment_get_minimum_increment (gtk_spin_button_get_adjustment (button));
}
static gboolean
gtk_spin_button_accessible_range_set_current_value (GtkAccessibleRange *accessible_range, double value)
accessible_range_set_current_value (GtkAccessibleRange *accessible_range,
double value)
{
GtkSpinButton *button = GTK_SPIN_BUTTON (accessible_range);
gtk_spin_button_set_value (button, value);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (accessible_range), value);
return TRUE;
}
static void
gtk_spin_button_accessible_range_init (GtkAccessibleRangeInterface *iface)
{
iface->get_minimum_increment = gtk_spin_button_accessible_range_get_minimum_increment;
iface->set_current_value = gtk_spin_button_accessible_range_set_current_value;
iface->set_current_value = accessible_range_set_current_value;
}
static void