2022-07-05 22:18:21 +00:00
|
|
|
/*
|
2022-07-19 10:23:11 +00:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2022-07-05 22:18:21 +00:00
|
|
|
* Copyright (c) 2022, Matthew Costa <ucosty@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BrowserWindow.h"
|
2023-11-05 12:45:43 +00:00
|
|
|
#include "Icon.h"
|
2023-05-17 15:54:36 +00:00
|
|
|
#include "InspectorWidget.h"
|
2022-07-14 03:41:13 +00:00
|
|
|
#include "Settings.h"
|
2023-08-05 16:42:26 +00:00
|
|
|
#include "StringUtils.h"
|
2023-07-29 18:46:47 +00:00
|
|
|
#include "TVGIconEngine.h"
|
2023-11-04 20:40:12 +00:00
|
|
|
#include <AK/TemporaryChange.h>
|
2023-05-15 17:43:58 +00:00
|
|
|
#include <LibGfx/ImageFormats/BMPWriter.h>
|
2023-07-02 21:37:59 +00:00
|
|
|
#include <LibGfx/Painter.h>
|
2023-10-23 16:49:53 +00:00
|
|
|
#include <LibWebView/SearchEngine.h>
|
2023-08-28 20:36:51 +00:00
|
|
|
#include <LibWebView/SourceHighlighter.h>
|
2023-10-13 13:52:06 +00:00
|
|
|
#include <LibWebView/URL.h>
|
2023-05-15 16:27:10 +00:00
|
|
|
#include <QClipboard>
|
2023-09-04 13:46:20 +00:00
|
|
|
#include <QColorDialog>
|
2022-07-05 22:18:21 +00:00
|
|
|
#include <QCoreApplication>
|
2023-05-21 04:53:38 +00:00
|
|
|
#include <QCursor>
|
2023-05-25 21:47:12 +00:00
|
|
|
#include <QFileDialog>
|
2022-09-09 12:23:36 +00:00
|
|
|
#include <QFont>
|
|
|
|
#include <QFontMetrics>
|
2023-05-15 16:27:10 +00:00
|
|
|
#include <QGuiApplication>
|
2023-05-15 17:43:58 +00:00
|
|
|
#include <QImage>
|
2023-05-17 18:23:34 +00:00
|
|
|
#include <QInputDialog>
|
2023-05-15 15:49:44 +00:00
|
|
|
#include <QMenu>
|
2023-05-16 11:56:12 +00:00
|
|
|
#include <QMessageBox>
|
2023-11-10 18:44:12 +00:00
|
|
|
#include <QMimeData>
|
2023-05-05 13:38:46 +00:00
|
|
|
#include <QPainter>
|
2022-07-13 02:39:38 +00:00
|
|
|
#include <QPoint>
|
2022-09-09 12:23:36 +00:00
|
|
|
#include <QResizeEvent>
|
2022-07-05 22:18:21 +00:00
|
|
|
|
2023-08-02 17:52:59 +00:00
|
|
|
namespace Ladybird {
|
|
|
|
|
2023-07-29 18:46:47 +00:00
|
|
|
static QIcon create_tvg_icon_with_theme_colors(QString name, QPalette const& palette)
|
2023-05-05 13:38:46 +00:00
|
|
|
{
|
2023-07-02 21:37:59 +00:00
|
|
|
auto path = QString(":/Icons/%1.tvg").arg(name);
|
2023-07-29 18:46:47 +00:00
|
|
|
auto icon_engine = TVGIconEngine::from_file(path);
|
|
|
|
VERIFY(icon_engine);
|
|
|
|
auto icon_filter = [](QColor color) {
|
|
|
|
return [color = Color::from_argb(color.rgba64().toArgb32())](Gfx::Color icon_color) {
|
|
|
|
return color.with_alpha((icon_color.alpha() * color.alpha()) / 255);
|
|
|
|
};
|
2023-05-05 13:38:46 +00:00
|
|
|
};
|
2023-07-29 18:46:47 +00:00
|
|
|
icon_engine->add_filter(QIcon::Mode::Normal, icon_filter(palette.color(QPalette::ColorGroup::Normal, QPalette::ColorRole::ButtonText)));
|
|
|
|
icon_engine->add_filter(QIcon::Mode::Disabled, icon_filter(palette.color(QPalette::ColorGroup::Disabled, QPalette::ColorRole::ButtonText)));
|
|
|
|
return QIcon(icon_engine);
|
2023-05-05 13:38:46 +00:00
|
|
|
}
|
|
|
|
|
2023-12-01 17:18:40 +00:00
|
|
|
Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path)
|
2022-10-01 18:46:24 +00:00
|
|
|
: QWidget(window)
|
|
|
|
, m_window(window)
|
2022-07-05 22:18:21 +00:00
|
|
|
{
|
|
|
|
m_layout = new QBoxLayout(QBoxLayout::Direction::TopToBottom, this);
|
2022-09-09 12:27:59 +00:00
|
|
|
m_layout->setSpacing(0);
|
2022-07-05 22:18:21 +00:00
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
2023-12-01 17:18:40 +00:00
|
|
|
m_view = new WebContentView(web_content_options, webdriver_content_ipc_path);
|
2022-10-01 18:46:24 +00:00
|
|
|
m_toolbar = new QToolBar(this);
|
2023-01-18 14:12:13 +00:00
|
|
|
m_location_edit = new LocationEdit(this);
|
2022-07-05 22:18:21 +00:00
|
|
|
|
2022-09-09 12:23:36 +00:00
|
|
|
m_hover_label = new QLabel(this);
|
2022-09-09 13:19:18 +00:00
|
|
|
m_hover_label->hide();
|
2022-09-09 12:23:36 +00:00
|
|
|
m_hover_label->setFrameShape(QFrame::Shape::Box);
|
|
|
|
m_hover_label->setAutoFillBackground(true);
|
|
|
|
|
2023-07-19 16:07:50 +00:00
|
|
|
auto* focus_location_editor_action = new QAction("Edit Location", this);
|
2022-09-12 07:12:04 +00:00
|
|
|
focus_location_editor_action->setShortcut(QKeySequence("Ctrl+L"));
|
|
|
|
addAction(focus_location_editor_action);
|
2022-07-07 00:56:09 +00:00
|
|
|
|
2022-07-05 22:18:21 +00:00
|
|
|
m_layout->addWidget(m_toolbar);
|
|
|
|
m_layout->addWidget(m_view);
|
|
|
|
|
2023-07-29 18:46:47 +00:00
|
|
|
recreate_toolbar_icons();
|
2023-05-05 13:38:46 +00:00
|
|
|
|
2023-05-13 12:07:12 +00:00
|
|
|
m_toolbar->addAction(&m_window->go_back_action());
|
|
|
|
m_toolbar->addAction(&m_window->go_forward_action());
|
|
|
|
m_toolbar->addAction(&m_window->reload_action());
|
2022-07-05 22:18:21 +00:00
|
|
|
m_toolbar->addWidget(m_location_edit);
|
2023-07-30 22:25:32 +00:00
|
|
|
m_toolbar->setIconSize({ 16, 16 });
|
|
|
|
// This is a little awkward, but without this Qt shrinks the button to the size of the icon.
|
|
|
|
// Note: toolButtonStyle="0" -> ToolButtonIconOnly.
|
|
|
|
m_toolbar->setStyleSheet("QToolButton[toolButtonStyle=\"0\"]{width:24px;height:24px}");
|
|
|
|
|
|
|
|
m_reset_zoom_button = new QToolButton(m_toolbar);
|
|
|
|
m_reset_zoom_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
|
2023-03-31 20:33:42 +00:00
|
|
|
m_reset_zoom_button->setToolTip("Reset zoom level");
|
2023-03-28 23:25:42 +00:00
|
|
|
m_reset_zoom_button_action = m_toolbar->addWidget(m_reset_zoom_button);
|
|
|
|
m_reset_zoom_button_action->setVisible(false);
|
|
|
|
|
|
|
|
QObject::connect(m_reset_zoom_button, &QAbstractButton::clicked, [this] {
|
|
|
|
view().reset_zoom();
|
|
|
|
update_reset_zoom_button();
|
2023-08-04 11:37:52 +00:00
|
|
|
m_window->update_zoom_menu();
|
2023-03-28 23:25:42 +00:00
|
|
|
});
|
|
|
|
|
2023-05-17 16:37:31 +00:00
|
|
|
view().on_activate_tab = [this] {
|
2023-03-20 23:52:00 +00:00
|
|
|
m_window->activate_tab(tab_index());
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
2023-03-20 23:52:00 +00:00
|
|
|
|
2023-05-17 16:37:31 +00:00
|
|
|
view().on_close = [this] {
|
2023-03-07 03:13:08 +00:00
|
|
|
m_window->close_tab(tab_index());
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
2023-03-07 03:13:08 +00:00
|
|
|
|
2023-05-17 16:37:31 +00:00
|
|
|
view().on_link_hover = [this](auto const& url) {
|
2023-12-04 14:55:47 +00:00
|
|
|
m_hover_label->setText(qstring_from_ak_string(url.to_deprecated_string()));
|
2022-09-09 12:23:36 +00:00
|
|
|
update_hover_label();
|
|
|
|
m_hover_label->show();
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
view().on_link_unhover = [this]() {
|
2022-09-09 12:23:36 +00:00
|
|
|
m_hover_label->hide();
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
2022-07-05 22:18:21 +00:00
|
|
|
|
2023-05-17 16:37:31 +00:00
|
|
|
view().on_load_start = [this](const URL& url, bool is_redirect) {
|
2022-11-24 00:52:16 +00:00
|
|
|
// If we are loading due to a redirect, we replace the current history entry
|
|
|
|
// with the loaded URL
|
|
|
|
if (is_redirect) {
|
|
|
|
m_history.replace_current(url, m_title.toUtf8().data());
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:43:54 +00:00
|
|
|
m_location_edit->setText(url.to_deprecated_string().characters());
|
2023-02-01 18:51:56 +00:00
|
|
|
m_location_edit->setCursorPosition(0);
|
2022-11-08 12:01:20 +00:00
|
|
|
|
|
|
|
// Don't add to history if back or forward is pressed
|
|
|
|
if (!m_is_history_navigation) {
|
|
|
|
m_history.push(url, m_title.toUtf8().data());
|
|
|
|
}
|
|
|
|
m_is_history_navigation = false;
|
|
|
|
|
2023-05-13 12:07:12 +00:00
|
|
|
m_window->go_back_action().setEnabled(m_history.can_go_back());
|
|
|
|
m_window->go_forward_action().setEnabled(m_history.can_go_forward());
|
2023-08-28 19:54:36 +00:00
|
|
|
m_window->reload_action().setEnabled(!m_history.is_empty());
|
2023-05-17 15:54:36 +00:00
|
|
|
|
|
|
|
if (m_inspector_widget)
|
2023-11-24 01:04:54 +00:00
|
|
|
m_inspector_widget->reset();
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
2023-05-17 15:54:36 +00:00
|
|
|
|
|
|
|
view().on_load_finish = [this](auto&) {
|
2023-11-24 01:04:54 +00:00
|
|
|
if (m_inspector_widget != nullptr && m_inspector_widget->isVisible())
|
|
|
|
m_inspector_widget->inspect();
|
2023-05-17 15:54:36 +00:00
|
|
|
};
|
|
|
|
|
2022-07-05 22:18:21 +00:00
|
|
|
QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed);
|
2023-05-17 16:37:31 +00:00
|
|
|
|
|
|
|
view().on_title_change = [this](auto const& title) {
|
2023-12-04 14:55:47 +00:00
|
|
|
m_title = qstring_from_ak_string(title);
|
2023-05-17 16:37:31 +00:00
|
|
|
m_history.update_title(title);
|
|
|
|
|
|
|
|
emit title_changed(tab_index(), m_title);
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_favicon_change = [this](auto const& bitmap) {
|
|
|
|
auto qimage = QImage(bitmap.scanline_u8(0), bitmap.width(), bitmap.height(), QImage::Format_ARGB32);
|
|
|
|
if (qimage.isNull())
|
|
|
|
return;
|
|
|
|
auto qpixmap = QPixmap::fromImage(qimage);
|
|
|
|
if (qpixmap.isNull())
|
|
|
|
return;
|
|
|
|
emit favicon_changed(tab_index(), QIcon(qpixmap));
|
|
|
|
};
|
|
|
|
|
2023-05-17 18:23:34 +00:00
|
|
|
view().on_request_alert = [this](auto const& message) {
|
|
|
|
m_dialog = new QMessageBox(QMessageBox::Icon::Warning, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok, &view());
|
|
|
|
m_dialog->exec();
|
|
|
|
|
|
|
|
view().alert_closed();
|
|
|
|
m_dialog = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_request_confirm = [this](auto const& message) {
|
|
|
|
m_dialog = new QMessageBox(QMessageBox::Icon::Question, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, &view());
|
|
|
|
auto result = m_dialog->exec();
|
|
|
|
|
|
|
|
view().confirm_closed(result == QMessageBox::StandardButton::Ok || result == QDialog::Accepted);
|
|
|
|
m_dialog = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_request_prompt = [this](auto const& message, auto const& default_) {
|
|
|
|
m_dialog = new QInputDialog(&view());
|
|
|
|
auto& dialog = static_cast<QInputDialog&>(*m_dialog);
|
|
|
|
|
|
|
|
dialog.setWindowTitle("Ladybird");
|
|
|
|
dialog.setLabelText(qstring_from_ak_string(message));
|
|
|
|
dialog.setTextValue(qstring_from_ak_string(default_));
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
2023-12-04 15:08:16 +00:00
|
|
|
view().prompt_closed(ak_string_from_qstring(dialog.textValue()));
|
2023-05-17 18:23:34 +00:00
|
|
|
else
|
|
|
|
view().prompt_closed({});
|
|
|
|
|
|
|
|
m_dialog = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_request_set_prompt_text = [this](auto const& message) {
|
|
|
|
if (m_dialog && is<QInputDialog>(*m_dialog))
|
|
|
|
static_cast<QInputDialog&>(*m_dialog).setTextValue(qstring_from_ak_string(message));
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_request_accept_dialog = [this]() {
|
|
|
|
if (m_dialog)
|
|
|
|
m_dialog->accept();
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_request_dismiss_dialog = [this]() {
|
|
|
|
if (m_dialog)
|
|
|
|
m_dialog->reject();
|
|
|
|
};
|
|
|
|
|
2023-09-04 13:46:20 +00:00
|
|
|
view().on_request_color_picker = [this](Color current_color) {
|
|
|
|
m_dialog = new QColorDialog(QColor(current_color.red(), current_color.green(), current_color.blue()), &view());
|
|
|
|
auto& dialog = static_cast<QColorDialog&>(*m_dialog);
|
|
|
|
|
|
|
|
dialog.setWindowTitle("Ladybird");
|
|
|
|
dialog.setOption(QColorDialog::ShowAlphaChannel, false);
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
view().color_picker_closed(Color(dialog.selectedColor().red(), dialog.selectedColor().green(), dialog.selectedColor().blue()));
|
|
|
|
else
|
|
|
|
view().color_picker_closed({});
|
|
|
|
|
|
|
|
m_dialog = nullptr;
|
|
|
|
};
|
|
|
|
|
2023-12-07 14:53:49 +00:00
|
|
|
m_select_dropdown = new QMenu("Select Dropdown", this);
|
|
|
|
QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() {
|
|
|
|
if (!m_select_dropdown->activeAction())
|
|
|
|
view().select_dropdown_closed({});
|
|
|
|
});
|
|
|
|
|
|
|
|
view().on_request_select_dropdown = [this](Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items) {
|
|
|
|
m_select_dropdown->clear();
|
|
|
|
m_select_dropdown->setMinimumWidth(minimum_width);
|
|
|
|
for (auto const& item : items) {
|
|
|
|
select_dropdown_add_item(m_select_dropdown, item);
|
|
|
|
}
|
|
|
|
|
2023-12-12 21:35:37 +00:00
|
|
|
m_select_dropdown->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
|
2023-12-07 14:53:49 +00:00
|
|
|
};
|
|
|
|
|
2022-09-12 07:12:04 +00:00
|
|
|
QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor);
|
2022-10-05 13:23:41 +00:00
|
|
|
|
2023-08-23 15:25:24 +00:00
|
|
|
view().on_received_source = [this](auto const& url, auto const& source) {
|
2023-08-28 20:36:51 +00:00
|
|
|
auto html = WebView::highlight_source(url, source);
|
2023-09-17 15:12:17 +00:00
|
|
|
m_window->new_tab(html, Web::HTML::ActivateTab::Yes);
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
2022-10-07 11:35:40 +00:00
|
|
|
|
2023-05-17 16:37:31 +00:00
|
|
|
view().on_navigate_back = [this]() {
|
|
|
|
back();
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_navigate_forward = [this]() {
|
|
|
|
forward();
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_refresh = [this]() {
|
|
|
|
reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
view().on_restore_window = [this]() {
|
2022-11-14 16:24:06 +00:00
|
|
|
m_window->showNormal();
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
view().on_reposition_window = [this](auto const& position) {
|
2022-11-14 16:24:06 +00:00
|
|
|
m_window->move(position.x(), position.y());
|
|
|
|
return Gfx::IntPoint { m_window->x(), m_window->y() };
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
view().on_resize_window = [this](auto const& size) {
|
2022-11-14 16:24:06 +00:00
|
|
|
m_window->resize(size.width(), size.height());
|
|
|
|
return Gfx::IntSize { m_window->width(), m_window->height() };
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
view().on_maximize_window = [this]() {
|
2022-11-14 16:24:06 +00:00
|
|
|
m_window->showMaximized();
|
|
|
|
return Gfx::IntRect { m_window->x(), m_window->y(), m_window->width(), m_window->height() };
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
view().on_minimize_window = [this]() {
|
2022-11-14 16:24:06 +00:00
|
|
|
m_window->showMinimized();
|
|
|
|
return Gfx::IntRect { m_window->x(), m_window->y(), m_window->width(), m_window->height() };
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
view().on_fullscreen_window = [this]() {
|
2022-11-14 16:24:06 +00:00
|
|
|
m_window->showFullScreen();
|
|
|
|
return Gfx::IntRect { m_window->x(), m_window->y(), m_window->width(), m_window->height() };
|
2023-05-17 16:37:31 +00:00
|
|
|
};
|
2023-05-15 15:49:44 +00:00
|
|
|
|
2023-11-10 18:44:12 +00:00
|
|
|
view().on_insert_clipboard_entry = [](auto const& data, auto const&, auto const& mime_type) {
|
|
|
|
QByteArray qdata { data.bytes_as_string_view().characters_without_null_termination(), static_cast<qsizetype>(data.bytes_as_string_view().length()) };
|
|
|
|
|
|
|
|
auto* mime_data = new QMimeData();
|
|
|
|
mime_data->setData(qstring_from_ak_string(mime_type), qdata);
|
|
|
|
|
|
|
|
auto* clipboard = QGuiApplication::clipboard();
|
|
|
|
clipboard->setMimeData(mime_data);
|
|
|
|
};
|
|
|
|
|
2023-10-23 16:49:53 +00:00
|
|
|
auto* search_selected_text_action = new QAction("&Search for <query>", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
search_selected_text_action->setIcon(load_icon_from_uri("resource://icons/16x16/find.png"sv));
|
2023-10-23 16:49:53 +00:00
|
|
|
QObject::connect(search_selected_text_action, &QAction::triggered, this, [this]() {
|
|
|
|
auto url = MUST(String::formatted(Settings::the()->search_engine().query_url, URL::percent_encode(*m_page_context_menu_search_text)));
|
|
|
|
m_window->new_tab(qstring_from_ak_string(url), Web::HTML::ActivateTab::Yes);
|
|
|
|
});
|
|
|
|
|
2023-05-16 11:56:12 +00:00
|
|
|
auto* take_visible_screenshot_action = new QAction("Take &Visible Screenshot", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
take_visible_screenshot_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-image.png"sv));
|
2023-05-16 11:56:12 +00:00
|
|
|
QObject::connect(take_visible_screenshot_action, &QAction::triggered, this, [this]() {
|
2023-05-17 13:53:13 +00:00
|
|
|
if (auto result = view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Visible); result.is_error()) {
|
2023-12-04 15:08:16 +00:00
|
|
|
auto error = MUST(String::formatted("{}", result.error()));
|
2023-05-16 11:56:12 +00:00
|
|
|
QMessageBox::warning(this, "Ladybird", qstring_from_ak_string(error));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
auto* take_full_screenshot_action = new QAction("Take &Full Screenshot", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
take_full_screenshot_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-image.png"sv));
|
2023-05-16 11:56:12 +00:00
|
|
|
QObject::connect(take_full_screenshot_action, &QAction::triggered, this, [this]() {
|
2023-05-17 13:53:13 +00:00
|
|
|
if (auto result = view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Full); result.is_error()) {
|
2023-12-04 15:08:16 +00:00
|
|
|
auto error = MUST(String::formatted("{}", result.error()));
|
2023-05-16 11:56:12 +00:00
|
|
|
QMessageBox::warning(this, "Ladybird", qstring_from_ak_string(error));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_page_context_menu = new QMenu("Context menu", this);
|
2023-05-15 15:49:44 +00:00
|
|
|
m_page_context_menu->addAction(&m_window->go_back_action());
|
|
|
|
m_page_context_menu->addAction(&m_window->go_forward_action());
|
|
|
|
m_page_context_menu->addAction(&m_window->reload_action());
|
|
|
|
m_page_context_menu->addSeparator();
|
|
|
|
m_page_context_menu->addAction(&m_window->copy_selection_action());
|
|
|
|
m_page_context_menu->addAction(&m_window->select_all_action());
|
|
|
|
m_page_context_menu->addSeparator();
|
2023-10-23 16:49:53 +00:00
|
|
|
m_page_context_menu->addAction(search_selected_text_action);
|
|
|
|
m_page_context_menu->addSeparator();
|
2023-05-16 11:56:12 +00:00
|
|
|
m_page_context_menu->addAction(take_visible_screenshot_action);
|
|
|
|
m_page_context_menu->addAction(take_full_screenshot_action);
|
|
|
|
m_page_context_menu->addSeparator();
|
2023-05-15 15:49:44 +00:00
|
|
|
m_page_context_menu->addAction(&m_window->view_source_action());
|
|
|
|
m_page_context_menu->addAction(&m_window->inspect_dom_node_action());
|
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
view().on_context_menu_request = [this, search_selected_text_action](Gfx::IntPoint content_position) {
|
2023-10-23 16:49:53 +00:00
|
|
|
auto selected_text = Settings::the()->enable_search()
|
|
|
|
? view().selected_text_with_whitespace_collapsed()
|
|
|
|
: OptionalNone {};
|
|
|
|
TemporaryChange change_url { m_page_context_menu_search_text, std::move(selected_text) };
|
|
|
|
|
|
|
|
if (m_page_context_menu_search_text.has_value()) {
|
|
|
|
auto action_text = WebView::format_search_query_for_display(Settings::the()->search_engine().query_url, *m_page_context_menu_search_text);
|
|
|
|
search_selected_text_action->setText(qstring_from_ak_string(action_text));
|
|
|
|
search_selected_text_action->setVisible(true);
|
|
|
|
} else {
|
|
|
|
search_selected_text_action->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
m_page_context_menu->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
|
2023-05-15 15:49:44 +00:00
|
|
|
};
|
2023-05-15 16:27:10 +00:00
|
|
|
|
2023-05-15 16:48:46 +00:00
|
|
|
auto* open_link_action = new QAction("&Open", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_link_action->setIcon(load_icon_from_uri("resource://icons/16x16/go-forward.png"sv));
|
2023-05-15 16:48:46 +00:00
|
|
|
QObject::connect(open_link_action, &QAction::triggered, this, [this]() {
|
|
|
|
open_link(m_link_context_menu_url);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto* open_link_in_new_tab_action = new QAction("&Open in New &Tab", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_link_in_new_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/new-tab.png"sv));
|
2023-05-15 16:48:46 +00:00
|
|
|
QObject::connect(open_link_in_new_tab_action, &QAction::triggered, this, [this]() {
|
|
|
|
open_link_in_new_tab(m_link_context_menu_url);
|
|
|
|
});
|
|
|
|
|
2023-12-05 13:04:15 +00:00
|
|
|
m_link_context_menu_copy_url_action = new QAction("Copy &URL", this);
|
|
|
|
m_link_context_menu_copy_url_action->setIcon(load_icon_from_uri("resource://icons/16x16/edit-copy.png"sv));
|
|
|
|
QObject::connect(m_link_context_menu_copy_url_action, &QAction::triggered, this, [this]() {
|
2023-05-15 16:48:46 +00:00
|
|
|
copy_link_url(m_link_context_menu_url);
|
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_link_context_menu = new QMenu("Link context menu", this);
|
2023-05-15 16:48:46 +00:00
|
|
|
m_link_context_menu->addAction(open_link_action);
|
|
|
|
m_link_context_menu->addAction(open_link_in_new_tab_action);
|
|
|
|
m_link_context_menu->addSeparator();
|
2023-12-05 13:04:15 +00:00
|
|
|
m_link_context_menu->addAction(m_link_context_menu_copy_url_action);
|
2023-05-15 16:48:46 +00:00
|
|
|
m_link_context_menu->addSeparator();
|
|
|
|
m_link_context_menu->addAction(&m_window->inspect_dom_node_action());
|
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
view().on_link_context_menu_request = [this](auto const& url, Gfx::IntPoint content_position) {
|
2023-05-15 16:48:46 +00:00
|
|
|
m_link_context_menu_url = url;
|
|
|
|
|
2023-12-05 13:04:15 +00:00
|
|
|
switch (WebView::url_type(url)) {
|
|
|
|
case WebView::URLType::Email:
|
|
|
|
m_link_context_menu_copy_url_action->setText("Copy &Email Address");
|
|
|
|
break;
|
|
|
|
case WebView::URLType::Telephone:
|
|
|
|
m_link_context_menu_copy_url_action->setText("Copy &Phone Number");
|
|
|
|
break;
|
|
|
|
case WebView::URLType::Other:
|
|
|
|
m_link_context_menu_copy_url_action->setText("Copy &URL");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
m_link_context_menu->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
|
2023-05-15 16:48:46 +00:00
|
|
|
};
|
|
|
|
|
2023-05-15 17:43:58 +00:00
|
|
|
auto* open_image_action = new QAction("&Open Image", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_image_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-image.png"sv));
|
2023-05-15 17:43:58 +00:00
|
|
|
QObject::connect(open_image_action, &QAction::triggered, this, [this]() {
|
|
|
|
open_link(m_image_context_menu_url);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto* open_image_in_new_tab_action = new QAction("&Open Image in New &Tab", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_image_in_new_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/new-tab.png"sv));
|
2023-05-15 17:43:58 +00:00
|
|
|
QObject::connect(open_image_in_new_tab_action, &QAction::triggered, this, [this]() {
|
|
|
|
open_link_in_new_tab(m_image_context_menu_url);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto* copy_image_action = new QAction("&Copy Image", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
copy_image_action->setIcon(load_icon_from_uri("resource://icons/16x16/edit-copy.png"sv));
|
2023-05-15 17:43:58 +00:00
|
|
|
QObject::connect(copy_image_action, &QAction::triggered, this, [this]() {
|
|
|
|
auto* bitmap = m_image_context_menu_bitmap.bitmap();
|
|
|
|
if (bitmap == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto data = Gfx::BMPWriter::encode(*bitmap);
|
|
|
|
if (data.is_error())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto image = QImage::fromData(data.value().data(), data.value().size(), "BMP");
|
|
|
|
if (image.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto* clipboard = QGuiApplication::clipboard();
|
|
|
|
clipboard->setImage(image);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto* copy_image_url_action = new QAction("Copy Image &URL", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
copy_image_url_action->setIcon(load_icon_from_uri("resource://icons/16x16/edit-copy.png"sv));
|
2023-05-15 17:43:58 +00:00
|
|
|
QObject::connect(copy_image_url_action, &QAction::triggered, this, [this]() {
|
|
|
|
copy_link_url(m_image_context_menu_url);
|
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_image_context_menu = new QMenu("Image context menu", this);
|
2023-05-15 17:43:58 +00:00
|
|
|
m_image_context_menu->addAction(open_image_action);
|
|
|
|
m_image_context_menu->addAction(open_image_in_new_tab_action);
|
|
|
|
m_image_context_menu->addSeparator();
|
|
|
|
m_image_context_menu->addAction(copy_image_action);
|
|
|
|
m_image_context_menu->addAction(copy_image_url_action);
|
|
|
|
m_image_context_menu->addSeparator();
|
|
|
|
m_image_context_menu->addAction(&m_window->inspect_dom_node_action());
|
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
view().on_image_context_menu_request = [this](auto& image_url, Gfx::IntPoint content_position, Gfx::ShareableBitmap const& shareable_bitmap) {
|
2023-05-15 17:43:58 +00:00
|
|
|
m_image_context_menu_url = image_url;
|
|
|
|
m_image_context_menu_bitmap = shareable_bitmap;
|
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
m_image_context_menu->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
|
2023-05-15 17:43:58 +00:00
|
|
|
};
|
|
|
|
|
2023-11-05 12:45:43 +00:00
|
|
|
m_media_context_menu_play_icon = load_icon_from_uri("resource://icons/16x16/play.png"sv);
|
|
|
|
m_media_context_menu_pause_icon = load_icon_from_uri("resource://icons/16x16/pause.png"sv);
|
|
|
|
m_media_context_menu_mute_icon = load_icon_from_uri("resource://icons/16x16/audio-volume-muted.png"sv);
|
|
|
|
m_media_context_menu_unmute_icon = load_icon_from_uri("resource://icons/16x16/audio-volume-high.png"sv);
|
2023-05-15 16:27:10 +00:00
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_media_context_menu_play_pause_action = new QAction("&Play", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
m_media_context_menu_play_pause_action->setIcon(m_media_context_menu_play_icon);
|
2023-06-16 14:51:38 +00:00
|
|
|
QObject::connect(m_media_context_menu_play_pause_action, &QAction::triggered, this, [this]() {
|
|
|
|
view().toggle_media_play_state();
|
2023-05-15 16:27:10 +00:00
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_media_context_menu_mute_unmute_action = new QAction("&Mute", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
m_media_context_menu_mute_unmute_action->setIcon(m_media_context_menu_mute_icon);
|
2023-06-16 15:29:54 +00:00
|
|
|
QObject::connect(m_media_context_menu_mute_unmute_action, &QAction::triggered, this, [this]() {
|
|
|
|
view().toggle_media_mute_state();
|
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_media_context_menu_controls_action = new QAction("Show &Controls", this);
|
2023-06-16 14:51:38 +00:00
|
|
|
m_media_context_menu_controls_action->setCheckable(true);
|
|
|
|
QObject::connect(m_media_context_menu_controls_action, &QAction::triggered, this, [this]() {
|
|
|
|
view().toggle_media_controls_state();
|
2023-05-15 16:27:10 +00:00
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_media_context_menu_loop_action = new QAction("&Loop", this);
|
2023-06-16 14:51:38 +00:00
|
|
|
m_media_context_menu_loop_action->setCheckable(true);
|
|
|
|
QObject::connect(m_media_context_menu_loop_action, &QAction::triggered, this, [this]() {
|
|
|
|
view().toggle_media_loop_state();
|
2023-05-15 16:27:10 +00:00
|
|
|
});
|
|
|
|
|
2023-06-19 11:15:13 +00:00
|
|
|
auto* open_audio_action = new QAction("&Open Audio", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_audio_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-sound.png"sv));
|
2023-06-19 11:15:13 +00:00
|
|
|
QObject::connect(open_audio_action, &QAction::triggered, this, [this]() {
|
|
|
|
open_link(m_media_context_menu_url);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto* open_audio_in_new_tab_action = new QAction("Open Audio in New &Tab", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_audio_in_new_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/new-tab.png"sv));
|
2023-06-19 11:15:13 +00:00
|
|
|
QObject::connect(open_audio_in_new_tab_action, &QAction::triggered, this, [this]() {
|
|
|
|
open_link_in_new_tab(m_media_context_menu_url);
|
|
|
|
});
|
|
|
|
|
2023-06-16 15:05:15 +00:00
|
|
|
auto* copy_audio_url_action = new QAction("Copy Audio &URL", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
copy_audio_url_action->setIcon(load_icon_from_uri("resource://icons/16x16/edit-copy.png"sv));
|
2023-06-16 15:05:15 +00:00
|
|
|
QObject::connect(copy_audio_url_action, &QAction::triggered, this, [this]() {
|
|
|
|
copy_link_url(m_media_context_menu_url);
|
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_audio_context_menu = new QMenu("Audio context menu", this);
|
2023-06-16 15:05:15 +00:00
|
|
|
m_audio_context_menu->addAction(m_media_context_menu_play_pause_action);
|
2023-06-16 15:29:54 +00:00
|
|
|
m_audio_context_menu->addAction(m_media_context_menu_mute_unmute_action);
|
2023-06-16 15:05:15 +00:00
|
|
|
m_audio_context_menu->addAction(m_media_context_menu_controls_action);
|
|
|
|
m_audio_context_menu->addAction(m_media_context_menu_loop_action);
|
|
|
|
m_audio_context_menu->addSeparator();
|
2023-06-19 11:15:13 +00:00
|
|
|
m_audio_context_menu->addAction(open_audio_action);
|
|
|
|
m_audio_context_menu->addAction(open_audio_in_new_tab_action);
|
|
|
|
m_audio_context_menu->addSeparator();
|
2023-06-16 15:05:15 +00:00
|
|
|
m_audio_context_menu->addAction(copy_audio_url_action);
|
|
|
|
m_audio_context_menu->addSeparator();
|
|
|
|
m_audio_context_menu->addAction(&m_window->inspect_dom_node_action());
|
|
|
|
|
2023-05-15 16:27:10 +00:00
|
|
|
auto* open_video_action = new QAction("&Open Video", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_video_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-video.png"sv));
|
2023-05-15 16:27:10 +00:00
|
|
|
QObject::connect(open_video_action, &QAction::triggered, this, [this]() {
|
2023-06-16 14:51:38 +00:00
|
|
|
open_link(m_media_context_menu_url);
|
2023-05-15 16:27:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto* open_video_in_new_tab_action = new QAction("Open Video in New &Tab", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
open_video_in_new_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/new-tab.png"sv));
|
2023-05-15 16:27:10 +00:00
|
|
|
QObject::connect(open_video_in_new_tab_action, &QAction::triggered, this, [this]() {
|
2023-06-16 14:51:38 +00:00
|
|
|
open_link_in_new_tab(m_media_context_menu_url);
|
2023-05-15 16:27:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto* copy_video_url_action = new QAction("Copy Video &URL", this);
|
2023-11-05 12:45:43 +00:00
|
|
|
copy_video_url_action->setIcon(load_icon_from_uri("resource://icons/16x16/edit-copy.png"sv));
|
2023-05-15 16:27:10 +00:00
|
|
|
QObject::connect(copy_video_url_action, &QAction::triggered, this, [this]() {
|
2023-06-16 14:51:38 +00:00
|
|
|
copy_link_url(m_media_context_menu_url);
|
2023-05-15 16:27:10 +00:00
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_video_context_menu = new QMenu("Video context menu", this);
|
2023-06-16 14:51:38 +00:00
|
|
|
m_video_context_menu->addAction(m_media_context_menu_play_pause_action);
|
2023-06-16 15:29:54 +00:00
|
|
|
m_video_context_menu->addAction(m_media_context_menu_mute_unmute_action);
|
2023-06-16 14:51:38 +00:00
|
|
|
m_video_context_menu->addAction(m_media_context_menu_controls_action);
|
|
|
|
m_video_context_menu->addAction(m_media_context_menu_loop_action);
|
2023-05-15 16:27:10 +00:00
|
|
|
m_video_context_menu->addSeparator();
|
|
|
|
m_video_context_menu->addAction(open_video_action);
|
|
|
|
m_video_context_menu->addAction(open_video_in_new_tab_action);
|
|
|
|
m_video_context_menu->addSeparator();
|
|
|
|
m_video_context_menu->addAction(copy_video_url_action);
|
|
|
|
m_video_context_menu->addSeparator();
|
|
|
|
m_video_context_menu->addAction(&m_window->inspect_dom_node_action());
|
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
view().on_media_context_menu_request = [this](Gfx::IntPoint content_position, Web::Page::MediaContextMenu const& menu) {
|
2023-06-16 14:51:38 +00:00
|
|
|
m_media_context_menu_url = menu.media_url;
|
2023-05-15 16:27:10 +00:00
|
|
|
|
2023-06-16 14:51:38 +00:00
|
|
|
if (menu.is_playing) {
|
2023-11-05 12:45:43 +00:00
|
|
|
m_media_context_menu_play_pause_action->setIcon(m_media_context_menu_pause_icon);
|
2023-06-16 14:51:38 +00:00
|
|
|
m_media_context_menu_play_pause_action->setText("&Pause");
|
2023-05-15 16:27:10 +00:00
|
|
|
} else {
|
2023-11-05 12:45:43 +00:00
|
|
|
m_media_context_menu_play_pause_action->setIcon(m_media_context_menu_play_icon);
|
2023-06-16 14:51:38 +00:00
|
|
|
m_media_context_menu_play_pause_action->setText("&Play");
|
2023-05-15 16:27:10 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 15:29:54 +00:00
|
|
|
if (menu.is_muted) {
|
2023-11-05 12:45:43 +00:00
|
|
|
m_media_context_menu_mute_unmute_action->setIcon(m_media_context_menu_unmute_icon);
|
2023-06-16 15:29:54 +00:00
|
|
|
m_media_context_menu_mute_unmute_action->setText("Un&mute");
|
|
|
|
} else {
|
2023-11-05 12:45:43 +00:00
|
|
|
m_media_context_menu_mute_unmute_action->setIcon(m_media_context_menu_mute_icon);
|
2023-06-16 15:29:54 +00:00
|
|
|
m_media_context_menu_mute_unmute_action->setText("&Mute");
|
|
|
|
}
|
|
|
|
|
2023-06-16 14:51:38 +00:00
|
|
|
m_media_context_menu_controls_action->setChecked(menu.has_user_agent_controls);
|
|
|
|
m_media_context_menu_loop_action->setChecked(menu.is_looping);
|
2023-05-15 16:27:10 +00:00
|
|
|
|
2023-12-12 21:33:36 +00:00
|
|
|
auto screen_position = view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio());
|
2023-06-16 14:51:38 +00:00
|
|
|
if (menu.is_video)
|
|
|
|
m_video_context_menu->exec(screen_position);
|
2023-06-16 15:05:15 +00:00
|
|
|
else
|
|
|
|
m_audio_context_menu->exec(screen_position);
|
2023-05-15 16:27:10 +00:00
|
|
|
};
|
2022-09-12 07:12:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 15:54:36 +00:00
|
|
|
Tab::~Tab()
|
|
|
|
{
|
|
|
|
close_sub_widgets();
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:53:49 +00:00
|
|
|
void Tab::select_dropdown_add_item(QMenu* menu, Web::HTML::SelectItem const& item)
|
|
|
|
{
|
|
|
|
if (item.type == Web::HTML::SelectItem::Type::OptionGroup) {
|
|
|
|
QAction* subtitle = new QAction(qstring_from_ak_string(item.label.value_or(""_string)), this);
|
|
|
|
subtitle->setDisabled(true);
|
|
|
|
menu->addAction(subtitle);
|
|
|
|
|
|
|
|
for (auto const& item : *item.items) {
|
|
|
|
select_dropdown_add_item(menu, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item.type == Web::HTML::SelectItem::Type::Option) {
|
|
|
|
QAction* action = new QAction(qstring_from_ak_string(item.label.value_or(""_string)), this);
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(item.selected);
|
|
|
|
action->setData(QVariant(qstring_from_ak_string(item.value.value_or(""_string))));
|
|
|
|
QObject::connect(action, &QAction::triggered, this, &Tab::select_dropdown_action);
|
|
|
|
menu->addAction(action);
|
|
|
|
}
|
|
|
|
if (item.type == Web::HTML::SelectItem::Type::Separator) {
|
|
|
|
menu->addSeparator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab::select_dropdown_action()
|
|
|
|
{
|
|
|
|
QAction* action = qobject_cast<QAction*>(sender());
|
|
|
|
auto value = action->data().value<QString>();
|
|
|
|
view().select_dropdown_closed(ak_string_from_qstring(value));
|
|
|
|
}
|
|
|
|
|
2023-03-28 23:25:42 +00:00
|
|
|
void Tab::update_reset_zoom_button()
|
|
|
|
{
|
|
|
|
auto zoom_level = view().zoom_level();
|
|
|
|
if (zoom_level != 1.0f) {
|
|
|
|
auto zoom_level_text = MUST(String::formatted("{}%", round_to<int>(zoom_level * 100)));
|
|
|
|
m_reset_zoom_button->setText(qstring_from_ak_string(zoom_level_text));
|
|
|
|
m_reset_zoom_button_action->setVisible(true);
|
|
|
|
} else {
|
|
|
|
m_reset_zoom_button_action->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-12 07:12:04 +00:00
|
|
|
void Tab::focus_location_editor()
|
|
|
|
{
|
|
|
|
m_location_edit->setFocus();
|
|
|
|
m_location_edit->selectAll();
|
2022-07-06 13:38:50 +00:00
|
|
|
}
|
|
|
|
|
2023-10-13 13:52:06 +00:00
|
|
|
void Tab::navigate(QString const& url_qstring)
|
2022-07-06 13:38:50 +00:00
|
|
|
{
|
2023-12-04 15:08:16 +00:00
|
|
|
auto url_string = ak_string_from_qstring(url_qstring);
|
2023-08-02 21:19:54 +00:00
|
|
|
view().load(url_string);
|
2022-07-06 13:38:50 +00:00
|
|
|
}
|
|
|
|
|
2023-09-17 15:12:17 +00:00
|
|
|
void Tab::load_html(StringView html)
|
2023-08-28 20:14:34 +00:00
|
|
|
{
|
2023-09-17 15:12:17 +00:00
|
|
|
view().load_html(html);
|
2023-08-28 20:14:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 13:38:50 +00:00
|
|
|
void Tab::back()
|
|
|
|
{
|
|
|
|
if (!m_history.can_go_back())
|
|
|
|
return;
|
|
|
|
|
2022-11-08 12:01:20 +00:00
|
|
|
m_is_history_navigation = true;
|
2022-07-06 13:38:50 +00:00
|
|
|
m_history.go_back();
|
2022-12-04 18:43:54 +00:00
|
|
|
view().load(m_history.current().url.to_deprecated_string());
|
2022-07-06 13:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Tab::forward()
|
|
|
|
{
|
|
|
|
if (!m_history.can_go_forward())
|
|
|
|
return;
|
|
|
|
|
2022-11-08 12:01:20 +00:00
|
|
|
m_is_history_navigation = true;
|
2022-07-06 13:38:50 +00:00
|
|
|
m_history.go_forward();
|
2022-12-04 18:43:54 +00:00
|
|
|
view().load(m_history.current().url.to_deprecated_string());
|
2022-07-06 13:38:50 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 22:18:21 +00:00
|
|
|
void Tab::reload()
|
|
|
|
{
|
2023-08-28 19:54:36 +00:00
|
|
|
if (m_history.is_empty())
|
|
|
|
return;
|
|
|
|
|
2022-11-08 23:35:55 +00:00
|
|
|
m_is_history_navigation = true;
|
2022-12-04 18:43:54 +00:00
|
|
|
view().load(m_history.current().url.to_deprecated_string());
|
2022-07-05 22:18:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 16:27:10 +00:00
|
|
|
void Tab::open_link(URL const& url)
|
|
|
|
{
|
|
|
|
view().on_link_click(url, "", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab::open_link_in_new_tab(URL const& url)
|
|
|
|
{
|
|
|
|
view().on_link_click(url, "_blank", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab::copy_link_url(URL const& url)
|
|
|
|
{
|
|
|
|
auto* clipboard = QGuiApplication::clipboard();
|
2023-12-05 13:04:15 +00:00
|
|
|
clipboard->setText(qstring_from_ak_string(WebView::url_text_to_copy(url)));
|
2023-05-15 16:27:10 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 22:18:21 +00:00
|
|
|
void Tab::location_edit_return_pressed()
|
|
|
|
{
|
2022-07-06 13:38:50 +00:00
|
|
|
navigate(m_location_edit->text());
|
2022-07-05 22:18:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 21:47:12 +00:00
|
|
|
void Tab::open_file()
|
|
|
|
{
|
|
|
|
auto filename = QFileDialog::getOpenFileName(this, "Open file", QDir::homePath(), "All Files (*.*)");
|
|
|
|
if (!filename.isNull())
|
2023-10-13 13:52:06 +00:00
|
|
|
navigate(filename);
|
2023-05-25 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 22:18:21 +00:00
|
|
|
int Tab::tab_index()
|
|
|
|
{
|
2022-09-21 19:17:13 +00:00
|
|
|
return m_window->tab_index(this);
|
2022-07-05 22:18:21 +00:00
|
|
|
}
|
2022-07-08 12:14:40 +00:00
|
|
|
|
2022-12-04 18:43:54 +00:00
|
|
|
void Tab::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
|
2022-07-08 12:14:40 +00:00
|
|
|
{
|
2022-10-03 21:53:04 +00:00
|
|
|
if (request == "dump-history")
|
|
|
|
m_history.dump();
|
|
|
|
else
|
|
|
|
m_view->debug_request(request, argument);
|
2022-07-08 12:14:40 +00:00
|
|
|
}
|
2022-09-09 12:23:36 +00:00
|
|
|
|
|
|
|
void Tab::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
if (m_hover_label->isVisible())
|
|
|
|
update_hover_label();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab::update_hover_label()
|
|
|
|
{
|
|
|
|
m_hover_label->resize(QFontMetrics(m_hover_label->font()).boundingRect(m_hover_label->text()).adjusted(-4, -2, 4, 2).size());
|
|
|
|
m_hover_label->move(6, height() - m_hover_label->height() - 8);
|
|
|
|
m_hover_label->raise();
|
|
|
|
}
|
2023-05-05 13:38:46 +00:00
|
|
|
|
|
|
|
bool Tab::event(QEvent* event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::PaletteChange) {
|
2023-07-29 18:46:47 +00:00
|
|
|
recreate_toolbar_icons();
|
2023-05-05 13:38:46 +00:00
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
|
|
|
|
2023-07-29 18:46:47 +00:00
|
|
|
void Tab::recreate_toolbar_icons()
|
2023-05-05 13:38:46 +00:00
|
|
|
{
|
2023-07-29 18:46:47 +00:00
|
|
|
m_window->go_back_action().setIcon(create_tvg_icon_with_theme_colors("back", palette()));
|
|
|
|
m_window->go_forward_action().setIcon(create_tvg_icon_with_theme_colors("forward", palette()));
|
|
|
|
m_window->reload_action().setIcon(create_tvg_icon_with_theme_colors("reload", palette()));
|
2023-05-05 13:38:46 +00:00
|
|
|
}
|
2023-05-17 15:54:36 +00:00
|
|
|
|
|
|
|
void Tab::show_inspector_window(InspectorTarget inspector_target)
|
|
|
|
{
|
2023-11-24 01:04:54 +00:00
|
|
|
if (!m_inspector_widget)
|
2023-12-04 16:03:40 +00:00
|
|
|
m_inspector_widget = new InspectorWidget(this, view());
|
2023-12-10 15:09:40 +00:00
|
|
|
else
|
|
|
|
m_inspector_widget->inspect();
|
2023-05-17 15:54:36 +00:00
|
|
|
|
|
|
|
m_inspector_widget->show();
|
2023-11-24 01:04:54 +00:00
|
|
|
m_inspector_widget->activateWindow();
|
|
|
|
m_inspector_widget->raise();
|
2023-05-17 15:54:36 +00:00
|
|
|
|
2023-11-24 01:04:54 +00:00
|
|
|
if (inspector_target == InspectorTarget::HoveredElement)
|
|
|
|
m_inspector_widget->select_hovered_node();
|
|
|
|
else
|
2023-05-17 15:54:36 +00:00
|
|
|
m_inspector_widget->select_default_node();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab::close_sub_widgets()
|
|
|
|
{
|
|
|
|
auto close_widget_window = [](auto* widget) {
|
|
|
|
if (widget)
|
|
|
|
widget->close();
|
|
|
|
};
|
|
|
|
|
|
|
|
close_widget_window(m_inspector_widget);
|
|
|
|
}
|
2023-08-02 17:52:59 +00:00
|
|
|
|
|
|
|
}
|