mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
elementsFromPoint cleanup
This commit is contained in:
@@ -384,7 +384,7 @@ pub const Element = struct {
|
|||||||
if (root != parser.documentToNode(parser.documentHTMLToDocument(state.document.?))) {
|
if (root != parser.documentToNode(parser.documentHTMLToDocument(state.document.?))) {
|
||||||
return &.{};
|
return &.{};
|
||||||
}
|
}
|
||||||
const heap_ptr = try state.arena.create(DOMRect);
|
const heap_ptr = try state.call_arena.create(DOMRect);
|
||||||
heap_ptr.* = try state.renderer.getRect(self);
|
heap_ptr.* = try state.renderer.getRect(self);
|
||||||
return heap_ptr[0..1];
|
return heap_ptr[0..1];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ pub const HTMLDocument = struct {
|
|||||||
|
|
||||||
// Returns the topmost Element at the specified coordinates (relative to the viewport).
|
// Returns the topmost Element at the specified coordinates (relative to the viewport).
|
||||||
// Since LightPanda requires the client to know what they are clicking on we do not return the underlying element at this moment
|
// 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 click without having rendered any element. This will change when css properties are supported.
|
// 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.
|
// 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, state: *SessionState) !?ElementUnion {
|
pub fn _elementFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, state: *SessionState) !?ElementUnion {
|
||||||
const ix: i32 = @intFromFloat(@floor(x));
|
const ix: i32 = @intFromFloat(@floor(x));
|
||||||
@@ -247,8 +247,9 @@ pub const HTMLDocument = struct {
|
|||||||
const element = state.renderer.getElementAtPosition(ix, iy) orelse return &.{};
|
const element = state.renderer.getElementAtPosition(ix, iy) orelse return &.{};
|
||||||
// TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
|
// TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
|
||||||
|
|
||||||
var list = try std.ArrayList(ElementUnion).initCapacity(state.call_arena, 3);
|
var list: std.ArrayListUnmanaged(ElementUnion) = .empty;
|
||||||
try list.append(try Element.toInterface(element));
|
try list.ensureTotalCapacity(state.call_arena, 3);
|
||||||
|
list.appendAssumeCapacity(try Element.toInterface(element));
|
||||||
|
|
||||||
// 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.
|
// 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.
|
||||||
// Thus we can add the HtmlHtmlElement and it's child HTMLBodyElement to the returned list.
|
// Thus we can add the HtmlHtmlElement and it's child HTMLBodyElement to the returned list.
|
||||||
@@ -257,13 +258,10 @@ pub const HTMLDocument = struct {
|
|||||||
const doc_elem = try parser.documentGetDocumentElement(parser.documentHTMLToDocument(state.document.?)) orelse {
|
const doc_elem = try parser.documentGetDocumentElement(parser.documentHTMLToDocument(state.document.?)) orelse {
|
||||||
return list.items;
|
return list.items;
|
||||||
};
|
};
|
||||||
const body = try parser.documentHTMLBody(state.document.?) orelse {
|
if (try parser.documentHTMLBody(state.document.?)) |body| {
|
||||||
try list.append(try Element.toInterface(doc_elem));
|
list.appendAssumeCapacity(try Element.toInterface(parser.bodyToElement(body)));
|
||||||
return list.items;
|
}
|
||||||
};
|
list.appendAssumeCapacity(try Element.toInterface(doc_elem));
|
||||||
|
|
||||||
try list.append(try Element.toInterface(parser.bodyToElement(body)));
|
|
||||||
try list.append(try Element.toInterface(doc_elem));
|
|
||||||
return list.items;
|
return list.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user