LibDevTools: Associate node actors with a DOM node identifier

This is a prepatory commit to be able to handle DOM mutations. Once a
node actor is created, the DOM node it is created for must continue to
be associated with the same actor even after DOM mutations. This change
stores an identifier on the node actor, and only creates new actors when
an actor for a node does not exist.
This commit is contained in:
Timothy Flynn 2025-03-06 19:49:27 -05:00 committed by Andreas Kling
commit ddea67034f
Notes: github-actions[bot] 2025-03-08 00:28:03 +00:00
6 changed files with 80 additions and 28 deletions

View file

@ -8,20 +8,35 @@
#include <AK/NonnullRefPtr.h>
#include <LibDevTools/Actor.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/Forward.h>
namespace DevTools {
struct NodeIdentifier {
static NodeIdentifier for_node(JsonObject const& node);
bool operator==(NodeIdentifier const&) const = default;
Web::UniqueNodeID id { 0 };
Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element;
};
class NodeActor final : public Actor {
public:
static constexpr auto base_name = "node"sv;
static NonnullRefPtr<NodeActor> create(DevToolsServer&, String name, WeakPtr<WalkerActor>);
static NonnullRefPtr<NodeActor> create(DevToolsServer&, String name, NodeIdentifier, WeakPtr<WalkerActor>);
virtual ~NodeActor() override;
virtual void handle_message(StringView type, JsonObject const&) override;
NodeIdentifier const& node_identifier() const { return m_node_identifier; }
private:
NodeActor(DevToolsServer&, String name, WeakPtr<WalkerActor>);
NodeActor(DevToolsServer&, String name, NodeIdentifier, WeakPtr<WalkerActor>);
NodeIdentifier m_node_identifier;
WeakPtr<WalkerActor> m_walker;
};