a11y: Use OAccessibleComponentHelper for text window Paragraph

Similar to how

    commit 7107db3fe7
    Author: Michael Weghorn <m.weghorn@posteo.de>
    Date:   Fri Jan 24 18:57:58 2025 +0100

        toolkit a11y: Use OAccessibleComponentHelper for grid control

did for AccessibleGridControlBase, also derive
from OAccessibleComponentHelper for Paragraph
to make use of the logic already implemented there
instead of having to implement all the XAccessibleComponent
and XAccessibleEventBroadcaster methods manually.

Paragraph::getBounds already
provides what is needed to implement
Paragraph::implGetBounds, so just rename it.

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 IDE editor ("Tools" -> "Macros"
-> "Edit Macros").

Change-Id: I88ac869d115ceb13ccf48932f6d66d95bbd2fc9b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180896
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2025-01-29 15:51:06 +01:00
parent 6e7fbfc362
commit 9ed4a07cee
2 changed files with 13 additions and 140 deletions
@@ -111,21 +111,19 @@ private:
typedef std::vector< ParagraphInfo > Paragraphs;
typedef ::cppu::WeakComponentImplHelper<
typedef cppu::ImplInheritanceHelper<
comphelper::OAccessibleComponentHelper,
css::accessibility::XAccessible,
css::accessibility::XAccessibleContext,
css::accessibility::XAccessibleComponent,
css::accessibility::XAccessibleEditableText,
css::accessibility::XAccessibleMultiLineText,
css::accessibility::XAccessibleTextAttributes,
css::accessibility::XAccessibleEventBroadcaster > ParagraphBase;
css::accessibility::XAccessibleTextAttributes> ParagraphBase;
// The Paragraph's number is the absolute position within the text engine (from
// 0 to N - 1), whereas the Paragraph's index is the position within the text
// view/accessible parent (from 0 to M - 1). Paragraphs outside the currently
// visible range have an index of -1.
class Paragraph final:
private cppu::BaseMutex, public ParagraphBase, private ::comphelper::OCommonAccessibleText
class Paragraph final
: public ParagraphBase, private ::comphelper::OCommonAccessibleText
{
public:
Paragraph(::rtl::Reference< Document > xDocument,
@@ -145,6 +143,9 @@ public:
css::uno::Any const & rNewValue);
private:
// OAccessibleComponentHelper
virtual css::awt::Rectangle implGetBounds() override;
// OCommonAccessibleText
virtual void implGetParagraphBoundary( const OUString& rText,
css::i18n::Boundary& rBoundary,
@@ -180,19 +181,9 @@ private:
virtual css::lang::Locale SAL_CALL getLocale() override;
virtual sal_Bool SAL_CALL containsPoint(css::awt::Point const & rPoint) override;
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
getAccessibleAtPoint(css::awt::Point const & 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;
virtual sal_Int32 SAL_CALL getForeground() override;
@@ -275,16 +266,6 @@ private:
virtual ::sal_Int32 SAL_CALL getNumberOfLineWithCaret( ) override;
virtual void SAL_CALL addAccessibleEventListener(
css::uno::Reference<
css::accessibility::XAccessibleEventListener > const & rListener) override;
virtual void SAL_CALL removeAccessibleEventListener(
css::uno::Reference<
css::accessibility::XAccessibleEventListener > const & rListener) override;
virtual void SAL_CALL disposing() override;
virtual OUString implGetText() override;
virtual css::lang::Locale implGetLocale() override;
@@ -298,9 +279,6 @@ private:
::rtl::Reference< Document > m_xDocument;
Paragraphs::size_type m_nNumber;
/// client id in the AccessibleEventNotifier queue
sal_uInt32 m_nClientId;
OUString m_aParagraphText;
};
@@ -81,11 +81,10 @@ void WindowListenerGuard::endListening()
}
Paragraph::Paragraph(::rtl::Reference< Document > xDocument,
Paragraphs::size_type nNumber):
ParagraphBase(m_aMutex),
Paragraphs::size_type nNumber)
:ParagraphBase(),
m_xDocument(std::move(xDocument)),
m_nNumber(nNumber),
m_nClientId(0)
m_nNumber(nNumber)
{
m_aParagraphText = m_xDocument->retrieveParagraphText(this);
}
@@ -116,10 +115,7 @@ void Paragraph::notifyEvent(::sal_Int16 nEventId,
css::uno::Any const & rOldValue,
css::uno::Any const & rNewValue)
{
if (m_nClientId)
comphelper::AccessibleEventNotifier::addEvent( m_nClientId, css::accessibility::AccessibleEventObject(
getXWeak(),
nEventId, rNewValue, rOldValue, -1) );
NotifyAccessibleEvent(nEventId, rOldValue, rNewValue);
}
// virtual
@@ -209,16 +205,6 @@ css::lang::Locale SAL_CALL Paragraph::getLocale()
return m_xDocument->retrieveLocale();
}
// virtual
sal_Bool SAL_CALL Paragraph::containsPoint(css::awt::Point const & rPoint)
{
checkDisposed();
css::awt::Rectangle aRect(m_xDocument->retrieveParagraphBounds(this,
false));
return rPoint.X >= 0 && rPoint.X < aRect.Width
&& rPoint.Y >= 0 && rPoint.Y < aRect.Height;
}
// virtual
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
Paragraph::getAccessibleAtPoint(css::awt::Point const &)
@@ -227,40 +213,11 @@ Paragraph::getAccessibleAtPoint(css::awt::Point const &)
return nullptr;
}
// virtual
css::awt::Rectangle SAL_CALL Paragraph::getBounds()
css::awt::Rectangle Paragraph::implGetBounds()
{
checkDisposed();
return m_xDocument->retrieveParagraphBounds(this, false);
}
// virtual
css::awt::Point SAL_CALL Paragraph::getLocation()
{
checkDisposed();
css::awt::Rectangle aRect(m_xDocument->retrieveParagraphBounds(this,
false));
return css::awt::Point(aRect.X, aRect.Y);
}
// virtual
css::awt::Point SAL_CALL Paragraph::getLocationOnScreen()
{
checkDisposed();
css::awt::Rectangle aRect(m_xDocument->retrieveParagraphBounds(this,
true));
return css::awt::Point(aRect.X, aRect.Y);
}
// virtual
css::awt::Size SAL_CALL Paragraph::getSize()
{
checkDisposed();
css::awt::Rectangle aRect(m_xDocument->retrieveParagraphBounds(this,
false));
return css::awt::Size(aRect.Width, aRect.Height);
}
// virtual
void SAL_CALL Paragraph::grabFocus()
{
@@ -569,68 +526,6 @@ css::accessibility::TextSegment SAL_CALL Paragraph::getTextAtLineWithCaret( )
return m_xDocument->retrieveParagraphLineWithCursor(this);
}
// virtual
void SAL_CALL Paragraph::addAccessibleEventListener(
css::uno::Reference<
css::accessibility::XAccessibleEventListener > const & rListener)
{
if (!rListener.is())
return;
::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
if (rBHelper.bDisposed || rBHelper.bInDispose)
{
aGuard.clear();
rListener->disposing(css::lang::EventObject(
getXWeak()));
}
else
{
if (!m_nClientId)
m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, rListener );
}
}
// virtual
void SAL_CALL Paragraph::removeAccessibleEventListener(
css::uno::Reference<
css::accessibility::XAccessibleEventListener > const & rListener)
{
comphelper::AccessibleEventNotifier::TClientId nId = 0;
{
osl::MutexGuard aGuard(rBHelper.rMutex);
if (rListener.is() && m_nClientId != 0
&& comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, rListener ) == 0)
{
nId = m_nClientId;
m_nClientId = 0;
}
}
if (nId != 0)
{
// 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(nId);
}
}
// virtual
void SAL_CALL Paragraph::disposing()
{
comphelper::AccessibleEventNotifier::TClientId nId = 0;
{
osl::MutexGuard aGuard(rBHelper.rMutex);
nId = m_nClientId;
m_nClientId = 0;
}
if (nId != 0)
comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(nId, *this);
}
// virtual
OUString Paragraph::implGetText()
{