Bug 257867

Summary: Support custom annotations for Accessibility in composition contexts.
Product: WebKit Reporter: Jack Wiig <jhwiig>
Component: AccessibilityAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, andresg_22, apinheiro, cfleizach, dmazzoni, ews-watchlist, jcraig, jdiggs, mifenton, samuel_white, tyler_w, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch none

Description Jack Wiig 2023-06-08 14:48:31 PDT
This change broadens the information that we can parse from an attributed string in a composition context. Now, annotations (attributes that have no meaningful value, usually @YES or "1") can be conveyed. We use this in accessibility to convey when an inline prediction is happening, so assistive technologies know not to process that text as part of the user's typing.
Comment 1 Radar WebKit Bug Importer 2023-06-08 14:48:42 PDT
<rdar://problem/110488738>
Comment 2 Jack Wiig 2023-06-08 15:01:08 PDT
Created attachment 466642 [details]
Patch
Comment 3 Jack Wiig 2023-06-08 16:23:37 PDT
Created attachment 466644 [details]
Patch
Comment 4 Jack Wiig 2023-06-09 11:28:09 PDT
Created attachment 466652 [details]
Patch
Comment 5 Jack Wiig 2023-06-09 11:42:33 PDT
Created attachment 466653 [details]
Patch
Comment 6 Jack Wiig 2023-06-09 11:52:59 PDT
Created attachment 466654 [details]
Patch
Comment 7 Tyler Wilcock 2023-06-09 13:52:29 PDT
Comment on attachment 466654 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=466654&action=review

> Source/WebKit/UIProcess/mac/WebViewImpl.mm:5111
> +            auto it = annotations.find(key);
> +            if (it == annotations.end())
> +                it = annotations.add(key, Vector<CharacterRange> { }).iterator;

I think HashMap::ensure does this (find a value, initializing it if necessary). Might express the intent a bit better (if it works here).

> Source/WebKit/UIProcess/mac/WebViewImpl.mm:5150
>              underlines = compositionUnderlines(string);
> +        annotations = compositionAnnotations(string);

The indentation is different between these two lines. Not sure which is right, though.

> Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:669
> +            auto it = annotations.find(name);
> +            if (it == annotations.end())
> +                it = annotations.add(name, Vector<WebCore::CharacterRange> { }).iterator;

Another place where HashMap::ensure might work?
Comment 8 Jack Wiig 2023-06-09 14:00:26 PDT
I didn't know the function of HashMap::ensure, but now that I do, I'll switch to using that. Thanks!

As for the indentation difference, the first line is the single-line else clause if HAVE(REDESIGNED_TEXT_CURSOR) is true, otherwise, it's just part of the same scope as the annotations line I added. I think the thought was it's safer to leave it indented to convey that it's part of an else block, but that was not code I wrote.
Comment 9 Tyler Wilcock 2023-06-09 14:02:10 PDT
> As for the indentation difference, the first line is the single-line else
> clause if HAVE(REDESIGNED_TEXT_CURSOR) is true, otherwise, it's just part of
> the same scope as the annotations line I added. I think the thought was it's
> safer to leave it indented to convey that it's part of an else block, but
> that was not code I wrote.
Got it, sounds good, thanks!
Comment 10 EWS 2023-06-09 23:54:07 PDT
Committed 265055@main (ef93c1b412c0): <https://commits.webkit.org/265055@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 466654 [details].
Comment 11 EWS 2024-05-28 17:08:09 PDT
Test gardening commit 279418@main (190ac0f18d5d): <https://commits.webkit.org/279418@main>

Reviewed commits have been landed. Closing PR #29202 and removing active labels.