summaryrefslogtreecommitdiff
path: root/Ladybird
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-11-16 09:06:47 -0500
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-25 07:58:58 -0700
commit9a5f9c101cf8a469f60622cf72bd17b58207d756 (patch)
treed2b2e92b7913bd3ba1f487052007994a347df4a0 /Ladybird
parentfad3fbfe26378b5711b5cf099e0e498675420e17 (diff)
downloadserenity-9a5f9c101cf8a469f60622cf72bd17b58207d756.zip
Ladybird: Implement updated alert/confirm/prompt IPC methods
WebContent now needs to interact with these dialogs asynchronously. This updates WebContentView to hold a pointer to whatever dialog is open, and implements the methods to interact with that dialog.
Diffstat (limited to 'Ladybird')
-rw-r--r--Ladybird/WebContentView.cpp53
-rw-r--r--Ladybird/WebContentView.h8
2 files changed, 49 insertions, 12 deletions
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp
index 084c237bd2..6a31bd9a12 100644
--- a/Ladybird/WebContentView.cpp
+++ b/Ladybird/WebContentView.cpp
@@ -41,6 +41,7 @@
#include <QApplication>
#include <QCursor>
#include <QIcon>
+#include <QInputDialog>
#include <QLineEdit>
#include <QMessageBox>
#include <QMouseEvent>
@@ -850,23 +851,55 @@ void WebContentView::notify_server_did_request_image_context_menu(Badge<WebConte
void WebContentView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
{
- QMessageBox::warning(this, "Ladybird", qstring_from_akstring(message));
+ m_dialog = new QMessageBox(QMessageBox::Icon::Warning, "Ladybird", qstring_from_akstring(message), QMessageBox::StandardButton::Ok, this);
+ m_dialog->exec();
+
+ client().async_alert_closed();
+ m_dialog = nullptr;
}
-bool WebContentView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
+void WebContentView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
{
- auto result = QMessageBox::question(this, "Ladybird", qstring_from_akstring(message),
- QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel);
+ m_dialog = new QMessageBox(QMessageBox::Icon::Question, "Ladybird", qstring_from_akstring(message), QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, this);
+ auto result = m_dialog->exec();
- return result == QMessageBox::StandardButton::Ok;
+ client().async_confirm_closed(result == QMessageBox::StandardButton::Ok || result == QDialog::Accepted);
+ m_dialog = nullptr;
}
-String WebContentView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
+void WebContentView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
{
- // FIXME
- (void)message;
- (void)default_;
- return String::empty();
+ m_dialog = new QInputDialog(this);
+ auto& dialog = static_cast<QInputDialog&>(*m_dialog);
+
+ dialog.setWindowTitle("Ladybird");
+ dialog.setLabelText(qstring_from_akstring(message));
+ dialog.setTextValue(qstring_from_akstring(default_));
+
+ if (dialog.exec() == QDialog::Accepted)
+ client().async_prompt_closed(akstring_from_qstring(dialog.textValue()));
+ 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_akstring(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::get_source()
diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h
index 50183fa869..f0c7ff7e06 100644
--- a/Ladybird/WebContentView.h
+++ b/Ladybird/WebContentView.h
@@ -132,8 +132,11 @@ public:
virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers) override;
virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&) override;
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) override;
- virtual bool notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) override;
- virtual String notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) 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_get_source(const AK::URL& url, String const& source) override;
virtual void notify_server_did_get_dom_tree(String const& dom_tree) override;
virtual void notify_server_did_get_dom_node_properties(i32 node_id, String const& specified_style, String const& computed_style, String const& custom_properties, String const& node_box_sizing) override;
@@ -185,6 +188,7 @@ private:
bool m_should_show_line_box_borders { false };
QPointer<QWidget> m_inspector_widget;
+ QPointer<QDialog> m_dialog;
Ladybird::ConsoleWidget* m_console_widget { nullptr };