summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2023-07-10 17:26:52 +0200
committerMarco Cecchetti <marco.cecchetti@collabora.com>2023-07-10 21:01:09 +0200
commit71af9d8913c752c1b7eb7f96067b0dabf8fe9a05 (patch)
tree013efdf688b3679533d10d23650efa0868391485 /sfx2
parent8a52bd5053f1627a9f73cdb3f30e8c74ec49f0dd (diff)
Get LOKDocumentFocusListener to handle enable/disable a11y properly
This patch fix the following problems: - Remove all children when accessibility is disabled - Update the currently focused paragraph when accessibility is enabled Change-Id: Ib65a14052ee8e0f965c0546897fd67641bba50ea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154278 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Marco Cecchetti <marco.cecchetti@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/view/viewsh.cxx54
1 files changed, 32 insertions, 22 deletions
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 4447eef4274a..a459fd5d79c9 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -519,20 +519,23 @@ public:
/// @throws lang::IndexOutOfBoundsException
/// @throws uno::RuntimeException
void detachRecursive(
- const uno::Reference< accessibility::XAccessible >& xAccessible
+ const uno::Reference< accessibility::XAccessible >& xAccessible,
+ bool bForce = false
);
/// @throws lang::IndexOutOfBoundsException
/// @throws uno::RuntimeException
void detachRecursive(
- const uno::Reference< accessibility::XAccessibleContext >& xContext
+ const uno::Reference< accessibility::XAccessibleContext >& xContext,
+ bool bForce = false
);
/// @throws lang::IndexOutOfBoundsException
/// @throws uno::RuntimeException
void detachRecursive(
const uno::Reference< accessibility::XAccessibleContext >& xContext,
- const sal_Int64 nStateSet
+ const sal_Int64 nStateSet,
+ bool bForce = false
);
/// @throws lang::IndexOutOfBoundsException
@@ -1032,25 +1035,30 @@ void LOKDocumentFocusListener::attachRecursive(
{
// Usually, when the document is loaded, a CARET_CHANGED accessibility event is automatically emitted
// for the first paragraph. That allows to notify the paragraph content to the client, even if no input
- // event occurred yet. However, in Cypress tests no accessibility event is automatically emitted until
- // some input event occurs. So we use the following workaround to notify the content of the focused
- // paragraph, without waiting for an input event.
+ // event occurred yet. However, when switching to a11y enabled in the client and in Cypress tests
+ // no accessibility event is automatically emitted until some input event occurs.
+ // So we use the following workaround to notify the content of the focused paragraph,
+ // without waiting for an input event.
// Here we update the paragraph info related to the focused paragraph,
// later when afterCallbackRegistered is executed we notify the paragraph content.
sal_Int64 nChildCount = xContext->getAccessibleChildCount();
if (nChildCount > 0)
{
- uno::Reference< accessibility::XAccessible > xChild( xContext->getAccessibleChild( 0 ) );
- if( xChild.is() )
+ for (sal_Int64 n = 0; n < nChildCount; ++n)
{
- uno::Reference<css::accessibility::XAccessibleText> xAccText(xChild, uno::UNO_QUERY);
- if (xAccText.is())
+ uno::Reference< accessibility::XAccessible > xChild(xContext->getAccessibleChild(n));
+ if (xChild.is())
{
- sal_Int32 nPos = xAccText->getCaretPosition();
- if (nPos >= 0)
+ uno::Reference<css::accessibility::XAccessibleText> xAccText(xChild, uno::UNO_QUERY);
+ if (xAccText.is())
{
- attachRecursive(xChild);
- updateParagraphInfo(xAccText, false, "LOKDocumentFocusListener::attachRecursive(3)");
+ sal_Int32 nPos = xAccText->getCaretPosition();
+ if (nPos >= 0)
+ {
+ attachRecursive(xChild);
+ updateParagraphInfo(xAccText, false, "LOKDocumentFocusListener::attachRecursive(3)");
+ break;
+ }
}
}
}
@@ -1060,18 +1068,20 @@ void LOKDocumentFocusListener::attachRecursive(
}
void LOKDocumentFocusListener::detachRecursive(
- const uno::Reference< accessibility::XAccessible >& xAccessible
+ const uno::Reference< accessibility::XAccessible >& xAccessible,
+ bool bForce
)
{
uno::Reference< accessibility::XAccessibleContext > xContext =
xAccessible->getAccessibleContext();
if( xContext.is() )
- detachRecursive(xContext);
+ detachRecursive(xContext, bForce);
}
void LOKDocumentFocusListener::detachRecursive(
- const uno::Reference< accessibility::XAccessibleContext >& xContext
+ const uno::Reference< accessibility::XAccessibleContext >& xContext,
+ bool bForce
)
{
aboutView("LOKDocumentFocusListener::detachRecursive (2)", this, m_pViewShell);
@@ -1094,12 +1104,13 @@ void LOKDocumentFocusListener::detachRecursive(
}
}
- detachRecursive(xContext, nStateSet);
+ detachRecursive(xContext, nStateSet, bForce);
}
void LOKDocumentFocusListener::detachRecursive(
const uno::Reference< accessibility::XAccessibleContext >& xContext,
- const sal_Int64 nStateSet
+ const sal_Int64 nStateSet,
+ bool bForce
)
{
uno::Reference< accessibility::XAccessibleEventBroadcaster > xBroadcaster =
@@ -1109,12 +1120,11 @@ void LOKDocumentFocusListener::detachRecursive(
{
xBroadcaster->removeAccessibleEventListener(static_cast< accessibility::XAccessibleEventListener *>(this));
- if( !( nStateSet & accessibility::AccessibleStateType::MANAGES_DESCENDANTS ) )
+ if( bForce || !( nStateSet & accessibility::AccessibleStateType::MANAGES_DESCENDANTS ) )
{
sal_Int64 nmax = xContext->getAccessibleChildCount();
if( nmax > MAX_ATTACHABLE_CHILDREN )
nmax = MAX_ATTACHABLE_CHILDREN;
-
for( sal_Int64 n = 0; n < nmax; n++ )
{
uno::Reference< accessibility::XAccessible > xChild( xContext->getAccessibleChild( n ) );
@@ -2626,7 +2636,7 @@ void SfxViewShell::SetLOKAccessibilityState(bool bEnabled)
{
try
{
- rDocumentFocusListener.detachRecursive(xAccessible);
+ rDocumentFocusListener.detachRecursive(xAccessible, /*bForce*/ true);
}
catch (const uno::Exception&)
{