1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:07:35 +00:00

WebContent: Support inspection of DOM in nested browsing contexts

This lets user select a node from a nested browsing context in the
Inspector (e.g. a node inside an `iframe` document) to highlight it on
the page.
This commit is contained in:
Vyacheslav Pukhanov 2021-11-24 20:05:39 +03:00 committed by Andreas Kling
parent 3f006d81fe
commit dee02ab30a

View file

@ -235,14 +235,21 @@ void ClientConnection::inspect_dom_tree()
Messages::WebContentServer::InspectDomNodeResponse ClientConnection::inspect_dom_node(i32 node_id)
{
if (auto* doc = page().top_level_browsing_context().active_document()) {
auto& top_context = page().top_level_browsing_context();
top_context.for_each_in_inclusive_subtree([&](auto& ctx) {
if (ctx.active_document() != nullptr) {
ctx.active_document()->set_inspected_node(nullptr);
}
return IterationDecision::Continue;
});
Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
if (!node || (&node->document() != doc)) {
doc->set_inspected_node(nullptr);
if (!node) {
return { false, "", "" };
}
doc->set_inspected_node(node);
node->document().set_inspected_node(node);
if (node->is_element()) {
auto& element = verify_cast<Web::DOM::Element>(*node);
@ -265,7 +272,6 @@ Messages::WebContentServer::InspectDomNodeResponse ClientConnection::inspect_dom
String computed_values_json = serialize_json(element.computed_style());
return { true, specified_values_json, computed_values_json };
}
}
return { false, "", "" };
}