mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
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.
This commit is contained in:
parent
fad3fbfe26
commit
9a5f9c101c
2 changed files with 49 additions and 12 deletions
|
@ -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()
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue