RFR: JDK-8314731 : Adds support for the alt attribute in the image type imput HTML tag.
ScientificWare
duke at openjdk.org
Tue Aug 22 16:43:17 UTC 2023
According [HTML 3.2 specification](https://www.w3.org/TR/2018/SPSD-html32-20180315/#input)
`alt` is not an attribute of the `imput` element.
According [HTML 4.01 specifications](https://www.w3.org/TR/html4/interact/forms.html#h-17.4) :
> ... For accessibility reasons, authors should provide [alternate text](https://www.w3.org/TR/html4/struct/objects.html#alternate-text) for the image via the [alt](https://www.w3.org/TR/html4/struct/objects.html#adef-alt) attribute. ...
This feature in not implemented in `FormView.java`.
⚠️ ~~This also affects the HTML 32 DTD~~

Left before the patch and right after the patch.
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
public class HTMLAddsSupportAltInputTag {
public static void main(String[] args) {
new HTMLAddsSupportAltInputTag();
}
public HTMLAddsSupportAltInputTag() {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(jEditorPane);
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setEditorKit(kit);
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("""
body {
color: #000;
font-family:times;
margin: 4px;
}
""");
String htmlString = """
<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:none_oracle_logo_50x50.jpg" alt="Logo Oracle JPG">
<p>
<input type=image name=point src="files:none_oracle_logo_50x50.jpg">
</body>
</html>
""";
Document doc = kit.createDefaultDocument();
jEditorPane.setDocument(doc);
jEditorPane.setText(htmlString);
JFrame jf = new JFrame("CSS named colors Test");
jf.getContentPane().add(scrollPane, BorderLayout.CENTER);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(new Dimension(400,200));
jf.setLocationRelativeTo(null);
jf.setVisible(true);
}
});
}
}
The image to use with de code above, save it with the name : `oracle_logo_50x50.jpg`

Designed from : [ScientificWare : Adds support for the alt attribute in the image type imput HTML tag](https://github.com/scientificware/jdk/issues/26)
-------------
Commit messages:
- FormView.java : Adds missing space in a while statement. Updates Copyright year.
- Merge master
- FormView.java : Adds support for the alt attribute in the image type imput tag.
Changes: https://git.openjdk.org/jdk/pull/15319/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15319&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8314731
Stats: 7 lines in 1 file changed: 2 ins; 1 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/15319.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/15319/head:pull/15319
PR: https://git.openjdk.org/jdk/pull/15319
More information about the client-libs-dev
mailing list