diff options
author | Arnaud Versini <arnaud.versini@gmail.com> | 2018-04-08 10:21:54 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-23 13:16:01 +0200 |
commit | 0c2beb9ecde1600d4879d2240b6af45ac8477e36 (patch) | |
tree | 26460bb4d32bc52681044d4b23235c531647c3cb /accessibility | |
parent | c0af8057188c0e95831f9e6d1ef96a424da6f9b2 (diff) |
accessibility : remove useless guards and simplify.
Change-Id: I9e0d5967f71b2bd822c64690f8e02a0c95c8b88f
Reviewed-on: https://gerrit.libreoffice.org/52581
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'accessibility')
14 files changed, 112 insertions, 78 deletions
diff --git a/accessibility/inc/standard/vclxaccessiblecheckbox.hxx b/accessibility/inc/standard/vclxaccessiblecheckbox.hxx index e57ef74eb503..5c4e21e18898 100644 --- a/accessibility/inc/standard/vclxaccessiblecheckbox.hxx +++ b/accessibility/inc/standard/vclxaccessiblecheckbox.hxx @@ -44,6 +44,8 @@ private: virtual ~VCLXAccessibleCheckBox() override = default; + sal_Int32 implGetMaximumValue(); + bool IsChecked(); bool IsIndeterminate(); diff --git a/accessibility/inc/standard/vclxaccessibleedit.hxx b/accessibility/inc/standard/vclxaccessibleedit.hxx index f41479c0ceef..a6207c202c42 100644 --- a/accessibility/inc/standard/vclxaccessibleedit.hxx +++ b/accessibility/inc/standard/vclxaccessibleedit.hxx @@ -46,6 +46,7 @@ private: virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override; virtual void FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) override; + sal_Int16 implGetAccessibleRole(); // OCommonAccessibleText virtual OUString implGetText() override; diff --git a/accessibility/inc/standard/vclxaccessiblelist.hxx b/accessibility/inc/standard/vclxaccessiblelist.hxx index f4301ee13950..71c4b0ff4892 100644 --- a/accessibility/inc/standard/vclxaccessiblelist.hxx +++ b/accessibility/inc/standard/vclxaccessiblelist.hxx @@ -92,7 +92,7 @@ public: getAccessibleContext() override; // XAccessibleContext - virtual sal_Int32 SAL_CALL getAccessibleChildCount() override; + virtual sal_Int32 SAL_CALL getAccessibleChildCount() override final; css::uno::Reference< css::accessibility::XAccessible> SAL_CALL getAccessibleChild (sal_Int32 i) override; virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL @@ -144,6 +144,8 @@ private: virtual ~VCLXAccessibleList() override = default; + sal_Int32 implGetAccessibleChildCount(); + /** This function is called from the implementation helper during a XComponent::dispose call. Free the list of items and the items themselves. */ diff --git a/accessibility/inc/standard/vclxaccessibletabcontrol.hxx b/accessibility/inc/standard/vclxaccessibletabcontrol.hxx index 9e0960d67ea7..8f248466bce9 100644 --- a/accessibility/inc/standard/vclxaccessibletabcontrol.hxx +++ b/accessibility/inc/standard/vclxaccessibletabcontrol.hxx @@ -44,6 +44,10 @@ private: AccessibleChildren m_aAccessibleChildren; VclPtr<TabControl> m_pTabControl; + css::uno::Reference< css::accessibility::XAccessible > implGetAccessibleChild( sal_Int32 i ); + bool implIsAccessibleChildSelected( sal_Int32 nChildIndex ); + + void UpdateFocused(); void UpdateSelected( sal_Int32 i, bool bSelected ); void UpdatePageText( sal_Int32 i ); diff --git a/accessibility/inc/standard/vclxaccessibletabpage.hxx b/accessibility/inc/standard/vclxaccessibletabpage.hxx index 495f4a36412a..9d64e665827a 100644 --- a/accessibility/inc/standard/vclxaccessibletabpage.hxx +++ b/accessibility/inc/standard/vclxaccessibletabpage.hxx @@ -55,6 +55,8 @@ private: bool m_bSelected; OUString m_sPageText; + sal_Int32 implGetAccessibleChildCount(); + bool IsFocused(); bool IsSelected(); diff --git a/accessibility/inc/standard/vclxaccessibletoolbox.hxx b/accessibility/inc/standard/vclxaccessibletoolbox.hxx index add703137fb2..192445291065 100644 --- a/accessibility/inc/standard/vclxaccessibletoolbox.hxx +++ b/accessibility/inc/standard/vclxaccessibletoolbox.hxx @@ -53,6 +53,8 @@ private: void UpdateCustomPopupItemp_Impl( vcl::Window* pWindow, bool bOpen ); void HandleSubToolBarEvent( const VclWindowEvent& rVclWindowEvent ); void ReleaseSubToolBox( ToolBox* _pSubToolBox ); + sal_Int32 implGetAccessibleChildCount(); + sal_Int32 implGetSelectedAccessibleChildCount(); virtual ~VCLXAccessibleToolBox() override; diff --git a/accessibility/source/standard/vclxaccessiblebutton.cxx b/accessibility/source/standard/vclxaccessiblebutton.cxx index ed3769f6093d..02412e3ce204 100644 --- a/accessibility/source/standard/vclxaccessiblebutton.cxx +++ b/accessibility/source/standard/vclxaccessiblebutton.cxx @@ -128,8 +128,6 @@ Sequence< OUString > VCLXAccessibleButton::getSupportedServiceNames() OUString VCLXAccessibleButton::getAccessibleName( ) { - OExternalLockGuard aGuard( this ); - OUString aName( VCLXAccessibleTextComponent::getAccessibleName() ); sal_Int32 nLength = aName.getLength(); diff --git a/accessibility/source/standard/vclxaccessiblecheckbox.cxx b/accessibility/source/standard/vclxaccessiblecheckbox.cxx index 8465562d2fe8..a0eff42c5874 100644 --- a/accessibility/source/standard/vclxaccessiblecheckbox.cxx +++ b/accessibility/source/standard/vclxaccessiblecheckbox.cxx @@ -285,8 +285,7 @@ sal_Bool VCLXAccessibleCheckBox::setCurrentValue( const Any& aNumber ) { sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0; OSL_VERIFY( aNumber >>= nValue ); - OSL_VERIFY( getMinimumValue() >>= nValueMin ); - OSL_VERIFY( getMaximumValue() >>= nValueMax ); + nValueMax=implGetMaximumValue(); if ( nValue < nValueMin ) nValue = nValueMin; @@ -306,17 +305,20 @@ Any VCLXAccessibleCheckBox::getMaximumValue( ) OExternalLockGuard aGuard( this ); Any aValue; + aValue <<= implGetMaximumValue(); + return aValue; +} + +sal_Int32 VCLXAccessibleCheckBox::implGetMaximumValue( ) +{ VclPtr< CheckBox > pCheckBox = GetAs< CheckBox >(); if ( pCheckBox && pCheckBox->IsTriStateEnabled() ) - aValue <<= sal_Int32(2); - else - aValue <<= sal_Int32(1); + return 2; - return aValue; + return 1; } - Any VCLXAccessibleCheckBox::getMinimumValue( ) { OExternalLockGuard aGuard( this ); diff --git a/accessibility/source/standard/vclxaccessibleedit.cxx b/accessibility/source/standard/vclxaccessibleedit.cxx index 4b8788d34461..850238c55a94 100644 --- a/accessibility/source/standard/vclxaccessibleedit.cxx +++ b/accessibility/source/standard/vclxaccessibleedit.cxx @@ -132,7 +132,7 @@ OUString VCLXAccessibleEdit::implGetText() { aText = OutputDevice::GetNonMnemonicString( pEdit->GetText() ); - if ( getAccessibleRole() == AccessibleRole::PASSWORD_TEXT ) + if ( implGetAccessibleRole() == AccessibleRole::PASSWORD_TEXT ) { sal_Unicode cEchoChar = pEdit->GetEchoChar(); if ( !cEchoChar ) @@ -197,14 +197,9 @@ sal_Int32 VCLXAccessibleEdit::getAccessibleChildCount() } -Reference< XAccessible > VCLXAccessibleEdit::getAccessibleChild( sal_Int32 i ) +Reference< XAccessible > VCLXAccessibleEdit::getAccessibleChild( sal_Int32 ) { - OExternalLockGuard aGuard( this ); - - if ( i < 0 || i >= getAccessibleChildCount() ) - throw IndexOutOfBoundsException(); - - return Reference< XAccessible >(); + throw IndexOutOfBoundsException(); } @@ -212,6 +207,11 @@ sal_Int16 VCLXAccessibleEdit::getAccessibleRole( ) { OExternalLockGuard aGuard( this ); + return implGetAccessibleRole(); +} + +sal_Int16 VCLXAccessibleEdit::implGetAccessibleRole( ) +{ sal_Int16 nRole; VclPtr< Edit > pEdit = GetAs< Edit >(); if ( pEdit && ( ( pEdit->GetStyle() & WB_PASSWORD ) || pEdit->GetEchoChar() ) ) diff --git a/accessibility/source/standard/vclxaccessiblelist.cxx b/accessibility/source/standard/vclxaccessiblelist.cxx index d896809ccb2e..bad775c7c558 100644 --- a/accessibility/source/standard/vclxaccessiblelist.cxx +++ b/accessibility/source/standard/vclxaccessiblelist.cxx @@ -525,7 +525,11 @@ sal_Int32 SAL_CALL VCLXAccessibleList::getAccessibleChildCount() { SolarMutexGuard aSolarGuard; ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return implGetAccessibleChildCount(); +} +sal_Int32 VCLXAccessibleList::implGetAccessibleChildCount() +{ sal_Int32 nCount = 0; if ( m_pListBoxHelper ) nCount = m_pListBoxHelper->GetEntryCount(); diff --git a/accessibility/source/standard/vclxaccessibletabcontrol.cxx b/accessibility/source/standard/vclxaccessibletabcontrol.cxx index 8a5a2c699181..d5f1529b4f17 100644 --- a/accessibility/source/standard/vclxaccessibletabcontrol.cxx +++ b/accessibility/source/standard/vclxaccessibletabcontrol.cxx @@ -355,9 +355,14 @@ Reference< XAccessible > VCLXAccessibleTabControl::getAccessibleChild( sal_Int32 { OExternalLockGuard aGuard( this ); - if ( i < 0 || i >= getAccessibleChildCount() ) + if ( i < 0 || static_cast<std::size_t>(i) >= m_aAccessibleChildren.size() ) throw IndexOutOfBoundsException(); + return implGetAccessibleChild( i ); +} + +Reference< XAccessible > VCLXAccessibleTabControl::implGetAccessibleChild( sal_Int32 i ) +{ Reference< XAccessible > xChild = m_aAccessibleChildren[i]; if ( !xChild.is() ) { @@ -398,7 +403,7 @@ void VCLXAccessibleTabControl::selectAccessibleChild( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) + if ( nChildIndex < 0 || static_cast<std::size_t>(nChildIndex) >= m_aAccessibleChildren.size() ) throw IndexOutOfBoundsException(); if ( m_pTabControl ) @@ -410,9 +415,14 @@ sal_Bool VCLXAccessibleTabControl::isAccessibleChildSelected( sal_Int32 nChildIn { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) + if ( nChildIndex < 0 || static_cast<std::size_t>(nChildIndex) >= m_aAccessibleChildren.size() ) throw IndexOutOfBoundsException(); + return implIsAccessibleChildSelected( nChildIndex ); +} + +bool VCLXAccessibleTabControl::implIsAccessibleChildSelected( sal_Int32 nChildIndex ) +{ bool bSelected = false; if ( m_pTabControl && m_pTabControl->GetCurPageId() == m_pTabControl->GetPageId( static_cast<sal_uInt16>(nChildIndex) ) ) bSelected = true; @@ -429,8 +439,6 @@ void VCLXAccessibleTabControl::clearAccessibleSelection( ) void VCLXAccessibleTabControl::selectAllAccessibleChildren( ) { - OExternalLockGuard aGuard( this ); - selectAccessibleChild( 0 ); } @@ -447,16 +455,16 @@ Reference< XAccessible > VCLXAccessibleTabControl::getSelectedAccessibleChild( s { OExternalLockGuard aGuard( this ); - if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) + if ( nSelectedChildIndex != 0 ) throw IndexOutOfBoundsException(); Reference< XAccessible > xChild; - for ( sal_Int32 i = 0, j = 0, nCount = getAccessibleChildCount(); i < nCount; i++ ) + for ( std::size_t i = 0, nCount = m_aAccessibleChildren.size(); i < nCount; i++ ) { - if ( isAccessibleChildSelected( i ) && ( j++ == nSelectedChildIndex ) ) + if ( implIsAccessibleChildSelected( i ) ) { - xChild = getAccessibleChild( i ); + xChild = implGetAccessibleChild( i ); break; } } @@ -469,7 +477,7 @@ void VCLXAccessibleTabControl::deselectAccessibleChild( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) + if ( nChildIndex < 0 || static_cast<std::size_t>(nChildIndex) >= m_aAccessibleChildren.size() ) throw IndexOutOfBoundsException(); // This method makes no sense in a tab control, and so does nothing. diff --git a/accessibility/source/standard/vclxaccessibletabpage.cxx b/accessibility/source/standard/vclxaccessibletabpage.cxx index b7ceddf4fea4..d60575539dd2 100644 --- a/accessibility/source/standard/vclxaccessibletabpage.cxx +++ b/accessibility/source/standard/vclxaccessibletabpage.cxx @@ -280,7 +280,11 @@ Reference< XAccessibleContext > VCLXAccessibleTabPage::getAccessibleContext( ) sal_Int32 VCLXAccessibleTabPage::getAccessibleChildCount() { OExternalLockGuard aGuard( this ); + return implGetAccessibleChildCount(); +} +sal_Int32 VCLXAccessibleTabPage::implGetAccessibleChildCount() +{ sal_Int32 nCount = 0; if ( m_pTabControl ) { @@ -297,7 +301,7 @@ Reference< XAccessible > VCLXAccessibleTabPage::getAccessibleChild( sal_Int32 i { OExternalLockGuard aGuard( this ); - if ( i < 0 || i >= getAccessibleChildCount() ) + if ( i < 0 || i >= implGetAccessibleChildCount() ) throw IndexOutOfBoundsException(); Reference< XAccessible > xChild; diff --git a/accessibility/source/standard/vclxaccessibletextcomponent.cxx b/accessibility/source/standard/vclxaccessibletextcomponent.cxx index 4430fa195254..851b20471dc8 100644 --- a/accessibility/source/standard/vclxaccessibletextcomponent.cxx +++ b/accessibility/source/standard/vclxaccessibletextcomponent.cxx @@ -144,8 +144,6 @@ sal_Int32 VCLXAccessibleTextComponent::getCaretPosition() sal_Bool VCLXAccessibleTextComponent::setCaretPosition( sal_Int32 nIndex ) { - OExternalLockGuard aGuard( this ); - return setSelection( nIndex, nIndex ); } @@ -357,7 +355,7 @@ sal_Bool VCLXAccessibleTextComponent::copyText( sal_Int32 nStartIndex, sal_Int32 Reference< datatransfer::clipboard::XClipboard > xClipboard = pWindow->GetClipboard(); if ( xClipboard.is() ) { - OUString sText( getTextRange( nStartIndex, nEndIndex ) ); + OUString sText( OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex ) ); vcl::unohelper::TextDataObject* pDataObj = new vcl::unohelper::TextDataObject( sText ); diff --git a/accessibility/source/standard/vclxaccessibletoolbox.cxx b/accessibility/source/standard/vclxaccessibletoolbox.cxx index a4f2f941492c..7f744038d505 100644 --- a/accessibility/source/standard/vclxaccessibletoolbox.cxx +++ b/accessibility/source/standard/vclxaccessibletoolbox.cxx @@ -694,7 +694,11 @@ Sequence< OUString > VCLXAccessibleToolBox::getSupportedServiceNames() sal_Int32 SAL_CALL VCLXAccessibleToolBox::getAccessibleChildCount( ) { comphelper::OExternalLockGuard aGuard( this ); + return implGetAccessibleChildCount(); +} + sal_Int32 VCLXAccessibleToolBox::implGetAccessibleChildCount( ) + { sal_Int32 nCount = 0; VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); if ( pToolBox ) @@ -706,49 +710,44 @@ sal_Int32 SAL_CALL VCLXAccessibleToolBox::getAccessibleChildCount( ) Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleChild( sal_Int32 i ) { - if ( i < 0 || i >= getAccessibleChildCount() ) - throw IndexOutOfBoundsException(); - comphelper::OExternalLockGuard aGuard( this ); VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); - if ( pToolBox ) + if ( (!pToolBox) || i < 0 || static_cast<size_t>(i) >= pToolBox->GetItemCount() ) + throw IndexOutOfBoundsException(); + + Reference< XAccessible > xChild; + // search for the child + ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find(i); + if ( m_aAccessibleChildren.end() == aIter ) { - Reference< XAccessible > xChild; - // search for the child - ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find(i); - if ( m_aAccessibleChildren.end() == aIter ) - { - sal_uInt16 nItemId = pToolBox->GetItemId( i ); - sal_uInt16 nHighlightItemId = pToolBox->GetHighlightItemId(); - vcl::Window* pItemWindow = pToolBox->GetItemWindow( nItemId ); - // not found -> create a new child - VCLXAccessibleToolBoxItem* pChild = new VCLXAccessibleToolBoxItem( pToolBox, i ); - Reference< XAccessible> xParent = pChild; - if ( pItemWindow ) - { - xChild = new OToolBoxWindowItem(0,::comphelper::getProcessComponentContext(),pItemWindow->GetAccessible(),xParent); - pItemWindow->SetAccessible(xChild); - pChild->SetChild( xChild ); - } - xChild = pChild; - if ( nHighlightItemId > 0 && nItemId == nHighlightItemId ) - pChild->SetFocus( true ); - if ( pToolBox->IsItemChecked( nItemId ) ) - pChild->SetChecked( true ); - if ( pToolBox->GetItemState( nItemId ) == TRISTATE_INDET ) - pChild->SetIndeterminate( true ); - m_aAccessibleChildren.emplace( i, xChild ); - } - else + sal_uInt16 nItemId = pToolBox->GetItemId( i ); + sal_uInt16 nHighlightItemId = pToolBox->GetHighlightItemId(); + vcl::Window* pItemWindow = pToolBox->GetItemWindow( nItemId ); + // not found -> create a new child + VCLXAccessibleToolBoxItem* pChild = new VCLXAccessibleToolBoxItem( pToolBox, i ); + Reference< XAccessible> xParent = pChild; + if ( pItemWindow ) { - // found it - xChild = aIter->second; + xChild = new OToolBoxWindowItem(0,::comphelper::getProcessComponentContext(),pItemWindow->GetAccessible(),xParent); + pItemWindow->SetAccessible(xChild); + pChild->SetChild( xChild ); } - return xChild; + xChild = pChild; + if ( nHighlightItemId > 0 && nItemId == nHighlightItemId ) + pChild->SetFocus( true ); + if ( pToolBox->IsItemChecked( nItemId ) ) + pChild->SetChecked( true ); + if ( pToolBox->GetItemState( nItemId ) == TRISTATE_INDET ) + pChild->SetIndeterminate( true ); + m_aAccessibleChildren.emplace( i, xChild ); } - - return nullptr; + else + { + // found it + xChild = aIter->second; + } + return xChild; } Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleAtPoint( const awt::Point& _rPoint ) @@ -801,19 +800,22 @@ Reference< XAccessible > VCLXAccessibleToolBox::GetChildAccessible( const VclWin void VCLXAccessibleToolBox::selectAccessibleChild( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) - throw IndexOutOfBoundsException(); + VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); + if ( (!pToolBox) || nChildIndex < 0 || static_cast<size_t> (nChildIndex) >= pToolBox->GetItemCount() ) + throw IndexOutOfBoundsException(); + pToolBox->ChangeHighlight( nChildIndex ); } sal_Bool VCLXAccessibleToolBox::isAccessibleChildSelected( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) - throw IndexOutOfBoundsException(); VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); - if ( pToolBox && pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nChildIndex ) ) + if ( (!pToolBox) || nChildIndex < 0 || static_cast<size_t>(nChildIndex) >= pToolBox->GetItemCount() ) + throw IndexOutOfBoundsException(); + + if ( pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nChildIndex ) ) return true; else return false; @@ -835,8 +837,9 @@ void VCLXAccessibleToolBox::selectAllAccessibleChildren( ) sal_Int32 VCLXAccessibleToolBox::getSelectedAccessibleChildCount( ) { OExternalLockGuard aGuard( this ); + sal_Int32 nRet = 0; - for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; i++ ) + for ( sal_Int32 i = 0, nCount = implGetAccessibleChildCount(); i < nCount; i++ ) { if ( isAccessibleChildSelected( i ) ) { @@ -850,24 +853,28 @@ sal_Int32 VCLXAccessibleToolBox::getSelectedAccessibleChildCount( ) Reference< XAccessible > VCLXAccessibleToolBox::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) + if ( nSelectedChildIndex != 0 ) throw IndexOutOfBoundsException(); + Reference< XAccessible > xChild; - for ( sal_Int32 i = 0, j = 0, nCount = getAccessibleChildCount(); i < nCount; i++ ) + for ( sal_Int32 i = 0, nCount = implGetAccessibleChildCount(); i < nCount; i++ ) { - if ( isAccessibleChildSelected( i ) && ( j++ == nSelectedChildIndex ) ) + if ( isAccessibleChildSelected( i ) ) { xChild = getAccessibleChild( i ); break; } } + if (!xChild) + throw IndexOutOfBoundsException(); + return xChild; } void VCLXAccessibleToolBox::deselectAccessibleChild( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) + if ( nChildIndex < 0 || nChildIndex >= implGetAccessibleChildCount() ) throw IndexOutOfBoundsException(); clearAccessibleSelection(); // a toolbox can only have (n)one selected child } |