Skip to content

Commit c9ce527

Browse files
committed
elementsFromPoint cleanup
1 parent 8d892d2 commit c9ce527

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/browser/dom/element.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub const Element = struct {
384384
if (root != parser.documentToNode(parser.documentHTMLToDocument(state.document.?))) {
385385
return &.{};
386386
}
387-
const heap_ptr = try state.arena.create(DOMRect);
387+
const heap_ptr = try state.call_arena.create(DOMRect);
388388
heap_ptr.* = try state.renderer.getRect(self);
389389
return heap_ptr[0..1];
390390
}

src/browser/html/document.zig

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub const HTMLDocument = struct {
230230

231231
// Returns the topmost Element at the specified coordinates (relative to the viewport).
232232
// Since LightPanda requires the client to know what they are clicking on we do not return the underlying element at this moment
233-
// This can currenty only happen if the first pixel is click without having rendered any element. This will change when css properties are supported.
233+
// This can currenty only happen if the first pixel is clicked without having rendered any element. This will change when css properties are supported.
234234
// This returns an ElementUnion instead of a *Parser.Element in case the element somehow hasn't passed through the js runtime yet.
235235
pub fn _elementFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, state: *SessionState) !?ElementUnion {
236236
const ix: i32 = @intFromFloat(@floor(x));
@@ -247,8 +247,9 @@ pub const HTMLDocument = struct {
247247
const element = state.renderer.getElementAtPosition(ix, iy) orelse return &.{};
248248
// TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
249249

250-
var list = try std.ArrayList(ElementUnion).initCapacity(state.call_arena, 3);
251-
try list.append(try Element.toInterface(element));
250+
var list: std.ArrayListUnmanaged(ElementUnion) = .empty;
251+
try list.ensureTotalCapacity(state.call_arena, 3);
252+
list.appendAssumeCapacity(try Element.toInterface(element));
252253

253254
// Since we are using a flat renderer there is no hierarchy of elements. What we do know is that the element is part of the main document.
254255
// Thus we can add the HtmlHtmlElement and it's child HTMLBodyElement to the returned list.
@@ -257,13 +258,10 @@ pub const HTMLDocument = struct {
257258
const doc_elem = try parser.documentGetDocumentElement(parser.documentHTMLToDocument(state.document.?)) orelse {
258259
return list.items;
259260
};
260-
const body = try parser.documentHTMLBody(state.document.?) orelse {
261-
try list.append(try Element.toInterface(doc_elem));
262-
return list.items;
263-
};
264-
265-
try list.append(try Element.toInterface(parser.bodyToElement(body)));
266-
try list.append(try Element.toInterface(doc_elem));
261+
if (try parser.documentHTMLBody(state.document.?)) |body| {
262+
list.appendAssumeCapacity(try Element.toInterface(parser.bodyToElement(body)));
263+
}
264+
list.appendAssumeCapacity(try Element.toInterface(doc_elem));
267265
return list.items;
268266
}
269267

0 commit comments

Comments
 (0)