include/svx/AccessibleTextHelper.hxx | 2 svtools/source/control/accessibleruler.cxx | 181 ++++------------------ svtools/source/control/accessibleruler.hxx | 57 ------ svx/source/accessibility/AccessibleTextHelper.cxx | 2 4 files changed, 46 insertions(+), 196 deletions(-)
New commits: commit bd4be5f4238d756a8ec6c3097d7a0fdf5ce87c8f Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Feb 12 10:51:28 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Feb 12 20:04:48 2025 +0100 svx a11y: Drop unused VectorOfStates typedefs Change-Id: I3d450b894f047766380b85ddb0f6364193b6117a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181484 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/include/svx/AccessibleTextHelper.hxx b/include/svx/AccessibleTextHelper.hxx index 963ae41e5b30..9979b5c71ce0 100644 --- a/include/svx/AccessibleTextHelper.hxx +++ b/include/svx/AccessibleTextHelper.hxx @@ -119,8 +119,6 @@ class AccessibleTextHelper_Impl; class SVX_DLLPUBLIC AccessibleTextHelper final { public: - typedef ::std::vector<sal_Int16> VectorOfStates; - /** Create accessible text object for given edit source @param pEditSource diff --git a/svx/source/accessibility/AccessibleTextHelper.cxx b/svx/source/accessibility/AccessibleTextHelper.cxx index 2f3e0c26505e..ccd686cab2bd 100644 --- a/svx/source/accessibility/AccessibleTextHelper.cxx +++ b/svx/source/accessibility/AccessibleTextHelper.cxx @@ -79,8 +79,6 @@ namespace accessibility class AccessibleTextHelper_Impl : public SfxListener { public: - typedef ::std::vector< sal_Int16 > VectorOfStates; - // receive pointer to our frontend class and view window AccessibleTextHelper_Impl(); virtual ~AccessibleTextHelper_Impl() override; commit 1fa13c73216e52e55684e907f9cb2ec4042c1bd8 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Feb 12 10:44:09 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Feb 12 20:04:42 2025 +0100 ruler a11y: Use comphelper::OAccessibleComponentHelper Turn SvtRulerAccessible into a comphelper::OAccessibleComponentHelper subclass. comphelper::OAccessibleComponentHelper already implements the logic for event handling and most of the location/bounds handling, so avoid reimplmenting it in SvtRulerAccessible. Turn SvtRulerAccessible::GetBoundingBox into the `implGetBounds` override of the base class and let it return an awt::Rectangle. No change in behavior seen when testing with Accerciser. (The class implements a11y e.g. for the ruler above the document in Writer.) Change-Id: I3e1f1dcd7533fb14317428e74b3be1a1e2e57277 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181477 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/svtools/source/control/accessibleruler.cxx b/svtools/source/control/accessibleruler.cxx index 8069665e63e1..0dc6c2301164 100644 --- a/svtools/source/control/accessibleruler.cxx +++ b/svtools/source/control/accessibleruler.cxx @@ -40,25 +40,14 @@ using namespace ::com::sun::star::accessibility; //===== internal ============================================================ -SvtRulerAccessible::SvtRulerAccessible( - uno::Reference< XAccessible > xParent, Ruler& rRepr, OUString aName ) : - - msName(std::move( aName )), - mxParent(std::move( xParent )), - mpRepr( &rRepr ), - mnClientId( 0 ) +SvtRulerAccessible::SvtRulerAccessible(uno::Reference<XAccessible> xParent, Ruler& rRepr, + OUString aName) + : msName(std::move(aName)) + , mxParent(std::move(xParent)) + , mpRepr(&rRepr) { } -SvtRulerAccessible::~SvtRulerAccessible() -{ - if( !m_bDisposed ) - { - osl_atomic_increment( &m_refCount ); - dispose(); // set mpRepr = NULL & release all children - } -} - //===== XAccessible ========================================================= uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleContext() @@ -68,54 +57,19 @@ uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleC //===== XAccessibleComponent ================================================ -sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint ) -{ - SolarMutexGuard aSolarGuard; - -// return GetBoundingBox().IsInside( vcl::unohelper::ConvertToVCLPoint( rPoint ) ); - return tools::Rectangle(Point(0, 0), GetBoundingBox().GetSize()) - .Contains(vcl::unohelper::ConvertToVCLPoint(rPoint)); -} - uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& ) { SolarMutexGuard aSolarGuard; - std::unique_lock aGuard( m_aMutex ); - throwIfDisposed(aGuard); + ensureAlive(); return uno::Reference< XAccessible >(); } -awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds() -{ - SolarMutexGuard aSolarGuard; - return vcl::unohelper::ConvertToAWTRect(GetBoundingBox()); -} - -awt::Point SAL_CALL SvtRulerAccessible::getLocation() -{ - SolarMutexGuard aSolarGuard; - return vcl::unohelper::ConvertToAWTPoint(GetBoundingBox().TopLeft()); -} - -awt::Point SAL_CALL SvtRulerAccessible::getLocationOnScreen() -{ - SolarMutexGuard aSolarGuard; - return vcl::unohelper::ConvertToAWTPoint(GetBoundingBoxOnScreen().TopLeft()); -} - -awt::Size SAL_CALL SvtRulerAccessible::getSize() -{ - SolarMutexGuard aSolarGuard; - return vcl::unohelper::ConvertToAWTSize(GetBoundingBox().GetSize()); -} - //===== XAccessibleContext ================================================== sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleChildCount() { SolarMutexGuard aSolarGuard; - std::unique_lock aGuard( m_aMutex ); - throwIfDisposed(aGuard); + ensureAlive(); return 0; } @@ -195,7 +149,7 @@ sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleStateSet() sal_Int64 nStateSet = 0; - if( !m_bDisposed ) + if (isAlive()) { nStateSet |= AccessibleStateType::ENABLED; @@ -228,39 +182,6 @@ lang::Locale SAL_CALL SvtRulerAccessible::getLocale() throw IllegalAccessibleComponentStateException(); } -void SAL_CALL SvtRulerAccessible::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) -{ - if (xListener.is()) - { - std::unique_lock aGuard( m_aMutex ); - if (!mnClientId) - mnClientId = comphelper::AccessibleEventNotifier::registerClient( ); - comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener ); - } -} - -void SAL_CALL SvtRulerAccessible::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) -{ - if (!xListener.is()) - return; - - std::unique_lock aGuard( m_aMutex ); - - if (!mnClientId) - return; - - sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener ); - if ( !nListenerCount ) - { - // no listeners anymore - // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client), - // and at least to us not firing any events anymore, in case somebody calls - // NotifyAccessibleEvent, again - comphelper::AccessibleEventNotifier::revokeClient( mnClientId ); - mnClientId = 0; - } -} - void SAL_CALL SvtRulerAccessible::grabFocus() { SolarMutexGuard aSolarGuard; @@ -312,33 +233,22 @@ Sequence< sal_Int8 > SAL_CALL SvtRulerAccessible::getImplementationId() return css::uno::Sequence<sal_Int8>(); } -void SvtRulerAccessible::disposing(std::unique_lock<std::mutex>&) +void SAL_CALL SvtRulerAccessible::disposing() { mpRepr = nullptr; // object dies with representation - // Send a disposing to all listeners. - if ( mnClientId ) - { - comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this ); - mnClientId = 0; - } - mxParent.clear(); -} - -tools::Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen() -{ - if (!mpRepr) - throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this)); + comphelper::OAccessibleComponentHelper::disposing(); - return tools::Rectangle(mpRepr->GetParent()->OutputToAbsoluteScreenPixel(mpRepr->GetPosPixel()), mpRepr->GetSizePixel()); + mxParent.clear(); } -tools::Rectangle SvtRulerAccessible::GetBoundingBox() +awt::Rectangle SvtRulerAccessible::implGetBounds() { if (!mpRepr) throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this)); - return tools::Rectangle(mpRepr->GetPosPixel(), mpRepr->GetSizePixel()); + return vcl::unohelper::ConvertToAWTRect( + tools::Rectangle(mpRepr->GetPosPixel(), mpRepr->GetSizePixel())); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/control/accessibleruler.hxx b/svtools/source/control/accessibleruler.hxx index 80e2657b04bf..8de7f46629ef 100644 --- a/svtools/source/control/accessibleruler.hxx +++ b/svtools/source/control/accessibleruler.hxx @@ -27,22 +27,16 @@ #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <cppuhelper/interfacecontainer.h> +#include <comphelper/accessiblecomponenthelper.hxx> #include <comphelper/compbase.hxx> #include <vcl/vclptr.hxx> namespace tools { class Rectangle; } class Ruler; - -typedef ::comphelper::WeakComponentImplHelper< - css::accessibility::XAccessible, - css::accessibility::XAccessibleComponent, - css::accessibility::XAccessibleContext, - css::accessibility::XAccessibleEventBroadcaster, - css::lang::XServiceInfo > - SvtRulerAccessible_Base; - -class SvtRulerAccessible final : public SvtRulerAccessible_Base +class SvtRulerAccessible final + : public cppu::ImplInheritanceHelper<comphelper::OAccessibleComponentHelper, + css::accessibility::XAccessible, css::lang::XServiceInfo> { public: //===== internal ======================================================== @@ -56,24 +50,9 @@ public: //===== XAccessibleComponent ============================================ - virtual sal_Bool SAL_CALL - containsPoint( const css::awt::Point& rPoint ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& rPoint ) override; - virtual css::awt::Rectangle SAL_CALL - getBounds() override; - - virtual css::awt::Point SAL_CALL - getLocation() override; - - virtual css::awt::Point SAL_CALL - getLocationOnScreen() override; - - virtual css::awt::Size SAL_CALL - getSize() override; - virtual void SAL_CALL grabFocus() override; @@ -113,13 +92,6 @@ public: virtual css::lang::Locale SAL_CALL getLocale() override; - //===== XAccessibleEventBroadcaster ===================================== - - virtual void SAL_CALL - addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; - - virtual void SAL_CALL - removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; //===== XServiceInfo ==================================================== @@ -137,21 +109,11 @@ public: virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override; -private: - - virtual ~SvtRulerAccessible() override; +protected: + virtual css::awt::Rectangle implGetBounds() override; - virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; - - /// @Return the object's current bounding box relative to the desktop. - /// - /// @throws css::uno::RuntimeException - tools::Rectangle GetBoundingBoxOnScreen(); - - /// @Return the object's current bounding box relative to the parent object. - /// - /// @throws css::uno::RuntimeException - tools::Rectangle GetBoundingBox(); +private: + virtual void SAL_CALL disposing() override; /// Name of this object. OUString msName; @@ -162,9 +124,6 @@ private: /// pointer to internal representation VclPtr<Ruler> mpRepr; - - /// client id in the AccessibleEventNotifier queue - sal_uInt32 mnClientId; }; #endif commit 83bfb947e7640e7ee1fa2998197aaa71d15378db Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Feb 12 10:29:20 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Feb 12 20:04:36 2025 +0100 ruler a11y: Guard XAccessible* methods by SolarMutex Guard implementations of the public XAccessible* methods by SolarMutex. No longer use a mutex in the helper methods. Mostly restrict use of UnoImplBase::m_aMutex to passing it to WeakComponentImplHelperBase::throwIfDisposed. This prepares for an upcoming commit to turn SvtRulerAccessible into a comphelper::OAccessibleComponentHelper subclass. Change-Id: I4ccf7b2cbe3b7be859dc34dac9f2f9b2db705c7b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181476 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/svtools/source/control/accessibleruler.cxx b/svtools/source/control/accessibleruler.cxx index 75df0c84c086..8069665e63e1 100644 --- a/svtools/source/control/accessibleruler.cxx +++ b/svtools/source/control/accessibleruler.cxx @@ -70,7 +70,8 @@ uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleC sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint ) { - // no guard -> done in getBounds() + SolarMutexGuard aSolarGuard; + // return GetBoundingBox().IsInside( vcl::unohelper::ConvertToVCLPoint( rPoint ) ); return tools::Rectangle(Point(0, 0), GetBoundingBox().GetSize()) .Contains(vcl::unohelper::ConvertToVCLPoint(rPoint)); @@ -78,6 +79,7 @@ sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint ) uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& ) { + SolarMutexGuard aSolarGuard; std::unique_lock aGuard( m_aMutex ); throwIfDisposed(aGuard); @@ -86,31 +88,32 @@ uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds() { - // no guard -> done in GetBoundingBox() + SolarMutexGuard aSolarGuard; return vcl::unohelper::ConvertToAWTRect(GetBoundingBox()); } awt::Point SAL_CALL SvtRulerAccessible::getLocation() { - // no guard -> done in GetBoundingBox() + SolarMutexGuard aSolarGuard; return vcl::unohelper::ConvertToAWTPoint(GetBoundingBox().TopLeft()); } awt::Point SAL_CALL SvtRulerAccessible::getLocationOnScreen() { - // no guard -> done in GetBoundingBoxOnScreen() + SolarMutexGuard aSolarGuard; return vcl::unohelper::ConvertToAWTPoint(GetBoundingBoxOnScreen().TopLeft()); } awt::Size SAL_CALL SvtRulerAccessible::getSize() { - // no guard -> done in GetBoundingBox() + SolarMutexGuard aSolarGuard; return vcl::unohelper::ConvertToAWTSize(GetBoundingBox().GetSize()); } //===== XAccessibleContext ================================================== sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleChildCount() { + SolarMutexGuard aSolarGuard; std::unique_lock aGuard( m_aMutex ); throwIfDisposed(aGuard); @@ -119,6 +122,7 @@ sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleChildCount() uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( sal_Int64 ) { + SolarMutexGuard aSolarGuard; uno::Reference< XAccessible > xChild ; return xChild; @@ -126,12 +130,13 @@ uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( s uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleParent() { + SolarMutexGuard aSolarGuard; return mxParent; } sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent() { - std::unique_lock aGuard( m_aMutex ); + SolarMutexGuard aSolarGuard; // Use a simple but slow solution for now. Optimize later. @@ -158,16 +163,19 @@ sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent() sal_Int16 SAL_CALL SvtRulerAccessible::getAccessibleRole() { + SolarMutexGuard aSolarGuard; return AccessibleRole::RULER; } OUString SAL_CALL SvtRulerAccessible::getAccessibleDescription() { + SolarMutexGuard aSolarGuard; return OUString(); } OUString SAL_CALL SvtRulerAccessible::getAccessibleName() { + SolarMutexGuard aSolarGuard; return msName; } @@ -176,13 +184,14 @@ OUString SAL_CALL SvtRulerAccessible::getAccessibleName() */ uno::Reference< XAccessibleRelationSet > SAL_CALL SvtRulerAccessible::getAccessibleRelationSet() { + SolarMutexGuard aSolarGuard; return uno::Reference< XAccessibleRelationSet >(); } sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleStateSet() { - std::unique_lock aGuard( m_aMutex ); + SolarMutexGuard aSolarGuard; sal_Int64 nStateSet = 0; @@ -206,7 +215,7 @@ sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleStateSet() lang::Locale SAL_CALL SvtRulerAccessible::getLocale() { - std::unique_lock aGuard( m_aMutex ); + SolarMutexGuard aSolarGuard; if( mxParent.is() ) { @@ -254,43 +263,31 @@ void SAL_CALL SvtRulerAccessible::removeAccessibleEventListener( const uno::Refe void SAL_CALL SvtRulerAccessible::grabFocus() { - VclPtr<Ruler> xRepr; - { - std::unique_lock aGuard( m_aMutex ); - xRepr = mpRepr; - } - if (!xRepr) + SolarMutexGuard aSolarGuard; + + if (!mpRepr) throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this)); - SolarMutexGuard aSolarGuard; - xRepr->GrabFocus(); + mpRepr->GrabFocus(); } sal_Int32 SvtRulerAccessible::getForeground( ) { - VclPtr<Ruler> xRepr; - { - std::unique_lock aGuard( m_aMutex ); - xRepr = mpRepr; - } - if (!xRepr) + SolarMutexGuard aSolarGuard; + + if (!mpRepr) throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this)); - SolarMutexGuard aSolarGuard; - return sal_Int32(xRepr->GetControlForeground()); + return sal_Int32(mpRepr->GetControlForeground()); } sal_Int32 SvtRulerAccessible::getBackground( ) { - VclPtr<Ruler> xRepr; - { - std::unique_lock aGuard( m_aMutex ); - xRepr = mpRepr; - } - if (!xRepr) + SolarMutexGuard aSolarGuard; + + if (!mpRepr) throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this)); - SolarMutexGuard aSolarGuard; - return sal_Int32(xRepr->GetControlBackground()); + return sal_Int32(mpRepr->GetControlBackground()); } // XServiceInfo @@ -330,30 +327,18 @@ void SvtRulerAccessible::disposing(std::unique_lock<std::mutex>&) tools::Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen() { - VclPtr<Ruler> xRepr; - { - std::unique_lock aGuard( m_aMutex ); - xRepr = mpRepr; - } - if (!xRepr) + if (!mpRepr) throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this)); - SolarMutexGuard aSolarGuard; - return tools::Rectangle( xRepr->GetParent()->OutputToAbsoluteScreenPixel( xRepr->GetPosPixel() ), xRepr->GetSizePixel() ); + return tools::Rectangle(mpRepr->GetParent()->OutputToAbsoluteScreenPixel(mpRepr->GetPosPixel()), mpRepr->GetSizePixel()); } tools::Rectangle SvtRulerAccessible::GetBoundingBox() { - VclPtr<Ruler> xRepr; - { - std::unique_lock aGuard( m_aMutex ); - xRepr = mpRepr; - } - if (!xRepr) + if (!mpRepr) throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this)); - SolarMutexGuard aSolarGuard; - return tools::Rectangle( xRepr->GetPosPixel(), xRepr->GetSizePixel() ); + return tools::Rectangle(mpRepr->GetPosPixel(), mpRepr->GetSizePixel()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */