[Libreoffice-commits] core.git: vcl/qt5

Michael Weghorn (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 21 15:43:22 UTC 2021


 vcl/qt5/Qt5AccessibleWidget.cxx |   59 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 54 insertions(+), 5 deletions(-)

New commits:
commit 96869931e35fa4fbc779755e89207062648ed58d
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Wed Jul 21 11:27:53 2021 +0200
Commit:     Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Wed Jul 21 17:42:45 2021 +0200

    qt5 a11y: Implement Qt5AccessibleWidget::textAtOffset
    
    The Orca screen reader uses
    'IAccessibleText::textAtOffset' e.g. in
    order to retrieve the text of the current Writer
    paragraph on cursor movement.
    
    With this and various other WIP changes
    to qt5 a11y on top which are required to make Orca
    speak at all (well, at least sometimes...), Orca
    now also speaks the text of paragraphs that contain
    more than just a single character.
    The single-character case was working because
    Orca has a special handling for this; a comment
    in the source code says:
    "We do this because Gecko's implementation of getTextAtOffset
    is broken if there is just one character in the string.")
    
    This implementation is inspired by the
    corresponding winaccessibility one,
    see 'CAccTextBase::get_textAtOffset' in
    winaccessibility/source/UAccCOM/AccTextBase.cxx.
    
    Change-Id: I67775a03c6e4384f410e1e9d727d7a412ba4112e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119310
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.weghorn at posteo.de>

diff --git a/vcl/qt5/Qt5AccessibleWidget.cxx b/vcl/qt5/Qt5AccessibleWidget.cxx
index ee93bc6a21de..0cf79919501c 100644
--- a/vcl/qt5/Qt5AccessibleWidget.cxx
+++ b/vcl/qt5/Qt5AccessibleWidget.cxx
@@ -32,6 +32,7 @@
 #include <com/sun/star/accessibility/AccessibleRole.hpp>
 #include <com/sun/star/accessibility/AccessibleScrollType.hpp>
 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
+#include <com/sun/star/accessibility/AccessibleTextType.hpp>
 #include <com/sun/star/accessibility/XAccessible.hpp>
 #include <com/sun/star/accessibility/XAccessibleAction.hpp>
 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
@@ -114,6 +115,33 @@ int Qt5AccessibleWidget::indexOfChild(const QAccessibleInterface* /* child */) c
 
 namespace
 {
+sal_Int16 lcl_matchQtTextBoundaryType(QAccessible::TextBoundaryType boundaryType)
+{
+    switch (boundaryType)
+    {
+        case QAccessible::CharBoundary:
+            return com::sun::star::accessibility::AccessibleTextType::CHARACTER;
+        case QAccessible::WordBoundary:
+            return com::sun::star::accessibility::AccessibleTextType::WORD;
+        case QAccessible::SentenceBoundary:
+            return com::sun::star::accessibility::AccessibleTextType::SENTENCE;
+        case QAccessible::ParagraphBoundary:
+            return com::sun::star::accessibility::AccessibleTextType::PARAGRAPH;
+        case QAccessible::LineBoundary:
+            return com::sun::star::accessibility::AccessibleTextType::LINE;
+        case QAccessible::NoBoundary:
+            // assert here, better handle it directly at call site
+            assert(false
+                   && "No match for QAccessible::NoBoundary, handle it separately at call site.");
+            break;
+        default:
+            break;
+    }
+
+    SAL_WARN("vcl.qt5", "Unmatched text boundary type: " << boundaryType);
+    return -1;
+}
+
 QAccessible::Relation lcl_matchUnoRelation(short relationType)
 {
     switch (relationType)
@@ -968,13 +996,34 @@ QString Qt5AccessibleWidget::textAfterOffset(int /* offset */,
     SAL_INFO("vcl.qt5", "Unsupported QAccessibleTextInterface::textAfterOffset");
     return QString();
 }
-QString Qt5AccessibleWidget::textAtOffset(int /* offset */,
-                                          QAccessible::TextBoundaryType /* boundaryType */,
-                                          int* /* startOffset */, int* /* endOffset */) const
+
+QString Qt5AccessibleWidget::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType,
+                                          int* startOffset, int* endOffset) const
 {
-    SAL_INFO("vcl.qt5", "Unsupported QAccessibleTextInterface::textAtOffset");
-    return QString();
+    if (startOffset == nullptr || endOffset == nullptr)
+        return QString();
+
+    if (boundaryType == QAccessible::NoBoundary)
+    {
+        const int nCharCount = characterCount();
+        *startOffset = 0;
+        *endOffset = nCharCount;
+        return text(0, nCharCount);
+    }
+
+    Reference<XAccessibleText> xText(m_xAccessible, UNO_QUERY);
+    if (!xText.is())
+        return QString();
+
+    sal_Int16 nUnoBoundaryType = lcl_matchQtTextBoundaryType(boundaryType);
+    assert(nUnoBoundaryType > 0);
+
+    const TextSegment segment = xText->getTextAtIndex(offset, nUnoBoundaryType);
+    *startOffset = segment.SegmentStart;
+    *endOffset = segment.SegmentEnd;
+    return toQString(segment.SegmentText);
 }
+
 QString Qt5AccessibleWidget::textBeforeOffset(int /* offset */,
                                               QAccessible::TextBoundaryType /* boundaryType */,
                                               int* /* startOffset */, int* /* endOffset */) const


More information about the Libreoffice-commits mailing list