mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +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:
parent
3f006d81fe
commit
dee02ab30a
1 changed files with 31 additions and 25 deletions
|
@ -235,36 +235,42 @@ void ClientConnection::inspect_dom_tree()
|
||||||
|
|
||||||
Messages::WebContentServer::InspectDomNodeResponse ClientConnection::inspect_dom_node(i32 node_id)
|
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();
|
||||||
Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
|
|
||||||
if (!node || (&node->document() != doc)) {
|
top_context.for_each_in_inclusive_subtree([&](auto& ctx) {
|
||||||
doc->set_inspected_node(nullptr);
|
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) {
|
||||||
|
return { false, "", "" };
|
||||||
|
}
|
||||||
|
|
||||||
|
node->document().set_inspected_node(node);
|
||||||
|
|
||||||
|
if (node->is_element()) {
|
||||||
|
auto& element = verify_cast<Web::DOM::Element>(*node);
|
||||||
|
if (!element.specified_css_values())
|
||||||
return { false, "", "" };
|
return { false, "", "" };
|
||||||
}
|
|
||||||
|
|
||||||
doc->set_inspected_node(node);
|
auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> String {
|
||||||
|
StringBuilder builder;
|
||||||
|
|
||||||
if (node->is_element()) {
|
JsonObjectSerializer serializer(builder);
|
||||||
auto& element = verify_cast<Web::DOM::Element>(*node);
|
properties.for_each_property([&](auto property_id, auto& value) {
|
||||||
if (!element.specified_css_values())
|
serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string());
|
||||||
return { false, "", "" };
|
});
|
||||||
|
serializer.finish();
|
||||||
|
|
||||||
auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> String {
|
return builder.to_string();
|
||||||
StringBuilder builder;
|
};
|
||||||
|
|
||||||
JsonObjectSerializer serializer(builder);
|
String specified_values_json = serialize_json(*element.specified_css_values());
|
||||||
properties.for_each_property([&](auto property_id, auto& value) {
|
String computed_values_json = serialize_json(element.computed_style());
|
||||||
serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string());
|
return { true, specified_values_json, computed_values_json };
|
||||||
});
|
|
||||||
serializer.finish();
|
|
||||||
|
|
||||||
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, "", "" };
|
return { false, "", "" };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue