diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index ee5ea9cbe0..5c6eebc868 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022-2023, Andreas Kling * Copyright (c) 2022, Matthew Costa * Copyright (c) 2022, Filiph Sandström * Copyright (c) 2023, Linus Groh @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -53,6 +55,18 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); menu->addAction(quit_action); + auto* edit_menu = menuBar()->addMenu("&Edit"); + + auto* copy_action = new QAction("&Copy", this); + copy_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Copy)); + edit_menu->addAction(copy_action); + QObject::connect(copy_action, &QAction::triggered, this, &BrowserWindow::copy_selected_text); + + auto* select_all_action = new QAction("Select &All", this); + select_all_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::SelectAll)); + edit_menu->addAction(select_all_action); + QObject::connect(select_all_action, &QAction::triggered, this, &BrowserWindow::select_all); + auto* view_menu = menuBar()->addMenu("&View"); auto* open_next_tab_action = new QAction("Open &Next Tab", this); @@ -455,3 +469,18 @@ void BrowserWindow::reset_zoom() if (m_current_tab) m_current_tab->view().reset_zoom(); } + +void BrowserWindow::select_all() +{ + if (auto* tab = m_current_tab) + tab->view().select_all(); +} + +void BrowserWindow::copy_selected_text() +{ + if (auto* tab = m_current_tab) { + auto text = tab->view().selected_text(); + auto* clipboard = QGuiApplication::clipboard(); + clipboard->setText(qstring_from_ak_deprecated_string(text)); + } +} diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index 4fb89cf198..7f2be67949 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -46,6 +46,8 @@ public slots: void zoom_in(); void zoom_out(); void reset_zoom(); + void select_all(); + void copy_selected_text(); private: void debug_request(DeprecatedString const& request, DeprecatedString const& argument = ""); diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index f320f3cd02..e9a99b07ad 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -1120,3 +1120,13 @@ void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString c { dbgln("TODO: support accessibility tree in Ladybird"); } + +DeprecatedString WebContentView::selected_text() +{ + return client().get_selected_text(); +} + +void WebContentView::select_all() +{ + client().async_select_all(); +} diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index b33b1599b4..d09d9ffa4f 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -112,6 +112,9 @@ public: void zoom_out(); void reset_zoom(); + DeprecatedString selected_text(); + void select_all(); + virtual void notify_server_did_layout(Badge, Gfx::IntSize content_size) override; virtual void notify_server_did_paint(Badge, i32 bitmap_id) override; virtual void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&) override;