From 4c1bc93f6fb9d2636e41baba45d44506bdd2bce3 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 9 Sep 2022 16:06:02 -0400 Subject: [PATCH] a11y: Be safe against state type changes For some of the a11y states, calling gtk_accessible_reset_state can change the type of the state value from boolean or tristate to undefined. Handle that, instead of throwing criticals. Related: !4910 --- gtk/a11y/gtkatspicontext.c | 69 ++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/gtk/a11y/gtkatspicontext.c b/gtk/a11y/gtkatspicontext.c index a0086365c4..7b62a1ea81 100644 --- a/gtk/a11y/gtkatspicontext.c +++ b/gtk/a11y/gtkatspicontext.c @@ -953,22 +953,30 @@ gtk_at_spi_context_state_change (GtkATContext *ctx, { value = gtk_accessible_attribute_set_get_value (states, GTK_ACCESSIBLE_STATE_CHECKED); - switch (gtk_tristate_accessible_value_get (value)) + if (value->value_class->type == GTK_ACCESSIBLE_VALUE_TYPE_TRISTATE) + { + switch (gtk_tristate_accessible_value_get (value)) + { + case GTK_ACCESSIBLE_TRISTATE_TRUE: + emit_state_changed (self, "checked", TRUE); + emit_state_changed (self, "indeterminate", FALSE); + break; + case GTK_ACCESSIBLE_TRISTATE_MIXED: + emit_state_changed (self, "checked", FALSE); + emit_state_changed (self, "indeterminate", TRUE); + break; + case GTK_ACCESSIBLE_TRISTATE_FALSE: + emit_state_changed (self, "checked", FALSE); + emit_state_changed (self, "indeterminate", FALSE); + break; + default: + break; + } + } + else { - case GTK_ACCESSIBLE_TRISTATE_TRUE: - emit_state_changed (self, "checked", TRUE); - emit_state_changed (self, "indeterminate", FALSE); - break; - case GTK_ACCESSIBLE_TRISTATE_MIXED: emit_state_changed (self, "checked", FALSE); emit_state_changed (self, "indeterminate", TRUE); - break; - case GTK_ACCESSIBLE_TRISTATE_FALSE: - emit_state_changed (self, "checked", FALSE); - emit_state_changed (self, "indeterminate", FALSE); - break; - default: - break; } } @@ -1011,22 +1019,31 @@ gtk_at_spi_context_state_change (GtkATContext *ctx, if (changed_states & GTK_ACCESSIBLE_STATE_CHANGE_PRESSED) { value = gtk_accessible_attribute_set_get_value (states, GTK_ACCESSIBLE_STATE_PRESSED); - switch (gtk_tristate_accessible_value_get (value)) + + if (value->value_class->type == GTK_ACCESSIBLE_VALUE_TYPE_TRISTATE) + { + switch (gtk_tristate_accessible_value_get (value)) + { + case GTK_ACCESSIBLE_TRISTATE_TRUE: + emit_state_changed (self, "pressed", TRUE); + emit_state_changed (self, "indeterminate", FALSE); + break; + case GTK_ACCESSIBLE_TRISTATE_MIXED: + emit_state_changed (self, "pressed", FALSE); + emit_state_changed (self, "indeterminate", TRUE); + break; + case GTK_ACCESSIBLE_TRISTATE_FALSE: + emit_state_changed (self, "pressed", FALSE); + emit_state_changed (self, "indeterminate", FALSE); + break; + default: + break; + } + } + else { - case GTK_ACCESSIBLE_TRISTATE_TRUE: - emit_state_changed (self, "pressed", TRUE); - emit_state_changed (self, "indeterminate", FALSE); - break; - case GTK_ACCESSIBLE_TRISTATE_MIXED: emit_state_changed (self, "pressed", FALSE); emit_state_changed (self, "indeterminate", TRUE); - break; - case GTK_ACCESSIBLE_TRISTATE_FALSE: - emit_state_changed (self, "pressed", FALSE); - emit_state_changed (self, "indeterminate", FALSE); - break; - default: - break; } }