mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:37:35 +00:00
Ladybird+LibWebView: Migrate dialog APIs to LibWebView callbacks
This commit is contained in:
parent
e6c01ef6e2
commit
ebdcba8b3b
15 changed files with 153 additions and 225 deletions
|
@ -416,7 +416,7 @@ struct HideCursor {
|
|||
[NSMenu popUpContextMenu:self.video_context_menu withEvent:event forView:self];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_alert = [self](auto const& message) {
|
||||
m_web_view_bridge->on_request_alert = [self](auto const& message) {
|
||||
auto* ns_message = Ladybird::string_to_ns_string(message);
|
||||
|
||||
self.dialog = [[NSAlert alloc] init];
|
||||
|
@ -429,7 +429,7 @@ struct HideCursor {
|
|||
}];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_confirm = [self](auto const& message) {
|
||||
m_web_view_bridge->on_request_confirm = [self](auto const& message) {
|
||||
auto* ns_message = Ladybird::string_to_ns_string(message);
|
||||
|
||||
self.dialog = [[NSAlert alloc] init];
|
||||
|
@ -444,7 +444,7 @@ struct HideCursor {
|
|||
}];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_prompt = [self](auto const& message, auto const& default_) {
|
||||
m_web_view_bridge->on_request_prompt = [self](auto const& message, auto const& default_) {
|
||||
auto* ns_message = Ladybird::string_to_ns_string(message);
|
||||
auto* ns_default = Ladybird::string_to_ns_string(default_);
|
||||
|
||||
|
@ -472,7 +472,7 @@ struct HideCursor {
|
|||
}];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_prompt_text_changed = [self](auto const& message) {
|
||||
m_web_view_bridge->on_request_set_prompt_text = [self](auto const& message) {
|
||||
if (self.dialog == nil || [self.dialog accessoryView] == nil) {
|
||||
return;
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ struct HideCursor {
|
|||
[input setStringValue:ns_message];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_dialog_accepted = [self]() {
|
||||
m_web_view_bridge->on_request_accept_dialog = [self]() {
|
||||
if (self.dialog == nil) {
|
||||
return;
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ struct HideCursor {
|
|||
returnCode:NSModalResponseOK];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_dialog_dismissed = [self]() {
|
||||
m_web_view_bridge->on_request_dismiss_dialog = [self]() {
|
||||
if (self.dialog == nil) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -197,58 +197,6 @@ void WebViewBridge::notify_server_did_leave_tooltip_area(Badge<WebView::WebConte
|
|||
if (on_tooltip_left)
|
||||
on_tooltip_left();
|
||||
}
|
||||
|
||||
void WebViewBridge::notify_server_did_request_alert(Badge<WebView::WebContentClient>, String const& message)
|
||||
{
|
||||
if (on_alert)
|
||||
on_alert(message);
|
||||
}
|
||||
|
||||
void WebViewBridge::alert_closed()
|
||||
{
|
||||
client().async_alert_closed();
|
||||
}
|
||||
|
||||
void WebViewBridge::notify_server_did_request_confirm(Badge<WebView::WebContentClient>, String const& message)
|
||||
{
|
||||
if (on_confirm)
|
||||
on_confirm(message);
|
||||
}
|
||||
|
||||
void WebViewBridge::confirm_closed(bool accepted)
|
||||
{
|
||||
client().async_confirm_closed(accepted);
|
||||
}
|
||||
|
||||
void WebViewBridge::notify_server_did_request_prompt(Badge<WebView::WebContentClient>, String const& message, String const& default_)
|
||||
{
|
||||
if (on_prompt)
|
||||
on_prompt(message, default_);
|
||||
}
|
||||
|
||||
void WebViewBridge::prompt_closed(Optional<String> response)
|
||||
{
|
||||
client().async_prompt_closed(move(response));
|
||||
}
|
||||
|
||||
void WebViewBridge::notify_server_did_request_set_prompt_text(Badge<WebView::WebContentClient>, String const& message)
|
||||
{
|
||||
if (on_prompt_text_changed)
|
||||
on_prompt_text_changed(message);
|
||||
}
|
||||
|
||||
void WebViewBridge::notify_server_did_request_accept_dialog(Badge<WebView::WebContentClient>)
|
||||
{
|
||||
if (on_dialog_accepted)
|
||||
on_dialog_accepted();
|
||||
}
|
||||
|
||||
void WebViewBridge::notify_server_did_request_dismiss_dialog(Badge<WebView::WebContentClient>)
|
||||
{
|
||||
if (on_dialog_dismissed)
|
||||
on_dialog_dismissed();
|
||||
}
|
||||
|
||||
void WebViewBridge::notify_server_did_request_file(Badge<WebView::WebContentClient>, DeprecatedString const& path, i32 request_id)
|
||||
{
|
||||
auto file = Core::File::open(path, Core::File::OpenMode::Read);
|
||||
|
|
|
@ -59,19 +59,6 @@ public:
|
|||
Function<void(DeprecatedString const&)> on_tooltip_entered;
|
||||
Function<void()> on_tooltip_left;
|
||||
|
||||
Function<void(String const&)> on_alert;
|
||||
void alert_closed();
|
||||
|
||||
Function<void(String const&)> on_confirm;
|
||||
void confirm_closed(bool);
|
||||
|
||||
Function<void(String const&, String const&)> on_prompt;
|
||||
Function<void(String const&)> on_prompt_text_changed;
|
||||
void prompt_closed(Optional<String>);
|
||||
|
||||
Function<void()> on_dialog_accepted;
|
||||
Function<void()> on_dialog_dismissed;
|
||||
|
||||
private:
|
||||
WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path);
|
||||
|
||||
|
@ -85,12 +72,6 @@ private:
|
|||
virtual void notify_server_did_request_scroll_into_view(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override;
|
||||
virtual void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
|
||||
virtual void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override;
|
||||
virtual void notify_server_did_request_alert(Badge<WebView::WebContentClient>, String const& message) override;
|
||||
virtual void notify_server_did_request_confirm(Badge<WebView::WebContentClient>, String const& message) override;
|
||||
virtual void notify_server_did_request_prompt(Badge<WebView::WebContentClient>, String const& message, String const& default_) override;
|
||||
virtual void notify_server_did_request_set_prompt_text(Badge<WebView::WebContentClient>, String const& message) override;
|
||||
virtual void notify_server_did_request_accept_dialog(Badge<WebView::WebContentClient>) override;
|
||||
virtual void notify_server_did_request_dismiss_dialog(Badge<WebView::WebContentClient>) override;
|
||||
virtual void notify_server_did_request_file(Badge<WebView::WebContentClient>, DeprecatedString const& path, i32) override;
|
||||
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QFontMetrics>
|
||||
#include <QGuiApplication>
|
||||
#include <QImage>
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
|
@ -165,6 +166,53 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView::
|
|||
emit favicon_changed(tab_index(), QIcon(qpixmap));
|
||||
};
|
||||
|
||||
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)
|
||||
view().prompt_closed(ak_string_from_qstring(dialog.textValue()).release_value_but_fixme_should_propagate_errors());
|
||||
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();
|
||||
};
|
||||
|
||||
QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor);
|
||||
|
||||
view().on_get_source = [this](auto const& url, auto const& source) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QPointer>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
|
@ -111,6 +112,8 @@ private:
|
|||
Ladybird::ConsoleWidget* m_console_widget { nullptr };
|
||||
OwnPtr<QMenu> m_console_context_menu;
|
||||
Ladybird::InspectorWidget* m_inspector_widget { nullptr };
|
||||
|
||||
QPointer<QDialog> m_dialog;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -37,9 +37,7 @@
|
|||
#include <QCursor>
|
||||
#include <QGuiApplication>
|
||||
#include <QIcon>
|
||||
#include <QInputDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QPaintEvent>
|
||||
|
@ -727,59 +725,6 @@ void WebContentView::notify_server_did_leave_tooltip_area(Badge<WebContentClient
|
|||
QToolTip::hideText();
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
|
||||
{
|
||||
m_dialog = new QMessageBox(QMessageBox::Icon::Warning, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok, this);
|
||||
m_dialog->exec();
|
||||
|
||||
client().async_alert_closed();
|
||||
m_dialog = nullptr;
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
|
||||
{
|
||||
m_dialog = new QMessageBox(QMessageBox::Icon::Question, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, this);
|
||||
auto result = m_dialog->exec();
|
||||
|
||||
client().async_confirm_closed(result == QMessageBox::StandardButton::Ok || result == QDialog::Accepted);
|
||||
m_dialog = nullptr;
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
|
||||
{
|
||||
m_dialog = new QInputDialog(this);
|
||||
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)
|
||||
client().async_prompt_closed(ak_string_from_qstring(dialog.textValue()).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
client().async_prompt_closed({});
|
||||
|
||||
m_dialog = nullptr;
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message)
|
||||
{
|
||||
if (m_dialog && is<QInputDialog>(*m_dialog))
|
||||
static_cast<QInputDialog&>(*m_dialog).setTextValue(qstring_from_ak_string(message));
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_request_accept_dialog(Badge<WebContentClient>)
|
||||
{
|
||||
if (m_dialog)
|
||||
m_dialog->accept();
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_request_dismiss_dialog(Badge<WebContentClient>)
|
||||
{
|
||||
if (m_dialog)
|
||||
m_dialog->reject();
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id)
|
||||
{
|
||||
auto file = Core::File::open(path, Core::File::OpenMode::Read);
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <LibWeb/HTML/ActivateTab.h>
|
||||
#include <LibWebView/ViewImplementation.h>
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QPointer>
|
||||
#include <QUrl>
|
||||
|
||||
class QTextEdit;
|
||||
|
@ -87,12 +86,6 @@ public:
|
|||
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override;
|
||||
virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
|
||||
virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override;
|
||||
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) override;
|
||||
virtual void notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) override;
|
||||
virtual void notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) override;
|
||||
virtual void notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message) override;
|
||||
virtual void notify_server_did_request_accept_dialog(Badge<WebContentClient>) override;
|
||||
virtual void notify_server_did_request_dismiss_dialog(Badge<WebContentClient>) override;
|
||||
virtual void notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32) override;
|
||||
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
|
||||
|
||||
|
@ -113,8 +106,6 @@ private:
|
|||
bool m_should_show_line_box_borders { false };
|
||||
UseLagomNetworking m_use_lagom_networking {};
|
||||
|
||||
QPointer<QDialog> m_dialog;
|
||||
|
||||
Gfx::IntRect m_viewport_rect;
|
||||
|
||||
StringView m_webdriver_content_ipc_path;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue