Skip to content
This repository was archived by the owner on Dec 25, 2022. It is now read-only.

Context menu for links #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,16 @@ void BrowserWindow::debug_request(String const& request, String const& argument)
}

void BrowserWindow::new_tab()
{
new_tab_with_url({});
}

void BrowserWindow::new_tab_with_url(QUrl const& url)
{
auto tab = make<Tab>(this, m_webdriver_fd_passing_socket);
auto tab_ptr = tab.ptr();
if (!url.isEmpty())
tab->navigate(url.toString());
m_tabs.append(std::move(tab));

if (m_current_tab == nullptr) {
Expand Down
1 change: 1 addition & 0 deletions BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public slots:
void tab_title_changed(int index, QString const&);
void tab_favicon_changed(int index, QIcon icon);
void new_tab();
void new_tab_with_url(QUrl const&);
void close_tab(int index);
void close_current_tab();
void open_next_tab();
Expand Down
1 change: 0 additions & 1 deletion ConsoleGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class ConsoleGlobalObject final : public JS::GlobalObject {
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& name) override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;


private:
virtual void visit_edges(Visitor&) override;

Expand Down
1 change: 0 additions & 1 deletion ConsoleWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ConsoleWidget final : public QWidget {
Function<void(i32)> on_request_messages;

private:

void request_console_messages();
void clear_output();

Expand Down
6 changes: 3 additions & 3 deletions SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include "Settings.h"
#include "SettingsDialog.h"
#include "Settings.h"
#include <QCloseEvent>
#include <QLabel>

Expand All @@ -27,15 +27,15 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
QObject::connect(m_ok_button, &QPushButton::released, this, [this] {
close();
});

setWindowTitle("Settings");
setFixedWidth(300);
setLayout(m_layout);
show();
setFocus();
}

void SettingsDialog::closeEvent(QCloseEvent *event)
void SettingsDialog::closeEvent(QCloseEvent* event)
{
save();
event->accept();
Expand Down
6 changes: 3 additions & 3 deletions SettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <QFormLayout>
#include <QDialog>
#include <QMainWindow>
#include <QFormLayout>
#include <QLineEdit>
#include <QMainWindow>
#include <QPushButton>

#pragma once
Expand All @@ -16,7 +16,7 @@ class SettingsDialog : public QDialog {
Q_OBJECT
public:
explicit SettingsDialog(QMainWindow* window);

void save();

virtual void closeEvent(QCloseEvent*) override;
Expand Down
24 changes: 23 additions & 1 deletion Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#include "Settings.h"
#include "Utilities.h"
#include <Browser/History.h>
#include <QCoreApplication>
#include <QClipboard>
#include <QFont>
#include <QFontMetrics>
#include <QGuiApplication>
#include <QPlainTextEdit>
#include <QPoint>
#include <QResizeEvent>
#include <QUrl>

extern String s_serenity_resource_root;
extern Browser::Settings* s_settings;
Expand Down Expand Up @@ -93,6 +95,26 @@ Tab::Tab(BrowserWindow* window, int webdriver_fd_passing_socket)
m_back_action->setEnabled(m_history.can_go_back());
m_forward_action->setEnabled(m_history.can_go_forward());
});

QObject::connect(m_view, &WebContentView::link_content_menu, [this](QPoint& local_position, QUrl const& url, unsigned) {
auto global_position = this->mapToGlobal(local_position);
auto menu = QMenu();

auto* copy_link_action = new QAction(tr("&Copy Link"));
auto* open_link_in_tab_action = new QAction(tr("Open link in a &new tab"));

menu.addAction(open_link_in_tab_action);
menu.addAction(copy_link_action);
auto res = menu.exec(global_position);

if (res == copy_link_action) {
QClipboard* clipboard = QGuiApplication::clipboard();
clipboard->setText(url.toString());
} else if (res == open_link_in_tab_action) {
auto browser_window = static_cast<BrowserWindow*>(m_window);
browser_window->new_tab_with_url(url);
}
});
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);
Expand Down
1 change: 0 additions & 1 deletion TimerQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,4 @@ void TimerQt::set_single_shot(bool single_shot)
m_timer->setSingleShot(single_shot);
}


}
12 changes: 12 additions & 0 deletions Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <AK/LexicalPath.h>
#include <AK/Platform.h>
#include <LibCore/File.h>
#include <LibGfx/Point.h>
#include <QCoreApplication>
#include <QPoint>

String s_serenity_resource_root;

Expand All @@ -24,6 +26,16 @@ QString qstring_from_akstring(AK::String const& akstring)
return QString::fromUtf8(akstring.characters(), akstring.length());
}

QUrl qurl_from_akurl(AK::URL const& akurl)
{
return QUrl(qstring_from_akstring(akurl.to_string()));
}

QPoint qpoint_from_intpoint(Gfx::IntPoint const& position)
{
return QPoint(position.x(), position.y());
}

void platform_init()
{
#ifdef AK_OS_ANDROID
Expand Down
8 changes: 8 additions & 0 deletions Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@

#pragma once

#define AK_DONT_REPLACE_STD
#include <AK/String.h>
#include <AK/URL.h>
#include <LibGfx/Forward.h>
#include <QPoint>
#include <QString>
#include <QUrl>

AK::String akstring_from_qstring(QString const&);
QString qstring_from_akstring(AK::String const&);
QUrl qurl_from_akurl(AK::URL const& akurl);
QPoint qpoint_from_intpoint(Gfx::IntPoint const& position);

void platform_init();

extern String s_serenity_resource_root;
10 changes: 6 additions & 4 deletions WebContentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,13 @@ void WebContentView::notify_server_did_request_context_menu(Badge<WebContentClie
(void)content_position;
}

void WebContentView::notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const& content_position, AK::URL const& url, String const&, unsigned)
void WebContentView::notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const& content_position, AK::URL const& url, String const&, unsigned modifiers)
{
// FIXME
(void)content_position;
(void)url;
auto view_offset = QPoint(horizontalScrollBar()->value(), verticalScrollBar()->value());
auto position_in_page = qpoint_from_intpoint(content_position);
auto position_in_view = position_in_page - view_offset;
auto qurl = qurl_from_akurl(url);
emit link_content_menu(position_in_view, qurl, modifiers);
}

void WebContentView::notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint const& content_position, AK::URL const& url, String const&, unsigned, Gfx::ShareableBitmap const& bitmap)
Expand Down
1 change: 1 addition & 0 deletions WebContentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class WebContentView final
Gfx::IntRect maximize_window();
Gfx::IntRect minimize_window();
Gfx::IntRect fullscreen_window();
void link_content_menu(QPoint& local_position, QUrl const&, unsigned modifiers);

private:
void request_repaint();
Expand Down
2 changes: 1 addition & 1 deletion WebSocketClientManagerLadybird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

#include "WebSocketClientManagerLadybird.h"
#include "WebSocketLadybird.h"
#include "WebSocketImplQt.h"
#include "WebSocketLadybird.h"

namespace Ladybird {

Expand Down
10 changes: 5 additions & 5 deletions WebSocketClientManagerLadybird.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Copyright (c) 2022, Dex♪ <dexes.ttp@gmail.com>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
* Copyright (c) 2022, Dex♪ <dexes.ttp@gmail.com>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/WebSockets/WebSocket.h>
#include <LibWebSocket/ConnectionInfo.h>
Expand Down