summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorVyacheslav Pukhanov <vyacheslav@pukhanov.ru>2021-11-24 20:05:39 +0300
committerAndreas Kling <kling@serenityos.org>2021-11-24 19:07:48 +0100
commitdee02ab30a4a950ab5ea8e1ab29e274057696d3f (patch)
tree2078a0c7416e0a42772c2fc3445b365e504783ef /Userland
parent3f006d81feacbdf088f554087ad4705712f8e871 (diff)
downloadserenity-dee02ab30a4a950ab5ea8e1ab29e274057696d3f.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Services/WebContent/ClientConnection.cpp52
1 files changed, 29 insertions, 23 deletions
diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp
index 8ec0806c77..982e54700a 100644
--- a/Userland/Services/WebContent/ClientConnection.cpp
+++ b/Userland/Services/WebContent/ClientConnection.cpp
@@ -235,36 +235,42 @@ 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()) {
- Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
- if (!node || (&node->document() != doc)) {
- doc->set_inspected_node(nullptr);
- return { false, "", "" };
+ 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;
+ });
- doc->set_inspected_node(node);
+ Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
+ if (!node) {
+ return { false, "", "" };
+ }
- if (node->is_element()) {
- auto& element = verify_cast<Web::DOM::Element>(*node);
- if (!element.specified_css_values())
- return { false, "", "" };
+ node->document().set_inspected_node(node);
- auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> String {
- StringBuilder builder;
+ if (node->is_element()) {
+ auto& element = verify_cast<Web::DOM::Element>(*node);
+ if (!element.specified_css_values())
+ return { false, "", "" };
- JsonObjectSerializer serializer(builder);
- properties.for_each_property([&](auto property_id, auto& value) {
- serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string());
- });
- serializer.finish();
+ auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> String {
+ StringBuilder builder;
- return builder.to_string();
- };
+ JsonObjectSerializer serializer(builder);
+ properties.for_each_property([&](auto property_id, auto& value) {
+ serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string());
+ });
+ serializer.finish();
- String specified_values_json = serialize_json(*element.specified_css_values());
- String computed_values_json = serialize_json(element.computed_style());
- return { true, specified_values_json, computed_values_json };
- }
+ return builder.to_string();
+ };
+
+ String specified_values_json = serialize_json(*element.specified_css_values());
+ String computed_values_json = serialize_json(element.computed_style());
+ return { true, specified_values_json, computed_values_json };
}
return { false, "", "" };