winaccessibility/inc/AccObjectWinManager.hxx | 2 winaccessibility/source/service/AccComponentEventListener.cxx | 27 +++++++--- winaccessibility/source/service/AccObjectWinManager.cxx | 20 ------- 3 files changed, 19 insertions(+), 30 deletions(-)
New commits: commit 0425b6eb47830b1fe630dc0128d5049f4b3e5582 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Tue Apr 16 19:02:30 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Apr 17 08:07:17 2024 +0200 tdf#160695 wina11y: Send status change events for toolbar buttons When the checked or indeterminate state of a toolbar button changes, forward the corresponding UNO a11y event as a corresponding MSAA event. For roles `AccessibleRole::PUSH_BUTTON` and `AccessibleRole::TOGGLE_BUTTON`, `AccObject::GetMSAAStateFromUNO` uses `STATE_SYSTEM_PRESSED` instead of `STATE_SYSTEM_CHECKED`, so also use `UnoMSAAEvent::STATE_PRESSED` for the event. It's unclear why sending of such events would generally be omitted for "special toolbar items" previously. The events can be used to implement announcement of toggled font attributes in NVDA, e.g. when the "Bold" button in the formatting toolbar is toggled via a keyboard shortcut, similar to how Orca does it (s. tdf#123864). Related NVDA issue for which I plan to submit a PR: [1] [1] https://github.com/nvaccess/nvda/issues/4248 Change-Id: Ic2846e338802c3cb7656de5b77e4df23bd5b0703 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166155 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/winaccessibility/inc/AccObjectWinManager.hxx b/winaccessibility/inc/AccObjectWinManager.hxx index 024a58fc8655..8e50adaf75c4 100644 --- a/winaccessibility/inc/AccObjectWinManager.hxx +++ b/winaccessibility/inc/AccObjectWinManager.hxx @@ -132,8 +132,6 @@ public: void UpdateChildState(css::accessibility::XAccessible* pXAcc); - bool IsSpecialToolbarItem(css::accessibility::XAccessible* pXAcc); - static short GetRole(css::accessibility::XAccessible* pXAcc); css::accessibility::XAccessible* GetAccDocByAccTopWin( css::accessibility::XAccessible* pXAcc ); diff --git a/winaccessibility/source/service/AccComponentEventListener.cxx b/winaccessibility/source/service/AccComponentEventListener.cxx index bc6475754097..a55b585544d2 100644 --- a/winaccessibility/source/service/AccComponentEventListener.cxx +++ b/winaccessibility/source/service/AccComponentEventListener.cxx @@ -207,6 +207,19 @@ void AccComponentEventListener::SetComponentState(sal_Int64 state, bool enable) */ void AccComponentEventListener::FireStatePropertyChange(sal_Int64 state, bool set) { + if (!m_xAccessible.is()) + return; + + css::uno::Reference<css::accessibility::XAccessibleContext> xAccContext = m_xAccessible->getAccessibleContext(); + if (!xAccContext.is()) + return; + + const sal_Int16 nRole = xAccContext->getAccessibleRole(); + // for these button roles, MSAA state STATE_SYSTEM_PRESSED is used instead of + // STATE_SYSTEM_CHECKED (s. AccObject::GetMSAAStateFromUNO) + const bool bPressedInsteadOfChecked + = (nRole == AccessibleRole::PUSH_BUTTON) || (nRole == AccessibleRole::TOGGLE_BUTTON); + if( set) { // new value @@ -216,11 +229,10 @@ void AccComponentEventListener::FireStatePropertyChange(sal_Int64 state, bool se case AccessibleStateType::INDETERMINATE: m_rObjManager.IncreaseState(m_xAccessible.get(), state); m_rObjManager.UpdateAction(m_xAccessible.get()); - - if (!m_rObjManager.IsSpecialToolbarItem(m_xAccessible.get())) - { + if (bPressedInsteadOfChecked) + m_rObjManager.NotifyAccEvent(m_xAccessible.get(), UnoMSAAEvent::STATE_PRESSED); + else m_rObjManager.NotifyAccEvent(m_xAccessible.get(), UnoMSAAEvent::STATE_CHECKED); - } break; case AccessibleStateType::PRESSED: m_rObjManager.IncreaseState(m_xAccessible.get(), state); @@ -256,11 +268,10 @@ void AccComponentEventListener::FireStatePropertyChange(sal_Int64 state, bool se case AccessibleStateType::INDETERMINATE: m_rObjManager.DecreaseState(m_xAccessible.get(), state); m_rObjManager.UpdateAction(m_xAccessible.get()); - - if (!m_rObjManager.IsSpecialToolbarItem(m_xAccessible.get())) - { + if (bPressedInsteadOfChecked) + m_rObjManager.NotifyAccEvent(m_xAccessible.get(), UnoMSAAEvent::STATE_PRESSED); + else m_rObjManager.NotifyAccEvent(m_xAccessible.get(), UnoMSAAEvent::STATE_CHECKED); - } break; case AccessibleStateType::PRESSED: m_rObjManager.DecreaseState(m_xAccessible.get(), state); diff --git a/winaccessibility/source/service/AccObjectWinManager.cxx b/winaccessibility/source/service/AccObjectWinManager.cxx index 6025a469aa18..2afb59d776db 100644 --- a/winaccessibility/source/service/AccObjectWinManager.cxx +++ b/winaccessibility/source/service/AccObjectWinManager.cxx @@ -1062,26 +1062,6 @@ void AccObjectWinManager::UpdateChildState(css::accessibility::XAccessible* pAcc } } - -bool AccObjectWinManager::IsSpecialToolbarItem(css::accessibility::XAccessible* pXAcc) -{ - if (pXAcc && oldFocus != pXAcc) - { - if (GetParentRole(pXAcc) == AccessibleRole::TOOL_BAR) - { - Reference< XAccessibleContext > pRContext(pXAcc->getAccessibleContext()); - if (pRContext.is()) - { - if (pRContext->getAccessibleRole() == AccessibleRole::TOGGLE_BUTTON) - { - return true; - } - } - } - } - return false; -} - short AccObjectWinManager::GetRole(css::accessibility::XAccessible* pXAcc) { assert(pXAcc != nullptr);