LibDevTools: Support highlighting DOM nodes hovered in the inspector

This commit is contained in:
Timothy Flynn 2025-02-20 08:58:35 -05:00 committed by Tim Flynn
commit 6e8d77ff7f
Notes: github-actions[bot] 2025-02-24 17:07:00 +00:00
10 changed files with 116 additions and 9 deletions

View file

@ -228,6 +228,28 @@ JsonValue WalkerActor::serialize_node(JsonObject const& node) const
return serialized;
}
Optional<WalkerActor::DOMNode> WalkerActor::dom_node(StringView actor)
{
auto maybe_dom_node = m_actor_to_dom_node_map.get(actor);
if (!maybe_dom_node.has_value() || !maybe_dom_node.value())
return {};
auto const& dom_node = *maybe_dom_node.value();
auto pseudo_element = dom_node.get_integer<UnderlyingType<Web::CSS::Selector::PseudoElement::Type>>("pseudo-element"sv).map([](auto value) {
VERIFY(value < to_underlying(Web::CSS::Selector::PseudoElement::Type::KnownPseudoElementCount));
return static_cast<Web::CSS::Selector::PseudoElement::Type>(value);
});
Web::UniqueNodeID node_id { 0 };
if (pseudo_element.has_value())
node_id = dom_node.get_integer<Web::UniqueNodeID::Type>("parent-id"sv).value();
else
node_id = dom_node.get_integer<Web::UniqueNodeID::Type>("id"sv).value();
return DOMNode { .node = dom_node, .id = node_id, .pseudo_element = pseudo_element };
}
Optional<JsonObject const&> WalkerActor::find_node_by_selector(JsonObject const& node, StringView selector)
{
auto matches = [&](auto const& candidate) {