From 1c3d0bc25f1a8bc506fecca7bf39d78f7f817ad3 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 26 Feb 2025 11:14:04 +0100 Subject: [PATCH] thumbnailview a11y: Use OAccessibleComponentHelper for ThumbnailViewItemAcc Similar to how commit e7dc7ebc9e14447a4ab75502a378f632a910c394 Author: Michael Weghorn Date: Tue Feb 25 12:14:24 2025 +0100 valueset a11y: Use OAccessibleComponentHelper for ValueItemAcc did for ValueItemAcc, also derive from OAccessibleComponentHelper for ThumbnailViewItemAcc to make use of the logic already implemented there instead of having to implement all the XAccessibleComponent and XAccessibleEventBroadcaster methods manually. ThumbnailViewItemAcc::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 initially when testing this with the ThumbnailView for "Recent Documents" in the LO Start Center with Accerciser and Orca and the qt6 VCL plugin. However, when closing LO, this now triggers an assertion: soffice.bin: /home/michi/development/git/libreoffice/comphelper/source/misc/accessibleeventnotifier.cxx:142: bool (anonymous namespace)::implLookupClient(const AccessibleEventNotifier::TClientId, ClientMap::iterator &): Assertion `rClients.end() != rPos && "AccessibleEventNotifier::implLookupClient: invalid client id " "(did you register your client?)!"' failed. This is the same preexisting issue as already described in more detail for ValueItemAcc in the above-mentioned commit (items don't get disposed) and will be addressed in an upcoming commit. Change-Id: Ie4e5c300ff6bdb160e756e7173c45c0f143fac69 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182225 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- sfx2/source/control/thumbnailviewitemacc.cxx | 87 +------------------- sfx2/source/control/thumbnailviewitemacc.hxx | 29 ++----- 2 files changed, 9 insertions(+), 107 deletions(-) diff --git a/sfx2/source/control/thumbnailviewitemacc.cxx b/sfx2/source/control/thumbnailviewitemacc.cxx index 3b22f82141d1..3e6f3406b2dd 100644 --- a/sfx2/source/control/thumbnailviewitemacc.cxx +++ b/sfx2/source/control/thumbnailviewitemacc.cxx @@ -192,58 +192,13 @@ lang::Locale SAL_CALL ThumbnailViewItemAcc::getLocale() return aRet; } -void SAL_CALL ThumbnailViewItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - std::scoped_lock aGuard( maMutex ); - - 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 ThumbnailViewItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - std::scoped_lock aGuard( maMutex ); - - 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 ThumbnailViewItemAcc::containsPoint( const awt::Point& aPoint ) -{ - 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 ThumbnailViewItemAcc::getAccessibleAtPoint( const awt::Point& ) { uno::Reference< accessibility::XAccessible > xRet; return xRet; } -awt::Rectangle SAL_CALL ThumbnailViewItemAcc::getBounds() +awt::Rectangle ThumbnailViewItemAcc::implGetBounds() { const SolarMutexGuard aSolarGuard; awt::Rectangle aRet; @@ -276,46 +231,6 @@ awt::Rectangle SAL_CALL ThumbnailViewItemAcc::getBounds() return aRet; } -awt::Point SAL_CALL ThumbnailViewItemAcc::getLocation() -{ - const awt::Rectangle aRect( getBounds() ); - awt::Point aRet; - - aRet.X = aRect.X; - aRet.Y = aRect.Y; - - return aRet; -} - -awt::Point SAL_CALL ThumbnailViewItemAcc::getLocationOnScreen() -{ - const SolarMutexGuard aSolarGuard; - awt::Point aRet; - - if (mpThumbnailViewItem) - { - const Point aPos = mpThumbnailViewItem->getDrawArea().TopLeft(); - const Point aScreenPos( - mpThumbnailViewItem->mrParent.GetDrawingArea()->get_accessible_location_on_screen()); - - aRet.X = aPos.X() + aScreenPos.X(); - aRet.Y = aPos.Y() + aScreenPos.Y(); - } - - return aRet; -} - -awt::Size SAL_CALL ThumbnailViewItemAcc::getSize() -{ - const awt::Rectangle aRect( getBounds() ); - awt::Size aRet; - - aRet.Width = aRect.Width; - aRet.Height = aRect.Height; - - return aRet; -} - void SAL_CALL ThumbnailViewItemAcc::grabFocus() { // nothing to do diff --git a/sfx2/source/control/thumbnailviewitemacc.hxx b/sfx2/source/control/thumbnailviewitemacc.hxx index ff342f698675..bd5aac054404 100644 --- a/sfx2/source/control/thumbnailviewitemacc.hxx +++ b/sfx2/source/control/thumbnailviewitemacc.hxx @@ -19,25 +19,17 @@ #pragma once +#include #include #include -#include -#include -#include - -#include class ThumbnailViewItem; -class ThumbnailViewItemAcc : public ::cppu::WeakImplHelper< css::accessibility::XAccessible, - css::accessibility::XAccessibleEventBroadcaster, - css::accessibility::XAccessibleContext, - css::accessibility::XAccessibleComponent> +class ThumbnailViewItemAcc + : public cppu::ImplInheritanceHelper { private: - - ::std::vector< css::uno::Reference< css::accessibility::XAccessibleEventListener > > - mxEventListeners; std::mutex maMutex; ThumbnailViewItem* mpThumbnailViewItem; @@ -52,10 +44,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; @@ -68,13 +56,12 @@ 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;