diff options
-rw-r--r-- | gtk/a11y/atspi/Value.xml | 18 | ||||
-rw-r--r-- | gtk/a11y/gtkatspivalue.c | 51 | ||||
-rw-r--r-- | gtk/gtkaccessiblerange.c | 42 | ||||
-rw-r--r-- | gtk/gtkaccessiblerange.h | 22 | ||||
-rw-r--r-- | gtk/gtkaccessiblerangeprivate.h | 18 | ||||
-rw-r--r-- | gtk/gtkpaned.c | 15 | ||||
-rw-r--r-- | gtk/gtkrange.c | 17 | ||||
-rw-r--r-- | gtk/gtkscalebutton.c | 22 | ||||
-rw-r--r-- | gtk/gtkspinbutton.c | 20 |
9 files changed, 92 insertions, 133 deletions
diff --git a/gtk/a11y/atspi/Value.xml b/gtk/a11y/atspi/Value.xml index ccd6c7aa59..cdf13f96ad 100644 --- a/gtk/a11y/atspi/Value.xml +++ b/gtk/a11y/atspi/Value.xml @@ -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> diff --git a/gtk/a11y/gtkatspivalue.c b/gtk/a11y/gtkatspivalue.c index 404121065a..5dab4e24c0 100644 --- a/gtk/a11y/gtkatspivalue.c +++ b/gtk/a11y/gtkatspivalue.c @@ -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; } - diff --git a/gtk/gtkaccessiblerange.c b/gtk/gtkaccessiblerange.c index bbe673aa2d..494170bb83 100644 --- a/gtk/gtkaccessiblerange.c +++ b/gtk/gtkaccessiblerange.c @@ -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" -G_DEFINE_INTERFACE (GtkAccessibleRange, gtk_accessible_range, GTK_TYPE_ACCESSIBLE) +#include "gtkaccessibleprivate.h" +#include "gtkatcontextprivate.h" +#include "gtkaccessiblevalueprivate.h" -static double -gtk_accessible_range_default_get_minimum_increment (GtkAccessibleRange *accessible_range) -{ - return 0.0; -} +G_DEFINE_INTERFACE (GtkAccessibleRange, gtk_accessible_range, GTK_TYPE_ACCESSIBLE) 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) diff --git a/gtk/gtkaccessiblerange.h b/gtk/gtkaccessiblerange.h index 903bfb5685..8429138bfb 100644 --- a/gtk/gtkaccessiblerange.h +++ b/gtk/gtkaccessiblerange.h @@ -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 @@ -24,23 +23,11 @@ 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 diff --git a/gtk/gtkaccessiblerangeprivate.h b/gtk/gtkaccessiblerangeprivate.h new file mode 100644 index 0000000000..e45bccbd86 --- /dev/null +++ b/gtk/gtkaccessiblerangeprivate.h @@ -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 diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c index 9dc76360e6..7596f6a689 100644 --- a/gtk/gtkpaned.c +++ b/gtk/gtkpaned.c @@ -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 diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index d38365c04a..6ad7af6d38 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -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 diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c index a81f0968f9..2918089bfd 100644 --- a/gtk/gtkscalebutton.c +++ b/gtk/gtkscalebutton.c @@ -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 diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 05b373fbbe..7b2074b655 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -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 |