Return null
from ComposeAccessible.getAccessibleContext when the node has been removed
#865
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The long story of this PR is this:
I reproduced the printed exception in JetBrains/compose-multiplatform#3728 and noticed that we don't report to the accessibility system anywhere when a node has been removed. So I thought it wasn't surprising that it would continue calling functions on it, which would then throw that exception.
So I set out to report node addition/removal by correctly firing
AccessibleContext.ACCESSIBLE_CHILD_PROPERTY
property change events. When that didn't do anything, I realized thatComposeAccessibleComponent
doesn't have the child/parent hierarchy set up correctly, and thought that perhaps this is confusing the system.Specifically
rootAccessible
inAccessibilityControllerImpl
(which is only the root for a singleSemanticsOwner
, so it's not really the root) doesn't report having a parent, even thoughComposeSceneAccessibleContext
returns it fromgetAccessibleChild
. So I fixed that. But unfortunately that didn't help either.Then I decided to see what exactly the system does when it receives an
ACCESSIBLE_CHILD_PROPERTY
property change event. Turns out thatAXChangeNotifier
(the accessible listener on macOS) doesn't even listen to that event, and its (native)ptr
isnull
altogether for some reason.So then I just gave up and implemented this PR. It simply marks
ComposeAccessible
s as removed when they are removed, and theirgetAccessibleContext
then returnsnull
. InCAccessibility.java
, all the getter functions check the return value ofgetAccessibleContext
and returnnull
if it returnsnull
.If we want to properly report
ACCESSIBLE_CHILD_PROPERTY
events and have the parents set up correctly, I can submit a separate PR, or just keep it stashed for now.Proposed Changes
When the semantics node of a
ComposeAccessible
is removed, mark it as removed, and have it returnnull
fromgetAccessibleContext
.Fixes: JetBrains/compose-multiplatform#3728