Files
ladybird/Libraries/LibDevTools/Actors/WalkerActor.h
Timothy Flynn c56bf8ac93 LibDevTools: Implement a real actor for DOM nodes
The DevTools client will now send requests to the node actor, rather
than just sending messages to other actors on the node's behalf.

This exposed a slight issue in the way we assign actor IDs. Node actors
are created in the walker actor constructor, which executes before the
actor ID is incremented. So we must be sure to increment the actor ID
before invoking any actor constructors. Otherwise, the walker actor and
the first node actor have the same numeric ID.
2025-02-24 12:05:29 -05:00

54 lines
1.5 KiB
C++

/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <LibDevTools/Actor.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/Forward.h>
namespace DevTools {
class WalkerActor final : public Actor {
public:
static constexpr auto base_name = "walker"sv;
static NonnullRefPtr<WalkerActor> create(DevToolsServer&, String name, WeakPtr<TabActor>, JsonObject dom_tree);
virtual ~WalkerActor() override;
virtual void handle_message(StringView type, JsonObject const&) override;
static bool is_suitable_for_dom_inspection(JsonValue const&);
JsonValue serialize_root() const;
struct DOMNode {
JsonObject const& node;
Web::UniqueNodeID id { 0 };
Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element;
};
Optional<DOMNode> dom_node(StringView actor);
private:
WalkerActor(DevToolsServer&, String name, WeakPtr<TabActor>, JsonObject dom_tree);
JsonValue serialize_node(JsonObject const&) const;
Optional<JsonObject const&> find_node_by_selector(JsonObject const& node, StringView selector);
void populate_dom_tree_cache(JsonObject& node, JsonObject const* parent = nullptr);
WeakPtr<TabActor> m_tab;
JsonObject m_dom_tree;
HashMap<JsonObject const*, JsonObject const*> m_dom_node_to_parent_map;
HashMap<String, JsonObject const*> m_actor_to_dom_node_map;
};
}