diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2021-07-21 11:27:53 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2021-07-21 17:42:45 +0200 |
commit | 96869931e35fa4fbc779755e89207062648ed58d (patch) | |
tree | d01222afe660137b2e5a33968b3663052ad79e73 | |
parent | cd2b5168e8ef1cb6e721bc5220421464ed723096 (diff) |
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@posteo.de>
-rw-r--r-- | vcl/qt5/Qt5AccessibleWidget.cxx | 59 |
1 files changed, 54 insertions, 5 deletions
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 |