chart2/source/controller/accessibility/AccessibleBase.cxx | 59 ++++---------- chart2/source/controller/inc/AccessibleBase.hxx | 6 - 2 files changed, 24 insertions(+), 41 deletions(-)
New commits: commit bdc21628d211f1ae1c6d97aed3b830f032ae64be Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Feb 24 22:09:15 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Feb 25 08:21:38 2025 +0100 chart a11y: Avoid const_cast AccessibleBase::BroadcastAccEvent is only called from non-const methods, so there is no need for it to be const itself. Drop the const qualifier and the now no longer needed const_cast of `this` inside the method. Change-Id: I9e8bb74d761135b1f22525fa79912f4694ca7654 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182121 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/chart2/source/controller/accessibility/AccessibleBase.cxx b/chart2/source/controller/accessibility/AccessibleBase.cxx index 6b2a532798f5..d97e4674a554 100644 --- a/chart2/source/controller/accessibility/AccessibleBase.cxx +++ b/chart2/source/controller/accessibility/AccessibleBase.cxx @@ -325,10 +325,7 @@ awt::Point AccessibleBase::GetUpperLeftOnScreen() const return aResult; } -void AccessibleBase::BroadcastAccEvent( - sal_Int16 nId, - const Any & rNew, - const Any & rOld ) const +void AccessibleBase::BroadcastAccEvent(sal_Int16 nId, const Any& rNew, const Any& rOld) { ClearableMutexGuard aGuard( m_aMutex ); @@ -337,10 +334,7 @@ void AccessibleBase::BroadcastAccEvent( // if we don't have a client id for the notifier, then we don't have listeners, then // we don't need to notify anything - // the const cast is needed, because UNO parameters are never const - const AccessibleEventObject aEvent( - const_cast< uno::XWeak * >( static_cast< const uno::XWeak * >( this )), - nId, rNew, rOld, -1 ); + const AccessibleEventObject aEvent(static_cast<uno::XWeak*>(this), nId, rNew, rOld, -1); // let the notifier handle this event ::comphelper::AccessibleEventNotifier::addEvent( m_nEventNotifierId, aEvent ); diff --git a/chart2/source/controller/inc/AccessibleBase.hxx b/chart2/source/controller/inc/AccessibleBase.hxx index 73eb7c318862..77bb2526c961 100644 --- a/chart2/source/controller/inc/AccessibleBase.hxx +++ b/chart2/source/controller/inc/AccessibleBase.hxx @@ -186,7 +186,7 @@ protected: */ void BroadcastAccEvent( sal_Int16 nId, const css::uno::Any & rNew, - const css::uno::Any & rOld ) const; + const css::uno::Any & rOld ); /** Removes all children from the internal lists and broadcasts child remove events. commit cceed7e86ad2fe07d7fa4162f473fc46222910e8 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Feb 24 22:03:38 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Feb 25 08:21:32 2025 +0100 chart a11y: Use rtl::Reference<AccessibleBase> Use an rtl::Reference of the specific AccessibleBase instead of a generic uno::Reference<XAccessible> and then still making assumptions that it's actually an Accessible object in various places. Change-Id: Iaccccc3e928d4f47b16b4681404b6c6169ac67c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182120 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/chart2/source/controller/accessibility/AccessibleBase.cxx b/chart2/source/controller/accessibility/AccessibleBase.cxx index d73724587c22..6b2a532798f5 100644 --- a/chart2/source/controller/accessibility/AccessibleBase.cxx +++ b/chart2/source/controller/accessibility/AccessibleBase.cxx @@ -144,15 +144,12 @@ bool AccessibleBase::NotifyEvent( EventType eEventType, const AccessibleUniqueId ClearableMutexGuard aGuard( m_aMutex ); // make local copy for notification - std::vector<Reference<XAccessible>> aLocalChildList(m_aChildList); + std::vector<rtl::Reference<AccessibleBase>> aLocalChildList(m_aChildList); aGuard.clear(); for (auto const& localChild : aLocalChildList) { - // Note: at this place we must be sure to have an AccessibleBase - // object in the UNO reference to XAccessible ! - bStop = (*static_cast< AccessibleBase * > - ( localChild.get() )).NotifyEvent( eEventType, rId ); + bStop = localChild->NotifyEvent(eEventType, rId); if (bStop) break; } @@ -252,7 +249,7 @@ void AccessibleBase::AddChild( AccessibleBase * pChild ) ClearableMutexGuard aGuard( m_aMutex ); - Reference< XAccessible > xChild( pChild ); + rtl::Reference<AccessibleBase> xChild(pChild); m_aChildList.push_back( xChild ); m_aChildOIDMap[ pChild->GetId() ] = xChild; @@ -261,16 +258,13 @@ void AccessibleBase::AddChild( AccessibleBase * pChild ) if( m_bChildrenInitialized ) { Any aEmpty, aNew; - aNew <<= xChild; + aNew <<= uno::Reference<XAccessible>(xChild); aGuard.clear(); BroadcastAccEvent( AccessibleEventId::CHILD, aNew, aEmpty ); } } -/** in this method we imply that the Reference< XAccessible > elements in the - vector are AccessibleBase objects ! - */ void AccessibleBase::RemoveChildByOId( const ObjectIdentifier& rOId ) { ClearableMutexGuard aGuard( m_aMutex ); @@ -279,7 +273,7 @@ void AccessibleBase::RemoveChildByOId( const ObjectIdentifier& rOId ) if( aIt == m_aChildOIDMap.end()) return; - Reference< XAccessible > xChild( aIt->second ); + rtl::Reference<AccessibleBase> xChild(aIt->second); // remove from map m_aChildOIDMap.erase( aIt ); @@ -301,15 +295,14 @@ void AccessibleBase::RemoveChildByOId( const ObjectIdentifier& rOId ) if( bInitialized ) { Any aEmpty, aOld; - aOld <<= xChild; + aOld <<= uno::Reference<XAccessible>(xChild); BroadcastAccEvent( AccessibleEventId::CHILD, aEmpty, aOld ); } // dispose the child - Reference< lang::XComponent > xComp( xChild, UNO_QUERY ); - if( xComp.is()) - xComp->dispose(); + if (xChild.is()) + xChild->dispose(); } awt::Point AccessibleBase::GetUpperLeftOnScreen() const @@ -360,7 +353,7 @@ void AccessibleBase::KillAllChildren() ClearableMutexGuard aGuard( m_aMutex ); // make local copy for notification, and remove all children - std::vector<Reference<XAccessible>> aLocalChildList; + std::vector<rtl::Reference<AccessibleBase>> aLocalChildList; aLocalChildList.swap( m_aChildList ); m_aChildOIDMap.clear(); @@ -368,16 +361,14 @@ void AccessibleBase::KillAllChildren() // call dispose for all children // and notify listeners - Reference< lang::XComponent > xComp; Any aEmpty, aOld; for (auto const& localChild : aLocalChildList) { - aOld <<= localChild; + aOld <<= uno::Reference<XAccessible>(localChild); BroadcastAccEvent( AccessibleEventId::CHILD, aEmpty, aOld ); - xComp.set(localChild, UNO_QUERY); - if( xComp.is()) - xComp->dispose(); + if (localChild.is()) + localChild->dispose(); } m_bChildrenInitialized = false; } @@ -477,7 +468,7 @@ Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleChild( sal_Int64 Reference< XAccessible > AccessibleBase::ImplGetAccessibleChildById( sal_Int64 i ) const { - Reference< XAccessible > xResult; + rtl::Reference<AccessibleBase> xResult; MutexGuard aGuard( m_aMutex); if( ! m_bMayHaveChildren || @@ -493,7 +484,7 @@ Reference< XAccessible > AccessibleBase::ImplGetAccessibleChildById( sal_Int64 i throw aEx; } else - xResult.set( m_aChildList[ i ] ); + xResult = m_aChildList[i]; return xResult; } @@ -585,20 +576,18 @@ Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleAtPoint( const aw ( aRect.Y <= aPoint.Y && aPoint.Y <= (aRect.Y + aRect.Height))) { ClearableMutexGuard aGuard( m_aMutex ); - std::vector<Reference<XAccessible>> aLocalChildList( m_aChildList ); + std::vector<rtl::Reference<AccessibleBase>> aLocalChildList(m_aChildList); aGuard.clear(); - Reference< XAccessibleComponent > aComp; - for (auto const& localChild : aLocalChildList) + for (const rtl::Reference<AccessibleBase>& xLocalChild : aLocalChildList) { - aComp.set(localChild, UNO_QUERY); - if( aComp.is()) + if (xLocalChild.is()) { - aRect = aComp->getBounds(); + aRect = xLocalChild->getBounds(); if( ( aRect.X <= aPoint.X && aPoint.X <= (aRect.X + aRect.Width) ) && ( aRect.Y <= aPoint.Y && aPoint.Y <= (aRect.Y + aRect.Height))) { - aResult = localChild; + aResult = xLocalChild; break; } } diff --git a/chart2/source/controller/inc/AccessibleBase.hxx b/chart2/source/controller/inc/AccessibleBase.hxx index 485381866d89..73eb7c318862 100644 --- a/chart2/source/controller/inc/AccessibleBase.hxx +++ b/chart2/source/controller/inc/AccessibleBase.hxx @@ -284,12 +284,12 @@ private: /** type of the hash containing a vector index for every AccessibleUniqueId of the object in the child list */ - typedef std::map< ObjectIdentifier, css::uno::Reference< css::accessibility::XAccessible > > ChildOIDMap; + typedef std::map<ObjectIdentifier, rtl::Reference<AccessibleBase>> ChildOIDMap; bool m_bIsDisposed; const bool m_bMayHaveChildren; bool m_bChildrenInitialized; - std::vector<css::uno::Reference<css::accessibility::XAccessible>> m_aChildList; + std::vector<rtl::Reference<AccessibleBase>> m_aChildList; ChildOIDMap m_aChildOIDMap;