Skip to content

Commit

Permalink
fix merge error #1974
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Oct 22, 2024
1 parent 39a7cdd commit 1976f5a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const element_orientation_unlocked: Rule = {
let media_transforms = [];
Object.keys(orientationTransforms).forEach(key => {
Object.keys(orientationTransforms[key]).forEach(tag => {
if (Object.keys(orientationTransforms[key][tag]).length > 0 && CSSUtil.selectorMatchesElem(ruleContext, tag))
if (Object.keys(orientationTransforms[key][tag]).length > 0 && CSSUtil.selectorMatchesElem(ruleContext, tag)) {
if (orientationTransforms[key][tag].transform)
media_transforms.push(orientationTransforms[key][tag].transform);
else
Expand Down
9 changes: 5 additions & 4 deletions accessibility-checker-engine/src/v4/rules/img_alt_null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { Rule, RuleResult, RuleFail, RulePotential, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { CommonUtil } from "../util/CommonUtil";
import { VisUtil } from "../util/VisUtil";
import { AriaUtil } from "../util/AriaUtil";
import { CommonUtil } from "../util/CommonUtil";

export const img_alt_null: Rule = {
id: "img_alt_null",
Expand Down Expand Up @@ -55,9 +56,9 @@ export const img_alt_null: Rule = {
return null;
}
// We have a title, but alt is empty
if (RPTUtil.getAriaLabel(ruleContext).length > 0) {
if (AriaUtil.getAriaLabel(ruleContext).length > 0) {
return RulePotential("potential_aria_override");
} else if (RPTUtil.attributeNonEmpty(ruleContext, "title")) {
} else if (CommonUtil.attributeNonEmpty(ruleContext, "title")) {
return RuleFail("fail_decorative");
} else {
return RulePass("pass");
Expand Down
93 changes: 47 additions & 46 deletions accessibility-checker-engine/src/v4/util/CSSUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,62 +239,63 @@ export class CSSUtil {
}
}

/**
* Returns the media query defined for the document
*
*
* @param {Document} doc
*/
export function getMediaOrientationTransform(doc: Document) {
let orientationTransforms = {}

// Iterate through all of the stylesheets and rules
for (let ssIndex = 0; ssIndex < doc.styleSheets.length; ++ssIndex) {
const sheet = doc.styleSheets[ssIndex] as CSSStyleSheet;
try {
if (sheet && sheet.cssRules) {
for (let rIndex = 0; rIndex < sheet.cssRules.length; ++rIndex) {
const sheetRule = sheet.cssRules[rIndex];
if (4 /* CSSRule.MEDIA_RULE */ === sheetRule.MEDIA_RULE) {
const rule = sheetRule as CSSMediaRule;
if (rule && rule.media) {
const mediaList = rule.media;
for (let i = 0; i < mediaList.length; i++) {
let elem_transforms = orientationTransforms[mediaList.item(i).toLocaleLowerCase()];
if (!elem_transforms) elem_transforms = {};
let styleRules = rule.cssRules;
for (let i = 0; i < styleRules.length; ++i) {
if (1 /* CSSRule.STYLE_RULE */ === styleRules[i].STYLE_RULE) {
const styleRule = styleRules[i] as CSSStyleRule;
const selector = styleRule.selectorText;
if (selector) {
let transforms = {};
const styles = styleRule.style;
for (let s=0; s < styles.length; ++s) {
const key = styles[s];
if (key.toLocaleLowerCase() === "transform") {
if (key === "all" && styles[key]) {
delete transforms[key];
break;
} else {
/**
* Returns the media query defined for the document
*
*
* @param {Document} doc
*/
public static getMediaOrientationTransform(doc: Document) {
let orientationTransforms = {}

// Iterate through all of the stylesheets and rules
for (let ssIndex = 0; ssIndex < doc.styleSheets.length; ++ssIndex) {
const sheet = doc.styleSheets[ssIndex] as CSSStyleSheet;
try {
if (sheet && sheet.cssRules) {
for (let rIndex = 0; rIndex < sheet.cssRules.length; ++rIndex) {
const sheetRule = sheet.cssRules[rIndex];
if (4 /* CSSRule.MEDIA_RULE */ === sheetRule.MEDIA_RULE) {
const rule = sheetRule as CSSMediaRule;
if (rule && rule.media) {
const mediaList = rule.media;
for (let i = 0; i < mediaList.length; i++) {
if (!mediaList.item(i)) continue;
let elem_transforms = orientationTransforms[mediaList.item(i).toLocaleLowerCase()];
if (!elem_transforms) elem_transforms = {};
let styleRules = rule.cssRules;
for (let i = 0; i < styleRules.length; ++i) {
if (1 /* CSSRule.STYLE_RULE */ === styleRules[i].STYLE_RULE) {
const styleRule = styleRules[i] as CSSStyleRule;
const selector = styleRule.selectorText;
if (selector) {
let transforms = {};
const styles = styleRule.style;
for (let s = 0; s < styles.length; ++s) {
const key = styles[s];
if (key.toLocaleLowerCase() === "transform") {
if (key === "all" && styles[key]) {
delete transforms[key];
break;
} else {
transforms[key] = styles[key];
}
} else if (key.toLocaleLowerCase() === "rotate") {
transforms[key] = styles[key];
}
} else if (key.toLocaleLowerCase() === "rotate") {
transforms[key] = styles[key];
elem_transforms[selector] =
transforms;
}
elem_transforms[selector] =
transforms;
}
}
if (mediaList.item(i))
orientationTransforms[mediaList.item(i).toLocaleLowerCase()] = elem_transforms;
}
orientationTransforms[
mediaList.item(i).toLocaleLowerCase()
] = elem_transforms;
}
}
}
}
}
}
} catch (err) {
if (
!err.toString().includes("Cannot access rules") &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,22 @@
UnitTest = {
ruleIds: ["aria_accessiblename_exists"],
results: [

{
"ruleId": "aria_accessiblename_exists",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/img[1]",
"aria": "/document[1]/img[1]"
},
"reasonId": "pass",
"message": "An accessible name is provided for the element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
Expand Down

0 comments on commit 1976f5a

Please sign in to comment.