RFR: JDK-8314731 : Add support for the alt attribute in the image type input HTML tag [v2]
Alexey Ivanov
aivanov at openjdk.org
Tue Oct 24 19:30:38 UTC 2023
On Tue, 24 Oct 2023 18:54:17 GMT, ScientificWare <duke at openjdk.org> wrote:
>>> 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);
> }
Yes, something similar:
String srcAtt = (String) attr.getAttribute(HTML.Attribute.SRC);
String altAtt = (String) attr.getAttribute(HTML.Attribute.ALT);
JButton button;
try {
URL base = ((HTMLDocument)getElement().getDocument()).getBase();
@SuppressWarnings("deprecation")
URL srcURL = new URL(base, srcAtt);
ImageIcon icon = altAtt != null
? new ImageIcon(srcURL, altAtt)
: new ImageIcon(srcURL);
button = icon.getImageLoadStatus() == MediaTracker.COMPLETE
? new JButton(icon)
: new JButton(altAtt != null ? altAtt : srcAtt);
} catch (MalformedURLException e) {
button = new JButton(altAtt != null ? altAtt : srcAtt);
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15319#discussion_r1370719498
More information about the client-libs-dev
mailing list