RFR: JDK-8314731 : Add support for the alt attribute in the image type input HTML tag [v2]
ScientificWare
duke at openjdk.org
Tue Oct 24 18:57:40 UTC 2023
On Mon, 23 Oct 2023 12:09:35 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:
>> src/java.desktop/share/classes/javax/swing/text/html/FormView.java line 282:
>>
>>> 280: @SuppressWarnings("deprecation")
>>> 281: URL srcURL = new URL(base, srcAtt);
>>> 282: ImageIcon icon = new ImageIcon(srcURL);
>>
>> You should probably pass `altAtt` as the `description` parameter, yet I'm unsure if it's ever used in this context.
>
>> You should probably pass `altAtt` as the `description` parameter, yet I'm unsure if it's ever used in this context.
>
> As I say, I'm unsure if it's used… The description could be exposed to Accessibility API. By default, `ImageIcon` uses the URL as the description if it isn't provided:
>
> https://github.com/openjdk/jdk/blob/99de9bb83ff70fe81c89751516a86a94c8f552be/src/java.desktop/share/classes/javax/swing/ImageIcon.java#L231-L233
>
> Now that you handle the `alt` attribute, you can pass the description if it's provided.

Did you have this in mind ?
<html>
<body>
<input type=image name=point src="file:oracle_logo_50x50.jpg" alt="Logo Oracle JPG">
<p>
<input type=image name=point src="file:oracle_logo_50x50.jpg">
<p>
<input type=image name=point src="file:none_oracle_logo_50x50.jpg" alt="Logo Oracle JPG">
<p>
<input type=image name=point src="file:none_oracle_logo_50x50.jpg">
<p>
<input type=image name=point src="files:none_oracle_logo_50x50.jpg" alt="Logo Oracle JPG">
<p>
<input type=image name=point src="files:none_oracle_logo_50x50.jpg">
<p>
</body>
</html>
String srcAtt = (String) attr.getAttribute(HTML.Attribute.SRC);
String altAtt = (String) attr.getAttribute(HTML.Attribute.ALT);
if (altAtt == null) {
altAtt = srcAtt;
}
JButton button;
try {
URL base = ((HTMLDocument)getElement().getDocument()).getBase();
@SuppressWarnings("deprecation")
URL srcURL = new URL(base, srcAtt);
ImageIcon icon = new ImageIcon(srcURL, altAtt);
button = new JButton(icon);
} catch (MalformedURLException e) {
button = new JButton(altAtt == null ? srcAtt : altAtt);
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15319#discussion_r1370684162
More information about the client-libs-dev
mailing list