diff --git a/Ladybird/Qt/InspectorWidget.cpp b/Ladybird/Qt/InspectorWidget.cpp index ce9d214c8c..0abac2828c 100644 --- a/Ladybird/Qt/InspectorWidget.cpp +++ b/Ladybird/Qt/InspectorWidget.cpp @@ -5,13 +5,8 @@ */ #include "InspectorWidget.h" -#include #include #include -#include -#include -#include -#include #include namespace Ladybird { @@ -27,43 +22,8 @@ InspectorWidget::InspectorWidget(WebContentView& content_view) m_inspector_client = make(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(); diff --git a/Ladybird/Qt/InspectorWidget.h b/Ladybird/Qt/InspectorWidget.h index c2097c2f67..243e2b488a 100644 --- a/Ladybird/Qt/InspectorWidget.h +++ b/Ladybird/Qt/InspectorWidget.h @@ -6,14 +6,10 @@ #pragma once -#include "ModelAdapter.h" #include "WebContentView.h" -#include #include #include -class QTableView; - namespace Ladybird { class WebContentView; @@ -32,21 +28,10 @@ public: void select_default_node(); private: - void load_style_json(StringView computed_style_json, StringView resolved_style_json, StringView custom_properties_json); - void clear_style_json(); - void closeEvent(QCloseEvent*) override; OwnPtr m_inspector_view; OwnPtr m_inspector_client; - - OwnPtr m_computed_style_model; - OwnPtr m_resolved_style_model; - OwnPtr m_custom_properties_model; - - QTableView* m_computed_style_table { nullptr }; - QTableView* m_resolved_style_table { nullptr }; - QTableView* m_custom_properties_table { nullptr }; }; } diff --git a/Ladybird/Qt/ModelAdapter.h b/Ladybird/Qt/ModelAdapter.h deleted file mode 100644 index e789281346..0000000000 --- a/Ladybird/Qt/ModelAdapter.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2023, Tim Flynn - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include "StringUtils.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Ladybird { - -template -class ModelAdapter : public QAbstractItemModel { -public: - using Type = typename ModelType::Type; - - static ErrorOr> create(Type type, StringView model, QObject* parent = nullptr) - { - auto json_model = TRY(JsonValue::from_string(model)); - if (!json_model.is_object()) - return Error::from_string_literal("Expected model to be a JSON object"); - - return adopt_own(*new ModelAdapter(type, move(json_model), parent)); - } - - virtual int rowCount(QModelIndex const& parent) const override - { - return m_model.row_count(to_web_view_model_index(parent)); - } - - virtual int columnCount(QModelIndex const& parent) const override - { - return m_model.column_count(to_web_view_model_index(parent)); - } - - virtual QModelIndex index(int row, int column, QModelIndex const& parent) const override - { - auto index = m_model.index(row, column, to_web_view_model_index(parent)); - return to_qt_model_index(index); - } - - virtual QModelIndex parent(QModelIndex const& index) const override - { - if constexpr (requires { m_model.parent(declval()); }) { - auto parent = m_model.parent(to_web_view_model_index(index)); - return to_qt_model_index(parent); - } else { - return {}; - } - } - - virtual QVariant data(QModelIndex const& index, int role) const override - { - if (role == Qt::DisplayRole) { - auto text = m_model.text_for_display(to_web_view_model_index(index)); - return qstring_from_ak_string(text); - } - - return {}; - } - - QModelIndex index_for_node(i32 node_id, Optional const& pseudo_element) const - { - if constexpr (requires { m_model.index_for_node(node_id, pseudo_element); }) { - auto parent = m_model.index_for_node(node_id, pseudo_element); - return to_qt_model_index(parent); - } else { - return {}; - } - } - -private: - ModelAdapter(Type type, JsonValue model, QObject* parent) - : QAbstractItemModel(parent) - , m_model(type, move(model)) - { - } - - ALWAYS_INLINE QModelIndex to_qt_model_index(WebView::ModelIndex const& index) const - { - if (!index.is_valid()) - return {}; - return createIndex(index.row, index.column, index.internal_data); - } - - ALWAYS_INLINE WebView::ModelIndex to_web_view_model_index(QModelIndex const& index) const - { - if (!index.isValid()) - return {}; - return { index.row(), index.column(), index.constInternalPointer() }; - } - - ModelType m_model; -}; - -using PropertyTableModel = ModelAdapter; - -}