From ed31a452b20426f08050fb59e18b9e2e4c9dc6d6 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 4 Jul 2025 11:34:34 +0800 Subject: [PATCH] Rely on js.zig for float->int translation Not only does this ensure compatibility with browsers, it doesn't crash when the value is NaN of Infinity. --- src/browser/html/document.zig | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/browser/html/document.zig b/src/browser/html/document.zig index ed406ea5..5544060f 100644 --- a/src/browser/html/document.zig +++ b/src/browser/html/document.zig @@ -233,19 +233,15 @@ pub const HTMLDocument = struct { // Since LightPanda requires the client to know what they are clicking on we do not return the underlying element at this moment // This can currenty only happen if the first pixel is clicked without having rendered any element. This will change when css properties are supported. // This returns an ElementUnion instead of a *Parser.Element in case the element somehow hasn't passed through the js runtime yet. - pub fn _elementFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, page: *Page) !?ElementUnion { - const ix: i32 = @intFromFloat(@floor(x)); - const iy: i32 = @intFromFloat(@floor(y)); - const element = page.renderer.getElementAtPosition(ix, iy) orelse return null; + pub fn _elementFromPoint(_: *parser.DocumentHTML, x: i32, y: i32, page: *Page) !?ElementUnion { + const element = page.renderer.getElementAtPosition(x, y) orelse return null; // TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?) return try Element.toInterface(element); } // Returns an array of all elements at the specified coordinates (relative to the viewport). The elements are ordered from the topmost to the bottommost box of the viewport. - pub fn _elementsFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, page: *Page) ![]ElementUnion { - const ix: i32 = @intFromFloat(@floor(x)); - const iy: i32 = @intFromFloat(@floor(y)); - const element = page.renderer.getElementAtPosition(ix, iy) orelse return &.{}; + pub fn _elementsFromPoint(_: *parser.DocumentHTML, x: i32, y: i32, page: *Page) ![]ElementUnion { + const element = page.renderer.getElementAtPosition(x, y) orelse return &.{}; // TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?) var list: std.ArrayListUnmanaged(ElementUnion) = .empty;