From a34b87cf44fdd028cf08f96e8f4b169650158ece Mon Sep 17 00:00:00 2001 From: Shunguo Date: Mon, 9 Oct 2023 16:15:39 -0500 Subject: [PATCH] update the rules #1676 --- .../v2/checker/accessibility/util/legacy.ts | 16 --- .../v4/rules/element_tabbable_unobscured.ts | 30 ++---- .../element_overlaid_hidden.html | 101 ++++++++++++++++++ .../element_overlaid_visible.html | 101 ++++++++++++++++++ ...nobscured.html => element_unobscured.html} | 0 5 files changed, 213 insertions(+), 35 deletions(-) create mode 100755 accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_hidden.html create mode 100755 accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_visible.html rename accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/{unobscured.html => element_unobscured.html} (100%) diff --git a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts index 2c22e9add..9523e5bc8 100644 --- a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts +++ b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts @@ -1369,22 +1369,6 @@ export class RPTUtil { return walkNode; } - /** - * return all the ancestor element names of the given element - * @param element - */ - public static getAncestorNames(element) { - if (!element) return null; - let ancestors = []; - let walkNode = DOMWalker.parentNode(element); - while (walkNode !== null) { - if (walkNode.nodeType === 1) - ancestors.push(walkNode.nodeName.toLowerCase()); - walkNode = DOMWalker.parentNode(walkNode); - } - return ancestors; - } - // return true if element1 and element2 are siblings public static isSibling(element1, element2) { if (element1 && element2) { diff --git a/accessibility-checker-engine/src/v4/rules/element_tabbable_unobscured.ts b/accessibility-checker-engine/src/v4/rules/element_tabbable_unobscured.ts index 0f2da7856..1b6ad509f 100644 --- a/accessibility-checker-engine/src/v4/rules/element_tabbable_unobscured.ts +++ b/accessibility-checker-engine/src/v4/rules/element_tabbable_unobscured.ts @@ -16,6 +16,7 @@ import { Rule, RuleResult, RuleContext, RulePass, RuleContextHierarchy, RulePote import { eRulePolicy, eToolkitLevel } from "../api/IRule"; import { VisUtil } from "../../v2/dom/VisUtil"; import { DOMMapper } from "../../v2/dom/DOMMapper"; +import { DOMUtil } from "../../v2/dom/DOMUtil"; export let element_tabbable_unobscured: Rule = { id: "element_tabbable_unobscured", @@ -48,7 +49,7 @@ export let element_tabbable_unobscured: Rule = { return null; const nodeName = ruleContext.nodeName.toLocaleLowerCase(); - + //ignore certain elements if (RPTUtil.getAncestor(ruleContext, ["pre", "code", "script", "meta"]) !== null || nodeName === "body" || nodeName === "html" ) @@ -71,7 +72,7 @@ export let element_tabbable_unobscured: Rule = { if (!win) { return null; } - + var cStyle = win.getComputedStyle(ruleContext); if (cStyle === null) return null; @@ -79,34 +80,25 @@ export let element_tabbable_unobscured: Rule = { let zindex = cStyle.zIndex; if (!zindex || zindex === 'auto') zindex = "0"; - - const ancestors = RPTUtil.getAncestorNames(ruleContext); - let ignoreList = nodeName +' *, ' + nodeName +', script'; - if (ancestors) { - ancestors.forEach(ancestor=> { - if (!["html", "body"].includes(ancestor)) - ignoreList += ", " + ancestor; - }); - } - var elems = doc.querySelectorAll('body *:not(' + ignoreList +')'); + + var elems = doc.querySelectorAll('body *:not(script)'); if (!elems || elems.length == 0) return; - + console.log("node="+nodeName +", id=" + ruleContext.getAttribute("id") +", bounds=" + JSON.stringify(bounds)+", zindex="+zindex); const mapper : DOMMapper = new DOMMapper(); let violations = []; elems.forEach(elem => { - // Skip hidden - if (VisUtil.isNodeVisible(elem)) { + if (VisUtil.isNodeVisible(elem) && !ruleContext.contains(elem) && !elem.contains(ruleContext)) { const bnds = mapper.getBounds(elem); - var zStyle = win.getComputedStyle(elem); + var zStyle = win.getComputedStyle(elem); let z_index; if (zStyle === null) z_index = 0; else { - z_index = zStyle.zIndex; - if (!z_index || !Number.isInteger(z_index)) + z_index = zStyle.zIndex; + if (!z_index || isNaN(z_index)) z_index = "0"; - } + } console.log("element="+elem.nodeName +", id=" + elem.getAttribute("id") +", bnds=" + JSON.stringify(bnds)+", z_index="+z_index); if (bnds.height !== 0 && bnds.width !== 0 && bnds.top <= bounds.top && bnds.left <= bounds.left && bnds.top + bnds.height >= bounds.top + bounds.height && bnds.left + bnds.height >= bounds.left + bounds.width && parseInt(zindex) <= parseInt(z_index)) diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_hidden.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_hidden.html new file mode 100755 index 000000000..de5cdab0b --- /dev/null +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_hidden.html @@ -0,0 +1,101 @@ + + + + + + + + RPT Test Suite + + + + + +
1
+
2
+ + + + + diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_visible.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_visible.html new file mode 100755 index 000000000..11119a2bb --- /dev/null +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_overlaid_visible.html @@ -0,0 +1,101 @@ + + + + + + + + RPT Test Suite + + + + + +
1
+
2
+ + + + + diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/unobscured.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_unobscured.html similarity index 100% rename from accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/unobscured.html rename to accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_unobscured_ruleunit/element_unobscured.html