forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add means to override platform accessibility API native Window title
On some platforms, e.g. macOS, the accessible name of the native window is calculated based on its child (e.g. the RootView). As a result, in a JavaScript alert dialog, VoiceOver repeats the title (e.g. "url.com says") and fails to present the message text. If we set the accessible name of the RootView to the message text, VoiceOver then repeats that message without speaking the title. This commit specifically handles this problem by doing the following: * On macOS, if the RootView is a dialog whose name is the same as the title and it has an explicitly-set description, expose that description as the RootView's accessible name. * Create a means for a View to explicitly set the accessible title of a native window so that it is not calculated based on the name of the RootView. This support is currently only implemented for macOS, but it can be implemented on other platforms should the need arise. * Use this override in JavascriptTabModalDialogViewViews, which already sets the accessible description of the RootView for screen readers such as NVDA and Orca which prefer the description over their own calculations. AX-Relnotes: VoiceOver will now speak the message text of JavaScript alert dialogs. Bug: 1199159 Change-Id: I8e3bfe91d701911ecf637b5c9717fc3cbce5d481 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3647873 Reviewed-by: Nektarios Paisios <[email protected]> Reviewed-by: Elly Fong-Jones <[email protected]> Commit-Queue: Joanmarie Diggs <[email protected]> Cr-Commit-Position: refs/heads/main@{#1010303}
- Loading branch information
Showing
7 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
chrome/browser/ui/views/javascript_tab_modal_dialog_view_views_browsertest_mac.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <string> | ||
|
||
#include "base/bind.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/views/javascript_tab_modal_dialog_view_views.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "ui/accessibility/platform/ax_platform_node_mac.h" | ||
#include "ui/views/accessibility/view_accessibility.h" | ||
#include "ui/views/bubble/bubble_frame_view.h" | ||
|
||
using JavaScriptTabModalDialogViewViewsBrowserTestMac = InProcessBrowserTest; | ||
|
||
IN_PROC_BROWSER_TEST_F(JavaScriptTabModalDialogViewViewsBrowserTestMac, | ||
AlertDialogAccessibleNameDescriptionAndRole) { | ||
std::u16string title = u"Title"; | ||
std::u16string message = u"The message"; | ||
auto* dialog_views = | ||
JavaScriptTabModalDialogViewViews::CreateAlertDialogForTesting( | ||
browser(), title, message); | ||
|
||
// For a JavaScript alert dialog, VoiceOver speaks the accessible name of | ||
// the native window followed by the accessible name of the RootView. For | ||
// reasons detailed below, we have to make some adjustments on the Mac to | ||
// ensure that the window's name contains the title (e.g. "url.com says") | ||
// and that the RootView's name contains the message text. This test verifies | ||
// this exposure as well as exposure through other properties that VoiceOver | ||
// ignores. | ||
|
||
// The RootView of a JavaScript alert dialog should have the accessible role | ||
// of dialog. On the Mac, that is exposed as the subrole of a group. | ||
gfx::NativeViewAccessible native_dialog = dialog_views->GetWidget() | ||
->GetRootView() | ||
->GetViewAccessibility() | ||
.GetNativeObject(); | ||
EXPECT_EQ(NSAccessibilityGroupRole, [native_dialog accessibilityRole]); | ||
EXPECT_TRUE([@"AXApplicationDialog" | ||
isEqualToString:(NSString*)[native_dialog accessibilitySubrole]]); | ||
|
||
// JavaScriptTabModalDialogViewViews sets the accessible description of the | ||
// RootView to the message contents. That description is exposed on the Mac | ||
// via accessibilityHelp. | ||
EXPECT_EQ(message, | ||
base::SysNSStringToUTF16([native_dialog accessibilityHelp])); | ||
|
||
// While some screen readers use the accessible description to know what to | ||
// present to the user, VoiceOver currently does not. Therefore, we override | ||
// the RootView's accessible name in ViewAXPlatformNodeDelegateMac. That name | ||
// is then exposed as the accessibilityTitle (and not accessibilityLabel) on | ||
// the Mac because in AXPlatformNodeCocoa, window roles (including dialog) do | ||
// not expose an accessibilityLabel. | ||
EXPECT_EQ(message, | ||
base::SysNSStringToUTF16([native_dialog accessibilityTitle])); | ||
EXPECT_EQ(u"", base::SysNSStringToUTF16([native_dialog accessibilityLabel])); | ||
|
||
// The parent of the native dialog should be a window. | ||
gfx::NativeViewAccessible native_window = [native_dialog accessibilityParent]; | ||
EXPECT_EQ(NSAccessibilityWindowRole, [native_window accessibilityRole]); | ||
|
||
// On the Mac, the native window's accessible title comes from the "contents" | ||
// of the window. In this case, that is the accessibilityTitle of the RootView | ||
// which we overrode as described above. As a result, the native window's | ||
// accessibilityTitle is now also the message text. It is not necessary to | ||
// unset it. (See next comment.) | ||
EXPECT_EQ(message, | ||
base::SysNSStringToUTF16([native_window accessibilityTitle])); | ||
|
||
// When an object has both an accessibilityLabel and an accessibilityTitle, | ||
// VoiceOver prefers the value of accessibilityLabel. Because the native | ||
// window is not an AXPlatformNodeCocoa object, we can set the value of | ||
// accessibilityLabel on the window to the original title ("url.com | ||
// says") via OverrideNativeWindowTitle and VoiceOver presents that | ||
// prior to speaking the RootView's message text. | ||
EXPECT_EQ(title, | ||
base::SysNSStringToUTF16([native_window accessibilityLabel])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters