diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-08-23 16:16:08 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-02 22:16:41 +0200 |
commit | 2d6a02f03bfa8f636826169178f0378b30f4b0b7 (patch) | |
tree | 38cb55ffcb7046ab5453f50784b1ca231d02a7bc /Userland/Applications/Browser | |
parent | d7485df92859490a46a0f91cf043f9d11df851e0 (diff) | |
download | serenity-2d6a02f03bfa8f636826169178f0378b30f4b0b7.zip |
Browser: Prevent opening multiple DOM Inspectors for the same Tab
Also simplify the logic by removing `Tab::view_dom_tree()`, and making
the Tab keep a pointer to the InspectorWidget instead of its Window,
since that's more often what we want to access.
Diffstat (limited to 'Userland/Applications/Browser')
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 33 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.h | 3 |
2 files changed, 20 insertions, 16 deletions
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 588d71e899..2cc11b5dc1 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Maciej Zygmanowski <sppmacd@pm.me> + * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -79,20 +80,6 @@ void Tab::view_source(const URL& url, const String& source) window->show(); } -void Tab::view_dom_tree(const String& dom_tree) -{ - auto window = GUI::Window::construct(&this->window()); - window->resize(300, 500); - window->set_title("DOM inspector"); - window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png")); - window->set_main_widget<InspectorWidget>(); - - auto* inspector_widget = static_cast<InspectorWidget*>(window->main_widget()); - inspector_widget->set_dom_json(dom_tree); - window->show(); - window->move_to_front(); -} - Tab::Tab(BrowserWindow& window) { load_from_gml(tab_gml); @@ -290,7 +277,8 @@ Tab::Tab(BrowserWindow& window) }; hooks().on_get_dom_tree = [this](auto& dom_tree) { - view_dom_tree(dom_tree); + if (m_dom_inspector_widget) + m_dom_inspector_widget->set_dom_json(dom_tree); }; hooks().on_js_console_output = [this](auto& method, auto& line) { @@ -479,7 +467,22 @@ BrowserWindow& Tab::window() void Tab::show_inspector_window(Browser::Tab::InspectorTarget) { + if (!m_dom_inspector_widget) { + auto window = GUI::Window::construct(&this->window()); + window->resize(300, 500); + window->set_title("DOM inspector"); + window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png")); + window->on_close = [&]() { + // FIXME: Clear inspected node for OOPWV + }; + m_dom_inspector_widget = window->set_main_widget<InspectorWidget>(); + } + m_web_content_view->inspect_dom_tree(); + + auto* window = m_dom_inspector_widget->window(); + window->show(); + window->move_to_front(); } } diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 2cfbef51f9..5e95648001 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -22,6 +22,7 @@ class WebViewHooks; namespace Browser { class BrowserWindow; +class InspectorWidget; class Tab final : public GUI::Widget { C_OBJECT(Tab); @@ -82,7 +83,6 @@ private: void update_bookmark_button(const String& url); void start_download(const URL& url); void view_source(const URL& url, const String& source); - void view_dom_tree(const String&); History m_history; @@ -90,6 +90,7 @@ private: RefPtr<GUI::UrlBox> m_location_box; RefPtr<GUI::Button> m_bookmark_button; + RefPtr<InspectorWidget> m_dom_inspector_widget; RefPtr<GUI::Window> m_console_window; RefPtr<GUI::Statusbar> m_statusbar; RefPtr<GUI::ToolbarContainer> m_toolbar_container; |