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

Commit b881209

Browse files
trflynn89linusg
authored andcommitted
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.
1 parent f570c5b commit b881209

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

WebContentView.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <QApplication>
4242
#include <QCursor>
4343
#include <QIcon>
44+
#include <QInputDialog>
4445
#include <QLineEdit>
4546
#include <QMessageBox>
4647
#include <QMouseEvent>
@@ -850,23 +851,55 @@ void WebContentView::notify_server_did_request_image_context_menu(Badge<WebConte
850851

851852
void WebContentView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
852853
{
853-
QMessageBox::warning(this, "Ladybird", qstring_from_akstring(message));
854+
m_dialog = new QMessageBox(QMessageBox::Icon::Warning, "Ladybird", qstring_from_akstring(message), QMessageBox::StandardButton::Ok, this);
855+
m_dialog->exec();
856+
857+
client().async_alert_closed();
858+
m_dialog = nullptr;
854859
}
855860

856-
bool WebContentView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
861+
void WebContentView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
857862
{
858-
auto result = QMessageBox::question(this, "Ladybird", qstring_from_akstring(message),
859-
QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel);
863+
m_dialog = new QMessageBox(QMessageBox::Icon::Question, "Ladybird", qstring_from_akstring(message), QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, this);
864+
auto result = m_dialog->exec();
860865

861-
return result == QMessageBox::StandardButton::Ok;
866+
client().async_confirm_closed(result == QMessageBox::StandardButton::Ok || result == QDialog::Accepted);
867+
m_dialog = nullptr;
862868
}
863869

864-
String WebContentView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
870+
void WebContentView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
865871
{
866-
// FIXME
867-
(void)message;
868-
(void)default_;
869-
return String::empty();
872+
m_dialog = new QInputDialog(this);
873+
auto& dialog = static_cast<QInputDialog&>(*m_dialog);
874+
875+
dialog.setWindowTitle("Ladybird");
876+
dialog.setLabelText(qstring_from_akstring(message));
877+
dialog.setTextValue(qstring_from_akstring(default_));
878+
879+
if (dialog.exec() == QDialog::Accepted)
880+
client().async_prompt_closed(akstring_from_qstring(dialog.textValue()));
881+
else
882+
client().async_prompt_closed({});
883+
884+
m_dialog = nullptr;
885+
}
886+
887+
void WebContentView::notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message)
888+
{
889+
if (m_dialog && is<QInputDialog>(*m_dialog))
890+
static_cast<QInputDialog&>(*m_dialog).setTextValue(qstring_from_akstring(message));
891+
}
892+
893+
void WebContentView::notify_server_did_request_accept_dialog(Badge<WebContentClient>)
894+
{
895+
if (m_dialog)
896+
m_dialog->accept();
897+
}
898+
899+
void WebContentView::notify_server_did_request_dismiss_dialog(Badge<WebContentClient>)
900+
{
901+
if (m_dialog)
902+
m_dialog->reject();
870903
}
871904

872905
void WebContentView::get_source()

WebContentView.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ class WebContentView final
132132
virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers) override;
133133
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;
134134
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) override;
135-
virtual bool notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) override;
136-
virtual String notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) override;
135+
virtual void notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) override;
136+
virtual void notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) override;
137+
virtual void notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message) override;
138+
virtual void notify_server_did_request_accept_dialog(Badge<WebContentClient>) override;
139+
virtual void notify_server_did_request_dismiss_dialog(Badge<WebContentClient>) override;
137140
virtual void notify_server_did_get_source(const AK::URL& url, String const& source) override;
138141
virtual void notify_server_did_get_dom_tree(String const& dom_tree) override;
139142
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 @@ class WebContentView final
185188
bool m_should_show_line_box_borders { false };
186189

187190
QPointer<QWidget> m_inspector_widget;
191+
QPointer<QDialog> m_dialog;
188192

189193
Ladybird::ConsoleWidget* m_console_widget { nullptr };
190194

0 commit comments

Comments
 (0)