Skip to content

Commit

Permalink
VHints: check aria-hidden on SVG elements
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Jan 7, 2020
1 parent 7892a8d commit 8e11554
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions content/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ interface KeydownCacheArray extends SafeObject {
[keyCode: number]: BOOL | 2 | undefined;
}

declare const enum kAria {
hidden = 1, disabled = 2,
}

/**
* only Element has string .tagName, .id
*
Expand Down
6 changes: 3 additions & 3 deletions content/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ if (Build.BTypes & BrowserType.Chrome && Build.BTypes & ~BrowserType.Chrome) { v
}
return true;
},
GetButtons_ (this: void, hints: SafeHTMLElement[], element: Element): void {
GetButtons_: function (this: void, hints, element): void {
let s: string | null;
const tag = element.localName, isClickable = tag === "a" || tag && (
tag === "button" ? !(element as HTMLButtonElement).disabled
Expand All @@ -855,12 +855,12 @@ if (Build.BTypes & BrowserType.Chrome && Build.BTypes & ~BrowserType.Chrome) { v
(s = element.getAttribute("role")) ? (<RegExpI> /^(button|link)$/i).test(s)
: Hints.ngEnabled_ && element.getAttribute("ng-click")));
if (!isClickable) { return; }
if ((s = element.getAttribute("aria-disabled")) != null && (!s || s.toLowerCase() === "true")) { return; }
if (!D.isAriaNotTrue_(element, kAria.disabled)) { return; }
const rect = D.getBoundingClientRect_(element);
if (rect.width > 2 && rect.height > 2 && getComputedStyle(element).visibility === "visible") {
hints.push(element as SafeHTMLElement);
}
},
} as HintsNS.Filter<SafeHTMLElement>,
findAndFollowLink_ (names: string[], isNext: boolean, lenLimit: number[], totalMax: number): boolean {
interface Candidate { [0]: number; [1]: string; [2]: Parameters<typeof Pagination.GetButtons_>[0][number]; }
// Note: this traverser should not need a prepareCrop
Expand Down
10 changes: 6 additions & 4 deletions content/link_hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,8 @@ var VHints = {
&& (arr = arr || VDom.getVisibleClientRect_(element))
&& (type < ClickType.scrollX
|| VSc.shouldScroll_need_safe_(element, type - ClickType.scrollX as 0 | 1) > 0)
&& ((s = element.getAttribute("aria-hidden")) == null || s && s.toLowerCase() !== "true")
&& ((s = element.getAttribute("aria-disabled")) == null || (s && s.toLowerCase() !== "true")
|| _this.mode_ > HintMode.min_job - 1)
&& VDom.isAriaNotTrue_(element, kAria.hidden)
&& (_this.mode_ > HintMode.min_job - 1 || VDom.isAriaNotTrue_(element, kAria.disabled))
) { hints.push([element, tag === "img" ? VDom.getCroppedRect_(element, arr) : arr, type]); }
},
_getClickableInMaybeSVG (hints: Hint[], element: SVGElement | Element): void {
Expand All @@ -534,7 +533,10 @@ var VHints = {
? ClickType.attrListener
: (element as SVGElement).tabIndex >= 0 ? ClickType.tabindex
: ClickType.Default;
if (type > ClickType.Default && (arr = VDom.getVisibleClientRect_(element))) {
if (type > ClickType.Default && (arr = VDom.getVisibleClientRect_(element))
&& VDom.isAriaNotTrue_(element as SafeElement, kAria.hidden)
&& (this.mode_ > HintMode.min_job - 1 || VDom.isAriaNotTrue_(element as SafeElement, kAria.disabled))
) {
hints.push([element as SVGElement, arr, type]);
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/dom_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ var VDom = {
return "";
} : (element: Element): string => "lang" in element ? (element as SafeHTMLElement).localName as string : ""
) as (element: Element) => string, // duplicate the signature, for easier F12 in VS Code
isAriaNotTrue_ (element: SafeElement, ariaType: kAria): boolean {
let s = element.getAttribute(ariaType ? "aria-disabled" : "aria-hidden");
return s == null || (!!s && s.toLowerCase() !== "true");
},
isInTouchMode_: Build.BTypes & BrowserType.Chrome ? function (): boolean {
const viewport = document.querySelector("meta[name=viewport]");
return !!viewport &&
Expand Down

0 comments on commit 8e11554

Please sign in to comment.