2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2020-01-02 16:55:19 +03:00
|
|
|
#include "InspectorWidget.h"
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
#include <LibGUI/Splitter.h>
|
2020-05-08 22:38:30 +03:00
|
|
|
#include <LibGUI/TabWidget.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/TableView.h>
|
|
|
|
#include <LibGUI/TreeView.h>
|
2020-03-07 12:32:51 +03:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/DOM/Element.h>
|
|
|
|
#include <LibWeb/DOMTreeModel.h>
|
2020-06-12 23:30:11 +03:00
|
|
|
#include <LibWeb/LayoutTreeModel.h>
|
2020-03-07 12:32:51 +03:00
|
|
|
#include <LibWeb/StylePropertiesModel.h>
|
2020-01-02 16:55:19 +03:00
|
|
|
|
2020-05-08 22:38:30 +03:00
|
|
|
namespace Browser {
|
|
|
|
|
2020-07-26 20:37:56 +03:00
|
|
|
void InspectorWidget::set_inspected_node(Web::DOM::Node* node)
|
2020-06-12 23:30:11 +03:00
|
|
|
{
|
2020-07-03 21:54:04 +03:00
|
|
|
m_document->set_inspected_node(node);
|
2020-06-12 23:30:11 +03:00
|
|
|
if (node && node->is_element()) {
|
2020-07-26 20:37:56 +03:00
|
|
|
auto& element = downcast<Web::DOM::Element>(*node);
|
2021-01-06 13:42:01 +03:00
|
|
|
if (element.specified_css_values()) {
|
|
|
|
m_style_table_view->set_model(Web::StylePropertiesModel::create(*element.specified_css_values()));
|
2020-06-12 23:30:11 +03:00
|
|
|
m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(*element.computed_style()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_style_table_view->set_model(nullptr);
|
|
|
|
m_computed_style_table_view->set_model(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-23 14:07:13 +03:00
|
|
|
InspectorWidget::InspectorWidget()
|
2020-01-02 16:55:19 +03:00
|
|
|
{
|
2020-03-04 11:43:54 +03:00
|
|
|
set_layout<GUI::VerticalBoxLayout>();
|
2020-03-04 21:07:55 +03:00
|
|
|
auto& splitter = add<GUI::VerticalSplitter>();
|
2020-06-12 23:30:11 +03:00
|
|
|
|
|
|
|
auto& top_tab_widget = splitter.add<GUI::TabWidget>();
|
|
|
|
|
|
|
|
m_dom_tree_view = top_tab_widget.add_tab<GUI::TreeView>("DOM");
|
2020-01-02 16:55:19 +03:00
|
|
|
m_dom_tree_view->on_selection = [this](auto& index) {
|
2020-07-26 20:37:56 +03:00
|
|
|
auto* node = static_cast<Web::DOM::Node*>(index.internal_data());
|
2020-06-12 23:30:11 +03:00
|
|
|
set_inspected_node(node);
|
|
|
|
};
|
|
|
|
|
|
|
|
m_layout_tree_view = top_tab_widget.add_tab<GUI::TreeView>("Layout");
|
|
|
|
m_layout_tree_view->on_selection = [this](auto& index) {
|
2020-11-22 17:53:01 +03:00
|
|
|
auto* node = static_cast<Web::Layout::Node*>(index.internal_data());
|
2020-11-22 16:46:36 +03:00
|
|
|
set_inspected_node(node->dom_node());
|
2020-01-02 16:55:19 +03:00
|
|
|
};
|
2020-02-23 14:23:48 +03:00
|
|
|
|
2020-06-12 23:30:11 +03:00
|
|
|
auto& bottom_tab_widget = splitter.add<GUI::TabWidget>();
|
2020-02-23 14:23:48 +03:00
|
|
|
|
2020-06-12 23:30:11 +03:00
|
|
|
m_style_table_view = bottom_tab_widget.add_tab<GUI::TableView>("Styles");
|
|
|
|
m_computed_style_table_view = bottom_tab_widget.add_tab<GUI::TableView>("Computed");
|
2020-01-02 16:55:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
InspectorWidget::~InspectorWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-26 20:37:56 +03:00
|
|
|
void InspectorWidget::set_document(Web::DOM::Document* document)
|
2020-01-02 16:55:19 +03:00
|
|
|
{
|
|
|
|
if (m_document == document)
|
|
|
|
return;
|
|
|
|
m_document = document;
|
2020-03-07 12:27:02 +03:00
|
|
|
m_dom_tree_view->set_model(Web::DOMTreeModel::create(*document));
|
2020-06-12 23:30:11 +03:00
|
|
|
m_layout_tree_view->set_model(Web::LayoutTreeModel::create(*document));
|
2020-01-02 16:55:19 +03:00
|
|
|
}
|
2020-05-08 22:38:30 +03:00
|
|
|
|
|
|
|
}
|