Skip to content

fix: roi rectangle adapt to retina display #2059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
59 changes: 34 additions & 25 deletions camel/toolkits/page_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,41 @@ var MultimodalWebSurfer = MultimodalWebSurfer || (function() {
labelElements(getInteractiveElements());
let elements = document.querySelectorAll("[__elementId]");
let results = {};
let scaleFactor = window.devicePixelRatio || 1;
for (let i=0; i<elements.length; i++) {
let key = elements[i].getAttribute("__elementId");
let rects = elements[i].getClientRects();
let ariaRole = getApproximateAriaRole(elements[i]);
let ariaName = getApproximateAriaName(elements[i]);
let vScrollable = elements[i].scrollHeight - elements[i].clientHeight >= 1;

let record = {
"tag_name": ariaRole[1],
"role": ariaRole[0],
"aria-name": ariaName,
"v-scrollable": vScrollable,
"rects": []
};

for (const rect of rects) {
let x = rect.left + rect.width/2;
let y = rect.top + rect.height/2;
if (isTopmost(elements[i], x, y)) {
record["rects"].push(JSON.parse(JSON.stringify(rect)));
}
}

if (record["rects"].length > 0) {
results[key] = record;
}
let key = elements[i].getAttribute("__elementId");
let rects = elements[i].getClientRects();
let ariaRole = getApproximateAriaRole(elements[i]);
let ariaName = getApproximateAriaName(elements[i]);
let vScrollable = elements[i].scrollHeight - elements[i].clientHeight >= 1;

let record = {
"tag_name": ariaRole[1],
"role": ariaRole[0],
"aria-name": ariaName,
"v-scrollable": vScrollable,
"rects": []
};

for (const rect of rects) {
let x = rect.left + rect.width/2;
let y = rect.top + rect.height/2;
if (isTopmost(elements[i], x, y)) {
record["rects"].push({
left: rect.left * scaleFactor,
top: rect.top * scaleFactor,
right: rect.right * scaleFactor,
bottom: rect.bottom * scaleFactor,
width: rect.width * scaleFactor,
height: rect.height * scaleFactor,
x: rect.x * scaleFactor,
y: rect.y * scaleFactor
});
}
}
if (record["rects"].length > 0) {
results[key] = record;
}
}
return results;
};
Expand Down
Loading