svtools/source/control/valueset.cxx |   37 ++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

New commits:
commit 09b4991701965f9b224bdce63b5a46da7e435bdf
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Sep 30 12:27:09 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Tue Oct 1 15:53:25 2024 +0200

    a11y: Only send active-desc-changed event when ValueSet has focus
    
    When the selected item in a ValueSet changes,
    only send an AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
    event for the newly selected item if the ValueSet itself
    has focus, as the active descendant is the currently
    active child of the current focus object.
    
    This prevents incorrect events that e.g. broke Orca's
    focus tracking and thus announcement of the current slide
    in Impress when moving between slides in the "Slides" panel:
    
    1) start Impress
    2) select the "Beehive" presentation template
    3) move focus to "Slides" panel
    4) use up and down key to navigate between slides
    
    Instead of saying "Slide 1" and "Slide 2" respectively,
    Orca sometimes announced "Layout, list with 16 items", as
    the 2 slides use a different layout, and thus switching
    between slides implicitly leads to the selection of the
    corresponding item in the "Layout" deck in the sidebar,
    which resulted in a corresponding ACTIVE_DESCENDANT_CHANGED
    event being sent prior to this commit, making Orca think
    that that item received keyboard focus.
    
    With this commit in place, Orca now announces "Slide 1"
    and "Slide 2" according to the newly selected slide
    in the "Slides" view.
    
    Change-Id: I543a4c94bae75dede7274a8b35f183ccd2ac0515
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174342
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/svtools/source/control/valueset.cxx 
b/svtools/source/control/valueset.cxx
index 58364b4aebfc..c80fc3f3e69a 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -32,6 +32,7 @@
 #include <vcl/lineinfo.hxx>
 
 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
+#include <com/sun/star/accessibility/AccessibleStateType.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <rtl/ustring.hxx>
 #include <sal/log.hxx>
@@ -804,25 +805,29 @@ void ValueSet::SelectItem( sal_uInt16 nItemId )
         }
     }
 
-    // focus event (select)
-    const size_t nPos = GetItemPos( mnSelItemId );
+    if (mxAccessible->getAccessibleStateSet() & 
css::accessibility::AccessibleStateType::FOCUSED)
+    {
+        // focus event (select)
+        const size_t nPos = GetItemPos(mnSelItemId);
 
-    ValueSetItem* pItem;
-    if( nPos != VALUESET_ITEM_NOTFOUND )
-        pItem = mItemList[nPos].get();
-    else
-        pItem = mpNoneItem.get();
+        ValueSetItem* pItem;
+        if (nPos != VALUESET_ITEM_NOTFOUND)
+            pItem = mItemList[nPos].get();
+        else
+            pItem = mpNoneItem.get();
 
-    ValueItemAcc* pItemAcc = nullptr;
-    if (pItem != nullptr)
-        pItemAcc = ValueItemAcc::getImplementation( pItem->GetAccessible( 
false/*bIsTransientChildrenDisabled*/ ) );
+        ValueItemAcc* pItemAcc = nullptr;
+        if (pItem != nullptr)
+            pItemAcc = ValueItemAcc::getImplementation(
+                pItem->GetAccessible(false /*bIsTransientChildrenDisabled*/));
 
-    if( pItemAcc )
-    {
-        Any aOldAny;
-        Any aNewAny;
-        aNewAny <<= Reference(getXWeak(pItemAcc));
-        ImplFireAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, 
aOldAny, aNewAny);
+        if (pItemAcc)
+        {
+            Any aOldAny;
+            Any aNewAny;
+            aNewAny <<= Reference(getXWeak(pItemAcc));
+            
ImplFireAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, 
aNewAny);
+        }
     }
 
     // selection event

Reply via email to