mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
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.
This commit is contained in:
parent
d7485df928
commit
2d6a02f03b
Notes:
sideshowbarker
2024-07-18 04:52:20 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/2d6a02f03bf Pull-request: https://github.com/SerenityOS/serenity/pull/9725 Issue: https://github.com/SerenityOS/serenity/issues/8935 Reviewed-by: https://github.com/awesomekling
2 changed files with 20 additions and 16 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue