Skip to content

Commit ed31a45

Browse files
committed
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.
1 parent f51ee7f commit ed31a45

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/browser/html/document.zig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,15 @@ pub const HTMLDocument = struct {
233233
// Since LightPanda requires the client to know what they are clicking on we do not return the underlying element at this moment
234234
// This can currenty only happen if the first pixel is clicked without having rendered any element. This will change when css properties are supported.
235235
// This returns an ElementUnion instead of a *Parser.Element in case the element somehow hasn't passed through the js runtime yet.
236-
pub fn _elementFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, page: *Page) !?ElementUnion {
237-
const ix: i32 = @intFromFloat(@floor(x));
238-
const iy: i32 = @intFromFloat(@floor(y));
239-
const element = page.renderer.getElementAtPosition(ix, iy) orelse return null;
236+
pub fn _elementFromPoint(_: *parser.DocumentHTML, x: i32, y: i32, page: *Page) !?ElementUnion {
237+
const element = page.renderer.getElementAtPosition(x, y) orelse return null;
240238
// TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
241239
return try Element.toInterface(element);
242240
}
243241

244242
// 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.
245-
pub fn _elementsFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, page: *Page) ![]ElementUnion {
246-
const ix: i32 = @intFromFloat(@floor(x));
247-
const iy: i32 = @intFromFloat(@floor(y));
248-
const element = page.renderer.getElementAtPosition(ix, iy) orelse return &.{};
243+
pub fn _elementsFromPoint(_: *parser.DocumentHTML, x: i32, y: i32, page: *Page) ![]ElementUnion {
244+
const element = page.renderer.getElementAtPosition(x, y) orelse return &.{};
249245
// TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
250246

251247
var list: std.ArrayListUnmanaged(ElementUnion) = .empty;

0 commit comments

Comments
 (0)