winaccessibility/inc/AccObject.hxx                      |    2 
 winaccessibility/source/UAccCOM/MAccessible.cxx         |   49 ++---------
 winaccessibility/source/UAccCOM/MAccessible.h           |    1 
 winaccessibility/source/UAccCOMIDL/UAccCOM.idl          |    1 
 winaccessibility/source/service/AccObject.cxx           |   67 ----------------
 winaccessibility/source/service/AccObjectWinManager.cxx |    1 
 6 files changed, 10 insertions(+), 111 deletions(-)

New commits:
commit e6c471dd7b2738b6575ac533daad33af2d6bbaa7
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Aug 21 10:37:33 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Aug 21 18:49:47 2024 +0200

    wina11y: Only require action iface for the actual object
    
    Quoting from the `IAccessible::accDoDefaultAction` doc [1]
    for the `varChild` param:
    
    > Specifies whether the default action belongs to the object
    > or one of the object's child elements.
    
    If the default object of a child and not the object itself
    should be triggered, there's no need for the object
    itself to also support actions itself.
    
    Therefore, only perform such a check in the
    `CHILDID_SELF` case.
    
    Also, return `S_FALSE` in case there's no action, as this is
    not a case of "An unknown or generic error occurred.", which
    is the meaning of `E_FAIL` [2].
    
    as other places do
    move that check in `CMAccessible::get_accDefaultAction`, if a child
    object is specified instead of requesting
    
    [1] 
https://learn.microsoft.com/en-us/windows/win32/api/oleacc/nf-oleacc-iaccessible-accdodefaultaction
    [2] https://learn.microsoft.com/en-us/windows/win32/winauto/return-values
    
    Change-Id: Idcd3ab8a415e73e496cf027506428518a9f4a203
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172184
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/winaccessibility/source/UAccCOM/MAccessible.cxx 
b/winaccessibility/source/UAccCOM/MAccessible.cxx
index 0d9d5bd41ffe..fbf035902aae 100644
--- a/winaccessibility/source/UAccCOM/MAccessible.cxx
+++ b/winaccessibility/source/UAccCOM/MAccessible.cxx
@@ -2229,15 +2229,13 @@ COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE 
CMAccessible::accDoDefaultAction(
         if (m_isDestroy) return S_FALSE;
         if( varChild.vt != VT_I4 )
             return E_INVALIDARG;
-        if (!m_xAction.is())
-            return E_FAIL;
-        if (m_xAction->getAccessibleActionCount() == 0)
-            return E_FAIL;
 
-        if(varChild.lVal==CHILDID_SELF)
+        if (varChild.lVal == CHILDID_SELF)
         {
-            if (m_xAction->getAccessibleActionCount() > 0)
-                m_xAction->doAccessibleAction(0);
+            if (!m_xAction.is() || m_xAction->getAccessibleActionCount() < 1)
+                return S_FALSE;
+
+            m_xAction->doAccessibleAction(0);
             return S_OK;
         }
 
commit dfd23124096b9428f2f7084a24de032750389c79
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Aug 21 10:16:51 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Aug 21 18:49:39 2024 +0200

    wina11y: Retrieve default action description on demand
    
    Instead of doing extra work to keep
    `CMAccessible::m_pszActionDescription` up to date,
    move the logic to retrieve the action description
    from the underlying `XAccessibleAction` into
    `CMAccessible::get_accDefaultAction` and do that
    on demand.
    
    This is similar to what was done for the accessible
    description in this commit:
    
        commit fcf4a26275d7503835f9aa23cb94938809840300
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Wed Jan 5 13:41:53 2022 +0000
    
            tdf#146306 wina11y: Retrieve accessible desc on demand
    
    As expected, the example mentioned in the commit
    message of
    
        Change-Id: I5569f70739135172ddb604f1f1bd958e32626ab0
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Wed Aug 21 09:49:51 2024 +0100
    
            wina11y: Unify handling to set action description
    
    still behaves the same as without this commit in place.
    
    Change-Id: I7d1ea0ce302df955314c8e46c530cc24d30fcd4b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172183
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/winaccessibility/inc/AccObject.hxx 
b/winaccessibility/inc/AccObject.hxx
index 1d922a8e2889..9810e7a42d72 100644
--- a/winaccessibility/inc/AccObject.hxx
+++ b/winaccessibility/inc/AccObject.hxx
@@ -73,7 +73,6 @@ public:
     virtual ~AccObject();
 
     bool UpdateAccessibleInfoFromUnoToMSAA(  ); //implement accessible 
information mapping
-    void UpdateActionDesc();
 
     IMAccessible*  GetIMAccessible();   //return COM interface in acc object
     css::uno::Reference<css::accessibility::XAccessible> const& 
GetXAccessible();
diff --git a/winaccessibility/source/UAccCOM/MAccessible.cxx 
b/winaccessibility/source/UAccCOM/MAccessible.cxx
index b131782120cb..0d9d5bd41ffe 100644
--- a/winaccessibility/source/UAccCOM/MAccessible.cxx
+++ b/winaccessibility/source/UAccCOM/MAccessible.cxx
@@ -194,7 +194,6 @@ AccObjectWinManager* CMAccessible::g_pAccObjectManager = 
nullptr;
 
 CMAccessible::CMAccessible():
 m_pszValue(nullptr),
-m_pszActionDescription(nullptr),
 m_iRole(0x00),
 m_dState(0x00),
 m_pIParent(nullptr),
@@ -216,11 +215,6 @@ CMAccessible::~CMAccessible()
         SysFreeString(std::exchange(m_pszValue, nullptr));
     }
 
