Repository navigation
Announce C/C++ completion popup selections to screen readers - #19549
Conversation
CompletionList's role and selected-state choices (listbox/option with aria-selected, or menu/menuitem with aria-current in Safari) move into CompletionListAria, so the C/C++ completion popup can apply the same ones. No behavior change. Addresses #19532
The C/C++ completion popup leaves keyboard focus in the editor, but nothing set the Ace input's aria-activedescendant, so screen readers didn't announce the selected completion. CppCompletionPopupMenu now gives its list and items the same roles as the other completion popups, labels the list "Completions", and points the input's aria-activedescendant at the selected item once the popup is visible, clearing it when the popup closes or empties. Item icons are marked presentational. The e2e tracker for aria-activedescendant writes now records only writes on the focused element: GWT's MenuBar also sets the attribute on its own, never-focused element while building items. Addresses #19532
appendPresentationImage wrote <img role="presentation"> with no alt attribute. HTML expects alt="" on a decorative image, and a screen reader that ignores the role can fall back to reading the source. It renders the completion type icons in both the R and C/C++ completion popups. Addresses #19532
Drop CppCompletionPopupMenu's onUnload override: ToolbarPopupMenu's onUnload already deselects the item, and that selection event clears the editor's aria-activedescendant. In the test, record aria-activedescendant writes on Ace text inputs rather than on the focused element, so a write made before focus arrives is still checked; fail rather than skip when the libclang/Rcpp probe can't be read; and require alt="" on the completion icons. Addresses #19532
gtritchie
left a comment
There was a problem hiding this comment.
Code review: 7 findings, posted inline except the one below. None are blocking; #1 is a pre-existing GWT hover behavior that the new ARIA state now mirrors.
Stale test header (e2e/rstudio/tests/panes/misc/completion_popup_aria.test.ts:1, :121): the file header still names only #6167 and #6168, and the suite comment says "The editor test creates a file", but the new C++ case (#19532) also creates one.
| // through the editor input's aria-activedescendant. | ||
| CompletionListAria.setListRole(menuBar_.getElement(), | ||
| constants_.completionsListLabel()); | ||
| addSelectionHandler(event -> setActiveItem(event.getSelectedItem())); |
There was a problem hiding this comment.
Mouse-out clears aria-activedescendant while the popup is open (plausible; mirrors existing behavior)
GWT MenuBar handles ONMOUSEOUT with itemOver(null, false) -> selectItem(null), and BaseMenuBar.onBrowserEvent passes mouse events through unchanged. This handler then calls setActiveItem(null), so whenever the pointer leaves an item, the editor input loses its active descendant until Arrow Down selects again. Moving between an item's icon and its text also clears and re-sets the attribute, which may make a screen reader repeat the item.
The visual highlight already clears the same way, so this follows an existing quirk rather than adding one. Worth deciding whether the ARIA state should hold the last keyboard selection instead.
There was a problem hiding this comment.
Leaving this as is. Confirmed that the fork's itemOver deselects on mouse-out (it only keeps the selection while a submenu is showing). But with nothing selected, Tab or Enter inserts nothing (acceptSelected sees index -1), so announcing no selection matches what the keys will do. Holding the last keyboard selection would announce an item that Tab won't insert. The icon-to-text flicker is the GWT menu hover quirk and only happens with the mouse.
| return onSelected_ != null; | ||
| } | ||
|
|
||
| private void setActiveItem(MenuItem item) |
There was a problem hiding this comment.
Clearing on close relies on a base-class side effect
This works today: ToolbarPopupMenu.onUnload (ToolbarPopupMenu.java:173-178) calls menuBar_.selectItem(null), which fires the SelectionEvent that reaches setActiveItem(null). Nothing in this class guarantees it, though, and announceable_ is never reset on close. CompletionList clears explicitly in its own onUnload (CompletionList.java:162-167); an equivalent override here would keep the guarantee local if the base class changes.
There was a problem hiding this comment.
Restored the onUnload override in 19d463a; it clears the editor's aria-activedescendant and resets announceable_.
| // setPopupPositionAndShow hides the popup while positioning it. VoiceOver | ||
| // ignores an active descendant that is hidden when named, and won't | ||
| // announce it once shown, so name it after the popup is visible. | ||
| private void announceWhenVisible() |
There was a problem hiding this comment.
Announce-timing logic is duplicated from CompletionList
announceable_, updateActiveDescendant() and the deferred visibility check repeat CompletionList.java:150-197, with different guards (isAttached() there, isShowing() && isVisible() here). Moving this into CompletionListAria alongside the roles would mean a future VoiceOver timing fix is made once, and the popups #19533 tracks could reuse it.
There was a problem hiding this comment.
Leaving the duplication. The two popups reach the announce step at different points: CompletionList announces once from onLoad, can swap its input through setInput, and checks its own isAttached(); the C++ popup re-announces after every refilter and checks the popup's isShowing() && isVisible(). A shared helper would need hooks for both, to replace about 15 lines in each. #19533's message announcements would likely go through AriaLiveService rather than aria-activedescendant, so I don't expect a third user.
| * through the editor input's aria-activedescendant, shared so every such | ||
| * popup reads the same way to a screen reader. | ||
| */ | ||
| public final class CompletionListAria |
There was a problem hiding this comment.
Shared helper lives in the console package
source/editors/text/cpp now imports this class and ConsoleConstants from views/console just for generic listbox roles and the "Completions" label. A neutral package (e.g. core/client/a11y) would avoid the cross-view dependency.
There was a problem hiding this comment.
Leaving it here. The cpp package already depends on console.shell.assist (CompletionManager, CompletionUtils) and console.shell.editor (InputEditorPosition, InputEditorSelection), since C++ completion is built on the console completion framework. Moving this class alone wouldn't remove the cross-view dependency, and the "Completions" label would still come from ConsoleConstants.
| ImageResource image) | ||
| { | ||
| sb.append(SafeHtmlUtil.createOpenTag("img", | ||
| "alt", "", |
There was a problem hiding this comment.
appendImage (line 69) is now dead code
On main its only caller was CppCompletionPopupMenu.java:64; this PR switches that call to appendPresentationImage, and git grep 'appendImage(' now finds only the definition. Removing it also keeps future callers from adding icons with no alt text.
| test.skip(!canComplete, 'C++ completion needs libclang and the Rcpp package'); | ||
|
|
||
| // C++ completion asks libclang for the members of `s` once `s.` is typed. | ||
| // The file must exist on disk, since completion compiles the saved file. |
There was a problem hiding this comment.
Comment misstates why the file must be on disk
Completion doesn't compile the saved file: onSourceDocUpdated (SessionClang.cpp:81-98) skips documents without a path and otherwise passes the editor contents to libclang as unsaved files, and CodeCompletion.cpp:546-548 looks up the translation unit by that path. The file on disk is needed so the document has a path that gets compile arguments. Suggested wording: "The file needs a path on disk, which is how it gets Rcpp compile arguments."
There was a problem hiding this comment.
Fixed in 19d463a with your wording; also updated the file header and the suite's sandbox comment.
- Restore CppCompletionPopupMenu.onUnload, so clearing the editor's aria-activedescendant on close doesn't depend on ToolbarPopupMenu deselecting the item, and announceable_ resets with it. - Remove SafeHtmlUtil.appendImage; its only caller now uses appendPresentationImage. - Name #19532 in the test file header, note that the C++ test also creates a file, and correct why the .cpp file needs a path on disk. Addresses #19532
|
Re-review of 19d463a: all seven findings are resolved, and the new changes raise nothing new. Fixed
Kept as is, rationale accepted
|
RStudio E2E - all platformsAll tests passed!
All platforms - commit |
On the Linux CI runners, libclang 18 fails to parse the Rcpp test file (#19559), so get_cpp_completions returns null and no popup appears; on the Windows runners no popup appears within 60 seconds either. The test passed only on macOS. Skip it unless the R session runs on macOS, checked from R so the session's platform is tested even against a remote server. Addresses #19532
Fixes #19532.
C/C++ completion uses its own popup (
CppCompletionPopupMenu), not theCompletionListpopup that #6167 made screen-reader accessible. Keyboard focus stays in the editor while the user arrows through it, and nothing set the Ace input'saria-activedescendant, so the selected completion wasn't announced.CppCompletionPopupMenupoints the editor input'saria-activedescendantat the selected item, through theInputEditorDisplay.setAriaActiveDescendantadded for Autocomplete popups not announced by screen readers #6167. As inCompletionList, the first selection is named only after the popup is visible, since VoiceOver ignores a target that is hidden when named. The attribute is cleared when the popup closes or has no results.aria-selected; menu/menuitem witharia-currentin Safari), and the list is labeled "Completions". Those role choices move fromCompletionListinto a sharedCompletionListAriahelper.SafeHtmlUtil.appendPresentationImagenow also writesalt="", which affects the R completion popup's icons too.This popup still has the gaps #19533 tracks for the R completion and history popups: message-only popups such as "(No matches)" aren't announced, the completion type is shown only by the now-hidden icon, and the signature tooltip (
CppCompletionToolTip) isn't linked to the selected item.Testing
e2e/rstudio/tests/panes/misc/completion_popup_aria.test.tsgains a C++ case: it typess.after astd::string s;in an Rcpp source file, then checks the active option, its role and label, that it was visible when named, that Arrow Down moves it, and that Escape clears it. (A standalone.cppfile only gets completions as an Rcpp or cpp11 source file.) It runs only against macOS sessions with libclang and Rcpp: on the Linux CI runners libclang 18 can't parse the file (#19559), and on the Windows runners no completion popup appears. It fails against the unfixed popup at thearia-activedescendantcheck.The spec's tracker for
aria-activedescendantwrites now records only writes on Ace text inputs, because GWT's MenuBar also sets the attribute on its own never-focused element.Not yet checked with a screen reader.