Skip to content

Commit

Permalink
Align alt-less img checking w/ current HTML-ARIA
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshowbarker committed Feb 27, 2020
1 parent 2d78043 commit 77584c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
18 changes: 14 additions & 4 deletions schema/html5/embed.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ namespace local = ""

## Images: <img>

img.elem =
element img { img.inner & img.attrs }
img.attrs =
shared-img.attrs =
( common.attrs
& img.attrs.src
& img.attrs.srcset?
& img.attrs.sizes?
& img.attrs.alt? # ARIA: if alt empty, only allowed role value is "presentation"; check in assertions
& img.attrs.generator-unable-to-provide-required-alt?
& img.attrs.height?
& img.attrs.width?
Expand All @@ -28,7 +25,18 @@ namespace local = ""
& img.attrs.border? # obsolete
& referrerpolicy?
& embedded.content.attrs.crossorigin?
)

no-alt-img.elem =
element img { img.inner & shared-img.attrs }

img.elem =
element img { img.inner & img.attrs }
img.attrs =
( shared-img.attrs
& img.attrs.alt
& ( common.attrs.aria.implicit.img
| common.attrs.aria.implicit.img
| common.attrs.aria.role.button
| common.attrs.aria.role.checkbox
| common.attrs.aria.role.img
Expand All @@ -48,6 +56,7 @@ namespace local = ""
| common.attrs.aria.role.treeitem
)?
)

img.attrs.src =
attribute src {
common.data.uri.non-empty
Expand Down Expand Up @@ -102,6 +111,7 @@ namespace local = ""
img.inner =
empty

common.elem.phrasing |= no-alt-img.elem
common.elem.phrasing |= img.elem

## Image with multiple sources: <picture>
Expand Down
17 changes: 6 additions & 11 deletions src/nu/validator/checker/schematronequiv/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@ public void startElement(String uri, String localName, String name,
boolean tabindex = false;
boolean languageJavaScript = false;
boolean typeNotTextJavaScript = false;
boolean hasAriaAttributes = false;
String xmlLang = null;
String lang = null;
String id = null;
Expand All @@ -1718,6 +1719,9 @@ public void startElement(String uri, String localName, String name,
String attUri = atts.getURI(i);
if (attUri.length() == 0) {
String attLocal = atts.getLocalName(i);
if (attLocal.startsWith("aria-")) {
hasAriaAttributes = true;
}
if ("embed".equals(localName)) {
for (int j = 0; j < attLocal.length(); j++) {
char c = attLocal.charAt(j);
Expand Down Expand Up @@ -2224,17 +2228,8 @@ msg, getDocumentLocator(),
+ "\u201Ca\u201D ancestor with the "
+ "\u201Chref\u201D attribute.");
}
if (atts.getIndex("", "alt") < 0) {
// img without alt attribute
if (role != null) {
for (String roleValue : roles) {
if (!("img".equals(roleValue))) {
err("Bad value \u201C" + roleValue + "\u201D"
+ " for attribute \u201Crole\u201D on"
+ " element \u201Cimg\u201D");
}
}
}
if (atts.getIndex("", "alt") < 0 //
&& role == null && !hasAriaAttributes) {
if ((titleVal == null || "".equals(titleVal))) {
if ((ancestorMask & FIGURE_MASK) == 0) {
err("An \u201Cimg\u201D element must have an"
Expand Down

0 comments on commit 77584c4

Please sign in to comment.