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
Notes: sideshowbarker 2024-07-18 04:46:35 +09:00
3 changed files with 32 additions and 0 deletions

View file

@ -219,6 +219,13 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
debug_request("dump-style-sheets");
});
auto* dump_styles_action = new QAction("Dump All Resolved Styles", this);
dump_styles_action->setIcon(QIcon(QString("%1/res/icons/16x16/filetype-css.png").arg(s_serenity_resource_root.characters())));
debug_menu->addAction(dump_styles_action);
QObject::connect(dump_styles_action, &QAction::triggered, this, [this] {
debug_request("dump-all-resolved-styles");
});
auto* dump_history_action = new QAction("Dump History", this);
dump_history_action->setIcon(QIcon(QString("%1/res/icons/16x16/history.png").arg(s_serenity_resource_root.characters())));
debug_menu->addAction(dump_history_action);

View file

@ -364,6 +364,11 @@ void BrowserWindow::build_menus()
active_tab().view().debug_request("dump-style-sheets");
},
this));
debug_menu.add_action(GUI::Action::create(
"Dump &All Resolved Styles", g_icon_bag.filetype_css, [this](auto&) {
active_tab().view().debug_request("dump-all-resolved-styles");
},
this));
debug_menu.add_action(GUI::Action::create("Dump &History", { Mod_Ctrl, Key_H }, g_icon_bag.history, [this](auto&) {
active_tab().m_history.dump();
}));

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);
}