From 9b70943c2837bbdd68b6120df1a26ed15e92670c Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 26 Feb 2025 10:50:22 +0100 Subject: [PATCH] thumbnailview a11y: Use OAccessibleComponentHelper for ThumbnailViewAcc Similar to how commit b5d197cf4b4fc5f4e6aca5e01e2cc9757293c63e Author: Michael Weghorn Date: Tue Feb 25 11:51:40 2025 +0100 valueset a11y: Use OAccessibleComponentHelper for ValueSetAcc did for ValueSetAcc, also derive from OAccessibleComponentHelper for ThumbnailViewAcc to make use of the logic already implemented there instead of having to implement all the XAccessibleComponent and XAccessibleEventBroadcaster methods manually. ThumbnailViewAcc::getBounds implements what is needed to implement OAccessibleComponentHelper::implGetBounds, so rename the method (and drop the mutex guard from that method, as callers of that method in the base class take care of that). Drop all of the other overrides that are no longer needed as the implementation is now provided by the OAccessibleComponentHelper base class. No change in behavior intended or observed when testing this with Accerciser and Orca and the qt6 VCL plugin with the ThumbnailView for "Recent Documents" in the LO Start Center. Change-Id: Ia875bb290acb12137f74defa5c5ab855c352a0ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182217 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- sfx2/source/control/thumbnailviewacc.cxx | 178 ++--------------------- sfx2/source/control/thumbnailviewacc.hxx | 45 ++---- 2 files changed, 18 insertions(+), 205 deletions(-) diff --git a/sfx2/source/control/thumbnailviewacc.cxx b/sfx2/source/control/thumbnailviewacc.cxx index 3315cb050354..b15ecca3b743 100644 --- a/sfx2/source/control/thumbnailviewacc.cxx +++ b/sfx2/source/control/thumbnailviewacc.cxx @@ -187,54 +187,6 @@ lang::Locale SAL_CALL ThumbnailViewAcc::getLocale() return aRet; } -void SAL_CALL ThumbnailViewAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - ThrowIfDisposed(); - std::unique_lock aGuard (m_aMutex); - - if( !rxListener.is() ) - return; - - bool bFound = false; - - for (auto const& eventListener : mxEventListeners) - { - if( eventListener == rxListener ) - { - bFound = true; - break; - } - } - - if (!bFound) - mxEventListeners.push_back( rxListener ); -} - -void SAL_CALL ThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - ThrowIfDisposed(); - std::unique_lock aGuard (m_aMutex); - - if( rxListener.is() ) - { - std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = - std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener); - - if (aIter != mxEventListeners.end()) - mxEventListeners.erase( aIter ); - } -} - -sal_Bool SAL_CALL ThumbnailViewAcc::containsPoint( const awt::Point& aPoint ) -{ - ThrowIfDisposed(); - const awt::Rectangle aRect( getBounds() ); - const Point aSize( aRect.Width, aRect.Height ); - const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y ); - - return tools::Rectangle( aNullPoint, aSize ).Contains( aTestPoint ); -} - uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleAtPoint( const awt::Point& aPoint ) { ThrowIfDisposed(); @@ -256,10 +208,8 @@ uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAcces return xRet; } -awt::Rectangle SAL_CALL ThumbnailViewAcc::getBounds() +awt::Rectangle ThumbnailViewAcc::implGetBounds() { - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; const Point aOutPos; const Size aOutSize(mpThumbnailView->GetOutputSizePixel()); awt::Rectangle aRet; @@ -272,54 +222,6 @@ awt::Rectangle SAL_CALL ThumbnailViewAcc::getBounds() return aRet; } -awt::Point SAL_CALL ThumbnailViewAcc::getLocation() -{ - ThrowIfDisposed(); - const awt::Rectangle aRect( getBounds() ); - awt::Point aRet; - - aRet.X = aRect.X; - aRet.Y = aRect.Y; - - return aRet; -} - -awt::Point SAL_CALL ThumbnailViewAcc::getLocationOnScreen() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - awt::Point aScreenLoc(0, 0); - - uno::Reference xParent(getAccessibleParent()); - if (xParent) - { - uno::Reference xParentContext(xParent->getAccessibleContext()); - uno::Reference xParentComponent(xParentContext, css::uno::UNO_QUERY); - OSL_ENSURE( xParentComponent.is(), "ThumbnailViewAcc::getLocationOnScreen: no parent component!" ); - if ( xParentComponent.is() ) - { - awt::Point aParentScreenLoc( xParentComponent->getLocationOnScreen() ); - awt::Point aOwnRelativeLoc( getLocation() ); - aScreenLoc.X = aParentScreenLoc.X + aOwnRelativeLoc.X; - aScreenLoc.Y = aParentScreenLoc.Y + aOwnRelativeLoc.Y; - } - } - - return aScreenLoc; -} - -awt::Size SAL_CALL ThumbnailViewAcc::getSize() -{ - ThrowIfDisposed(); - const awt::Rectangle aRect( getBounds() ); - awt::Size aRet; - - aRet.Width = aRect.Width; - aRet.Height = aRect.Height; - - return aRet; -} - void SAL_CALL ThumbnailViewAcc::grabFocus() { ThrowIfDisposed(); @@ -433,42 +335,6 @@ void SAL_CALL ThumbnailViewAcc::deselectAccessibleChild( sal_Int64 nChildIndex) //FIXME TODO ; } -void ThumbnailViewAcc::disposing(std::unique_lock& rGuard) -{ - ::std::vector > aListenerListCopy; - - // unlock because we need to take solar and the lock mutex in the correct order - rGuard.unlock(); - { - const SolarMutexGuard aSolarGuard; - std::unique_lock aGuard (m_aMutex); - - // Reset the pointer to the parent. It has to be the one who has - // disposed us because he is dying. - mpThumbnailView = nullptr; - - if (mxEventListeners.empty()) - return; - - // Make a copy of the list and clear the original. - aListenerListCopy = std::move(mxEventListeners); - } - - // Inform all listeners that this objects is disposing. - lang::EventObject aEvent (static_cast(this)); - for (auto const& listener : aListenerListCopy) - { - try - { - listener->disposing (aEvent); - } - catch(const uno::Exception&) - { - // Ignore exceptions. - } - } -} - sal_uInt16 ThumbnailViewAcc::getItemCount() const { return mpThumbnailView->ImplGetVisibleItemCount(); @@ -481,45 +347,19 @@ ThumbnailViewItem* ThumbnailViewAcc::getItem (sal_uInt16 nIndex) const void ThumbnailViewAcc::ThrowIfDisposed() { - if (m_bDisposed) - { - SAL_WARN("sfx", "Calling disposed object. Throwing exception:"); - throw lang::DisposedException ( - u"object has been already disposed"_ustr, - getXWeak()); - } - else - { - DBG_ASSERT (mpThumbnailView!=nullptr, "ValueSetAcc not disposed but mpThumbnailView == NULL"); - } + ensureAlive(); + + DBG_ASSERT (mpThumbnailView!=nullptr, "ValueSetAcc not disposed but mpThumbnailView == NULL"); } void ThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue ) { - if( !nEventId ) - return; + NotifyAccessibleEvent(nEventId, rOldValue, rNewValue); +} - std::unique_lock aGuard(m_aMutex); - ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners ); - aGuard.unlock(); - accessibility::AccessibleEventObject aEvtObject; - - aEvtObject.EventId = nEventId; - aEvtObject.Source = getXWeak(); - aEvtObject.NewValue = rNewValue; - aEvtObject.OldValue = rOldValue; - aEvtObject.IndexHint = -1; - - for (auto const& tmpListener : aTmpListeners) - { - try - { - tmpListener->notifyEvent( aEvtObject ); - } - catch(const uno::Exception&) - { - } - } +bool ThumbnailViewAcc::HasAccessibleListeners() const +{ + return OAccessibleComponentHelper::hasAccessibleListeners(); } void ThumbnailViewAcc::GetFocus() diff --git a/sfx2/source/control/thumbnailviewacc.hxx b/sfx2/source/control/thumbnailviewacc.hxx index 9184bfdb0149..944e05d9a27e 100644 --- a/sfx2/source/control/thumbnailviewacc.hxx +++ b/sfx2/source/control/thumbnailviewacc.hxx @@ -19,30 +19,20 @@ #pragma once +#include #include #include #include -#include -#include #include -#include - -#include class ThumbnailView; class ThumbnailViewItem; -typedef comphelper::WeakComponentImplHelper< - css::accessibility::XAccessible, - css::accessibility::XAccessibleEventBroadcaster, - css::accessibility::XAccessibleContext, - css::accessibility::XAccessibleComponent, - css::accessibility::XAccessibleSelection > - ValueSetAccComponentBase; - -class ThumbnailViewAcc : - public ValueSetAccComponentBase +class ThumbnailViewAcc + : public cppu::ImplInheritanceHelper { public: @@ -53,11 +43,7 @@ public: const css::uno::Any& rOldValue, const css::uno::Any& rNewValue ); - bool HasAccessibleListeners() const - { - std::unique_lock aGuard (m_aMutex); - return( mxEventListeners.size() > 0 ); - } + bool HasAccessibleListeners() const; public: /** Called by the corresponding ValueSet when it gets the focus. @@ -73,10 +59,6 @@ public: // XAccessible virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) 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; - // XAccessibleContext virtual sal_Int64 SAL_CALL getAccessibleChildCount( ) override; virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 i ) override; @@ -89,13 +71,11 @@ public: virtual sal_Int64 SAL_CALL getAccessibleStateSet( ) override; virtual css::lang::Locale SAL_CALL getLocale( ) override; + // OCommonAccessibleComponent + virtual css::awt::Rectangle implGetBounds() override; + // XAccessibleComponent - virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) override; virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) 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; virtual sal_Int32 SAL_CALL getForeground( ) override; virtual sal_Int32 SAL_CALL getBackground( ) override; @@ -110,15 +90,8 @@ public: virtual void SAL_CALL deselectAccessibleChild( sal_Int64 nSelectedChildIndex ) override; private: - ::std::vector< css::uno::Reference< - css::accessibility::XAccessibleEventListener > > mxEventListeners; ThumbnailView* mpThumbnailView; - /** Tell all listeners that the object is dying. This callback is - usually called from the WeakComponentImplHelper class. - */ - virtual void disposing(std::unique_lock&) override; - /** Return the number of items. This takes the None-Item into account. */ sal_uInt16 getItemCount() const;