LibDevTools: Add a helper to extract a DOM node JSON object more easily

The pattern of:

    auto tab = get_tab();
    auto walker = get_walker();

    if (tab && walker) {
        if (auto node = walker->dom_node(node_id)) {
            delegate().do_something(tab->description(), node);
        }
    }

Is getting a bit unergonomic and is often repeated. This patch just adds
a helper to WalkerActor to do most of this work, so now we have:

    if (auto node = WalkerActor::dom_node_for(get_walker(), node_id)) {
        delegate().do_something(node->tab->description(), node);
    }
This commit is contained in:
Timothy Flynn 2025-03-05 16:16:49 -05:00 committed by Andreas Kling
commit ee88edc750
Notes: github-actions[bot] 2025-03-08 00:28:09 +00:00
5 changed files with 22 additions and 19 deletions

View file

@ -95,19 +95,14 @@ JsonValue PageStyleActor::serialize_style() const
template<typename Callback>
void PageStyleActor::inspect_dom_node(StringView node_actor, Callback&& callback)
{
auto tab = InspectorActor::tab_for(m_inspector);
auto walker = InspectorActor::walker_for(m_inspector);
if (!tab || !walker)
return;
auto const& dom_node = walker->dom_node(node_actor);
auto dom_node = WalkerActor::dom_node_for(InspectorActor::walker_for(m_inspector), node_actor);
if (!dom_node.has_value())
return;
auto block_token = block_responses();
devtools().delegate().inspect_dom_node(
tab->description(), dom_node->id, dom_node->pseudo_element,
dom_node->tab->description(), dom_node->id, dom_node->pseudo_element,
[weak_self = make_weak_ptr<PageStyleActor>(), block_token = move(block_token), callback = forward<Callback>(callback)](ErrorOr<DOMNodeProperties> properties) mutable {
if (properties.is_error()) {
dbgln_if(DEVTOOLS_DEBUG, "Unable to inspect DOM node: {}", properties.error());