mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(clicking): handle negative area results in computeQuadArea (#3413)
This patch fixes a case in which computeQuadArea calculates the area size correctly, but returns the area as a negative number. This occurs when DOM.getContentQuads returns quads in a specific order. E.g. the array: [ { x: 463, y: 68.5 },{ x: 437, y: 68.5 },{ x: 437, y: 94.5 },{ x: 463, y: 94.5 } ] will receive area size of -676.
This commit is contained in:
parent
fae441cd42
commit
81edbbb58e
@ -626,7 +626,7 @@ function computeQuadArea(quad) {
|
|||||||
const p2 = quad[(i + 1) % quad.length];
|
const p2 = quad[(i + 1) % quad.length];
|
||||||
area += (p1.x * p2.y - p2.x * p1.y) / 2;
|
area += (p1.x * p2.y - p2.x * p1.y) / 2;
|
||||||
}
|
}
|
||||||
return area;
|
return Math.abs(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.tracePublicAPI(ElementHandle);
|
helper.tracePublicAPI(ElementHandle);
|
||||||
|
21
test/assets/input/rotatedButton.html
Normal file
21
test/assets/input/rotatedButton.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Rotated button test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="mouse-helper.js"></script>
|
||||||
|
<button onclick="clicked();">Click target</button>
|
||||||
|
<style>
|
||||||
|
button {
|
||||||
|
transform: rotateY(180deg);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
window.result = 'Was not clicked';
|
||||||
|
function clicked() {
|
||||||
|
result = 'Clicked';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -312,6 +312,11 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
await page.click('button');
|
await page.click('button');
|
||||||
expect(await page.evaluate(() => window.result)).toBe('Clicked');
|
expect(await page.evaluate(() => window.result)).toBe('Clicked');
|
||||||
});
|
});
|
||||||
|
it('should click a rotated button', async({page, server}) => {
|
||||||
|
await page.goto(server.PREFIX + '/input/rotatedButton.html');
|
||||||
|
await page.click('button');
|
||||||
|
expect(await page.evaluate(() => result)).toBe('Clicked');
|
||||||
|
});
|
||||||
it('should select the text with mouse', async({page, server}) => {
|
it('should select the text with mouse', async({page, server}) => {
|
||||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||||
await page.focus('textarea');
|
await page.focus('textarea');
|
||||||
|
Loading…
Reference in New Issue
Block a user