New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8273986: JEditorPane HTML Demo - Accessibility issues #12707
Conversation
👋 Welcome back abhiscxk! A progress list of the required criteria for merging this PR into |
@azuev-java Request you to please review this PR. |
@kumarabhi006 The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
You might to bump up the copyright year in both headers. Other than that looks good. |
Copyright year updated. |
@kumarabhi006 This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 427 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@@ -684,9 +685,11 @@ public AccessibleContext getAccessibleContext() { | |||
if (theEditor == null) { | |||
return null; | |||
} | |||
if (accessibleContext == null) { | |||
if (accessibleContext == null | |||
|| doc != theEditor.getDocument()) { | |||
AccessibleHTML a = new AccessibleHTML(theEditor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "AccessibleHTML" internally registers the listener on the editor to update the state/doc. Why that notification does not work and it is necessary to recreate the "AccessibleHTML" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "AccessibleHTML" does internally register the listener on the editor to update the state/doc.
But the rootHTMLAccessibleContext
is not updated/created for the new root element on doc change and when getAccessibleChildrenCount
is called it returns the child count 0, because the API is get called on the old object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the "rootHTMLAccessibleContext" depends on the doc then I think it should be updated in that listener at the same moment the doc is replaced. especially taking into account that the "rootElementInfo" is updated already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I think the rootElementInfo
needs to update for rootHTMLAccessibleContext
everytime whenever doc change happened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrserb The elementInfo
variable is updated for rootHTMLAccessibleContext
while setting up the rootElementInfo
on doc change.
It does report the children correctly and as of now there is no need to re-create the accessibleContext everytime on doc change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrserb Please review the latest changes.
@@ -183,6 +183,9 @@ private void buildInfo() { | |||
Element root = doc.getDefaultRootElement(); | |||
|
|||
rootElementInfo = new ElementInfo(root); | |||
if (rootHTMLAccessibleContext != null) { | |||
rootHTMLAccessibleContext.setElementInfo(rootElementInfo); | |||
} | |||
rootElementInfo.validate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we should call validate first, so it will be in the valid state before being leaked to the "setElementInfo" method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be verified by the test, you can check the number of children returned by the a11y API is correct when the doc is replaced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be verified by the test, you can check the number of children returned by the a11y API is correct when the doc is replaced.
Probably we don't required a test because I think we can verify the number of children by using JAccessWalker a11y tool, so whenever there is a doc change, the component hierarchy should be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we should call validate first, so it will be in the valid state before being leaked to the "setElementInfo" method.
Ok, I will check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we should call validate first, so it will be in the valid state before being leaked to the "setElementInfo" method.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be verified by the test, you can check the number of children returned by the a11y API is correct when the doc is replaced.
Added an automated test to verify the fix. Along with test, few html files and support files are also pushed.
Please review the latest changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix all that "Whitespace error" in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix all that "Whitespace error" in the test.
Fixed.
@azuev-java As discussed earlier, the access specifier for Please review the latest changes. |
My question would be - is it really necessary to bring the entire HTML set from the demo to test the accessibility? Can we just create a small and simple HTML document with some structure that should be interpreted as a document with nested children? Additionally - i do not understand why do we even need an interactive UI test with the robot and such. Why is it necessary? Why simple creation of JEditorPane and assigning url to it does not work? |
The idea to get entire HTML set is that we can validate the child count for existing HTML doc (index and title html files). It should be similar to swingset2 demo.
I think we can, I will try to check this.
When html files are loaded in JEditorPane and I try to get the child count, it always returned 1. So, I thought to change the page and get child count using interactive UI and it does return the correct child count.
I am not sure why it doesn't return the correct child count by simply assigning url to JEditorpane. |
@azuev-java As suggested, I tried to create two simple html files for test. Modified the test case to load the url and get the accessible child count for both html files. The usage of robot as well as interactive UI is removed. Cross-checked with the JAccessWalker tool, the child count is same for the test and in JAccessWalker component tree. Extra delay added in test case to get the correct child count else the child count always returns 1. |
private static JEditorPane jep; | ||
private static AccessibleContext ac; | ||
private static URL url; | ||
private static JFrame frame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these ui-related fields should be accessed on EDT in the test.
url can be made local variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. URL is declared as local variable now.
loadHtmlPage(url); | ||
}); | ||
addDelay(500); | ||
int childCount2 = ac.getAccessibleChildrenCount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: "ac" initialized on EDT, and accessed here w/o synchronization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am facing an error local variables referenced from a lambda expression must be final or effectively final
when I tried to get the ChildrenCount and assign it to local variable childCount2
on EDT.
My piece of code looks like this in main
method
int childCount2 = 0;
SwingUtilities.invokeAndWait(() -> {
childCount2 = ac.getAccessibleChildrenCount();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrserb Accessing the accessibleContext (ac)
on EDT now. Moved the local variables (childCount1 and childCount2
) to class variable and assigned the values on EDT.
Please review the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrserb Please review the latest changes.
childCount2 = ac.getAccessibleChildrenCount(); | ||
}); | ||
|
||
if ((childCount1 != childCount2) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version will update the childCount1/2 on EDT but then will use it in the main thread w/o synchronization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the if block should also be inside EDT as mentioned below. Right?
SwingUtilities.invokeAndWait(() -> {
childCount2 = ac.getAccessibleChildrenCount();
if ((childCount1 != childCount2) &&
(childCount1 != 0 && childCount2 != 0)) {
System.out.println("passed");
} else {
System.out.println("Test1 html page accessible children" +
" count is: "+ childCount1);
System.out.println("Test2 html page accessible children" +
" count is: "+ childCount2);
throw new RuntimeException("getAccessibleChildrenCount" +
" returned wrong child count");
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version will update the childCount1/2 on EDT but then will use it in the main thread w/o synchronization.
Updated the childCount1/2 to be used on EDT in stead of main thread.
/integrate |
Going to push as commit 9764948.
Your commit was automatically rebased without conflicts. |
@kumarabhi006 Pushed as commit 9764948. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
JAccessWalker was not able to show component tree correctly if we switch pages for HTML content.
Observation:
The issue observed is that the children are not reported correct for root element when switching of pages happened. The reason behind it is that the
getAccessibleChildrenCount
API is called on the oldaccessibleContext
object which return the children count as 0. Whenever we switch the page the children count is recalculated based on the root element but theaccessibleContext
object used to retrieve the child remains unchanged and due to that it return the children count 0.Solution:
Added a method to update the root element info to find out the children count correctly whenever we switch the pages in JEditorPane.
Checked with the SwingSet2 JEditorPane demo and it reports well the component tree in JAccessWalker. Test case also added to verify the fix.
Steps to verify:
JBS contains the steps to reproduce the scenario.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/12707/head:pull/12707
$ git checkout pull/12707
Update a local copy of the PR:
$ git checkout pull/12707
$ git pull https://git.openjdk.org/jdk.git pull/12707/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 12707
View PR using the GUI difftool:
$ git pr show -t 12707
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12707.diff