1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

Ladybird/Qt: Port the Inspector to the WebView property tables

This commit is contained in:
Timothy Flynn 2023-11-27 16:10:03 -05:00 committed by Andreas Kling
parent 0037fdaf11
commit b5d5e48ffc
3 changed files with 1 additions and 189 deletions

View file

@ -5,13 +5,8 @@
*/
#include "InspectorWidget.h"
#include <AK/JsonObject.h>
#include <LibWebView/InspectorClient.h>
#include <QCloseEvent>
#include <QHeaderView>
#include <QSplitter>
#include <QTabWidget>
#include <QTableView>
#include <QVBoxLayout>
namespace Ladybird {
@ -27,43 +22,8 @@ InspectorWidget::InspectorWidget(WebContentView& content_view)
m_inspector_client = make<WebView::InspectorClient>(content_view, *m_inspector_view);
m_inspector_client->on_dom_node_properties_received = [this](auto properties_or_error) {
if (properties_or_error.is_error()) {
clear_style_json();
} else {
auto properties = properties_or_error.release_value();
load_style_json(properties.computed_style_json, properties.resolved_style_json, properties.custom_properties_json);
}
};
setLayout(new QVBoxLayout);
auto* splitter = new QSplitter(this);
splitter->setOrientation(Qt::Vertical);
layout()->addWidget(splitter);
splitter->addWidget(m_inspector_view.ptr());
splitter->setStretchFactor(0, 2);
auto add_table_tab = [&](auto* tab_widget, auto name) {
auto* table_view = new QTableView;
table_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
table_view->verticalHeader()->setVisible(false);
table_view->horizontalHeader()->setVisible(false);
auto* container = new QWidget;
container->setLayout(new QVBoxLayout);
container->layout()->addWidget(table_view);
tab_widget->addTab(container, name);
return table_view;
};
auto* node_tabs = new QTabWidget;
m_computed_style_table = add_table_tab(node_tabs, "Computed");
m_resolved_style_table = add_table_tab(node_tabs, "Resolved");
m_custom_properties_table = add_table_tab(node_tabs, "Variables");
splitter->addWidget(node_tabs);
layout()->addWidget(m_inspector_view.ptr());
setWindowTitle("Inspector");
resize(875, 825);
@ -79,7 +39,6 @@ void InspectorWidget::inspect()
void InspectorWidget::reset()
{
m_inspector_client->reset();
clear_style_json();
}
void InspectorWidget::select_hovered_node()
@ -92,30 +51,6 @@ void InspectorWidget::select_default_node()
m_inspector_client->select_default_node();
}
void InspectorWidget::load_style_json(StringView computed_style_json, StringView resolved_style_json, StringView custom_properties_json)
{
m_computed_style_model = PropertyTableModel::create(PropertyTableModel::Type::StyleProperties, computed_style_json).release_value_but_fixme_should_propagate_errors();
m_computed_style_table->setModel(m_computed_style_model);
m_resolved_style_model = PropertyTableModel::create(PropertyTableModel::Type::StyleProperties, resolved_style_json).release_value_but_fixme_should_propagate_errors();
m_resolved_style_table->setModel(m_resolved_style_model);
m_custom_properties_model = PropertyTableModel::create(PropertyTableModel::Type::StyleProperties, custom_properties_json).release_value_but_fixme_should_propagate_errors();
m_custom_properties_table->setModel(m_custom_properties_model);
}
void InspectorWidget::clear_style_json()
{
m_computed_style_table->setModel(nullptr);
m_computed_style_model = nullptr;
m_resolved_style_table->setModel(nullptr);
m_resolved_style_model = nullptr;
m_custom_properties_table->setModel(nullptr);
m_custom_properties_model = nullptr;
}
void InspectorWidget::closeEvent(QCloseEvent* event)
{
event->accept();