From b5ea14b88455deaee4900311d84f1cdf3baf960b Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 10 Mar 2022 11:24:55 +0000 Subject: [PATCH] WebContent: Show box-model metrics for (some) pseudo-elements This only applies to pseudo-elements which have a Layout::Box, so this excludes any that are InlineNodes. --- .../Services/WebContent/ConnectionFromClient.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 009dc65f8e..001ffdd3f8 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -302,11 +302,12 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect return builder.to_string(); }; - auto serialize_node_box_sizing_json = [](Web::DOM::Element const& element) -> String { - if (!element.layout_node()) { + auto serialize_node_box_sizing_json = [](Web::Layout::Node const* layout_node) -> String { + if (!layout_node || !layout_node->is_box()) { return ""; } - auto box_model = static_cast(*element.layout_node()).box_model(); + auto* box = static_cast(layout_node); + auto box_model = box->box_model(); StringBuilder builder; auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); MUST(serializer.add("padding_top", box_model.padding.top)); @@ -321,8 +322,8 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect MUST(serializer.add("border_right", box_model.border.right)); MUST(serializer.add("border_bottom", box_model.border.bottom)); MUST(serializer.add("border_left", box_model.border.left)); - MUST(serializer.add("content_width", static_cast(*element.layout_node()).content_width())); - MUST(serializer.add("content_height", static_cast(*element.layout_node()).content_height())); + MUST(serializer.add("content_width", box->content_width())); + MUST(serializer.add("content_height", box->content_height())); MUST(serializer.finish()); return builder.to_string(); @@ -340,14 +341,14 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect String specified_values_json = serialize_json(pseudo_element_style); String computed_values_json = "{}"; String custom_properties_json = "{}"; - String node_box_sizing_json = "{}"; + String node_box_sizing_json = serialize_node_box_sizing_json(pseudo_element_node.ptr()); return { true, specified_values_json, computed_values_json, custom_properties_json, node_box_sizing_json }; } String specified_values_json = serialize_json(*element.specified_css_values()); String computed_values_json = serialize_json(element.computed_style()); String custom_properties_json = serialize_custom_properties_json(element); - String node_box_sizing_json = serialize_node_box_sizing_json(element); + String node_box_sizing_json = serialize_node_box_sizing_json(element.layout_node()); return { true, specified_values_json, computed_values_json, custom_properties_json, node_box_sizing_json }; }