mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibDevTools: Handle null DOM node properties for inspected nodes
In particular, if a node does not have a computed style, we must still include the "computed" object in the response. Otherwise, DevTools will continue to display the properties from the previously selected node.
This commit is contained in:
parent
b55d2909f6
commit
d0b4673640
Notes:
github-actions[bot]
2025-07-02 19:29:07 +00:00
Author: https://github.com/trflynn89
Commit: d0b4673640
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5277
1 changed files with 41 additions and 37 deletions
|
@ -16,18 +16,21 @@
|
||||||
|
|
||||||
namespace DevTools {
|
namespace DevTools {
|
||||||
|
|
||||||
static void received_layout(JsonObject& response, JsonObject const& node_box_sizing)
|
static void received_layout(JsonObject& response, JsonValue const& node_box_sizing)
|
||||||
{
|
{
|
||||||
|
if (!node_box_sizing.is_object())
|
||||||
|
return;
|
||||||
|
|
||||||
response.set("autoMargins"sv, JsonObject {});
|
response.set("autoMargins"sv, JsonObject {});
|
||||||
|
|
||||||
auto pixel_value = [&](auto key) {
|
auto pixel_value = [&](auto key) {
|
||||||
return node_box_sizing.get_double_with_precision_loss(key).value_or(0);
|
return node_box_sizing.as_object().get_double_with_precision_loss(key).value_or(0);
|
||||||
};
|
};
|
||||||
auto set_pixel_value = [&](auto key) {
|
auto set_pixel_value = [&](auto key) {
|
||||||
response.set(key, MUST(String::formatted("{}px", pixel_value(key))));
|
response.set(key, MUST(String::formatted("{}px", pixel_value(key))));
|
||||||
};
|
};
|
||||||
auto set_computed_value = [&](auto key) {
|
auto set_computed_value = [&](auto key) {
|
||||||
response.set(key, node_box_sizing.get_string(key).value_or(String {}));
|
response.set(key, node_box_sizing.as_object().get_string(key).value_or(String {}));
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: This response should also contain "top", "right", "bottom", and "left", but our box model metrics in
|
// FIXME: This response should also contain "top", "right", "bottom", and "left", but our box model metrics in
|
||||||
|
@ -59,25 +62,28 @@ static void received_layout(JsonObject& response, JsonObject const& node_box_siz
|
||||||
set_computed_value("z-index"sv);
|
set_computed_value("z-index"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void received_computed_style(JsonObject& response, JsonObject const& computed_style)
|
static void received_computed_style(JsonObject& response, JsonValue const& computed_style)
|
||||||
{
|
{
|
||||||
JsonObject computed;
|
JsonObject computed;
|
||||||
|
|
||||||
computed_style.for_each_member([&](String const& name, JsonValue const& value) {
|
if (computed_style.is_object()) {
|
||||||
|
computed_style.as_object().for_each_member([&](String const& name, JsonValue const& value) {
|
||||||
JsonObject property;
|
JsonObject property;
|
||||||
property.set("matched"sv, true);
|
property.set("matched"sv, true);
|
||||||
property.set("value"sv, value);
|
property.set("value"sv, value);
|
||||||
computed.set(name, move(property));
|
computed.set(name, move(property));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
response.set("computed"sv, move(computed));
|
response.set("computed"sv, move(computed));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void received_fonts(JsonObject& response, JsonArray const& fonts)
|
static void received_fonts(JsonObject& response, JsonValue const& fonts)
|
||||||
{
|
{
|
||||||
JsonArray font_faces;
|
JsonArray font_faces;
|
||||||
|
|
||||||
fonts.for_each([&](JsonValue const& font) {
|
if (fonts.is_array()) {
|
||||||
|
fonts.as_array().for_each([&](JsonValue const& font) {
|
||||||
if (!font.is_object())
|
if (!font.is_object())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -100,6 +106,7 @@ static void received_fonts(JsonObject& response, JsonArray const& fonts)
|
||||||
|
|
||||||
font_faces.must_append(move(font_face));
|
font_faces.must_append(move(font_face));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
response.set("fontFaces"sv, move(font_faces));
|
response.set("fontFaces"sv, move(font_faces));
|
||||||
}
|
}
|
||||||
|
@ -209,16 +216,13 @@ void PageStyleActor::received_dom_node_properties(WebView::DOMNodeProperties con
|
||||||
|
|
||||||
switch (properties.type) {
|
switch (properties.type) {
|
||||||
case WebView::DOMNodeProperties::Type::ComputedStyle:
|
case WebView::DOMNodeProperties::Type::ComputedStyle:
|
||||||
if (properties.properties.is_object())
|
received_computed_style(response, properties.properties);
|
||||||
received_computed_style(response, properties.properties.as_object());
|
|
||||||
break;
|
break;
|
||||||
case WebView::DOMNodeProperties::Type::Layout:
|
case WebView::DOMNodeProperties::Type::Layout:
|
||||||
if (properties.properties.is_object())
|
received_layout(response, properties.properties);
|
||||||
received_layout(response, properties.properties.as_object());
|
|
||||||
break;
|
break;
|
||||||
case WebView::DOMNodeProperties::Type::UsedFonts:
|
case WebView::DOMNodeProperties::Type::UsedFonts:
|
||||||
if (properties.properties.is_array())
|
received_fonts(response, properties.properties);
|
||||||
received_fonts(response, properties.properties.as_array());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue