@@ -267,18 +267,25 @@ fn rectToQuad(rect: DOMRect) Quad {
267
267
}
268
268
269
269
fn scrollIntoViewIfNeeded (cmd : anytype ) ! void {
270
- _ = (try cmd .params (struct {
270
+ const params = (try cmd .params (struct {
271
271
nodeId : ? Node.Id = null ,
272
272
backendNodeId : ? u32 = null ,
273
273
objectId : ? []const u8 = null ,
274
274
rect : ? DOMRect = null ,
275
275
})) orelse return error .InvalidParams ;
276
+ // Only 1 of nodeId, backendNodeId, objectId may be set, but chrome just takes the first non-null
276
277
277
- // Only 1 of nodeId, backendNodeId, objectId may be set, but we don't want to error unnecessarily
278
- // TBD what do other browsers do in this user error sceneario?
278
+ // We retrieve the node to at least check if it exists and is valid.
279
+ const bc = cmd .browser_context orelse return error .BrowserContextNotLoaded ;
280
+ const node = try getNode (cmd .arena , bc , params .nodeId , params .backendNodeId , params .objectId );
279
281
280
- // Since element.scrollIntoViewIfNeeded is a no-op we do not bother retrieving the node.
281
- // This however also means we also do not error in case the node is not found.
282
+ const node_type = parser .nodeType (node ._node ) catch return error .InvalidNode ;
283
+ switch (node_type ) {
284
+ .element = > {},
285
+ .document = > {},
286
+ .text = > {},
287
+ else = > return error .NodeDoesNotHaveGeometry ,
288
+ }
282
289
283
290
return cmd .sendResult (null , .{});
284
291
}
@@ -296,6 +303,8 @@ fn getNode(arena: Allocator, browser_context: anytype, node_id: ?Node.Id, backen
296
303
return error .MissingParams ;
297
304
}
298
305
306
+ // https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getContentQuads
307
+ // Related to: https://drafts.csswg.org/cssom-view/#the-geometryutils-interface
299
308
fn getContentQuads (cmd : anytype ) ! void {
300
309
const params = (try cmd .params (struct {
301
310
nodeId : ? Node.Id = null ,
@@ -307,8 +316,15 @@ fn getContentQuads(cmd: anytype) !void {
307
316
308
317
const node = try getNode (cmd .arena , bc , params .nodeId , params .backendNodeId , params .objectId );
309
318
319
+ // TODO likely if the following CSS properties are set the quads should be empty
320
+ // visibility: hidden
321
+ // display: none
322
+
310
323
if (try parser .nodeType (node ._node ) != .element ) return error .NodeIsNotAnElement ;
311
- // TBD should the funcion work on nodes that are not elements, but may have geometry like Window?
324
+ // TODO implement for document or text
325
+ // Most likely document would require some hierachgy in the renderer. It is left unimplemented till we have a good example.
326
+ // Text may be tricky, multiple quads in case of multiple lines? empty quads of text = ""?
327
+ // Elements like SVGElement may have multiple quads.
312
328
313
329
const element = parser .nodeToElement (node ._node );
314
330
const rect = try bc .session .page .? .state .renderer .getRect (element );
0 commit comments