From abf7c02acb4761a833726fed33ad88fc0c8177a3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 10 Feb 2021 08:37:13 +0100 Subject: LibWeb: Move window.confirm() to using a PageClient callback This allows us to move the GUI::MessageBox out of DOM::Window and up to the widget layer. --- Userland/Libraries/LibWeb/DOM/Window.cpp | 6 +++--- Userland/Libraries/LibWeb/InProcessWebView.cpp | 6 ++++++ Userland/Libraries/LibWeb/InProcessWebView.h | 1 + Userland/Libraries/LibWeb/Page/Page.h | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp index 648d083696..cf1a164c38 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.cpp +++ b/Userland/Libraries/LibWeb/DOM/Window.cpp @@ -25,7 +25,6 @@ */ #include -#include #include #include #include @@ -67,8 +66,9 @@ void Window::alert(const String& message) bool Window::confirm(const String& message) { - auto confirm_result = GUI::MessageBox::show(nullptr, message, "Confirm", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel); - return confirm_result == GUI::Dialog::ExecResult::ExecOK; + if (auto* page = m_document.page()) + return page->client().page_did_request_confirm(message); + return false; } i32 Window::set_interval(JS::Function& callback, i32 interval) diff --git a/Userland/Libraries/LibWeb/InProcessWebView.cpp b/Userland/Libraries/LibWeb/InProcessWebView.cpp index c0ccaed81f..942a8b62e6 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/InProcessWebView.cpp @@ -420,4 +420,10 @@ void InProcessWebView::page_did_request_alert(const String& message) GUI::MessageBox::show(window(), message, "Alert", GUI::MessageBox::Type::Information); } +bool InProcessWebView::page_did_request_confirm(const String& message) +{ + auto confirm_result = GUI::MessageBox::show(window(), message, "Confirm", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel); + return confirm_result == GUI::Dialog::ExecResult::ExecOK; +} + } diff --git a/Userland/Libraries/LibWeb/InProcessWebView.h b/Userland/Libraries/LibWeb/InProcessWebView.h index cad88401cd..2350b2b3d8 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.h +++ b/Userland/Libraries/LibWeb/InProcessWebView.h @@ -106,6 +106,7 @@ private: virtual void page_did_layout() override; virtual void page_did_request_scroll_into_view(const Gfx::IntRect&) override; virtual void page_did_request_alert(const String&) override; + virtual bool page_did_request_confirm(const String&) override; void layout_and_sync_size(); diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index fb94463482..537c85bbfa 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -105,6 +105,7 @@ public: virtual void page_did_layout() { } virtual void page_did_request_scroll_into_view(const Gfx::IntRect&) { } virtual void page_did_request_alert(const String&) { } + virtual bool page_did_request_confirm(const String&) { return false; } }; } -- cgit v1.2.3