Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8087557: [Win] [Accessibility, Dialogs] Alert Dialog content is not f…
…ully read by Screen Reader

Reviewed-by: kcr
Backport-of: b951503
  • Loading branch information
arapte committed Nov 22, 2022
1 parent f34d86d commit 4d86a0e
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
Expand Up @@ -53,6 +53,7 @@
import javafx.css.StyleableStringProperty;
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.AccessibleRole;
import javafx.scene.Node;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.image.Image;
Expand Down Expand Up @@ -209,6 +210,7 @@ static Label createContentLabel(String text) {
*/
public DialogPane() {
getStyleClass().add("dialog-pane");
setAccessibleRole(AccessibleRole.DIALOG);

headerTextPanel = new GridPane();
getChildren().add(headerTextPanel);
Expand Down
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.javafx.scene.control;

import javafx.scene.AccessibleRole;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

/** Tests for the {@link Dialog} class. */
public class DialogTest {

private Dialog<ButtonType> dialog;

@Before
public void setUp() {
dialog = new Dialog<>();
}

@After
public void cleanUp() {
// Set a dummy result so the dialog can be closed.
dialog.setResult(new ButtonType(""));
dialog.hide();
}

@Test
public void testAccessibleRole() {
assertEquals(AccessibleRole.DIALOG, dialog.getDialogPane().getAccessibleRole());
}
}

Expand Up @@ -1299,6 +1299,7 @@ private MacVariant accessibilityAttributeValue(long attribute) {
case PAGE_ITEM: result = "page"; break;
case TAB_ITEM: result = "tab"; break;
case LIST_VIEW: result = "list"; break;
case DIALOG: result = "dialog"; break;
default:
MacRole macRole = getRole(role);
MacSubrole subRole = MacSubrole.getRole(role);
Expand Down
Expand Up @@ -105,6 +105,7 @@ final class WinAccessible extends Accessible {
private static final int UIA_ToggleToggleStatePropertyId = 30086;
private static final int UIA_AriaRolePropertyId = 30101;
private static final int UIA_ProviderDescriptionPropertyId = 30107;
private static final int UIA_IsDialogPropertyId = 30174;

/* Control Pattern Identifiers */
private static final int UIA_InvokePatternId = 10000;
Expand Down Expand Up @@ -795,6 +796,7 @@ private WinVariant GetPropertyValue(int propertyId) {
switch (role) {
case TITLED_PANE: description = "title pane"; break;
case PAGE_ITEM: description = "page"; break;
case DIALOG: description = "dialog"; break;
default:
}
}
Expand Down Expand Up @@ -834,6 +836,12 @@ private WinVariant GetPropertyValue(int propertyId) {
variant.boolVal = focus != null ? focus : false;
break;
}
case UIA_IsDialogPropertyId: {
AccessibleRole role = (AccessibleRole) getAttribute(ROLE);
variant = new WinVariant();
variant.vt = WinVariant.VT_BOOL;
variant.boolVal = (role == AccessibleRole.DIALOG);
} break;
case UIA_IsContentElementPropertyId:
case UIA_IsControlElementPropertyId: {
//TODO how to handle ControlElement versus ContentElement
Expand Down
Expand Up @@ -822,4 +822,18 @@ public enum AccessibleRole {
* </ul>
*/
TREE_VIEW,

/**
* Dialog role.
* <p>
* Attributes:
* <ul>
* <li> {@link AccessibleAttribute#TEXT} </li>
* <li> {@link AccessibleAttribute#ROLE_DESCRIPTION} </li>
* <li> {@link AccessibleAttribute#CHILDREN} </li>
* </ul>
*
* @since 17.0.6
*/
DIALOG
}
Expand Up @@ -6508,7 +6508,13 @@ Accessible getAccessible() {
}
return getRoot();//not sure
}
case ROLE: return AccessibleRole.PARENT;
case ROLE: {
if (getRoot() != null && getRoot().getAccessibleRole() == AccessibleRole.DIALOG) {
return AccessibleRole.DIALOG;
} else {
return AccessibleRole.PARENT;
}
}
case SCENE: return Scene.this;
case FOCUS_NODE: {
if (transientFocusContainer != null) {
Expand Down

1 comment on commit 4d86a0e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.