gtk4 a11y: Forward text change events
Bridge text-related a11y change events for the gtk4 VCL plugin
by using the new functions to notify about text, text caret
and text selection changes recently introduced in Gtk
in commit [1]
commit 0ca8d74842837b1ad5dc42c1fcff8b1270e5750b
Author: Matthias Clasen <mclasen@redhat.com>
Date: Tue Feb 20 12:18:27 2024 -0500
a11y: Add GtkAccessibleText interface
With this in place, having a Writer paragraph selected in
Accerciser's treeview, the text in the "Text" section of the
"Interface Viewer" tab in Accerciser now updates when typing
in LibreOffice (i.e. text changes are propagated there right
away as expected).
[1] https://gitlab.gnome.org/GNOME/gtk/-/commit/0ca8d74842837b1ad5dc42c1fcff8b1270e5750b
Change-Id: I33c93613ddde3650d81ce11d605dc70b0569080a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163746
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
diff --git a/vcl/unx/gtk4/gtkaccessibleeventlistener.cxx b/vcl/unx/gtk4/gtkaccessibleeventlistener.cxx
index 4211340d..6e50b85 100644
--- a/vcl/unx/gtk4/gtkaccessibleeventlistener.cxx
+++ b/vcl/unx/gtk4/gtkaccessibleeventlistener.cxx
@@ -9,6 +9,7 @@
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/TextSegment.hpp>
#include <sal/log.hxx>
#include "gtkaccessibleeventlistener.hxx"
@@ -40,6 +41,14 @@ void GtkAccessibleEventListener::notifyEvent(
{
switch (rEvent.EventId)
{
#if GTK_CHECK_VERSION(4, 13, 8)
case css::accessibility::AccessibleEventId::CARET_CHANGED:
{
if (GTK_IS_ACCESSIBLE_TEXT(m_pLoAccessible))
gtk_accessible_text_update_caret_position(GTK_ACCESSIBLE_TEXT(m_pLoAccessible));
break;
}
#endif
case css::accessibility::AccessibleEventId::STATE_CHANGED:
{
sal_Int64 nState;
@@ -62,6 +71,37 @@ void GtkAccessibleEventListener::notifyEvent(
}
break;
}
#if GTK_CHECK_VERSION(4, 13, 8)
case css::accessibility::AccessibleEventId::TEXT_CHANGED:
{
if (!GTK_IS_ACCESSIBLE_TEXT(m_pLoAccessible))
break;
GtkAccessibleText* pText = GTK_ACCESSIBLE_TEXT(m_pLoAccessible);
css::accessibility::TextSegment aDeletedText;
css::accessibility::TextSegment aInsertedText;
if (rEvent.OldValue >>= aDeletedText)
{
gtk_accessible_text_update_contents(
pText, GTK_ACCESSIBLE_TEXT_CONTENT_CHANGE_REMOVE, aDeletedText.SegmentStart,
aDeletedText.SegmentEnd);
}
if (rEvent.NewValue >>= aInsertedText)
{
gtk_accessible_text_update_contents(
pText, GTK_ACCESSIBLE_TEXT_CONTENT_CHANGE_INSERT, aInsertedText.SegmentStart,
aInsertedText.SegmentEnd);
}
return;
}
case css::accessibility::AccessibleEventId::TEXT_SELECTION_CHANGED:
{
if (GTK_IS_ACCESSIBLE_TEXT(m_pLoAccessible))
gtk_accessible_text_update_selection_bound(GTK_ACCESSIBLE_TEXT(m_pLoAccessible));
break;
}
#endif
default:
break;
}