test/source/a11y/AccessibilityTools.cxx        |   18 +++++++++++-------
 toolkit/source/awt/vclxaccessiblecomponent.cxx |    6 +++++-
 2 files changed, 16 insertions(+), 8 deletions(-)

New commits:
commit 3b1da48e8c5506e366977a5e888ec3897e3e1ca3
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Jul 31 14:48:07 2023 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Aug 2 05:10:18 2023 +0200

    a11y: Don't always append window type to a11y name in debug builds
    
    Appending " (Type = <number>)" to the accessible name is probably
    meant for debugging purposes to see what type of window is
    involved, but doing that by default in debug builds has disadvantages,
    e.g.:
    
    1) It affects how assistive tooling, like screen readers, handles
    the accessible objects, therefore the behaviour with a debug build
    (what a developer working on something experiences) does not
    necessarily match what happens in non-debug builds (what end
    users will experience).
    
    For instance, when Orca announces the "Update styles" push button
    in Writer's formatting toolbar, it not only announces the extra
    type information for the objects in the hierarchy it announces
    anyway, but announces the panel in addition, since it has a non-empty
    name due to the appended type information.
    
    Announcement without this change in place (from Orca log):
    
        INFO:speech:SPEECH OUTPUT: ' (Type = 371) panel.'
        INFO:speech:SPEECH OUTPUT: 'Formatting (Type = 356) tool bar'
        INFO:speech:SPEECH OUTPUT: 'Update push button.'
    
    Announcement with this change in place:
    
        INFO:speech:SPEECH OUTPUT: 'Formatting tool bar'
        INFO:speech:SPEECH OUTPUT: 'Update push button.'
    
    2) It breaks selecting the object under the mouse cursor in
    Accerciser at least with the qt6 VCL plugin when the object is in
    a dialog, because the window name retrieved via the accessibility
    APIs (with the appended type information) does not match the one
    retrieved via Wnck [1].
    
    Therefore, don't append the type information by default,
    but only if environment variable
    `LIBO_APPEND_WINDOW_TYPE_TO_ACCESSIBLE_NAME` ist set
    (typically `LIBO_APPEND_WINDOW_TYPE_TO_ACCESSIBLE_NAME=1`,
    but any value other than "0" will do),
    so that can still be used for cases where having the type as
    part of the accessible name is useful.
    
    [1] 
https://gitlab.gnome.org/GNOME/accerciser/-/blob/5af3fdbfb8a7832e434ad6fc7d2ecaad18f2e32e/plugins/quick_select.py#L109
    
    Change-Id: Ie33b14fbdf9731b02c8c620d7a5ac718ef99367d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155094
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/test/source/a11y/AccessibilityTools.cxx 
b/test/source/a11y/AccessibilityTools.cxx
index b51c7cbac239..d19c42b388e0 100644
--- a/test/source/a11y/AccessibilityTools.cxx
+++ b/test/source/a11y/AccessibilityTools.cxx
@@ -190,14 +190,18 @@ bool AccessibilityTools::nameEquals(const 
uno::Reference<accessibility::XAccessi
 
 #if OSL_DEBUG_LEVEL > 0
     // see VCLXAccessibleComponent::getAccessibleName()
-    auto pVCLXAccessibleComponent = 
dynamic_cast<VCLXAccessibleComponent*>(xCtx.get());
-    if (pVCLXAccessibleComponent)
+    static const char* pEnvAppendType = 
getenv("LIBO_APPEND_WINDOW_TYPE_TO_ACCESSIBLE_NAME");
+    if (pEnvAppendType && OUString::createFromAscii(pEnvAppendType) != u"0")
     {
-        auto windowType = pVCLXAccessibleComponent->GetWindow()->GetType();
-        if (rest
-            == Concat2View(u" (Type = " + 
OUString::number(static_cast<sal_Int32>(windowType))
-                           + ")"))
-            return true;
+        auto pVCLXAccessibleComponent = 
dynamic_cast<VCLXAccessibleComponent*>(xCtx.get());
+        if (pVCLXAccessibleComponent)
+        {
+            auto windowType = pVCLXAccessibleComponent->GetWindow()->GetType();
+            if (rest
+                == Concat2View(u" (Type = " + 
OUString::number(static_cast<sal_Int32>(windowType))
+                               + ")"))
+                return true;
+        }
     }
 #endif
     return false;
diff --git a/toolkit/source/awt/vclxaccessiblecomponent.cxx 
b/toolkit/source/awt/vclxaccessiblecomponent.cxx
index 19ba5c4fbfc2..36d0451b2575 100644
--- a/toolkit/source/awt/vclxaccessiblecomponent.cxx
+++ b/toolkit/source/awt/vclxaccessiblecomponent.cxx
@@ -629,7 +629,11 @@ OUString VCLXAccessibleComponent::getAccessibleName(  )
     {
         aName = GetWindow()->GetAccessibleName();
 #if OSL_DEBUG_LEVEL > 0
-        aName += " (Type = " + 
OUString::number(static_cast<sal_Int32>(GetWindow()->GetType())) + ")";
+        // append window type to accessible name for debugging purposes
+        // if LIBO_APPEND_WINDOW_TYPE_TO_ACCESSIBLE_NAME environment variable 
is set
+        static const char* pEnvAppendType = 
getenv("LIBO_APPEND_WINDOW_TYPE_TO_ACCESSIBLE_NAME");
+        if (pEnvAppendType && OUString::createFromAscii(pEnvAppendType) != 
u"0")
+            aName += " (Type = " + 
OUString::number(static_cast<sal_Int32>(GetWindow()->GetType())) + ")";
 #endif
     }
     return aName;

Reply via email to