From: LukᚠTyrychtr Date: Wed, 14 Sep 2022 12:40:54 +0000 (+0200) Subject: Introduce GtkAccessibleRange X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~9^2~202^2~14 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a7814a0963daca3383d38e48c1fb5cbdb09830dc;p=gtk4.git Introduce GtkAccessibleRange This introduces GtkAccessibleRange, an interface which allows the accessibility backend to work with a control which can adjust a value. --- diff --git a/gtk/gtk.h b/gtk/gtk.h index f995ba4689..e889c68677 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/gtk/gtkaccessible.c b/gtk/gtkaccessible.c index 1daab9b0c3..ce79f750b4 100644 --- a/gtk/gtkaccessible.c +++ b/gtk/gtkaccessible.c @@ -656,6 +656,33 @@ gtk_accessible_role_to_name (GtkAccessibleRole role, return role_names[role]; } +/*< private > + * gtk_accessible_role_is_range_subclass: + * @role: a `GtkAccessibleRole` + * + * Checks if @role is considered to be a subclass of %GTK_ACCESSIBLE_ROLE_RANGE + * according to the WAI-ARIA specification. + * + * Returns: whether the @role is range-like + */ +gboolean +gtk_accessible_role_is_range_subclass (GtkAccessibleRole role) +{ + /* Same trick as in gtkatcontext.c */ + switch ((int) role) + { + case GTK_ACCESSIBLE_ROLE_METER: + case GTK_ACCESSIBLE_ROLE_PROGRESS_BAR: + case GTK_ACCESSIBLE_ROLE_SCROLLBAR: + case GTK_ACCESSIBLE_ROLE_SLIDER: + case GTK_ACCESSIBLE_ROLE_SPIN_BUTTON: + return true; + default: + break; + } + return false; +} + /* * gtk_accessible_platform_changed: * @self: a `GtkAccessible` diff --git a/gtk/gtkaccessibleprivate.h b/gtk/gtkaccessibleprivate.h index 873af7009a..eefd30a38b 100644 --- a/gtk/gtkaccessibleprivate.h +++ b/gtk/gtkaccessibleprivate.h @@ -40,6 +40,8 @@ GtkATContext * gtk_accessible_get_at_context (GtkAccessible *self); const char * gtk_accessible_role_to_name (GtkAccessibleRole role, const char *domain); +gboolean gtk_accessible_role_is_range_subclass (GtkAccessibleRole role); + gboolean gtk_accessible_should_present (GtkAccessible *self); void gtk_accessible_platform_changed (GtkAccessible *self, diff --git a/gtk/gtkaccessiblerange.c b/gtk/gtkaccessiblerange.c new file mode 100644 index 0000000000..555e1eb921 --- /dev/null +++ b/gtk/gtkaccessiblerange.c @@ -0,0 +1,76 @@ +/* gtkaccessiblerange.c: Accessible range interface + * + * Copyright © 2022 Red Hat Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +/** + * GtkAccessibleRange: + * + * This interface describes range controls, e. g. controls which have a single + * value which can optionally be changed by the user. + * + * This interface is expected to be implemented by controls of the + * %GTK_ACCESSIBLE_ROLE_METER, %GTK_ACCESSIBLE_ROLE_PROGRESS_BAR, + * %GTK_ACCESSIBLE_ROLE_SCROLLBAR, %GTK_ACCESSIBLE_ROLE_SLIDER and %GTK_ACCESSIBLE_ROLE_SPIN_BUTTON + * role. If that is not the case, a warning will be issued at runtime. + * + * In addition to this interface, its implementors are expected to provide the + * correct values for the following properties: %GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, + * %GTK_ACCESSIBLE_PROPERTY_VALUE_MIN and %GTK_ACCESSIBLE_PROPERTY_VALUE_NOW. + */ + +#include "config.h" + +#include "gtkaccessiblerange.h" + +G_DEFINE_INTERFACE (GtkAccessibleRange, gtk_accessible_range, GTK_TYPE_ACCESSIBLE) + +static void +gtk_accessible_range_default_init (GtkAccessibleRangeInterface *iface) +{ +} + + /* + * gtk_accessible_range_get_minimum_increment: + * @self: a `GtkAccessibleRange` + * + * Returns the minimum increment which this `GtkAccessibleRange` supports. + * + * Returns: the minimum increment + */ +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); +} + + /* + * gtk_accessible_range_set_current_value: + * @self: a `GtkAccessibleRange` + * + * Sets the current value of this `GtkAccessibleRange`. + */ +void +gtk_accessible_range_set_current_value (GtkAccessibleRange *self, double value) +{ + g_return_if_fail (GTK_IS_ACCESSIBLE_RANGE (self)); + + return GTK_ACCESSIBLE_RANGE_GET_IFACE (self)->set_current_value (self, value); +} \ No newline at end of file diff --git a/gtk/gtkaccessiblerange.h b/gtk/gtkaccessiblerange.h new file mode 100644 index 0000000000..45ffefc257 --- /dev/null +++ b/gtk/gtkaccessiblerange.h @@ -0,0 +1,50 @@ +/* gtkaccessiblerange.h: Accessible range interface + * + * Copyright © 2022 Red Hat Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include + +G_BEGIN_DECLS +#define GTK_TYPE_ACCESSIBLE_RANGE (gtk_accessible_range_get_type()) + +GDK_AVAILABLE_IN_ALL +G_DECLARE_INTERFACE (GtkAccessibleRange, gtk_accessible_range, GTK, ACCESSIBLE_RANGE, GtkAccessible) + +struct _GtkAccessibleRangeInterface +{ + GTypeInterface g_iface; + + double (* get_minimum_increment) (GtkAccessibleRange *self); + void (* 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); + +G_END_DECLS \ No newline at end of file diff --git a/gtk/meson.build b/gtk/meson.build index bfb03d7575..1aab513f36 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -156,6 +156,7 @@ gtk_public_sources = files([ 'gtkaboutdialog.c', 'gtkaccelgroup.c', 'gtkaccessible.c', + 'gtkaccessiblerange.c', 'gtkactionable.c', 'gtkactionbar.c', 'gtkadjustment.c', @@ -448,6 +449,7 @@ gtk_public_headers = files([ 'gtkaboutdialog.h', 'gtkaccelgroup.h', 'gtkaccessible.h', + 'gtkaccessiblerange.h', 'gtkactionable.h', 'gtkactionbar.h', 'gtkadjustment.h',