summaryrefslogtreecommitdiff
path: root/Userland/Applications/Browser
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@gmail.com>2021-09-01 17:03:18 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-06 18:20:26 +0200
commit2b2158595fc60c86468cead2d9f9a322e791c021 (patch)
tree94c588df4f0466a17b4b0b03f7538ebc04b1bf59 /Userland/Applications/Browser
parent931f462b6e85643e82763ab932308aca0f6bb6cd (diff)
downloadserenity-2b2158595fc60c86468cead2d9f9a322e791c021.zip
Browser: Move `show_console_window()` to Tab
Having the BrowserWindow assigning Tab's internals felt a bit wrong. This is also a step towards removing BrowserWindow as a friend class. While I was at it, changed the Tab to having a pointer to the ConsoleWidget instead of the Window, since that is usually what we want to use, and it's awkward having to static_cast the main-widget repeatedly.
Diffstat (limited to 'Userland/Applications/Browser')
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp17
-rw-r--r--Userland/Applications/Browser/Tab.cpp27
-rw-r--r--Userland/Applications/Browser/Tab.h5
3 files changed, 28 insertions, 21 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index 7d77766c33..58c32f73b7 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -211,22 +211,7 @@ void BrowserWindow::build_menus()
auto js_console_action = GUI::Action::create(
"Open &JS Console", { Mod_Ctrl, Key_I }, [this](auto&) {
- auto& tab = active_tab();
- if (!tab.m_console_window) {
- tab.m_console_window = GUI::Window::construct(this);
- tab.m_console_window->resize(500, 300);
- tab.m_console_window->set_title("JS Console");
- tab.m_console_window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-javascript.png"));
- tab.m_console_window->set_main_widget<ConsoleWidget>();
- }
- auto* console_widget = static_cast<ConsoleWidget*>(tab.m_console_window->main_widget());
- console_widget->on_js_input = [&tab](const String& js_source) {
- tab.m_web_content_view->js_console_input(js_source);
- };
- console_widget->clear_output();
- tab.m_web_content_view->js_console_initialize();
- tab.m_console_window->show();
- tab.m_console_window->move_to_front();
+ active_tab().show_console_window();
},
this);
js_console_action->set_status_tip("Open JavaScript console for this page");
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp
index dfd961a146..0a292b4119 100644
--- a/Userland/Applications/Browser/Tab.cpp
+++ b/Userland/Applications/Browser/Tab.cpp
@@ -294,10 +294,8 @@ Tab::Tab(BrowserWindow& window)
};
hooks().on_js_console_output = [this](auto& method, auto& line) {
- if (m_console_window) {
- auto* console_widget = static_cast<ConsoleWidget*>(m_console_window->main_widget());
- console_widget->handle_js_console_output(method, line);
- }
+ if (m_console_widget)
+ m_console_widget->handle_js_console_output(method, line);
};
auto focus_location_box_action = GUI::Action::create(
@@ -503,4 +501,25 @@ void Tab::show_inspector_window(Browser::Tab::InspectorTarget inspector_target)
window->move_to_front();
}
+void Tab::show_console_window()
+{
+ if (!m_console_widget) {
+ auto console_window = GUI::Window::construct(&window());
+ console_window->resize(500, 300);
+ console_window->set_title("JS Console");
+ console_window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-javascript.png"));
+ m_console_widget = console_window->set_main_widget<ConsoleWidget>();
+ m_console_widget->on_js_input = [this](String const& js_source) {
+ m_web_content_view->js_console_input(js_source);
+ };
+ }
+
+ m_console_widget->clear_output();
+ m_web_content_view->js_console_initialize();
+
+ auto* window = m_console_widget->window();
+ window->show();
+ window->move_to_front();
+}
+
}
diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h
index 5e95648001..02fbc9e3f9 100644
--- a/Userland/Applications/Browser/Tab.h
+++ b/Userland/Applications/Browser/Tab.h
@@ -23,6 +23,7 @@ namespace Browser {
class BrowserWindow;
class InspectorWidget;
+class ConsoleWidget;
class Tab final : public GUI::Widget {
C_OBJECT(Tab);
@@ -66,6 +67,8 @@ public:
};
void show_inspector_window(InspectorTarget);
+ void show_console_window();
+
const String& title() const { return m_title; }
const Gfx::Bitmap* icon() const { return m_icon; }
@@ -91,7 +94,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<ConsoleWidget> m_console_widget;
RefPtr<GUI::Statusbar> m_statusbar;
RefPtr<GUI::ToolbarContainer> m_toolbar_container;