vcl/qt5/Qt5AccessibleWidget.cxx |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

New commits:
commit 0b904a8b3ceb648cf6466cb33f07310a3c70f793
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu May 30 23:41:10 2019 +0200
Commit:     Katarina Behrens <katarina.behr...@cib.de>
CommitDate: Mon Jun 3 18:12:45 2019 +0200

    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: Katarina Behrens <katarina.behr...@cib.de>
    (cherry picked from commit 93c81657c6111b4bb97a2bb9ec155465f9a6f523)
    Reviewed-on: https://gerrit.libreoffice.org/73379

diff --git a/vcl/qt5/Qt5AccessibleWidget.cxx b/vcl/qt5/Qt5AccessibleWidget.cxx
index b76acb4a1c57..e2cc0a31765c 100644
--- a/vcl/qt5/Qt5AccessibleWidget.cxx
+++ b/vcl/qt5/Qt5AccessibleWidget.cxx
@@ -830,6 +830,22 @@ QString Qt5AccessibleWidget::attributes(int offset, int* 
startOffset, int* endOf
     if (!xText.is())
         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>());
     const PropertyValue* pValues = attribs.getConstArray();
     OUString aRet;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to