diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-09-01 17:03:18 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 18:20:26 +0200 |
commit | 2b2158595fc60c86468cead2d9f9a322e791c021 (patch) | |
tree | 94c588df4f0466a17b4b0b03f7538ebc04b1bf59 /Userland/Applications/Browser/Tab.cpp | |
parent | 931f462b6e85643e82763ab932308aca0f6bb6cd (diff) | |
download | serenity-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/Tab.cpp')
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
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(); +} + } |