Skip to content
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

JDK-8314731 : Add support for the alt attribute in the image type input HTML tag #15319

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

scientificware
Copy link
Contributor

@scientificware scientificware commented Aug 17, 2023

This is referenced in Java Bug Database as

This is tracked in JBS as

According HTML 3.2 specification

alt is not an attribute of the input element.

According HTML 4.01 specifications :

... For accessibility reasons, authors should provide alternate text for the image via the alt attribute. ...

This feature is not implemented in FormView.java.

⚠️ This also affects the HTML 32 DTD

Screenshot_20230817_025316

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 the code above, save it with the name : oracle_logo_50x50.jpg
oracle_logo_50x50.jpg

Designed from : ScientificWare : JDK-8314731 : Add support for the alt attribute in the image type input HTML tag


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8314731: Add support for the alt attribute in the image type input HTML tag (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15319/head:pull/15319
$ git checkout pull/15319

Update a local copy of the PR:
$ git checkout pull/15319
$ git pull https://git.openjdk.org/jdk.git pull/15319/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15319

View PR using the GUI difftool:
$ git pr show -t 15319

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15319.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 17, 2023

👋 Welcome back scientificware! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 17, 2023

@scientificware The following label will be automatically applied to this pull request:

  • client

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.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Aug 17, 2023
@scientificware scientificware changed the title Adds support for the alt attribute in the image type imput HTML tag. Adds support for the alt attribute in the image type imput HTML tag Aug 17, 2023
@victordyakov
Copy link

@scientificware scientificware changed the title Adds support for the alt attribute in the image type imput HTML tag JDK-8314731 : Adds support for the alt attribute in the image type imput HTML tag.ge type imput HTML tag Aug 22, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 22, 2023
@scientificware scientificware changed the title JDK-8314731 : Adds support for the alt attribute in the image type imput HTML tag.ge type imput HTML tag JDK-8314731 : Adds support for the alt attribute in the image type imput HTML tag. Aug 22, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 22, 2023

Webrevs

@scientificware scientificware changed the title JDK-8314731 : Adds support for the alt attribute in the image type imput HTML tag. JDK-8314731: Adds support for the alt attribute in the image type imput HTML tag. Aug 22, 2023
@scientificware scientificware changed the title JDK-8314731: Adds support for the alt attribute in the image type imput HTML tag. JDK-8314731 : Adds support for the alt attribute in the image type input HTML tag Aug 22, 2023
@scientificware scientificware changed the title JDK-8314731 : Adds support for the alt attribute in the image type input HTML tag JDK-8314731 : Add support for the alt attribute in the image type input HTML tag Aug 22, 2023
…java


FormView.java : Remove a redundant space.

Co-authored-by: Andrey Turbanov <turbanoff@gmail.com>
@bridgekeeper
Copy link

bridgekeeper bot commented Sep 27, 2023

@scientificware This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@scientificware
Copy link
Contributor Author

Waiting for a review.

Copy link
Member

@aivanov-jdk aivanov-jdk left a comment

Choose a reason for hiding this comment

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

Can you write a regression test for it?

JButton button;
try {
URL base = ((HTMLDocument)getElement().getDocument()).getBase();
@SuppressWarnings("deprecation")
URL srcURL = new URL(base, srcAtt);
Icon icon = new ImageIcon(srcURL);
button = new JButton(icon);
ImageIcon icon = new ImageIcon(srcURL);
Copy link
Member

Choose a reason for hiding this comment

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

You should probably pass altAtt as the description parameter, yet I'm unsure if it's ever used in this context.

Copy link
Member

Choose a reason for hiding this comment

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

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:

public ImageIcon (URL location) {
this(location, location.toExternalForm());
}

Now that you handle the alt attribute, you can pass the description if it's provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

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);
            }

Copy link
Member

Choose a reason for hiding this comment

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

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);
            }

Icon icon = new ImageIcon(srcURL);
button = new JButton(icon);
ImageIcon icon = new ImageIcon(srcURL);
button = icon.getImageLoadStatus() == MediaTracker.COMPLETE ? new JButton(icon) : new JButton(altAtt);
Copy link
Member

Choose a reason for hiding this comment

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

Initially I thought the status could change, it can't.

Looks good to me.

Icon icon = new ImageIcon(srcURL);
button = new JButton(icon);
ImageIcon icon = new ImageIcon(srcURL);
button = icon.getImageLoadStatus() == MediaTracker.COMPLETE ? new JButton(icon) : new JButton(altAtt);
} catch (MalformedURLException e) {
button = new JButton(srcAtt);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
button = new JButton(srcAtt);
button = new JButton(altAtt);

If altAtt is provided, it should be used to handle invalid srcAtt too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aivanov-jdk My apologies, I forgot to reply. I wanted to distinguish the two cases : (Missing resource or bad resource name) and malformed URL. Like in the previous example I gave.

Copy link
Member

Choose a reason for hiding this comment

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

@aivanov-jdk My apologies, I forgot to reply. I wanted to distinguish the two cases : (Missing resource or bad resource name) and malformed URL. Like in the previous example I gave.

What purpose does this distinction serve?

It could give an additional insight to the app developer. At the same time, the app developer should ensure the image loads.

Does the user of the app care about it [the distinction]? Unlikely. The end result is the image isn't loaded. As HTML specifies, the alt attribute contains the image description, which is more useful to the user in all the cases where the image failed to load.

Therefore I think you should fallback to altAtt if it's provided.

This actually raises another question: what if altAtt isn't provided? Should it fallback to srcURL?

Copy link
Contributor Author

@scientificware scientificware Oct 23, 2023

Choose a reason for hiding this comment

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

What purpose does this distinction serve?

Definitely an application developer and because it's the context of this HTML implementation, may I preserve this distinction ?

This actually raises another question: what if altAtt isn't provided? Should it fallback to srcURL?

Yes, it's a logical error on my part.

Copy link
Member

Choose a reason for hiding this comment

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

What purpose does this distinction serve?

Definitely an application developer and because it's the context of this HTML implementation, may I preserve this distinction ?

Okay, let it be. However, I still think it's not the right thing.

There was nothing else but the src attribute, now there is.

This actually raises another question: what if altAtt isn't provided? Should it fallback to srcURL?

Yes, it's a logical error on my part.

Are you going to address it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

            <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>
  • Left before the Patch
  • Right with your suggestion and if the distinction is preserved.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's what I meant.

A button with the plain source is better than a button without a title at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you going to address it?

Yes.

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

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

I don't have a problem with this change, but there's no goal to bring Swing HTML up to any later HTML spec version.

@openjdk
Copy link

openjdk bot commented Oct 18, 2023

@scientificware This change is no longer ready for integration - check the PR body for details.

@scientificware
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 23, 2023
@openjdk
Copy link

openjdk bot commented Oct 23, 2023

@scientificware
Your change (at version 0e08107) is now ready to be sponsored by a Committer.

JButton button;
try {
URL base = ((HTMLDocument)getElement().getDocument()).getBase();
@SuppressWarnings("deprecation")
URL srcURL = new URL(base, srcAtt);
Icon icon = new ImageIcon(srcURL);
button = new JButton(icon);
ImageIcon icon = new ImageIcon(srcURL);
Copy link
Member

Choose a reason for hiding this comment

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

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:

public ImageIcon (URL location) {
this(location, location.toExternalForm());
}

Now that you handle the alt attribute, you can pass the description if it's provided.

Icon icon = new ImageIcon(srcURL);
button = new JButton(icon);
ImageIcon icon = new ImageIcon(srcURL);
button = icon.getImageLoadStatus() == MediaTracker.COMPLETE ? new JButton(icon) : new JButton(altAtt);
Copy link
Member

Choose a reason for hiding this comment

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

Should it fallback to src attribute if the alt attribute is missing?

@aivanov-jdk
Copy link
Member

/reviewers 2

@openjdk
Copy link

openjdk bot commented Oct 23, 2023

@aivanov-jdk
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@openjdk openjdk bot removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated labels Oct 23, 2023
@aivanov-jdk
Copy link
Member

Is it possible to write a jtreg test for this feature? Do we want to test it?

- Fall back to the src attribute if the alt attribute is missing.
…_alt_attribute_support' of github.com:scientificware/jdk into scientificware-patch-006-HTML-adds_input_tag_image_type_alt_attribute_support
- Pass altAtt as the description parameter in the ImageIcon constructor.
@openjdk
Copy link

openjdk bot commented Nov 2, 2023

⚠️ @scientificware This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

Copy link
Member

@aivanov-jdk aivanov-jdk left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@aivanov-jdk
Copy link
Member

I wonder if it's possible to write a (unit) test which verifies the new behaviour… and whether it's worth doing.

@openjdk
Copy link

openjdk bot commented Nov 21, 2023

⚠️ @scientificware the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout scientificware-patch-006-HTML-adds_input_tag_image_type_alt_attribute_support
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 21, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Jan 4, 2024

@scientificware This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@prrace
Copy link
Contributor

prrace commented Jan 16, 2024

@scientificware - are you still working on this ?

@scientificware
Copy link
Contributor Author

@prrace Yes but I have to postpone this work.

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 12, 2024

@scientificware This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@prrace
Copy link
Contributor

prrace commented May 1, 2024

@scientificware please say when you will be getting back to this

@scientificware
Copy link
Contributor Author

scientificware commented May 1, 2024

@prrace Sorry for the delay about all my contributions but I won a racing bib for the "Marathon Pour Tous" of Paris 2024 Olympic Games. So I have suspended all projects becauseof my training plan until september.

My intent is to deliver the unit test in december.

@aivanov-jdk
Copy link
Member

I won a racing bib for the "Marathon Pour Tous" of Paris 2024 Olympic Games.

Congratulations! Good luck!

…I have suspended all projects becauseof my training plan until september.

My intent is to deliver the unit test in december.

@scientificware Could you please convert this PR to draft then? Click Convert to draft on the right side below the list of reviewers.

@scientificware scientificware marked this pull request as draft May 7, 2024 21:17
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 7, 2024
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 2, 2024

@scientificware This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org
5 participants