Kaydet (Commit) 0b904a8b authored tarafından Michael Weghorn's avatar Michael Weghorn Kaydeden (comit) Katarina Behrens

tdf#122200 Qt5AccessibleWidget: Handle special offset values

Handle special values for offset in 'Qt5AccessibleWidget::attributes'
the same way that the base class's 'QAccessibleTextWidget::attributes'
does, s. [1].

In particular, an offset matching the text length can
be passed e.g. by "accerciser" or screen readers,
which previously resulted in an 'IndexOutOfBoundsException'
being thrown when the index was later checked in the
call to 'VCLXAccessibleStatusBarItem::getCharacterAttributes'.

See also 'IAccessibleText::attributes' documentation at [2] and
the page on special offset values referenced there [3].

[1] https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/accessible/qaccessiblewidgets.cpp?h=5.12.4#n791
[2] https://accessibility.linuxfoundation.org/a11yspecs/ia2/docs/html/interface_i_accessible_text.html#a29e5c8f69ec13c683ed6bca53333e6a5
[3] https://accessibility.linuxfoundation.org/a11yspecs/ia2/docs/html/_general_info.html#_specialOffsets

Change-Id: I623995aeb689b31c5b49fb3ace8e4dd4c18927d2
Reviewed-on: https://gerrit.libreoffice.org/73225
Tested-by: Jenkins
Reviewed-by: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
(cherry picked from commit 93c81657)
Reviewed-on: https://gerrit.libreoffice.org/73379
üst 55e531de
...@@ -830,6 +830,22 @@ QString Qt5AccessibleWidget::attributes(int offset, int* startOffset, int* endOf ...@@ -830,6 +830,22 @@ QString Qt5AccessibleWidget::attributes(int offset, int* startOffset, int* endOf
if (!xText.is()) if (!xText.is())
return QString(); return QString();
// handle special values for offset the same way base class's QAccessibleTextWidget::attributes does
// (as defined in IAccessible 2: -1 -> length, -2 -> cursor position)
if (offset == -2)
offset = cursorPosition(); // currently always returns 0
const int nTextLength = characterCount();
if (offset == -1 || offset == nTextLength)
offset = nTextLength - 1;
if (offset < 0 || offset > nTextLength)
{
*startOffset = -1;
*endOffset = -1;
return QString();
}
Sequence<PropertyValue> attribs = xText->getCharacterAttributes(offset, Sequence<OUString>()); Sequence<PropertyValue> attribs = xText->getCharacterAttributes(offset, Sequence<OUString>());
const PropertyValue* pValues = attribs.getConstArray(); const PropertyValue* pValues = attribs.getConstArray();
OUString aRet; OUString aRet;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment