Skip to content

Commit 032d381

Browse files
committed
elementsFromPoint cleanup
1 parent 674743f commit 032d381

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
@@ -217,7 +217,7 @@ pub const HTMLDocument = struct {
217217

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

237-
var list = try std.ArrayList(ElementUnion).initCapacity(state.call_arena, 3);
238-
try list.append(try Element.toInterface(element));
237+
var list: std.ArrayListUnmanaged(ElementUnion) = .empty;
238+
try list.ensureTotalCapacity(state.call_arena, 3);
239+
list.appendAssumeCapacity(try Element.toInterface(element));
239240

240241
// 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.
241242
// Thus we can add the HtmlHtmlElement and it's child HTMLBodyElement to the returned list.
@@ -244,13 +245,10 @@ pub const HTMLDocument = struct {
244245
const doc_elem = try parser.documentGetDocumentElement(parser.documentHTMLToDocument(state.document.?)) orelse {
245246
return list.items;
246247
};
247-
const body = try parser.documentHTMLBody(state.document.?) orelse {
248-
try list.append(try Element.toInterface(doc_elem));
249-
return list.items;
250-
};
251-
252-
try list.append(try Element.toInterface(parser.bodyToElement(body)));
253-
try list.append(try Element.toInterface(doc_elem));
248+
if (try parser.documentHTMLBody(state.document.?)) |body| {
249+
list.appendAssumeCapacity(try Element.toInterface(parser.bodyToElement(body)));
250+
}
251+
list.appendAssumeCapacity(try Element.toInterface(doc_elem));
254252
return list.items;
255253
}
256254
};

0 commit comments

Comments
 (0)