Skip to content

Commit

Permalink
fix the bound issue #1674
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Oct 30, 2023
1 parent 4ef2326 commit ada4f8e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion accessibility-checker-engine/src/v2/dom/DOMMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export class DOMMapper extends CommonMapper {
return retVal;
}

getBounds(node: Node) : Bounds {
/**
* get scaled bounds for screenshot etc. adjusted for devicePixelRatio and scroll
* @param node
* @returns
*/
getAdjustedBounds(node: Node) : Bounds {
if (node.nodeType === 1 /*Node.ELEMENT_NODE*/) {
let adjustment = 1;
if (node.ownerDocument && node.ownerDocument.defaultView && node.ownerDocument.defaultView.devicePixelRatio) {
Expand All @@ -59,4 +64,29 @@ export class DOMMapper extends CommonMapper {

return null;
}

/**
* get real CSS bounds in css pixels, adjusted for scroll only
* @param node
* @returns
*/
getBounds(node: Node) : Bounds {
if (node.nodeType === 1 /*Node.ELEMENT_NODE*/) {
const bounds = (node as Element).getBoundingClientRect();

// adjusted for scroll if any
if (bounds) {
let scrollX = node && node.ownerDocument && node.ownerDocument.defaultView && node.ownerDocument.defaultView.scrollX || 0;
let scrollY = node && node.ownerDocument && node.ownerDocument.defaultView && node.ownerDocument.defaultView.scrollY || 0;
return {
"left": Math.ceil(bounds.left + scrollX),
"top": Math.ceil(bounds.top + scrollY),
"height": Math.ceil(bounds.height),
"width": Math.ceil(bounds.width)
};
}
}

return null;
}
}

0 comments on commit ada4f8e

Please sign in to comment.