-    if(m_pszActionDescription!=nullptr)
-    {
-        SysFreeString(std::exchange(m_pszActionDescription, nullptr));
-    }
-
     if(m_pIParent)
     {
         m_pIParent->Release();
@@ -2201,10 +2195,12 @@ COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE 
CMAccessible::get_accDefaultActio
         {
             if(varChild.lVal==CHILDID_SELF)
             {
-                if (!m_xAction.is())
-                    return DISP_E_MEMBERNOTFOUND;
+                if (!m_xAction.is() || m_xAction->getAccessibleActionCount() < 
1)
+                    return S_FALSE;
+
+                const OUString sActionDescription = 
m_xAction->getAccessibleActionDescription(0);
                 SysFreeString(*pszDefaultAction);
-                *pszDefaultAction = SysAllocString(m_pszActionDescription);
+                *pszDefaultAction = 
SysAllocString(o3tl::toW(sActionDescription.getStr()));
                 return S_OK;
             }
 
@@ -2255,29 +2251,6 @@ COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE 
CMAccessible::accDoDefaultAction(
     } catch(...) { return E_FAIL; }
 }
 
-/**
-* UNO set description information for action to COM.
-* @param szAction, the action description of the current object.
-* @return S_OK if successful.
-*/
-COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::Put_ActionDescription( const 
OLECHAR* szAction)
-{
-    // internal IMAccessible - no mutex meeded
-
-    try {
-        if (m_isDestroy) return S_FALSE;
-
-        if(szAction == nullptr)
-        {
-            return E_INVALIDARG;
-        }
-        SysFreeString(m_pszActionDescription );
-        m_pszActionDescription = SysAllocString( szAction );
-        return S_OK;
-
-        } catch(...) { return E_FAIL; }
-}
-
 bool CMAccessible::GetXInterfaceFromXAccessible(XAccessible* pXAcc, 
XInterface** ppXI, XInterfaceType eType)
 {
     switch(eType)
diff --git a/winaccessibility/source/UAccCOM/MAccessible.h 
b/winaccessibility/source/UAccCOM/MAccessible.h
index 13dfd9ab6c39..0bcbda08fa02 100644
--- a/winaccessibility/source/UAccCOM/MAccessible.h
+++ b/winaccessibility/source/UAccCOM/MAccessible.h
@@ -146,7 +146,6 @@ public:
     STDMETHOD(Put_XAccChildID)(long dChildID) override;
     STDMETHOD(Put_XAccObjectManager)(hyper pManager) override;
     STDMETHOD(NotifyDestroy)() override;
-    STDMETHOD(Put_ActionDescription)( const OLECHAR* szAction) override;
     STDMETHOD(SetDefaultAction)(hyper pAction) override;
     STDMETHOD(GetUNOInterface)(hyper*) override;
     STDMETHOD(SetXAccessible)(hyper) override;
diff --git a/winaccessibility/source/UAccCOMIDL/UAccCOM.idl 
b/winaccessibility/source/UAccCOMIDL/UAccCOM.idl
index 8212df86e7ff..20281fcfe910 100644
--- a/winaccessibility/source/UAccCOMIDL/UAccCOM.idl
+++ b/winaccessibility/source/UAccCOMIDL/UAccCOM.idl
@@ -44,7 +44,6 @@ import "defines.idl";
         [id(19), helpstring("method SetXAccessible")] HRESULT 
SetXAccessible(hyper XAccessible);
         [id(20), helpstring("method GetUNOInterface")] HRESULT 
GetUNOInterface(hyper* UNOInterface);
         [id(23), helpstring("method SetDefaultAction")] HRESULT 
SetDefaultAction(hyper pAction);
-        [id(24), helpstring("method Put_ActionDescription")] HRESULT 
Put_ActionDescription( const OLECHAR* szAction);
         [id(25), helpstring("method Put_XAccObjectManager")] HRESULT 
Put_XAccObjectManager(hyper pManager);
         [id(26), helpstring("method NotifyDestroy")] HRESULT NotifyDestroy();
     };
diff --git a/winaccessibility/source/service/AccObject.cxx 
b/winaccessibility/source/service/AccObject.cxx
index 1effc0650992..3b4a0fc7a3e2 100644
--- a/winaccessibility/source/service/AccObject.cxx
+++ b/winaccessibility/source/service/AccObject.cxx
@@ -357,7 +357,6 @@ void  AccObject::UpdateAction()
     {
         if( m_xAccActionRef->getAccessibleActionCount() > 0 )
         {
-            UpdateActionDesc();
             m_pIMAcc->SetDefaultAction(
                     reinterpret_cast<hyper>(m_xAccActionRef.get()));
         }
@@ -706,23 +705,6 @@ AccObject* AccObject::NextChild()
     return nullptr;
 }
 
-/**
-   * update action description desc
-   * @param
-   * @return
-   */
-void AccObject::UpdateActionDesc()
-{
-    if (!m_pIMAcc)
-        return;
-
-    if (!m_xAccActionRef.is() || m_xAccActionRef->getAccessibleActionCount() 
<= 0)
-        return;
-
-    const OUString sActionDesc = 
m_xAccActionRef->getAccessibleActionDescription(0);
-    m_pIMAcc->Put_ActionDescription(o3tl::toW(sActionDesc.getStr()));
-}
-
 /**
    * update role information from uno to com
    * @param
@@ -929,8 +911,6 @@ bool AccObject::UpdateAccessibleInfoFromUnoToMSAA()
 
     UpdateValue();
 
-    UpdateActionDesc();
-
     UpdateRole();
 
     UpdateState();
diff --git a/winaccessibility/source/service/AccObjectWinManager.cxx 
b/winaccessibility/source/service/AccObjectWinManager.cxx
index cc72fc502f1f..8e08d4cafedf 100644
--- a/winaccessibility/source/service/AccObjectWinManager.cxx
+++ b/winaccessibility/source/service/AccObjectWinManager.cxx
@@ -176,7 +176,6 @@ bool AccObjectWinManager::NotifyAccEvent(XAccessible* 
pXAcc, UnoMSAAEvent eEvent
     case UnoMSAAEvent::STATE_FOCUSED:
         {
             UpdateAccFocus(pXAcc);
-            selfAccObj->UpdateActionDesc();
             UpdateValue(pXAcc);
             NotifyWinEvent( EVENT_OBJECT_FOCUS,hAcc, OBJID_CLIENT,dChildID  );
             break;
commit 525ba5e4d7936dbf4209354dd5a143af93270b95
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Aug 21 09:49:51 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Aug 21 18:49:32 2024 +0200

    wina11y: Unify handling to set action description
    
    Drop `AccObject::UpdateDefaultAction` and let
    `AccObject::UpdateActionDesc` take care of
    setting the action description for all roles.
    
    It's unclear to me
    
    * why the action description would only be set
      for particular roles
    
    * why `AccObject::UpdateActionDesc` would call
      `AccObject::UpdateDefaultAction` for particular
      roles if it was basically setting the description
      the same way that `AccObject::UpdateActionDesc`
      does directly for other roles (except for
      `AccObject::UpdateDefaultAction` not checking
      that there's at least one action).
    
    Also simplify the code a bit while at it.
    
    Testing with the "Don't Save" button in the "Save Document?"
    dialog seen when pressing Alt+F4 with a modified Writer doc
    gives the expected result in NVDA's Python console:
    
        >>> focus.role
        <Role.BUTTON: 9>
        >>> focus.name
        'Don’t Save'
        >>> focus.IAccessibleActionObject.nActions()
        1
        >>> focus.IAccessibleActionObject.description(0)
        'press'
    
    If any particular reason for not setting the action description
    for particular roles should show up in the future, they can
    still be excluded in one central place now.
    
    Change-Id: I5569f70739135172ddb604f1f1bd958e32626ab0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172182
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/winaccessibility/inc/AccObject.hxx 
b/winaccessibility/inc/AccObject.hxx
index 46fc12aa65e1..1d922a8e2889 100644
--- a/winaccessibility/inc/AccObject.hxx
+++ b/winaccessibility/inc/AccObject.hxx
@@ -59,7 +59,6 @@ private:
     css::uno::Reference < css::accessibility::XAccessibleAction > 
m_xAccActionRef;
     css::uno::Reference < css::accessibility::XAccessibleContext > 
m_xAccContextRef;
 
-    void UpdateActionDesc();
     void UpdateRole();
 
     DWORD GetMSAAStateFromUNO(sal_Int64 xState);//translate state from UNO to 
MSAA value
@@ -74,7 +73,7 @@ public:
     virtual ~AccObject();
 
     bool UpdateAccessibleInfoFromUnoToMSAA(  ); //implement accessible 
information mapping
-    void UpdateDefaultAction();
+    void UpdateActionDesc();
 
     IMAccessible*  GetIMAccessible();   //return COM interface in acc object
     css::uno::Reference<css::accessibility::XAccessible> const& 
GetXAccessible();
diff --git a/winaccessibility/source/service/AccObject.cxx 
b/winaccessibility/source/service/AccObject.cxx
index bd06d941c37f..1effc0650992 100644
--- a/winaccessibility/source/service/AccObject.cxx
+++ b/winaccessibility/source/service/AccObject.cxx
@@ -357,7 +357,7 @@ void  AccObject::UpdateAction()
     {
         if( m_xAccActionRef->getAccessibleActionCount() > 0 )
         {
-            UpdateDefaultAction( );
+            UpdateActionDesc();
             m_pIMAcc->SetDefaultAction(
                     reinterpret_cast<hyper>(m_xAccActionRef.get()));
         }
@@ -387,33 +387,6 @@ void AccObject::UpdateValue()
     SetValue( pAny );
 }
 
-/**
-   * Set special default action description string via UNO role.
-   * @param Role UNO role
-   * @return
-   */
-void AccObject::UpdateDefaultAction( )
-{
-    if(!m_xAccActionRef.is())
-        return ;
-
-    switch(m_accRole)
-    {
-    case PUSH_BUTTON:
-    case TOGGLE_BUTTON:
-    case RADIO_BUTTON:
-    case MENU_ITEM:
-    case RADIO_MENU_ITEM:
-    case CHECK_MENU_ITEM:
-    case LIST_ITEM:
-    case CHECK_BOX:
-    case TREE_ITEM:
-    case BUTTON_DROPDOWN:
-        m_pIMAcc->Put_ActionDescription( 
o3tl::toW(m_xAccActionRef->getAccessibleActionDescription(sal_Int32(0)).getStr())
 );
-        return;
-    }
-}
-
 /**
    * Set value property via pAny.
    * @param pAny New value.
@@ -732,6 +705,7 @@ AccObject* AccObject::NextChild()
         return  *pInd;
     return nullptr;
 }
+
 /**
    * update action description desc
    * @param
@@ -742,34 +716,13 @@ void AccObject::UpdateActionDesc()
     if (!m_pIMAcc)
         return;
 
-    long Role = m_accRole;
-
-    if(  Role == PUSH_BUTTON || Role == RADIO_BUTTON || Role == MENU_ITEM ||
-            Role == LIST_ITEM || Role == CHECK_BOX || Role == TREE_ITEM ||
-            Role == CHECK_MENU_ITEM || Role == RADIO_MENU_ITEM )
-    {
-        UpdateDefaultAction(  );
-    }
-    else
-    {
-
-        if( m_xAccActionRef.is() )
-        {
-            if( m_xAccActionRef->getAccessibleActionCount() > 0 )
-            {
-                if (!(Role == SPIN_BOX || Role == COMBO_BOX || Role == 
DATE_EDITOR ||
-                      Role == EDIT_BAR || Role == PASSWORD_TEXT || Role == 
TEXT))
-                {
-                    const OUString sActionDesc = 
m_xAccActionRef->getAccessibleActionDescription(0);
-                    // if string is non-empty, action is set.
-                    if (!sActionDesc.isEmpty())
-                        
m_pIMAcc->Put_ActionDescription(o3tl::toW(sActionDesc.getStr()));
-                }
-            }
-        }
-    }
+    if (!m_xAccActionRef.is() || m_xAccActionRef->getAccessibleActionCount() 
<= 0)
+        return;
 
+    const OUString sActionDesc = 
m_xAccActionRef->getAccessibleActionDescription(0);
+    m_pIMAcc->Put_ActionDescription(o3tl::toW(sActionDesc.getStr()));
 }
+
 /**
    * update role information from uno to com
    * @param
diff --git a/winaccessibility/source/service/AccObjectWinManager.cxx 
b/winaccessibility/source/service/AccObjectWinManager.cxx
index bf3c63825903..cc72fc502f1f 100644
--- a/winaccessibility/source/service/AccObjectWinManager.cxx
+++ b/winaccessibility/source/service/AccObjectWinManager.cxx
@@ -176,7 +176,7 @@ bool AccObjectWinManager::NotifyAccEvent(XAccessible* 
pXAcc, UnoMSAAEvent eEvent
     case UnoMSAAEvent::STATE_FOCUSED:
         {
             UpdateAccFocus(pXAcc);
-            selfAccObj->UpdateDefaultAction( );
+            selfAccObj->UpdateActionDesc();
             UpdateValue(pXAcc);
             NotifyWinEvent( EVENT_OBJECT_FOCUS,hAcc, OBJID_CLIENT,dChildID  );
             break;

Reply via email to