Ladybird: Add "View Source" menu action (Ctrl+U)

This commit is contained in:
Andreas Kling 2022-07-09 17:46:11 +02:00 committed by Andrew Kaster
parent 1400a160bc
commit 74c71804c7
Notes: sideshowbarker 2024-07-17 06:24:08 +09:00
3 changed files with 29 additions and 0 deletions

View file

@ -9,6 +9,7 @@
#include "WebView.h"
#include <LibCore/EventLoop.h>
#include <QAction>
#include <QPlainTextEdit>
#include <QStatusBar>
extern String s_serenity_resource_root;
@ -31,6 +32,24 @@ BrowserWindow::BrowserWindow(Core::EventLoop& event_loop)
quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
menu->addAction(quit_action);
auto* inspect_menu = menuBar()->addMenu("&Inspect");
auto* view_source_action = new QAction("View &Source");
view_source_action->setIcon(QIcon(QString("%1/res/icons/16x16/filetype-html.png").arg(s_serenity_resource_root.characters())));
view_source_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_U));
inspect_menu->addAction(view_source_action);
QObject::connect(view_source_action, &QAction::triggered, this, [this] {
if (m_current_tab) {
auto source = m_current_tab->view().source();
auto* text_edit = new QPlainTextEdit;
text_edit->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont));
text_edit->resize(800, 600);
text_edit->setPlainText(source.characters());
text_edit->show();
}
});
auto* debug_menu = menuBar()->addMenu("&Debug");
auto* dump_dom_tree_action = new QAction("Dump DOM Tree");

View file

@ -664,3 +664,11 @@ void WebView::debug_request(String const& request, String const& argument)
doc->window().local_storage()->dump();
}
}
String WebView::source() const
{
auto* document = m_page_client->page().top_level_browsing_context().active_document();
if (!document)
return String::empty();
return document->source();
}

View file

@ -32,6 +32,8 @@ public:
void debug_request(String const& request, String const& argument);
String source() const;
signals:
void linkHovered(QString, int timeout = 0);
void linkUnhovered();