diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index 277c90c831..460ecfc3fb 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -333,6 +333,42 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(this, &QWidget::customContextMenuRequested, this, &BrowserWindow::show_context_menu); + m_context_menu = make("Context menu", this); + auto* inspect_element_action = new QAction("&Inspect Element", this); + connect(inspect_element_action, &QAction::triggered, this, [this] { + if (m_current_tab) + m_current_tab->view().show_inspector(WebContentView::InspectorTarget::HoveredElement); + }); + m_go_back_action = make("Go Back"); + connect(m_go_back_action, &QAction::triggered, this, [this] { + if (m_current_tab) + m_current_tab->back(); + }); + m_go_forward_action = make("Go Forward"); + connect(m_go_forward_action, &QAction::triggered, this, [this] { + if (m_current_tab) + m_current_tab->forward(); + }); + m_reload_action = make("&Reload"); + connect(m_reload_action, &QAction::triggered, this, [this] { + if (m_current_tab) + m_current_tab->reload(); + }); + m_context_menu->addAction(m_go_back_action); + m_context_menu->addAction(m_go_forward_action); + m_context_menu->addAction(m_reload_action); + m_context_menu->addSeparator(); + m_context_menu->addAction(copy_action); + m_context_menu->addAction(select_all_action); + m_context_menu->addSeparator(); + m_context_menu->addAction(view_source_action); + m_context_menu->addAction(inspect_element_action); + m_go_back_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Back)); + m_go_forward_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Forward)); + m_reload_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Refresh)); + m_go_back_action->setEnabled(false); + m_go_forward_action->setEnabled(false); + new_tab(s_settings->new_tab_page(), Web::HTML::ActivateTab::Yes); setCentralWidget(m_tabs_container); @@ -340,16 +376,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive void BrowserWindow::show_context_menu(QPoint const& point) { - QMenu contextMenu("Context menu", this); - - QAction inspect_action("&Inspect Element", this); - connect(&inspect_action, &QAction::triggered, this, [this] { - if (!m_current_tab) - return; - m_current_tab->view().show_inspector(WebContentView::InspectorTarget::HoveredElement); - }); - contextMenu.addAction(&inspect_action); - contextMenu.exec(mapToGlobal(point)); + m_context_menu->exec(mapToGlobal(point)); } void BrowserWindow::set_current_tab(Tab* tab) diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index 1c769020e6..1cc0e2c63b 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -32,6 +32,21 @@ public: int tab_index(Tab*); + QAction& go_back_action() + { + return *m_go_back_action; + } + + QAction& go_forward_action() + { + return *m_go_forward_action; + } + + QAction& reload_action() + { + return *m_reload_action; + } + public slots: void tab_title_changed(int index, QString const&); void tab_favicon_changed(int index, QIcon icon); @@ -68,6 +83,11 @@ private: Tab* m_current_tab { nullptr }; QMenu* m_zoom_menu { nullptr }; + OwnPtr m_context_menu {}; + OwnPtr m_go_back_action {}; + OwnPtr m_go_forward_action {}; + OwnPtr m_reload_action {}; + Browser::CookieJar& m_cookie_jar; StringView m_webdriver_content_ipc_path; diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index a5b312267e..3735601ecc 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -74,20 +74,11 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView:: m_layout->addWidget(m_toolbar); m_layout->addWidget(m_view); - m_back_action = make("Back"); - m_back_action->setEnabled(false); - m_back_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Back)); - m_forward_action = make("Forward"); - m_forward_action->setEnabled(false); - m_forward_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Forward)); - m_reload_action = make("Reload"); - m_reload_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Refresh)); - rerender_toolbar_icons(); - m_toolbar->addAction(m_back_action); - m_toolbar->addAction(m_forward_action); - m_toolbar->addAction(m_reload_action); + m_toolbar->addAction(&m_window->go_back_action()); + m_toolbar->addAction(&m_window->go_forward_action()); + m_toolbar->addAction(&m_window->reload_action()); m_toolbar->addWidget(m_location_edit); m_reset_zoom_button->setToolTip("Reset zoom level"); m_reset_zoom_button_action = m_toolbar->addWidget(m_reset_zoom_button); @@ -143,16 +134,12 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView:: } m_is_history_navigation = false; - m_back_action->setEnabled(m_history.can_go_back()); - m_forward_action->setEnabled(m_history.can_go_forward()); + m_window->go_back_action().setEnabled(m_history.can_go_back()); + m_window->go_forward_action().setEnabled(m_history.can_go_forward()); }); QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed); QObject::connect(m_view, &WebContentView::title_changed, this, &Tab::page_title_changed); QObject::connect(m_view, &WebContentView::favicon_changed, this, &Tab::page_favicon_changed); - - QObject::connect(m_back_action, &QAction::triggered, this, &Tab::back); - QObject::connect(m_forward_action, &QAction::triggered, this, &Tab::forward); - QObject::connect(m_reload_action, &QAction::triggered, this, &Tab::reload); QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor); QObject::connect(m_view, &WebContentView::got_source, this, [this](AK::URL, QString const& source) { @@ -300,7 +287,7 @@ bool Tab::event(QEvent* event) void Tab::rerender_toolbar_icons() { - m_back_action->setIcon(render_svg_icon_with_theme_colors("back", palette())); - m_forward_action->setIcon(render_svg_icon_with_theme_colors("forward", palette())); - m_reload_action->setIcon(render_svg_icon_with_theme_colors("reload", palette())); + m_window->go_back_action().setIcon(render_svg_icon_with_theme_colors("back", palette())); + m_window->go_forward_action().setIcon(render_svg_icon_with_theme_colors("forward", palette())); + m_window->reload_action().setIcon(render_svg_icon_with_theme_colors("reload", palette())); } diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index 38066b954f..3646a6d764 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -67,10 +67,6 @@ private: QString m_title; QLabel* m_hover_label { nullptr }; - OwnPtr m_back_action; - OwnPtr m_forward_action; - OwnPtr m_reload_action; - int tab_index(); bool m_is_history_navigation { false };