diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-09 11:31:03 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-09 11:31:03 +0100 |
commit | e3d975e94390664807c2793aa2b91b6bbeff064c (patch) | |
tree | f1145d860c07d5890e7f35ebe85e704768069976 /Applications/Browser | |
parent | 0f76366b34c4b9d0b19550dff49ebfbe47c1783c (diff) | |
download | serenity-e3d975e94390664807c2793aa2b91b6bbeff064c.zip |
LibHTML+Browser: Add a simple DOM inspector popup window
LibHTML now provides a DOMTreeModel which can be used to view a given
Document's DOM tree. :^)
Diffstat (limited to 'Applications/Browser')
-rw-r--r-- | Applications/Browser/main.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index 69e86b16a9..b17894207c 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -9,9 +9,11 @@ #include <LibGUI/GStatusBar.h> #include <LibGUI/GTextBox.h> #include <LibGUI/GToolBar.h> +#include <LibGUI/GTreeView.h> #include <LibGUI/GWindow.h> #include <LibHTML/CSS/StyleResolver.h> #include <LibHTML/DOM/Element.h> +#include <LibHTML/DOMTreeModel.h> #include <LibHTML/Dump.h> #include <LibHTML/HtmlView.h> #include <LibHTML/Layout/LayoutBlock.h> @@ -129,6 +131,27 @@ int main(int argc, char** argv) })); menubar->add_menu(move(app_menu)); + RefPtr<GWindow> dom_inspector_window; + RefPtr<GTreeView> dom_tree_view; + + auto inspect_menu = make<GMenu>("Inspect"); + inspect_menu->add_action(GAction::create("Inspect DOM tree", [&](auto&) { + if (!dom_inspector_window) { + dom_inspector_window = GWindow::construct(); + dom_inspector_window->set_rect(100, 100, 300, 500); + dom_inspector_window->set_title("DOM inspector"); + dom_tree_view = GTreeView::construct(nullptr); + dom_inspector_window->set_main_widget(dom_tree_view); + } + if (html_widget->document()) + dom_tree_view->set_model(DOMTreeModel::create(*html_widget->document())); + else + dom_tree_view->set_model(nullptr); + dom_inspector_window->show(); + dom_inspector_window->move_to_front(); + })); + menubar->add_menu(move(inspect_menu)); + auto debug_menu = make<GMenu>("Debug"); debug_menu->add_action(GAction::create("Dump DOM tree", [&](auto&) { dump_tree(*html_widget->document()); |