@@ -21,6 +21,8 @@ const std = @import("std");
2121const parser = @import ("../netsurf.zig" );
2222const SessionState = @import ("../env.zig" ).SessionState ;
2323
24+ const Element = @import ("../dom/element.zig" ).Element ;
25+ const ElementUnion = @import ("../dom/element.zig" ).Union ;
2426const Document = @import ("../dom/document.zig" ).Document ;
2527const NodeList = @import ("../dom/nodelist.zig" ).NodeList ;
2628const Location = @import ("location.zig" ).Location ;
@@ -208,15 +210,16 @@ pub const HTMLDocument = struct {
208210 return "" ;
209211 }
210212
211- pub fn _elementFromPoint (_ : * parser.DocumentHTML , x : f32 , y : f32 , state : * SessionState ) ! ? * parser.Element {
213+ // This returns an ElementUnion instead of a *Parser.Element in case the element somehow hasn't passed through the js runtime yet.
214+ pub fn _elementFromPoint (_ : * parser.DocumentHTML , x : f32 , y : f32 , state : * SessionState ) ! ? ElementUnion {
212215 const ix : i32 = @intFromFloat (@floor (x ));
213216 const iy : i32 = @intFromFloat (@floor (y ));
214217 const element = state .renderer .getElementAtPosition (ix , iy ) orelse return null ;
215218 // TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
216- return element ;
219+ return try Element . toInterface ( element ) ;
217220 }
218221
219- pub fn _elementsFromPoint (_ : * parser.DocumentHTML , x : f32 , y : f32 , state : * SessionState ) ! []* parser.Element {
222+ pub fn _elementsFromPoint (_ : * parser.DocumentHTML , x : f32 , y : f32 , state : * SessionState ) ! []ElementUnion {
220223 const ix : i32 = @intFromFloat (@floor (x ));
221224 const iy : i32 = @intFromFloat (@floor (y ));
222225 const element = state .renderer .getElementAtPosition (ix , iy ) orelse return &.{};
@@ -225,8 +228,8 @@ pub const HTMLDocument = struct {
225228 // We need to return either 0 or 1 item, so we cannot fix the size to [1]*parser.Element
226229 // Converting the pointer to a slice []parser.Element is not supported by our framework.
227230 // So instead we just need to allocate the pointer to create a slice of 1.
228- const heap_ptr = try state .call_arena .create (@TypeOf ( element ) );
229- heap_ptr .* = element ;
231+ const heap_ptr = try state .call_arena .create (ElementUnion );
232+ heap_ptr .* = try Element . toInterface ( element ) ;
230233 return heap_ptr [0.. 1];
231234 }
232235};
0 commit comments