|
10 | 10 | #include "Settings.h"
|
11 | 11 | #include "Utilities.h"
|
12 | 12 | #include <Browser/History.h>
|
13 |
| -#include <QCoreApplication> |
14 | 13 | #include <QFont>
|
15 | 14 | #include <QFontMetrics>
|
16 | 15 | #include <QPlainTextEdit>
|
| 16 | +#include <QClipboard> |
| 17 | +#include <QFont> |
| 18 | +#include <QFontMetrics> |
| 19 | +#include <QGuiApplication> |
17 | 20 | #include <QPoint>
|
18 | 21 | #include <QResizeEvent>
|
| 22 | +#include <QUrl> |
19 | 23 |
|
20 | 24 | extern String s_serenity_resource_root;
|
21 | 25 | extern Browser::Settings* s_settings;
|
@@ -93,6 +97,27 @@ Tab::Tab(BrowserWindow* window, int webdriver_fd_passing_socket)
|
93 | 97 | m_back_action->setEnabled(m_history.can_go_back());
|
94 | 98 | m_forward_action->setEnabled(m_history.can_go_forward());
|
95 | 99 | });
|
| 100 | + |
| 101 | + QObject::connect(m_view, &WebContentView::link_content_menu, [this] (QPoint &local_position, const QUrl& url, unsigned ){ |
| 102 | + auto global_position = this->mapToGlobal(local_position); |
| 103 | + auto menu = QMenu(); |
| 104 | + |
| 105 | + auto copy_link_action = new QAction(tr("&Copy Link")); |
| 106 | + auto open_link_in_tab_action = new QAction(tr("Open link in a &new tab")); |
| 107 | + |
| 108 | + menu.addAction(open_link_in_tab_action); |
| 109 | + menu.addAction(copy_link_action); |
| 110 | + auto res = menu.exec(global_position); |
| 111 | + |
| 112 | + if (res == copy_link_action) { |
| 113 | + QClipboard *clipboard = QGuiApplication::clipboard(); |
| 114 | + clipboard->setText(url.toString()); |
| 115 | + qDebug() << "Copied to clipboard text:" << url.toString(); |
| 116 | + } else if (res == open_link_in_tab_action){ |
| 117 | + auto browser_window = static_cast<BrowserWindow*>(m_window); |
| 118 | + return browser_window->new_tab_with_url(url); |
| 119 | + } |
| 120 | + }); |
96 | 121 | QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed);
|
97 | 122 | QObject::connect(m_view, &WebContentView::title_changed, this, &Tab::page_title_changed);
|
98 | 123 | QObject::connect(m_view, &WebContentView::favicon_changed, this, &Tab::page_favicon_changed);
|
|
0 commit comments