Ladybird: Allow right clicking and inspecting elements

This adds "Inspect Element" (currently the only entry) to the context
menu for the page, which will do what you expect (most of the time),
and bring up the Inspector with hovered element selected.
This commit is contained in:
MacDue 2023-05-08 21:15:35 +01:00 committed by Andreas Kling
commit 09773048b6
Notes: sideshowbarker 2024-07-16 20:26:59 +09:00
7 changed files with 101 additions and 9 deletions

View file

@ -330,11 +330,28 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
QObject::connect(m_tabs_container, &QTabWidget::tabCloseRequested, this, &BrowserWindow::close_tab);
QObject::connect(close_current_tab_action, &QAction::triggered, this, &BrowserWindow::close_current_tab);
setContextMenuPolicy(Qt::CustomContextMenu);
QObject::connect(this, &QWidget::customContextMenuRequested, this, &BrowserWindow::show_context_menu);
new_tab(s_settings->new_tab_page(), Web::HTML::ActivateTab::Yes);
setCentralWidget(m_tabs_container);
}
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));
}
void BrowserWindow::set_current_tab(Tab* tab)
{
m_current_tab = tab;