comphelper/source/misc/accessiblecomponenthelper.cxx | 15 +-------------- include/comphelper/accessiblecomponenthelper.hxx | 8 ++------ 2 files changed, 3 insertions(+), 20 deletions(-)
New commits: commit 6a68b96c6a449f3861cda5af8e77dbe15dcce5d6 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Dec 12 11:08:54 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Dec 12 22:59:35 2024 +0100 tdf#164294 a11y: Don't rely on "creator" to determine child index In OCommonAccessibleComponent::getAccessibleIndexInParent, no longer rely on OCommonAccessibleComponent::m_aCreator to have been set to the "creator" (i.e. the XAccessible whose XAccessible::getAccessibleContext() created this object) in order to determine the index of the object in its parent. Instead, call XAccessible::getAccessibleContext on the parent's child XAccessible objects and compare that to `this`. At least for SvxPixelCtlAccessible (and most likely other child classes), OCommonAccessibleComponent::m_aCreator isn't set (by a call to OCommonAccessibleComponent::lateInit), so the logic would fail, and an incorrect index of -1 was returned. Simplify the logic and no longer depend on OCommonAccessibleComponent::m_aCreator in that method. This also prepares for further decoupling VCLXAccessibleComponent from the VCLXWindow toolkit/UNO class. (The VCLXAccessibleComponent ctor currently calls OCommonAccessibleComponent::lateInit with its VCLXWindow, but overrides VCLXAccessibleComponent::getAccessibleIndexInParent without making use of the "creator" there.) Comments suggest that the previous logic was there to avoid calling XAccessible::getAccessibleContext for performance reasons. If that's a concern for a particular subclass, overriding OCommonAccessibleComponent::getAccessibleIndexInParent in that subclass (and making use of whatever internal details help to efficiently implement the method) seems like a better and more reliable solution to me. Change-Id: I29fb7cd42512a02fc1cc56835bb83f847e9ec0fd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178354 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/comphelper/source/misc/accessiblecomponenthelper.cxx b/comphelper/source/misc/accessiblecomponenthelper.cxx index 5d5ca53286ff..e9b7ae39818e 100644 --- a/comphelper/source/misc/accessiblecomponenthelper.cxx +++ b/comphelper/source/misc/accessiblecomponenthelper.cxx @@ -181,24 +181,11 @@ namespace comphelper return -1; // iterate over parent's children and search for this object - - // our own XAccessible for comparing with the children of our parent - Reference< XAccessible > xCreator( m_aCreator); - - OSL_ENSURE( xCreator.is(), "OCommonAccessibleComponent::getAccessibleIndexInParent: invalid creator!" ); - // two ideas why this could be NULL: - // * nobody called our late ctor (init), so we never had a creator at all -> bad - // * the creator is already dead. In this case, we should have been disposed, and - // never survived the above OContextEntryGuard. - // in all other situations the creator should be non-NULL - if (!xCreator.is()) - return -1; - sal_Int64 nChildCount = xParentContext->getAccessibleChildCount(); for (sal_Int64 nChild = 0; nChild < nChildCount; ++nChild) { Reference< XAccessible > xChild( xParentContext->getAccessibleChild( nChild ) ); - if ( xChild.get() == xCreator.get() ) + if (xChild.is() && xChild->getAccessibleContext().get() == this) return nChild; } } diff --git a/include/comphelper/accessiblecomponenthelper.hxx b/include/comphelper/accessiblecomponenthelper.hxx index 3774baf683d5..3adf81c9c97f 100644 --- a/include/comphelper/accessiblecomponenthelper.hxx +++ b/include/comphelper/accessiblecomponenthelper.hxx @@ -65,11 +65,6 @@ namespace comphelper separation of XAccessible from XAccessibleContext), you may pass <code>this</code> here.</p> <p>The object is hold weak, so its life time is not affected.</p> - - <p>The object is needed for performance reasons: for <method>getAccessibleIndexInParent</method>, - all children (which are XAccessible's theirself) of our parent have to be asked. If we know our - XAccessible, we can compare it with all the children, instead of asking all children for their - context and comparing this context with ourself.</p> */ void lateInit( const css::uno::Reference< css::accessibility::XAccessible >& _rxAccessible ); @@ -99,7 +94,8 @@ namespace comphelper // XAccessibleContext - default implementations /** default implementation for retrieving the index of this object within the parent <p>This basic implementation here returns the index <code>i</code> of the child for which - <code><parent>.getAccessibleChild( i )</code> equals our creator.</p> + <code><parent>.getAccessibleChild(i).getAccessibleContext()</code> returns + a reference to this OCommonAccessibleComponent object.</p> */ virtual sal_Int64 SAL_CALL getAccessibleIndexInParent( ) override; /** default implementation for retrieving the locale