Serenity Operating System
at hosted 77 lines 3.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include "InspectorWidget.h" 28#include <LibGUI/BoxLayout.h> 29#include <LibGUI/Splitter.h> 30#include <LibGUI/TableView.h> 31#include <LibGUI/TreeView.h> 32#include <LibGUI/TabWidget.h> 33#include <LibWeb/DOM/Document.h> 34#include <LibWeb/DOM/Element.h> 35#include <LibWeb/DOMTreeModel.h> 36#include <LibWeb/StylePropertiesModel.h> 37 38InspectorWidget::InspectorWidget() 39{ 40 set_layout<GUI::VerticalBoxLayout>(); 41 auto& splitter = add<GUI::VerticalSplitter>(); 42 m_dom_tree_view = splitter.add<GUI::TreeView>(); 43 m_dom_tree_view->on_selection = [this](auto& index) { 44 auto* node = static_cast<Web::Node*>(index.internal_data()); 45 node->document().set_inspected_node(node); 46 if (node->is_element()) { 47 auto& element = Web::to<Web::Element>(*node); 48 if (element.resolved_style()) { 49 m_style_table_view->set_model(Web::StylePropertiesModel::create(*element.resolved_style())); 50 m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(*element.computed_style())); 51 } 52 } else { 53 m_style_table_view->set_model(nullptr); 54 m_computed_style_table_view->set_model(nullptr); 55 } 56 }; 57 58 auto& tab_widget = splitter.add<GUI::TabWidget>(); 59 60 m_style_table_view = tab_widget.add_tab<GUI::TableView>("Styles"); 61 m_style_table_view->set_size_columns_to_fit_content(true); 62 63 m_computed_style_table_view = tab_widget.add_tab<GUI::TableView>("Computed"); 64 m_computed_style_table_view->set_size_columns_to_fit_content(true); 65} 66 67InspectorWidget::~InspectorWidget() 68{ 69} 70 71void InspectorWidget::set_document(Web::Document* document) 72{ 73 if (m_document == document) 74 return; 75 m_document = document; 76 m_dom_tree_view->set_model(Web::DOMTreeModel::create(*document)); 77}