mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 08:18:59 +00:00
Allign error detection
This commit is contained in:
@@ -267,18 +267,25 @@ fn rectToQuad(rect: DOMRect) Quad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn scrollIntoViewIfNeeded(cmd: anytype) !void {
|
fn scrollIntoViewIfNeeded(cmd: anytype) !void {
|
||||||
_ = (try cmd.params(struct {
|
const params = (try cmd.params(struct {
|
||||||
nodeId: ?Node.Id = null,
|
nodeId: ?Node.Id = null,
|
||||||
backendNodeId: ?u32 = null,
|
backendNodeId: ?u32 = null,
|
||||||
objectId: ?[]const u8 = null,
|
objectId: ?[]const u8 = null,
|
||||||
rect: ?DOMRect = null,
|
rect: ?DOMRect = null,
|
||||||
})) orelse return error.InvalidParams;
|
})) orelse return error.InvalidParams;
|
||||||
|
// Only 1 of nodeId, backendNodeId, objectId may be set, but chrome just takes the first non-null
|
||||||
|
|
||||||
// Only 1 of nodeId, backendNodeId, objectId may be set, but we don't want to error unnecessarily
|
// We retrieve the node to at least check if it exists and is valid.
|
||||||
// TBD what do other browsers do in this user error sceneario?
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||||
|
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
|
||||||
|
|
||||||
// Since element.scrollIntoViewIfNeeded is a no-op we do not bother retrieving the node.
|
const node_type = parser.nodeType(node._node) catch return error.InvalidNode;
|
||||||
// This however also means we also do not error in case the node is not found.
|
switch (node_type) {
|
||||||
|
.element => {},
|
||||||
|
.document => {},
|
||||||
|
.text => {},
|
||||||
|
else => return error.NodeDoesNotHaveGeometry,
|
||||||
|
}
|
||||||
|
|
||||||
return cmd.sendResult(null, .{});
|
return cmd.sendResult(null, .{});
|
||||||
}
|
}
|
||||||
@@ -296,6 +303,8 @@ fn getNode(arena: Allocator, browser_context: anytype, node_id: ?Node.Id, backen
|
|||||||
return error.MissingParams;
|
return error.MissingParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getContentQuads
|
||||||
|
// Related to: https://drafts.csswg.org/cssom-view/#the-geometryutils-interface
|
||||||
fn getContentQuads(cmd: anytype) !void {
|
fn getContentQuads(cmd: anytype) !void {
|
||||||
const params = (try cmd.params(struct {
|
const params = (try cmd.params(struct {
|
||||||
nodeId: ?Node.Id = null,
|
nodeId: ?Node.Id = null,
|
||||||
@@ -307,8 +316,15 @@ fn getContentQuads(cmd: anytype) !void {
|
|||||||
|
|
||||||
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
|
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
|
||||||
|
|
||||||
|
// TODO likely if the following CSS properties are set the quads should be empty
|
||||||
|
// visibility: hidden
|
||||||
|
// display: none
|
||||||
|
|
||||||
if (try parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
|
if (try parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
|
||||||
// TBD should the funcion work on nodes that are not elements, but may have geometry like Window?
|
// TODO implement for document or text
|
||||||
|
// Most likely document would require some hierachgy in the renderer. It is left unimplemented till we have a good example.
|
||||||
|
// Text may be tricky, multiple quads in case of multiple lines? empty quads of text = ""?
|
||||||
|
// Elements like SVGElement may have multiple quads.
|
||||||
|
|
||||||
const element = parser.nodeToElement(node._node);
|
const element = parser.nodeToElement(node._node);
|
||||||
const rect = try bc.session.page.?.state.renderer.getRect(element);
|
const rect = try bc.session.page.?.state.renderer.getRect(element);
|
||||||
|
|||||||
Reference in New Issue
Block a user