mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibDevTools: Store highlighter actors by type
We will be asked for different highlighters throughout the DevTools session, e.g. ViewportSizeOnResizeHighlighter and BoxModelHighlighter. The latter will be responsible for rendering and overlay on DOM nodes when the user hovers over a node in the inspector panel.
This commit is contained in:
@@ -29,7 +29,7 @@ InspectorActor::InspectorActor(DevToolsServer& devtools, String name, WeakPtr<Ta
|
||||
|
||||
InspectorActor::~InspectorActor() = default;
|
||||
|
||||
void InspectorActor::handle_message(StringView type, JsonObject const&)
|
||||
void InspectorActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
@@ -44,10 +44,17 @@ void InspectorActor::handle_message(StringView type, JsonObject const&)
|
||||
}
|
||||
|
||||
if (type == "getHighlighterByType"sv) {
|
||||
if (!m_highlighter)
|
||||
m_highlighter = devtools().register_actor<HighlighterActor>();
|
||||
auto type_name = message.get_string("typeName"sv);
|
||||
if (!type_name.has_value()) {
|
||||
send_missing_parameter_error("typeName"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
response.set("highlighter"sv, m_highlighter->serialize_highlighter());
|
||||
auto highlighter = m_highlighters.ensure(*type_name, [&]() -> NonnullRefPtr<HighlighterActor> {
|
||||
return devtools().register_actor<HighlighterActor>();
|
||||
});
|
||||
|
||||
response.set("highlighter"sv, highlighter->serialize_highlighter());
|
||||
send_message(move(response));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibDevTools/Actor.h>
|
||||
|
||||
@@ -27,7 +28,7 @@ private:
|
||||
|
||||
WeakPtr<TabActor> m_tab;
|
||||
WeakPtr<PageStyleActor> m_page_style;
|
||||
WeakPtr<HighlighterActor> m_highlighter;
|
||||
HashMap<String, WeakPtr<HighlighterActor>> m_highlighters;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user