event-editor/multi-choice: Implement GtkAccessible
This is needed to have the toggle button communicate with the screen reader to use the parent widget to retrieve accessible information, rather than the toggle button itself. Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/603>
This commit is contained in:
@@ -2,6 +2,7 @@ using Gtk 4.0;
|
||||
|
||||
template $GcalMultiChoice: Box {
|
||||
spacing: 6;
|
||||
accessible-role: spin_button;
|
||||
|
||||
Button down_button {
|
||||
icon-name: "pan-start-symbolic";
|
||||
@@ -15,6 +16,7 @@ template $GcalMultiChoice: Box {
|
||||
}
|
||||
|
||||
ToggleButton button {
|
||||
accessible-role: none;
|
||||
toggled => $button_toggled_cb() swapped;
|
||||
|
||||
styles [
|
||||
@@ -23,16 +25,6 @@ template $GcalMultiChoice: Box {
|
||||
"popup",
|
||||
]
|
||||
|
||||
accessibility {
|
||||
labelled-by: [
|
||||
template,
|
||||
];
|
||||
|
||||
described-by: [
|
||||
template,
|
||||
];
|
||||
}
|
||||
|
||||
Stack stack {
|
||||
hexpand: true;
|
||||
vexpand: true;
|
||||
|
||||
@@ -73,7 +73,10 @@ enum
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
|
||||
|
||||
G_DEFINE_TYPE (GcalMultiChoice, gcal_multi_choice, GTK_TYPE_BOX)
|
||||
static void gcal_multi_choice_accessible_init (GtkAccessibleInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GcalMultiChoice, gcal_multi_choice, GTK_TYPE_BOX,
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE, gcal_multi_choice_accessible_init))
|
||||
|
||||
/*
|
||||
* Auxiliary methods
|
||||
@@ -195,15 +198,15 @@ update_sensitivity (GcalMultiChoice *self)
|
||||
|
||||
gtk_widget_set_can_target (self->button, has_popup);
|
||||
|
||||
gtk_accessible_update_property (GTK_ACCESSIBLE (self->button),
|
||||
gtk_accessible_update_property (GTK_ACCESSIBLE (self),
|
||||
GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, has_popup,
|
||||
-1);
|
||||
if (self->popover != NULL)
|
||||
gtk_accessible_update_relation (GTK_ACCESSIBLE (self->button),
|
||||
gtk_accessible_update_relation (GTK_ACCESSIBLE (self),
|
||||
GTK_ACCESSIBLE_RELATION_CONTROLS, self->popover, NULL,
|
||||
-1);
|
||||
else
|
||||
gtk_accessible_reset_relation (GTK_ACCESSIBLE (self->button),
|
||||
gtk_accessible_reset_relation (GTK_ACCESSIBLE (self),
|
||||
GTK_ACCESSIBLE_RELATION_CONTROLS);
|
||||
}
|
||||
|
||||
@@ -466,6 +469,19 @@ gcal_multi_choice_grab_focus (GtkWidget *widget)
|
||||
return gtk_widget_grab_focus (self->button);
|
||||
}
|
||||
|
||||
/*
|
||||
* GtkAccessible overrides
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
gcal_multi_choice_accessible_get_platform_state (GtkAccessible *accessible,
|
||||
GtkAccessiblePlatformState state)
|
||||
{
|
||||
GcalMultiChoice *self = GCAL_MULTI_CHOICE (accessible);
|
||||
|
||||
return gtk_accessible_get_platform_state (GTK_ACCESSIBLE (self->button), state);
|
||||
}
|
||||
|
||||
/*
|
||||
* Init
|
||||
*/
|
||||
@@ -552,6 +568,12 @@ gcal_multi_choice_class_init (GcalMultiChoiceClass *class)
|
||||
gtk_widget_class_set_css_name (widget_class, "navigator");
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_multi_choice_accessible_init (GtkAccessibleInterface *iface)
|
||||
{
|
||||
iface->get_platform_state = gcal_multi_choice_accessible_get_platform_state;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_multi_choice_init (GcalMultiChoice *self)
|
||||
{
|
||||
@@ -733,3 +755,4 @@ gcal_multi_choice_get_popover (GcalMultiChoice *self)
|
||||
|
||||
return GTK_POPOVER (self->popover);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user