Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/commons/dom/create-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default function createGrid(
) {
// Prevent multiple calls per run
if (cache.get('gridCreated') && !parentVNode) {
if (cache.get('gridSize')) {
return cache.get('gridSize');
}
return constants.gridSize;
}
cache.set('gridCreated', true);
Expand Down Expand Up @@ -110,6 +113,10 @@ export default function createGrid(

node = treeWalker.nextNode();
}

if (cache.get('gridSize')) {
return cache.get('gridSize');
}
return constants.gridSize;
}

Expand Down Expand Up @@ -430,6 +437,9 @@ class Grid {
* @returns {number}
*/
toGridIndex(num) {
if (cache.get('gridSize')) {
return Math.floor(num / cache.get('gridSize'));
}
return Math.floor(num / constants.gridSize);
}

Expand Down
11 changes: 9 additions & 2 deletions lib/commons/dom/get-element-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import createGrid from './create-grid';
* @param {Node} node
* @return {Node[]}
*/
function getElementStack(node) {
function getElementStack(node, isCoordsPassed = false, x, y) {
createGrid();

const vNode = getNodeFromTree(node);
Expand All @@ -19,7 +19,14 @@ function getElementStack(node) {
return [];
}

return getRectStack(grid, vNode.boundingClientRect);
return getRectStack(
grid,
vNode.boundingClientRect,
false,
isCoordsPassed,
x,
y
);
}

export default getElementStack;
15 changes: 13 additions & 2 deletions lib/commons/dom/get-overflow-hidden-ancestors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cache from '../../core/base/cache';
import memoize from '../../core/utils/memoize';

/**
Expand All @@ -17,8 +18,18 @@ const getOverflowHiddenAncestors = memoize(

const overflow = vNode.getComputedStylePropertyValue('overflow');

if (overflow === 'hidden') {
ancestors.push(vNode);
if (cache.get('200%ZoomRule')) {
if (
overflow.includes('hidden') ||
overflow.includes('clip') ||
overflow.includes('scroll')
) {
ancestors.push(vNode);
}
} else {
if (overflow.includes('hidden')) {
ancestors.push(vNode);
}
}

return ancestors.concat(getOverflowHiddenAncestors(vNode.parent));
Expand Down
19 changes: 16 additions & 3 deletions lib/commons/dom/get-rect-stack.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import visuallySort from './visually-sort';
import { getRectCenter } from '../math';

export function getRectStack(grid, rect, recursed = false) {
export function getRectStack(
grid,
rect,
recursed = false,
isCoordsPassed,
x,
y
) {
const center = getRectCenter(rect);
const gridCell = grid.getCellFromPoint(center) || [];

const floorX = Math.floor(center.x);
const floorY = Math.floor(center.y);
let floorX = Math.floor(center.x);
let floorY = Math.floor(center.y);

if (isCoordsPassed) {
floorX = Math.floor(x);
floorY = Math.floor(y);
}

let stack = gridCell.filter(gridCellNode => {
return gridCellNode.clientRects.some(clientRect => {
const rectX = clientRect.left;
Expand Down
12 changes: 10 additions & 2 deletions lib/commons/dom/get-visible-child-text-rects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getNodeFromTree, memoize } from '../../core/utils';
import { sanitize } from '../text';
import { getRectCenter, isPointInRect, getIntersectionRect } from '../math';
import { getIntersectionRect, getRectCenter, isPointInRect } from '../math';
import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors';
import cache from '../../core/base/cache';

/**
* Get the visible text client rects of a node.
Expand All @@ -23,13 +24,19 @@ const getVisibleChildTextRects = memoize(
}

const contentRects = getContentRects(textNode);
if (isOutsideNodeBounds(contentRects, nodeRect)) {
if (
isOutsideNodeBounds(contentRects, nodeRect) &&
!cache.get('200%ZoomRule')
) {
return;
}

clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes));
});

if (clientRects.length <= 0 && cache.get('200%ZoomRule')) {
return [];
}
/**
* if all text rects are larger than the bounds of the node,
* or goes outside of the bounds of the node, we need to use
Expand All @@ -44,6 +51,7 @@ const getVisibleChildTextRects = memoize(
*
* @see https://github.com/dequelabs/axe-core/issues/4253
*/

return clientRects.length
? clientRects
: filterHiddenRects([nodeRect], overflowHiddenNodes);
Expand Down
Loading