1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:07:34 +00:00

Ladybird+LibWebView: Migrate dialog APIs to LibWebView callbacks

This commit is contained in:
Timothy Flynn 2023-05-17 14:23:34 -04:00 committed by Tim Flynn
parent e6c01ef6e2
commit ebdcba8b3b
15 changed files with 153 additions and 225 deletions

View file

@ -10,9 +10,6 @@
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Application.h>
#include <LibGUI/Desktop.h>
#include <LibGUI/Dialog.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Scrollbar.h>
#include <LibGUI/Window.h>
@ -234,61 +231,6 @@ void OutOfProcessWebView::notify_server_did_leave_tooltip_area(Badge<WebContentC
GUI::Application::the()->hide_tooltip();
}
void OutOfProcessWebView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
{
m_dialog = GUI::MessageBox::create(window(), message, "Alert"sv, GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::OK).release_value_but_fixme_should_propagate_errors();
m_dialog->set_icon(window()->icon());
m_dialog->exec();
client().async_alert_closed();
m_dialog = nullptr;
}
void OutOfProcessWebView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
{
m_dialog = GUI::MessageBox::create(window(), message, "Confirm"sv, GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel).release_value_but_fixme_should_propagate_errors();
m_dialog->set_icon(window()->icon());
client().async_confirm_closed(m_dialog->exec() == GUI::Dialog::ExecResult::OK);
m_dialog = nullptr;
}
void OutOfProcessWebView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
{
String mutable_value = default_;
m_dialog = GUI::InputBox::create(window(), mutable_value, message, "Prompt"sv, GUI::InputType::Text).release_value_but_fixme_should_propagate_errors();
m_dialog->set_icon(window()->icon());
if (m_dialog->exec() == GUI::InputBox::ExecResult::OK) {
auto const& dialog = static_cast<GUI::InputBox const&>(*m_dialog);
auto response = dialog.text_value();
client().async_prompt_closed(move(response));
} else {
client().async_prompt_closed({});
}
m_dialog = nullptr;
}
void OutOfProcessWebView::notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message)
{
if (m_dialog && is<GUI::InputBox>(*m_dialog))
static_cast<GUI::InputBox&>(*m_dialog).set_text_value(message);
}
void OutOfProcessWebView::notify_server_did_request_accept_dialog(Badge<WebContentClient>)
{
if (m_dialog)
m_dialog->done(GUI::Dialog::ExecResult::OK);
}
void OutOfProcessWebView::notify_server_did_request_dismiss_dialog(Badge<WebContentClient>)
{
if (m_dialog)
m_dialog->done(GUI::Dialog::ExecResult::Cancel);
}
void OutOfProcessWebView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id)
{
auto file = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), path);

View file

@ -92,12 +92,6 @@ private:
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;
@ -109,8 +103,6 @@ private:
void enqueue_input_event(InputEvent const&);
void process_next_input_event();
RefPtr<GUI::Dialog> m_dialog;
bool m_is_awaiting_response_for_input_event { false };
Queue<InputEvent> m_pending_input_events;

View file

@ -152,6 +152,21 @@ void ViewImplementation::js_console_request_messages(i32 start_index)
client().async_js_console_request_messages(start_index);
}
void ViewImplementation::alert_closed()
{
client().async_alert_closed();
}
void ViewImplementation::confirm_closed(bool accepted)
{
client().async_confirm_closed(accepted);
}
void ViewImplementation::prompt_closed(Optional<String> response)
{
client().async_prompt_closed(move(response));
}
void ViewImplementation::toggle_media_play_state()
{
client().async_toggle_media_play_state();

View file

@ -75,6 +75,10 @@ public:
void js_console_input(DeprecatedString const& js_source);
void js_console_request_messages(i32 start_index);
void alert_closed();
void confirm_closed(bool accepted);
void prompt_closed(Optional<String> response);
void toggle_media_play_state();
void toggle_media_mute_state();
void toggle_media_loop_state();
@ -104,6 +108,12 @@ public:
Function<void()> on_navigate_forward;
Function<void()> on_refresh;
Function<void(Gfx::Bitmap const&)> on_favicon_change;
Function<void(String const& message)> on_request_alert;
Function<void(String const& message)> on_request_confirm;
Function<void(String const& message, String const& default_)> on_request_prompt;
Function<void(String const& message)> on_request_set_prompt_text;
Function<void()> on_request_accept_dialog;
Function<void()> on_request_dismiss_dialog;
Function<void(const AK::URL&, DeprecatedString const&)> on_get_source;
Function<void(DeprecatedString const&)> on_get_dom_tree;
Function<void(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing, DeprecatedString const& aria_properties_state)> on_get_dom_node_properties;
@ -133,12 +143,6 @@ public:
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) = 0;
virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) = 0;
virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) = 0;
virtual void notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_accept_dialog(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_dismiss_dialog(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32) = 0;
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0;

View file

@ -220,32 +220,38 @@ void WebContentClient::did_get_js_console_messages(i32 start_index, Vector<Depre
void WebContentClient::did_request_alert(String const& message)
{
m_view.notify_server_did_request_alert({}, message);
if (m_view.on_request_alert)
m_view.on_request_alert(message);
}
void WebContentClient::did_request_confirm(String const& message)
{
m_view.notify_server_did_request_confirm({}, message);
if (m_view.on_request_confirm)
m_view.on_request_confirm(message);
}
void WebContentClient::did_request_prompt(String const& message, String const& default_)
{
m_view.notify_server_did_request_prompt({}, message, default_);
if (m_view.on_request_prompt)
m_view.on_request_prompt(message, default_);
}
void WebContentClient::did_request_set_prompt_text(String const& message)
{
m_view.notify_server_did_request_set_prompt_text({}, message);
if (m_view.on_request_set_prompt_text)
m_view.on_request_set_prompt_text(message);
}
void WebContentClient::did_request_accept_dialog()
{
m_view.notify_server_did_request_accept_dialog({});
if (m_view.on_request_accept_dialog)
m_view.on_request_accept_dialog();
}
void WebContentClient::did_request_dismiss_dialog()
{
m_view.notify_server_did_request_dismiss_dialog({});
if (m_view.on_request_dismiss_dialog)
m_view.on_request_dismiss_dialog();
}
void WebContentClient::did_change_favicon(Gfx::ShareableBitmap const& favicon)