mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
cdp: sent setchildnodes once per node
This commit is contained in:
@@ -29,6 +29,7 @@ const Node = @This();
|
|||||||
|
|
||||||
id: Id,
|
id: Id,
|
||||||
_node: *parser.Node,
|
_node: *parser.Node,
|
||||||
|
set_child_nodes_event: bool,
|
||||||
|
|
||||||
// Whenever we send a node to the client, we register it here for future lookup.
|
// Whenever we send a node to the client, we register it here for future lookup.
|
||||||
// We maintain a node -> id and id -> node lookup.
|
// We maintain a node -> id and id -> node lookup.
|
||||||
@@ -85,6 +86,7 @@ pub const Registry = struct {
|
|||||||
node.* = .{
|
node.* = .{
|
||||||
._node = n,
|
._node = n,
|
||||||
.id = id,
|
.id = id,
|
||||||
|
.set_child_nodes_event = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
node_lookup_gop.value_ptr.* = node;
|
node_lookup_gop.value_ptr.* = node;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ fn performSearch(cmd: anytype) !void {
|
|||||||
// dispatchSetChildNodes send the setChildNodes event for the whole DOM tree
|
// dispatchSetChildNodes send the setChildNodes event for the whole DOM tree
|
||||||
// hierarchy of each nodes.
|
// hierarchy of each nodes.
|
||||||
// We dispatch event in the reverse order: from the top level to the direct parents.
|
// We dispatch event in the reverse order: from the top level to the direct parents.
|
||||||
// TODO we should dispatch a node only if it has never been sent.
|
// We should dispatch a node only if it has never been sent.
|
||||||
fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
||||||
const arena = cmd.arena;
|
const arena = cmd.arena;
|
||||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||||
@@ -103,6 +103,7 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
|||||||
|
|
||||||
// Register the node.
|
// Register the node.
|
||||||
const node = try bc.node_registry.register(p);
|
const node = try bc.node_registry.register(p);
|
||||||
|
if (node.set_child_nodes_event) break;
|
||||||
try parents.append(arena, node);
|
try parents.append(arena, node);
|
||||||
n = p;
|
n = p;
|
||||||
}
|
}
|
||||||
@@ -111,14 +112,13 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
|||||||
const plen = parents.items.len;
|
const plen = parents.items.len;
|
||||||
if (plen == 0) return;
|
if (plen == 0) return;
|
||||||
|
|
||||||
var uniq: std.AutoHashMapUnmanaged(Node.Id, bool) = .{};
|
|
||||||
var i: usize = plen;
|
var i: usize = plen;
|
||||||
while (i > 0) {
|
while (i > 0) {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
const node = parents.items[i];
|
const node = parents.items[i];
|
||||||
|
if (node.set_child_nodes_event) continue;
|
||||||
|
|
||||||
if (uniq.contains(node.id)) continue;
|
node.set_child_nodes_event = true;
|
||||||
try uniq.putNoClobber(arena, node.id, true);
|
|
||||||
|
|
||||||
// If the node has no parent, it's the root node.
|
// If the node has no parent, it's the root node.
|
||||||
// We don't dispatch event for it because we assume the root node is
|
// We don't dispatch event for it because we assume the root node is
|
||||||
|
|||||||
Reference in New Issue
Block a user