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

Ladybird+Browser: Add a 'Dump All Resolved Styles' debug option

This option dumps all styles for all elements in the document; very
helpful for finding properties that have changed unintentionally :^)
This commit is contained in:
Ali Mohammad Pur 2023-05-27 15:33:08 +03:30 committed by Andreas Kling
parent 549260d311
commit e47f81d954
3 changed files with 32 additions and 0 deletions

View file

@ -368,6 +368,26 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec
}
}
if (request == "dump-all-resolved-styles") {
if (auto* doc = page().top_level_browsing_context().active_document()) {
Queue<Web::DOM::Node*> elements_to_visit;
elements_to_visit.enqueue(doc->document_element());
while (!elements_to_visit.is_empty()) {
auto element = elements_to_visit.dequeue();
for (auto& child : element->children_as_vector())
elements_to_visit.enqueue(child.ptr());
if (element->is_element()) {
auto styles = doc->style_computer().compute_style(*static_cast<Web::DOM::Element*>(element)).release_value_but_fixme_should_propagate_errors();
dbgln("+ Element {}", element->debug_description());
auto& properties = styles->properties();
for (size_t i = 0; i < properties.size(); ++i)
dbgln("| {} = {}", Web::CSS::string_from_property_id(static_cast<Web::CSS::PropertyID>(i)), properties[i].has_value() ? properties[i]->style->to_string() : ""_short_string);
dbgln("---");
}
}
}
}
if (request == "collect-garbage") {
Web::Bindings::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
}