tdf#67919 access toolbar button dropdown menu from macOS VoiceOver

The fix was copied from the following NeoOffice source code files which
are licensed under the Mozilla Public License, v. 2.0:

https://github.com/neooffice/NeoOffice/blob/NeoOffice-2022_7/accessibility/source/standard/vclxaccessibletoolboxitem.cxx
https://github.com/neooffice/NeoOffice/blob/NeoOffice-2022_7/include/vcl/toolbox.hxx
https://github.com/neooffice/NeoOffice/blob/NeoOffice-2022_7/vcl/source/window/toolbox.cxx

Change-Id: Ibd24c6df4ecd7fdac1c56763d1daec09936a9b31
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170426
Reviewed-by: Patrick Luby <guibomacdev@gmail.com>
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Patrick Luby 2024-07-13 07:21:17 -04:00 committed by Michael Meeks
parent be1b9f955b
commit 3c30273d72
3 changed files with 50 additions and 12 deletions

View file

@ -632,19 +632,27 @@ OUString SAL_CALL VCLXAccessibleToolBoxItem::getToolTipText( )
sal_Int32 VCLXAccessibleToolBoxItem::getAccessibleActionCount( ) sal_Int32 VCLXAccessibleToolBoxItem::getAccessibleActionCount( )
{ {
// only one action -> "Click" // "Click" and maybe "Toggle Popup"
return 1; return ( m_pToolBox && m_pToolBox->ItemHasDropdown( m_nItemId ) ? 2 : 1 );
} }
sal_Bool VCLXAccessibleToolBoxItem::doAccessibleAction ( sal_Int32 nIndex ) sal_Bool VCLXAccessibleToolBoxItem::doAccessibleAction ( sal_Int32 nIndex )
{ {
OExternalLockGuard aGuard( this ); OExternalLockGuard aGuard( this );
if ( nIndex != 0 ) switch ( nIndex )
throw IndexOutOfBoundsException(); {
case 0:
if ( m_pToolBox ) if ( m_pToolBox )
m_pToolBox->TriggerItem( m_nItemId ); m_pToolBox->TriggerItem( m_nItemId );
break;
case 1:
if ( m_pToolBox && m_pToolBox->ItemHasDropdown( m_nItemId ) )
m_pToolBox->TriggerItemDropdown( m_nItemId );
break;
default:
throw IndexOutOfBoundsException();
}
return true; return true;
} }
@ -653,17 +661,22 @@ OUString VCLXAccessibleToolBoxItem::getAccessibleActionDescription ( sal_Int32 n
{ {
OExternalLockGuard aGuard( this ); OExternalLockGuard aGuard( this );
if ( nIndex != 0 ) switch ( nIndex )
throw IndexOutOfBoundsException(); {
case 0:
return RID_STR_ACC_ACTION_CLICK; return RID_STR_ACC_ACTION_CLICK;
case 1:
return RID_STR_ACC_ACTION_TOGGLEPOPUP;
default:
throw IndexOutOfBoundsException();
}
} }
Reference< XAccessibleKeyBinding > VCLXAccessibleToolBoxItem::getAccessibleActionKeyBinding( sal_Int32 nIndex ) Reference< XAccessibleKeyBinding > VCLXAccessibleToolBoxItem::getAccessibleActionKeyBinding( sal_Int32 nIndex )
{ {
OContextEntryGuard aGuard( this ); OContextEntryGuard aGuard( this );
if ( nIndex != 0 ) if (nIndex < 0 || nIndex >= getAccessibleActionCount())
throw IndexOutOfBoundsException(); throw IndexOutOfBoundsException();
return Reference< XAccessibleKeyBinding >(); return Reference< XAccessibleKeyBinding >();

View file

@ -389,6 +389,9 @@ public:
void TriggerItem( ToolBoxItemId nItemId ); void TriggerItem( ToolBoxItemId nItemId );
bool ItemHasDropdown( ToolBoxItemId nItemId );
void TriggerItemDropdown( ToolBoxItemId nItemId );
/// Shows or hides items. /// Shows or hides items.
void ShowItem(ToolBoxItemId nItemId, bool bVisible = true); void ShowItem(ToolBoxItemId nItemId, bool bVisible = true);

View file

@ -4153,6 +4153,28 @@ void ToolBox::TriggerItem( ToolBoxItemId nItemId )
ImplActivateItem( aKeyCode ); ImplActivateItem( aKeyCode );
} }
bool ToolBox::ItemHasDropdown( ToolBoxItemId nItemId )
{
ImplToolItem* pItem = ImplGetItem( nItemId );
return pItem && pItem->mnBits & ToolBoxItemBits::DROPDOWN;
}
void ToolBox::TriggerItemDropdown( ToolBoxItemId nItemId )
{
if( mpFloatWin || !ItemHasDropdown( nItemId ) )
return;
// Prevent highlighting of triggered item
mnHighItemId = ToolBoxItemId(0);
mnDownItemId = mnCurItemId = nItemId;
mnCurPos = GetItemPos( mnCurItemId );
mnMouseModifier = 0;
mpData->mbDropDownByKeyboard = false;
mpData->maDropdownClickHdl.Call( this );
}
// calls the button's action handler // calls the button's action handler
// returns true if action was called // returns true if action was called
bool ToolBox::ImplActivateItem( vcl::KeyCode aKeyCode ) bool ToolBox::ImplActivateItem( vcl::KeyCode aKeyCode )