mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
Per the PointerEvents spec and Chromium's behavior, untrusted (JS- constructed) MouseEvent coordinates should be floored to integers. PointerEvent overrides this behavior: for non-click types (pointerdown, pointermove, etc.), fractional coordinates are preserved. For click, auxclick, and contextmenu events, coordinates are floored via the MouseEvent base class. Trusted events (created by the user agent) always preserve fractional coordinate values.
40 lines
1.9 KiB
HTML
40 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
test(() => {
|
|
// MouseEvent should floor all coordinates.
|
|
let e = new MouseEvent("click", { clientX: 10.5, clientY: 20.5, screenX: 30.5, screenY: 40.5 });
|
|
|
|
println(`MouseEvent screenX: ${e.screenX}`);
|
|
println(`MouseEvent screenY: ${e.screenY}`);
|
|
println(`MouseEvent clientX: ${e.clientX}`);
|
|
println(`MouseEvent clientY: ${e.clientY}`);
|
|
println(`MouseEvent pageX: ${e.pageX}`);
|
|
println(`MouseEvent pageY: ${e.pageY}`);
|
|
println(`MouseEvent offsetX: ${e.offsetX}`);
|
|
println(`MouseEvent offsetY: ${e.offsetY}`);
|
|
|
|
// PointerEvent should preserve fractional coordinates for non-click types.
|
|
let pe = new PointerEvent("pointerdown", { clientX: 5.25, clientY: 15.75, screenX: 0.111, screenY: 0.222 });
|
|
|
|
println(`PointerEvent pointerdown screenX: ${pe.screenX}`);
|
|
println(`PointerEvent pointerdown clientX: ${pe.clientX}`);
|
|
println(`PointerEvent pointerdown pageX: ${pe.pageX}`);
|
|
println(`PointerEvent pointerdown offsetX: ${pe.offsetX}`);
|
|
|
|
// PointerEvent click/auxclick/contextmenu should floor coordinates.
|
|
let click = new PointerEvent("click", { clientX: 5.25, clientY: 15.75, screenX: 0.111, screenY: 0.222 });
|
|
|
|
println(`PointerEvent click screenX: ${click.screenX}`);
|
|
println(`PointerEvent click clientX: ${click.clientX}`);
|
|
println(`PointerEvent click pageX: ${click.pageX}`);
|
|
println(`PointerEvent click offsetX: ${click.offsetX}`);
|
|
|
|
let auxclick = new PointerEvent("auxclick", { clientX: 5.25, clientY: 15.75 });
|
|
println(`PointerEvent auxclick clientX: ${auxclick.clientX}`);
|
|
|
|
let ctx = new PointerEvent("contextmenu", { clientX: 5.25, clientY: 15.75 });
|
|
println(`PointerEvent contextmenu clientX: ${ctx.clientX}`);
|
|
});
|
|
</script>
|