mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
Ladybird: Add the node properties tabs to the inspector
This now allows you to view the computed and resolved style values, along with the CSS variables of a node.
This commit is contained in:
parent
aa85a88158
commit
33249c727a
5 changed files with 103 additions and 19 deletions
|
@ -6,9 +6,16 @@
|
|||
|
||||
#define AK_DONT_REPLACE_STD
|
||||
|
||||
#include "InspectorWidget.h"
|
||||
#include <LibWebView/DOMTreeModel.h>
|
||||
#include <LibWebView/StylePropertiesModel.h>
|
||||
|
||||
#include "InspectorWidget.h"
|
||||
#include <QCloseEvent>
|
||||
#include <QHeaderView>
|
||||
#include <QSplitter>
|
||||
#include <QStringList>
|
||||
#include <QTabWidget>
|
||||
#include <QTableView>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
@ -17,12 +24,15 @@ namespace Ladybird {
|
|||
InspectorWidget::InspectorWidget()
|
||||
{
|
||||
setLayout(new QVBoxLayout);
|
||||
m_tree_view = new QTreeView;
|
||||
m_tree_view->setHeaderHidden(true);
|
||||
m_tree_view->expandToDepth(3);
|
||||
layout()->addWidget(m_tree_view);
|
||||
m_tree_view->setModel(&m_dom_model);
|
||||
QObject::connect(m_tree_view->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
auto splitter = new QSplitter(this);
|
||||
layout()->addWidget(splitter);
|
||||
splitter->setOrientation(Qt::Vertical);
|
||||
auto tree_view = new QTreeView;
|
||||
tree_view->setHeaderHidden(true);
|
||||
tree_view->expandToDepth(3);
|
||||
splitter->addWidget(tree_view);
|
||||
tree_view->setModel(&m_dom_model);
|
||||
QObject::connect(tree_view->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
[this](QItemSelection const& selected, QItemSelection const&) {
|
||||
auto indexes = selected.indexes();
|
||||
if (indexes.size()) {
|
||||
|
@ -30,16 +40,49 @@ InspectorWidget::InspectorWidget()
|
|||
set_selection(index);
|
||||
}
|
||||
});
|
||||
|
||||
auto add_table_tab = [&](auto* tab_widget, auto& model, auto name) {
|
||||
auto container = new QWidget;
|
||||
auto table_view = new QTableView;
|
||||
table_view->setModel(&model);
|
||||
container->setLayout(new QVBoxLayout);
|
||||
container->layout()->addWidget(table_view);
|
||||
table_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
table_view->verticalHeader()->setVisible(false);
|
||||
table_view->horizontalHeader()->setVisible(false);
|
||||
tab_widget->addTab(container, name);
|
||||
};
|
||||
|
||||
auto node_tabs = new QTabWidget;
|
||||
add_table_tab(node_tabs, m_computed_style_model, "Computed");
|
||||
add_table_tab(node_tabs, m_resolved_style_model, "Resolved");
|
||||
add_table_tab(node_tabs, m_custom_properties_model, "Variables");
|
||||
splitter->addWidget(node_tabs);
|
||||
}
|
||||
|
||||
void InspectorWidget::set_dom_json(StringView dom_json)
|
||||
{
|
||||
m_dom_model.set_underlying_model(WebView::DOMTreeModel::create(dom_json));
|
||||
}
|
||||
|
||||
void InspectorWidget::clear_dom_json()
|
||||
{
|
||||
m_dom_model.set_underlying_model(nullptr);
|
||||
clear_style_json();
|
||||
}
|
||||
|
||||
void InspectorWidget::set_dom_json(StringView dom_json)
|
||||
void InspectorWidget::load_style_json(StringView computed_style_json, StringView resolved_style_json, StringView custom_properties_json)
|
||||
{
|
||||
m_dom_model.set_underlying_model(::WebView::DOMTreeModel::create(dom_json));
|
||||
m_computed_style_model.set_underlying_model(WebView::StylePropertiesModel::create(computed_style_json));
|
||||
m_resolved_style_model.set_underlying_model(WebView::StylePropertiesModel::create(resolved_style_json));
|
||||
m_custom_properties_model.set_underlying_model(WebView::StylePropertiesModel::create(custom_properties_json));
|
||||
}
|
||||
|
||||
void InspectorWidget::clear_style_json()
|
||||
{
|
||||
m_computed_style_model.set_underlying_model(nullptr);
|
||||
m_resolved_style_model.set_underlying_model(nullptr);
|
||||
m_custom_properties_model.set_underlying_model(nullptr);
|
||||
}
|
||||
|
||||
void InspectorWidget::closeEvent(QCloseEvent* event)
|
||||
|
@ -70,7 +113,13 @@ void InspectorWidget::set_selection(GUI::ModelIndex index)
|
|||
m_selection = selection;
|
||||
|
||||
VERIFY(on_dom_node_inspected);
|
||||
on_dom_node_inspected(m_selection.dom_node_id, m_selection.pseudo_element);
|
||||
auto maybe_inspected_node_properties = on_dom_node_inspected(m_selection.dom_node_id, m_selection.pseudo_element);
|
||||
if (!maybe_inspected_node_properties.is_error()) {
|
||||
auto properties = maybe_inspected_node_properties.release_value();
|
||||
load_style_json(properties.computed_style_json, properties.resolved_style_json, properties.custom_properties_json);
|
||||
} else {
|
||||
clear_style_json();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue