Files
ladybird/Tests/LibWeb/Text/input/UIEvents/MouseEvent-constructed-coordinates.html
Andreas Kling 2a547ec687 LibWeb: Initialize pageX/pageY and offsetX/offsetY in event constructors
When constructing MouseEvent, PointerEvent, DragEvent, or WheelEvent
from JavaScript, pageX/pageY and offsetX/offsetY were left at 0
instead of being initialized from clientX/clientY.

Per the CSSOM View spec, pageX should be clientX + scrollX (which is 0
for a newly constructed event with no associated window), and offsetX
should be clientX minus the target's bounding rect origin (which is 0
for an event with no target). So both should default to clientX.
2026-03-08 18:09:10 +01:00

26 lines
993 B
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
// Constructed MouseEvent should initialize pageX/pageY and offsetX/offsetY from clientX/clientY.
let e = new MouseEvent("click", { clientX: 10.5, clientY: 20.5, screenX: 30.5, screenY: 40.5 });
println(`screenX: ${e.screenX}`);
println(`screenY: ${e.screenY}`);
println(`clientX: ${e.clientX}`);
println(`clientY: ${e.clientY}`);
println(`pageX: ${e.pageX}`);
println(`pageY: ${e.pageY}`);
println(`offsetX: ${e.offsetX}`);
println(`offsetY: ${e.offsetY}`);
// PointerEvent should behave the same way.
let pe = new PointerEvent("pointerdown", { clientX: 5.25, clientY: 15.75 });
println(`PointerEvent pageX: ${pe.pageX}`);
println(`PointerEvent pageY: ${pe.pageY}`);
println(`PointerEvent offsetX: ${pe.offsetX}`);
println(`PointerEvent offsetY: ${pe.offsetY}`);
});
</script>