Title: [236004] trunk/Source
Revision
236004
Author
[email protected]
Date
2018-09-14 04:01:06 -0700 (Fri, 14 Sep 2018)

Log Message

[GTK] Make script dialogs modal to the current web view only
https://bugs.webkit.org/show_bug.cgi?id=189545

Reviewed by Michael Catanzaro.

Source/WebCore/platform/gtk/po:

* POTFILES.in:

Source/WebKit:

Change the default implementation of script dialogs to use an embedded window, like the HTTP auth dialog,
instead of a GtkMessageDialog. This patch adds a base class WebKitWebViewDialog shared by
WebKitAuthenticationDialog and the new WebKitScriptDialogImpl.

* SourcesGTK.txt: Add new files to compilation.
* UIProcess/API/glib/WebKitScriptDialogPrivate.h:
* UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
(webkitAuthenticationDialogInitialize): Do not use a frame and use a better styled title.
(webkit_authentication_dialog_class_init): Remove implementation of vfuncs that are now implemented by the
parent.
* UIProcess/API/gtk/WebKitAuthenticationDialog.h:
* UIProcess/API/gtk/WebKitScriptDialogGtk.cpp:
(webkitScriptDialogAccept): Use WebKitScriptDialogImpl API.
(webkitScriptDialogDismiss): Ditto.
(webkitScriptDialogSetUserInput): Ditto.
* UIProcess/API/gtk/WebKitScriptDialogImpl.cpp: Added.
(webkitScriptDialogImplClose):
(webkitScriptDialogImplKeyPressEvent):
(webkitScriptDialogImplMap):
(webkitScriptDialogImplConstructed):
(webkitScriptDialogImplDispose):
(webkit_script_dialog_impl_class_init):
(webkitScriptDialogImplAddButton):
(webkitScriptDialogImplNew):
(webkitScriptDialogImplCancel):
(webkitScriptDialogImplConfirm):
(webkitScriptDialogImplSetEntryText):
* UIProcess/API/gtk/WebKitScriptDialogImpl.h: Added.
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewChildIsInternalWidget): Rename authenticationDialog as just dialog.
(webkitWebViewBaseAddDialog): Ditto.
(webkitWebViewBaseContainerRemove): Ditto.
(webkitWebViewBaseContainerForall): Ditto.
(webkitWebViewBaseConstructed): Ditto.
(webkitWebViewBaseSizeAllocate): Ditto.
(webkitWebViewBaseKeyPressEvent): Ditto.
(webkitWebViewBaseHandleMouseEvent): Ditto.
(webkitWebViewBaseButtonPressEvent): Ditto.
(webkitWebViewBaseButtonReleaseEvent): Ditto.
(webkitWebViewBaseHandleWheelEvent): Ditto.
(webkitWebViewBaseScrollEvent): Ditto.
(webkitWebViewBaseMotionNotifyEvent): Ditto.
(webkitWebViewBaseCrossingNotifyEvent): Ditto.
(webkitWebViewBaseTouchEvent): Ditto.
(webkitWebViewBaseFocus): Ditto.
(webkitWebViewBaseDestroy): Ditto.
* UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
* UIProcess/API/gtk/WebKitWebViewDialog.cpp: Added.
(webkitWebViewDialogDraw):
(webkitWebViewDialogSizeAllocate):
(webkitWebViewDialogConstructed):
(webkit_web_view_dialog_class_init):
* UIProcess/API/gtk/WebKitWebViewDialog.h: Added.
* UIProcess/API/gtk/WebKitWebViewGtk.cpp:
(webkitWebViewAuthenticate):
(webkitWebViewScriptDialog):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/platform/gtk/po/ChangeLog (236003 => 236004)


--- trunk/Source/WebCore/platform/gtk/po/ChangeLog	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebCore/platform/gtk/po/ChangeLog	2018-09-14 11:01:06 UTC (rev 236004)
@@ -1,3 +1,12 @@
+2018-09-14  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Make script dialogs modal to the current web view only
+        https://bugs.webkit.org/show_bug.cgi?id=189545
+
+        Reviewed by Michael Catanzaro.
+
+        * POTFILES.in:
+
 2018-08-16  Piotr Drąg  <[email protected]>
 
         [l10n] Updated Polish translation of WebKitGTK+ for 2.22

Modified: trunk/Source/WebCore/platform/gtk/po/POTFILES.in (236003 => 236004)


--- trunk/Source/WebCore/platform/gtk/po/POTFILES.in	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebCore/platform/gtk/po/POTFILES.in	2018-09-14 11:01:06 UTC (rev 236004)
@@ -29,7 +29,7 @@
 ../../../WebKit/UIProcess/API/gtk/WebKitColorChooserRequest.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitPrintCustomWidget.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitPrintOperation.cpp
-../../../WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp
+../../../WebKit/UIProcess/API/gtk/WebKitScriptDialogImpl.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebInspector.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp

Modified: trunk/Source/WebKit/ChangeLog (236003 => 236004)


--- trunk/Source/WebKit/ChangeLog	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/ChangeLog	2018-09-14 11:01:06 UTC (rev 236004)
@@ -1,3 +1,67 @@
+2018-09-14  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Make script dialogs modal to the current web view only
+        https://bugs.webkit.org/show_bug.cgi?id=189545
+
+        Reviewed by Michael Catanzaro.
+
+        Change the default implementation of script dialogs to use an embedded window, like the HTTP auth dialog,
+        instead of a GtkMessageDialog. This patch adds a base class WebKitWebViewDialog shared by
+        WebKitAuthenticationDialog and the new WebKitScriptDialogImpl.
+
+        * SourcesGTK.txt: Add new files to compilation.
+        * UIProcess/API/glib/WebKitScriptDialogPrivate.h:
+        * UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
+        (webkitAuthenticationDialogInitialize): Do not use a frame and use a better styled title.
+        (webkit_authentication_dialog_class_init): Remove implementation of vfuncs that are now implemented by the
+        parent.
+        * UIProcess/API/gtk/WebKitAuthenticationDialog.h:
+        * UIProcess/API/gtk/WebKitScriptDialogGtk.cpp:
+        (webkitScriptDialogAccept): Use WebKitScriptDialogImpl API.
+        (webkitScriptDialogDismiss): Ditto.
+        (webkitScriptDialogSetUserInput): Ditto.
+        * UIProcess/API/gtk/WebKitScriptDialogImpl.cpp: Added.
+        (webkitScriptDialogImplClose):
+        (webkitScriptDialogImplKeyPressEvent):
+        (webkitScriptDialogImplMap):
+        (webkitScriptDialogImplConstructed):
+        (webkitScriptDialogImplDispose):
+        (webkit_script_dialog_impl_class_init):
+        (webkitScriptDialogImplAddButton):
+        (webkitScriptDialogImplNew):
+        (webkitScriptDialogImplCancel):
+        (webkitScriptDialogImplConfirm):
+        (webkitScriptDialogImplSetEntryText):
+        * UIProcess/API/gtk/WebKitScriptDialogImpl.h: Added.
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewChildIsInternalWidget): Rename authenticationDialog as just dialog.
+        (webkitWebViewBaseAddDialog): Ditto.
+        (webkitWebViewBaseContainerRemove): Ditto.
+        (webkitWebViewBaseContainerForall): Ditto.
+        (webkitWebViewBaseConstructed): Ditto.
+        (webkitWebViewBaseSizeAllocate): Ditto.
+        (webkitWebViewBaseKeyPressEvent): Ditto.
+        (webkitWebViewBaseHandleMouseEvent): Ditto.
+        (webkitWebViewBaseButtonPressEvent): Ditto.
+        (webkitWebViewBaseButtonReleaseEvent): Ditto.
+        (webkitWebViewBaseHandleWheelEvent): Ditto.
+        (webkitWebViewBaseScrollEvent): Ditto.
+        (webkitWebViewBaseMotionNotifyEvent): Ditto.
+        (webkitWebViewBaseCrossingNotifyEvent): Ditto.
+        (webkitWebViewBaseTouchEvent): Ditto.
+        (webkitWebViewBaseFocus): Ditto.
+        (webkitWebViewBaseDestroy): Ditto.
+        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
+        * UIProcess/API/gtk/WebKitWebViewDialog.cpp: Added.
+        (webkitWebViewDialogDraw):
+        (webkitWebViewDialogSizeAllocate):
+        (webkitWebViewDialogConstructed):
+        (webkit_web_view_dialog_class_init):
+        * UIProcess/API/gtk/WebKitWebViewDialog.h: Added.
+        * UIProcess/API/gtk/WebKitWebViewGtk.cpp:
+        (webkitWebViewAuthenticate):
+        (webkitWebViewScriptDialog):
+
 2018-09-13  Ryan Haddad  <[email protected]>
 
         Unreviewed, rolling out r235954.

Modified: trunk/Source/WebKit/SourcesGTK.txt (236003 => 236004)


--- trunk/Source/WebKit/SourcesGTK.txt	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/SourcesGTK.txt	2018-09-14 11:01:06 UTC (rev 236004)
@@ -191,10 +191,12 @@
 UIProcess/API/gtk/WebKitPrintOperation.cpp @no-unify
 UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp @no-unify
 UIProcess/API/gtk/WebKitScriptDialogGtk.cpp @no-unify
+UIProcess/API/gtk/WebKitScriptDialogImpl.cpp @no-unify
 UIProcess/API/gtk/WebKitVersion.cpp @no-unify
 UIProcess/API/gtk/WebKitWebInspector.cpp @no-unify
 UIProcess/API/gtk/WebKitWebViewBase.cpp @no-unify
 UIProcess/API/gtk/WebKitWebViewBaseAccessible.cpp @no-unify
+UIProcess/API/gtk/WebKitWebViewDialog.cpp @no-unify
 UIProcess/API/gtk/WebKitWebViewGtk.cpp @no-unify
 
 UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitScriptDialogPrivate.h (236003 => 236004)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitScriptDialogPrivate.h	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitScriptDialogPrivate.h	2018-09-14 11:01:06 UTC (rev 236004)
@@ -20,7 +20,6 @@
 #pragma once
 
 #include "WebKitScriptDialog.h"
-#include "WebKitWebView.h"
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
@@ -50,7 +49,6 @@
 };
 
 WebKitScriptDialog* webkitScriptDialogCreate(unsigned type, const CString& message, const CString& defaultText, Function<void(bool, const String&)>&& completionHandler);
-void webkitScriptDialogRun(WebKitScriptDialog*, WebKitWebView*);
 bool webkitScriptDialogIsRunning(WebKitScriptDialog*);
 void webkitScriptDialogAccept(WebKitScriptDialog*);
 void webkitScriptDialogDismiss(WebKitScriptDialog*);

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp (236003 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp	2018-09-14 11:01:06 UTC (rev 236004)
@@ -38,10 +38,9 @@
     GtkWidget* rememberCheckButton;
     GtkWidget* defaultButton;
     unsigned long authenticationCancelledID;
-    GRefPtr<GtkStyleContext> styleContext;
 };
 
-WEBKIT_DEFINE_TYPE(WebKitAuthenticationDialog, webkit_authentication_dialog, GTK_TYPE_EVENT_BOX)
+WEBKIT_DEFINE_TYPE(WebKitAuthenticationDialog, webkit_authentication_dialog, WEBKIT_TYPE_WEB_VIEW_DIALOG)
 
 static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog)
 {
@@ -82,28 +81,28 @@
 
 static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* authDialog)
 {
-    GtkWidget* frame = gtk_frame_new(0);
-    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
+    GtkWidget* vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20);
 
-    GtkWidget* vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
-    gtk_container_set_border_width(GTK_CONTAINER(vBox), 12);
+    GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_style_context_add_class(gtk_widget_get_style_context(box), GTK_STYLE_CLASS_TITLEBAR);
+    gtk_widget_set_size_request(box, -1, 16);
+    GtkWidget* title = gtk_label_new(_("Authentication Required"));
+    gtk_widget_set_margin_top(title, 6);
+    gtk_widget_set_margin_bottom(title, 6);
+    gtk_style_context_add_class(gtk_widget_get_style_context(title), GTK_STYLE_CLASS_TITLE);
+    gtk_box_set_center_widget(GTK_BOX(box), title);
+    gtk_widget_show(title);
+    gtk_box_pack_start(GTK_BOX(vBox), box, TRUE, FALSE, 0);
+    gtk_widget_show(box);
 
-    GtkWidget* label = gtk_label_new(nullptr);
-    // Title of the HTTP authentication dialog.
-    GUniquePtr<char> title(g_strdup_printf("<b>%s</b>", _("Authentication Required")));
-    gtk_label_set_markup(GTK_LABEL(label), title.get());
-    gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
-    gtk_widget_show(label);
-    gtk_box_pack_start(GTK_BOX(vBox), label, FALSE, FALSE, 0);
-
     GtkWidget* buttonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
-    gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
-    gtk_container_set_border_width(GTK_CONTAINER(buttonBox), 5);
-    gtk_box_set_spacing(GTK_BOX(buttonBox), 6);
+    gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_EXPAND);
+    gtk_widget_set_hexpand(buttonBox, TRUE);
+    gtk_style_context_add_class(gtk_widget_get_style_context(buttonBox), "dialog-action-area");
 
     GtkWidget* button = gtk_button_new_with_mnemonic(_("_Cancel"));
     g_signal_connect(button, "clicked", G_CALLBACK(cancelButtonClicked), authDialog);
-    gtk_box_pack_end(GTK_BOX(buttonBox), button, FALSE, TRUE, 0);
+    gtk_box_pack_start(GTK_BOX(buttonBox), button, FALSE, TRUE, 0);
     gtk_widget_show(button);
 
     WebKitAuthenticationDialogPrivate* priv = authDialog->priv;
@@ -114,14 +113,15 @@
     gtk_box_pack_end(GTK_BOX(buttonBox), button, FALSE, TRUE, 0);
     gtk_widget_show(button);
 
-    GtkWidget* authBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
-    gtk_container_set_border_width(GTK_CONTAINER(authBox), 5);
+    GtkWidget* authBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
+    gtk_widget_set_margin_start(authBox, 10);
+    gtk_widget_set_margin_end(authBox, 10);
 
     const WebCore::AuthenticationChallenge& challenge = webkitAuthenticationRequestGetAuthenticationChallenge(priv->request.get())->core();
     // Prompt on the HTTP authentication dialog.
     GUniquePtr<char> prompt(g_strdup_printf(_("Authentication required by %s:%i"),
         challenge.protectionSpace().host().utf8().data(), challenge.protectionSpace().port()));
-    label = createLabelWithLineWrap(prompt.get());
+    GtkWidget* label = createLabelWithLineWrap(prompt.get());
     gtk_widget_show(label);
     gtk_box_pack_start(GTK_BOX(authBox), label, FALSE, FALSE, 0);
 
@@ -189,38 +189,12 @@
     gtk_box_pack_end(GTK_BOX(vBox), buttonBox, FALSE, TRUE, 0);
     gtk_widget_show(buttonBox);
 
-    gtk_container_add(GTK_CONTAINER(frame), vBox);
+    gtk_container_add(GTK_CONTAINER(authDialog), vBox);
     gtk_widget_show(vBox);
 
-    gtk_container_add(GTK_CONTAINER(authDialog), frame);
-    gtk_widget_show(frame);
-
     authDialog->priv->authenticationCancelledID = g_signal_connect(authDialog->priv->request.get(), "cancelled", G_CALLBACK(authenticationCancelled), authDialog);
 }
 
-static gboolean webkitAuthenticationDialogDraw(GtkWidget* widget, cairo_t* cr)
-{
-    WebKitAuthenticationDialogPrivate* priv = WEBKIT_AUTHENTICATION_DIALOG(widget)->priv;
-
-    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
-    cairo_set_source_rgba(cr, 0, 0, 0, 0.5);
-    cairo_paint(cr);
-
-    if (GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget))) {
-        GtkAllocation allocation;
-        gtk_widget_get_allocation(child, &allocation);
-
-        gtk_style_context_save(priv->styleContext.get());
-        gtk_style_context_add_class(priv->styleContext.get(), GTK_STYLE_CLASS_BACKGROUND);
-        gtk_render_background(priv->styleContext.get(), cr, allocation.x, allocation.y, allocation.width, allocation.height);
-        gtk_style_context_restore(priv->styleContext.get());
-    }
-
-    GTK_WIDGET_CLASS(webkit_authentication_dialog_parent_class)->draw(widget, cr);
-
-    return FALSE;
-}
-
 static void webkitAuthenticationDialogMap(GtkWidget* widget)
 {
     WebKitAuthenticationDialogPrivate* priv = WEBKIT_AUTHENTICATION_DIALOG(widget)->priv;
@@ -230,39 +204,6 @@
     GTK_WIDGET_CLASS(webkit_authentication_dialog_parent_class)->map(widget);
 }
 
-static void webkitAuthenticationDialogSizeAllocate(GtkWidget* widget, GtkAllocation* allocation)
-{
-    GTK_WIDGET_CLASS(webkit_authentication_dialog_parent_class)->size_allocate(widget, allocation);
-
-    GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget));
-    if (!child)
-        return;
-
-    GtkRequisition naturalSize;
-    gtk_widget_get_preferred_size(child, 0, &naturalSize);
-
-    GtkAllocation childAllocation;
-    gtk_widget_get_allocation(child, &childAllocation);
-
-    childAllocation.x += (allocation->width - naturalSize.width) / 2;
-    childAllocation.y += (allocation->height - naturalSize.height) / 2;
-    childAllocation.width = naturalSize.width;
-    childAllocation.height = naturalSize.height;
-    gtk_widget_size_allocate(child, &childAllocation);
-}
-
-static void webkitAuthenticationDialogConstructed(GObject* object)
-{
-    G_OBJECT_CLASS(webkit_authentication_dialog_parent_class)->constructed(object);
-
-    WebKitAuthenticationDialogPrivate* priv = WEBKIT_AUTHENTICATION_DIALOG(object)->priv;
-    priv->styleContext = adoptGRef(gtk_style_context_new());
-    GtkWidgetPath* path = gtk_widget_path_new();
-    gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
-    gtk_style_context_set_path(priv->styleContext.get(), path);
-    gtk_widget_path_free(path);
-}
-
 static void webkitAuthenticationDialogDispose(GObject* object)
 {
     WebKitAuthenticationDialogPrivate* priv = WEBKIT_AUTHENTICATION_DIALOG(object)->priv;
@@ -277,13 +218,10 @@
 static void webkit_authentication_dialog_class_init(WebKitAuthenticationDialogClass* klass)
 {
     GObjectClass* objectClass = G_OBJECT_CLASS(klass);
-    objectClass->constructed = webkitAuthenticationDialogConstructed;
     objectClass->dispose = webkitAuthenticationDialogDispose;
 
     GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(klass);
-    widgetClass->draw = webkitAuthenticationDialogDraw;
     widgetClass->map = webkitAuthenticationDialogMap;
-    widgetClass->size_allocate = webkitAuthenticationDialogSizeAllocate;
 }
 
 GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest* request, CredentialStorageMode mode)

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.h (236003 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.h	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.h	2018-09-14 11:01:06 UTC (rev 236004)
@@ -17,10 +17,10 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef WebKitAuthenticationDialog_h
-#define WebKitAuthenticationDialog_h
+#pragma once
 
 #include "WebKitAuthenticationRequest.h"
+#include "WebKitWebViewDialog.h"
 #include <gtk/gtk.h>
 
 enum CredentialStorageMode {
@@ -42,13 +42,13 @@
 typedef struct _WebKitAuthenticationDialogPrivate WebKitAuthenticationDialogPrivate;
 
 struct _WebKitAuthenticationDialog {
-    GtkEventBox parent;
+    WebKitWebViewDialog parent;
 
     WebKitAuthenticationDialogPrivate* priv;
 };
 
 struct _WebKitAuthenticationDialogClass {
-    GtkEventBoxClass parentClass;
+    WebKitWebViewDialogClass parentClass;
 };
 
 GType webkit_authentication_dialog_get_type();
@@ -56,4 +56,3 @@
 
 G_END_DECLS
 
-#endif // WebKitAuthenticationDialog_h

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp (236003 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp	2018-09-14 11:01:06 UTC (rev 236004)
@@ -20,122 +20,27 @@
 #include "config.h"
 #include "WebKitScriptDialog.h"
 
+#include "WebKitScriptDialogImpl.h"
 #include "WebKitScriptDialogPrivate.h"
-#include "WebKitWebViewPrivate.h"
-#include <WebCore/GtkUtilities.h>
-#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-#include <wtf/glib/GUniquePtr.h>
 
-static void scriptDialogResponseCallback(GtkWidget* dialog, int responseID, WebKitScriptDialog* scriptDialog)
-{
-    switch (scriptDialog->type) {
-    case WEBKIT_SCRIPT_DIALOG_ALERT:
-        break;
-    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
-    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
-        scriptDialog->confirmed = responseID == GTK_RESPONSE_OK;
-        break;
-    case WEBKIT_SCRIPT_DIALOG_PROMPT:
-        if (responseID == GTK_RESPONSE_OK) {
-            if (auto* entry = g_object_get_data(G_OBJECT(dialog), "wk-script-dialog-entry"))
-                scriptDialog->text = gtk_entry_get_text(GTK_ENTRY(entry));
-        }
-        break;
-    }
-
-    scriptDialog->nativeDialog = nullptr;
-    webkit_script_dialog_close(scriptDialog);
-    webkit_script_dialog_unref(scriptDialog);
-    gtk_widget_destroy(dialog);
-}
-
-static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, GtkMessageType type, GtkButtonsType buttons, int defaultResponse, const char* primaryText, const char* secondaryText = nullptr)
-{
-    GtkWidget* parent = gtk_widget_get_toplevel(GTK_WIDGET(webView));
-    GtkWidget* dialog = gtk_message_dialog_new(WebCore::widgetIsOnscreenToplevelWindow(parent) ? GTK_WINDOW(parent) : nullptr,
-        GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, "%s", primaryText);
-    if (secondaryText)
-        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", secondaryText);
-    GUniquePtr<char> title(g_strdup_printf("_javascript_ - %s", webkitWebViewGetPage(webView).pageLoadState().url().utf8().data()));
-    gtk_window_set_title(GTK_WINDOW(dialog), title.get());
-    if (buttons != GTK_BUTTONS_NONE)
-        gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);
-
-    return dialog;
-}
-
-void webkitScriptDialogRun(WebKitScriptDialog* scriptDialog, WebKitWebView* webView)
-{
-    GtkWidget* dialog = nullptr;
-
-    switch (scriptDialog->type) {
-    case WEBKIT_SCRIPT_DIALOG_ALERT:
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, GTK_RESPONSE_CLOSE, scriptDialog->message.data());
-        break;
-    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data());
-        break;
-    case WEBKIT_SCRIPT_DIALOG_PROMPT: {
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data());
-        GtkWidget* entry = gtk_entry_new();
-        g_object_set_data(G_OBJECT(dialog), "wk-script-dialog-entry", entry);
-        gtk_entry_set_text(GTK_ENTRY(entry), scriptDialog->defaultText.data());
-        gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry);
-        gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
-        gtk_widget_show(entry);
-        break;
-    }
-    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, GTK_RESPONSE_OK,
-            _("Are you sure you want to leave this page?"), scriptDialog->message.data());
-        gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Stay on Page"), GTK_RESPONSE_CLOSE, _("Leave Page"), GTK_RESPONSE_OK, nullptr);
-        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
-        break;
-    }
-
-    ASSERT(dialog);
-    scriptDialog->nativeDialog = dialog;
-    g_signal_connect(dialog, "response", G_CALLBACK(scriptDialogResponseCallback), webkit_script_dialog_ref(scriptDialog));
-    gtk_widget_show(dialog);
-}
-
 void webkitScriptDialogAccept(WebKitScriptDialog* scriptDialog)
 {
-    int response = 0;
-    switch (scriptDialog->type) {
-    case WEBKIT_SCRIPT_DIALOG_ALERT:
-        response = GTK_RESPONSE_CLOSE;
-        break;
-    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
-    case WEBKIT_SCRIPT_DIALOG_PROMPT:
-    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
-        response = GTK_RESPONSE_OK;
-        break;
-    }
-    ASSERT(scriptDialog->nativeDialog);
-    gtk_dialog_response(GTK_DIALOG(scriptDialog->nativeDialog), response);
+    if (!WEBKIT_IS_SCRIPT_DIALOG_IMPL(scriptDialog->nativeDialog))
+        return;
+    webkitScriptDialogImplConfirm(WEBKIT_SCRIPT_DIALOG_IMPL(scriptDialog->nativeDialog));
 }
 
 void webkitScriptDialogDismiss(WebKitScriptDialog* scriptDialog)
 {
-    ASSERT(scriptDialog->nativeDialog);
-    gtk_dialog_response(GTK_DIALOG(scriptDialog->nativeDialog), GTK_RESPONSE_CLOSE);
+    if (!WEBKIT_IS_SCRIPT_DIALOG_IMPL(scriptDialog->nativeDialog))
+        return;
+    webkitScriptDialogImplCancel(WEBKIT_SCRIPT_DIALOG_IMPL(scriptDialog->nativeDialog));
 }
 
 void webkitScriptDialogSetUserInput(WebKitScriptDialog* scriptDialog, const String& userInput)
 {
-    if (scriptDialog->type != WEBKIT_SCRIPT_DIALOG_PROMPT)
+    if (!WEBKIT_IS_SCRIPT_DIALOG_IMPL(scriptDialog->nativeDialog))
         return;
 
-    ASSERT(scriptDialog->nativeDialog);
-    GtkWidget* dialogContentArea = gtk_dialog_get_content_area(GTK_DIALOG(scriptDialog->nativeDialog));
-    GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(dialogContentArea)));
-    for (GList* child = children.get(); child; child = g_list_next(child)) {
-        GtkWidget* childWidget = GTK_WIDGET(child->data);
-        if (GTK_IS_ENTRY(childWidget)) {
-            gtk_entry_set_text(GTK_ENTRY(childWidget), userInput.utf8().data());
-            break;
-        }
-    }
+    webkitScriptDialogImplSetEntryText(WEBKIT_SCRIPT_DIALOG_IMPL(scriptDialog->nativeDialog), userInput);
 }

Added: trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogImpl.cpp (0 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogImpl.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogImpl.cpp	2018-09-14 11:01:06 UTC (rev 236004)
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitScriptDialogImpl.h"
+
+#include "WebKitScriptDialogPrivate.h"
+#include <glib/gi18n-lib.h>
+#include <wtf/glib/WTFGType.h>
+#include <wtf/text/CString.h>
+
+struct _WebKitScriptDialogImplPrivate {
+    WebKitScriptDialog* dialog;
+    GtkWidget* vbox;
+    GtkWidget* title;
+    GtkWidget* label;
+    GtkWidget* entry;
+    GtkWidget* actionArea;
+    GtkWidget* defaultButton;
+};
+
+WEBKIT_DEFINE_TYPE(WebKitScriptDialogImpl, webkit_script_dialog_impl, WEBKIT_TYPE_WEB_VIEW_DIALOG)
+
+static void webkitScriptDialogImplClose(WebKitScriptDialogImpl* dialog)
+{
+    webkit_script_dialog_close(dialog->priv->dialog);
+    gtk_widget_destroy(GTK_WIDGET(dialog));
+}
+
+static gboolean webkitScriptDialogImplKeyPressEvent(GtkWidget* widget, GdkEventKey* keyEvent)
+{
+    if (keyEvent->keyval == GDK_KEY_Escape) {
+        webkitScriptDialogImplClose(WEBKIT_SCRIPT_DIALOG_IMPL(widget));
+        return GDK_EVENT_STOP;
+    }
+
+    return GDK_EVENT_PROPAGATE;
+}
+
+static void webkitScriptDialogImplMap(GtkWidget* widget)
+{
+    WebKitScriptDialogImplPrivate* priv = WEBKIT_SCRIPT_DIALOG_IMPL(widget)->priv;
+    gtk_widget_grab_default(priv->defaultButton);
+
+    switch (priv->dialog->type) {
+    case WEBKIT_SCRIPT_DIALOG_ALERT:
+    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
+    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
+        gtk_widget_grab_focus(priv->defaultButton);
+        break;
+    case WEBKIT_SCRIPT_DIALOG_PROMPT:
+        gtk_widget_grab_focus(priv->entry);
+        break;
+    }
+
+    GTK_WIDGET_CLASS(webkit_script_dialog_impl_parent_class)->map(widget);
+}
+
+static void webkitScriptDialogImplConstructed(GObject* object)
+{
+    G_OBJECT_CLASS(webkit_script_dialog_impl_parent_class)->constructed(object);
+
+    auto* dialog = WEBKIT_SCRIPT_DIALOG_IMPL(object);
+    WebKitScriptDialogImplPrivate* priv = dialog->priv;
+
+    priv->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20);
+    gtk_container_set_border_width(GTK_CONTAINER(priv->vbox), 0);
+    gtk_container_add(GTK_CONTAINER(dialog), priv->vbox);
+    gtk_widget_show(priv->vbox);
+
+    GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_style_context_add_class(gtk_widget_get_style_context(box), GTK_STYLE_CLASS_TITLEBAR);
+    gtk_widget_set_size_request(box, -1, 16);
+    priv->title = gtk_label_new(nullptr);
+    gtk_widget_set_margin_top(priv->title, 6);
+    gtk_widget_set_margin_bottom(priv->title, 6);
+    gtk_style_context_add_class(gtk_widget_get_style_context(priv->title), GTK_STYLE_CLASS_TITLE);
+    gtk_box_set_center_widget(GTK_BOX(box), priv->title);
+    gtk_widget_show(priv->title);
+    gtk_box_pack_start(GTK_BOX(priv->vbox), box, TRUE, FALSE, 0);
+    gtk_widget_show(box);
+
+    box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 30);
+    gtk_widget_set_margin_start(box, 30);
+    gtk_widget_set_margin_end(box, 30);
+    gtk_box_pack_start(GTK_BOX(priv->vbox), box, TRUE, FALSE, 0);
+    gtk_widget_show(box);
+
+    GtkWidget* messageArea = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
+    gtk_box_pack_start(GTK_BOX(box), messageArea, TRUE, TRUE, 0);
+    gtk_widget_show(messageArea);
+
+    priv->label = gtk_label_new(nullptr);
+    gtk_widget_set_halign(priv->label, GTK_ALIGN_CENTER);
+    gtk_widget_set_valign(priv->label, GTK_ALIGN_START);
+    gtk_label_set_line_wrap(GTK_LABEL(priv->label), TRUE);
+    gtk_label_set_max_width_chars(GTK_LABEL(priv->label), 60);
+    gtk_box_pack_start(GTK_BOX(messageArea), priv->label, TRUE, FALSE, 0);
+    gtk_widget_show(priv->label);
+
+    GtkWidget* actionBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_style_context_add_class(gtk_widget_get_style_context(actionBox), "dialog-action-box");
+    gtk_box_pack_end(GTK_BOX(priv->vbox), actionBox, FALSE, TRUE, 0);
+    gtk_widget_show(actionBox);
+
+    priv->actionArea = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
+    gtk_button_box_set_layout(GTK_BUTTON_BOX(priv->actionArea), GTK_BUTTONBOX_EXPAND);
+    gtk_widget_set_hexpand(priv->actionArea, TRUE);
+    gtk_style_context_add_class(gtk_widget_get_style_context(priv->actionArea), "dialog-action-area");
+    gtk_box_pack_end(GTK_BOX(actionBox), priv->actionArea, FALSE, TRUE, 0);
+    gtk_widget_show(priv->actionArea);
+}
+
+static void webkitScriptDialogImplDispose(GObject* object)
+{
+    auto* dialog = WEBKIT_SCRIPT_DIALOG_IMPL(object);
+    if (dialog->priv->dialog) {
+        dialog->priv->dialog->nativeDialog = nullptr;
+        webkit_script_dialog_unref(dialog->priv->dialog);
+        dialog->priv->dialog = nullptr;
+    }
+
+    G_OBJECT_CLASS(webkit_script_dialog_impl_parent_class)->dispose(object);
+}
+
+static void webkit_script_dialog_impl_class_init(WebKitScriptDialogImplClass* klass)
+{
+    GObjectClass* objectClass = G_OBJECT_CLASS(klass);
+    objectClass->constructed = webkitScriptDialogImplConstructed;
+    objectClass->dispose = webkitScriptDialogImplDispose;
+
+    GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(klass);
+    widgetClass->key_press_event = webkitScriptDialogImplKeyPressEvent;
+    widgetClass->map = webkitScriptDialogImplMap;
+    gtk_widget_class_set_accessible_role(widgetClass, ATK_ROLE_ALERT);
+}
+
+static GtkWidget* webkitScriptDialogImplAddButton(WebKitScriptDialogImpl* dialog, const char* text)
+{
+    WebKitScriptDialogImplPrivate* priv = dialog->priv;
+    GtkWidget* button = gtk_button_new_with_label(text);
+    gtk_button_set_use_underline(GTK_BUTTON(button), TRUE);
+    gtk_style_context_add_class(gtk_widget_get_style_context(button), "text-button");
+    gtk_widget_set_can_default(button, TRUE);
+
+    gtk_widget_set_valign(button, GTK_ALIGN_BASELINE);
+    gtk_container_add(GTK_CONTAINER(priv->actionArea), button);
+    gtk_widget_show(button);
+
+    return button;
+}
+
+GtkWidget* webkitScriptDialogImplNew(WebKitScriptDialog* scriptDialog, const char* title)
+{
+    auto* dialog = WEBKIT_SCRIPT_DIALOG_IMPL(g_object_new(WEBKIT_TYPE_SCRIPT_DIALOG_IMPL, nullptr));
+    dialog->priv->dialog = webkit_script_dialog_ref(scriptDialog);
+    dialog->priv->dialog->nativeDialog = GTK_WIDGET(dialog);
+
+    switch (scriptDialog->type) {
+    case WEBKIT_SCRIPT_DIALOG_ALERT: {
+        gtk_label_set_text(GTK_LABEL(dialog->priv->title), title);
+
+        GtkWidget* button = webkitScriptDialogImplAddButton(dialog, _("_Close"));
+        dialog->priv->defaultButton = button;
+        g_signal_connect_swapped(button, "clicked", G_CALLBACK(webkitScriptDialogImplCancel), dialog);
+        gtk_label_set_text(GTK_LABEL(dialog->priv->label), scriptDialog->message.data());
+        break;
+    }
+    case WEBKIT_SCRIPT_DIALOG_PROMPT:
+        dialog->priv->entry = gtk_entry_new();
+        gtk_entry_set_text(GTK_ENTRY(dialog->priv->entry), scriptDialog->defaultText.data());
+        gtk_container_add(GTK_CONTAINER(dialog->priv->vbox), dialog->priv->entry);
+        gtk_entry_set_activates_default(GTK_ENTRY(dialog->priv->entry), TRUE);
+        gtk_widget_show(dialog->priv->entry);
+
+        FALLTHROUGH;
+    case WEBKIT_SCRIPT_DIALOG_CONFIRM: {
+        gtk_label_set_text(GTK_LABEL(dialog->priv->title), title);
+
+        GtkWidget* button = webkitScriptDialogImplAddButton(dialog, _("_Cancel"));
+        g_signal_connect_swapped(button, "clicked", G_CALLBACK(webkitScriptDialogImplCancel), dialog);
+        button = webkitScriptDialogImplAddButton(dialog, _("_OK"));
+        dialog->priv->defaultButton = button;
+        g_signal_connect_swapped(button, "clicked", G_CALLBACK(webkitScriptDialogImplConfirm), dialog);
+        gtk_label_set_text(GTK_LABEL(dialog->priv->label), scriptDialog->message.data());
+        break;
+    }
+    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM: {
+        gtk_label_set_text(GTK_LABEL(dialog->priv->title), _("Are you sure you want to leave this page?"));
+
+        GtkWidget* button = webkitScriptDialogImplAddButton(dialog, _("Stay on Page"));
+        g_signal_connect_swapped(button, "clicked", G_CALLBACK(webkitScriptDialogImplCancel), dialog);
+        button = webkitScriptDialogImplAddButton(dialog, _("Leave Page"));
+        dialog->priv->defaultButton = button;
+        g_signal_connect_swapped(button, "clicked", G_CALLBACK(webkitScriptDialogImplConfirm), dialog);
+        gtk_label_set_text(GTK_LABEL(dialog->priv->label), scriptDialog->message.data());
+        break;
+    }
+    }
+
+    return GTK_WIDGET(dialog);
+}
+
+void webkitScriptDialogImplCancel(WebKitScriptDialogImpl* dialog)
+{
+    switch (dialog->priv->dialog->type) {
+    case WEBKIT_SCRIPT_DIALOG_ALERT:
+    case WEBKIT_SCRIPT_DIALOG_PROMPT:
+        break;
+    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
+    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
+        dialog->priv->dialog->confirmed = false;
+        break;
+    }
+    webkitScriptDialogImplClose(dialog);
+}
+
+void webkitScriptDialogImplConfirm(WebKitScriptDialogImpl* dialog)
+{
+    switch (dialog->priv->dialog->type) {
+    case WEBKIT_SCRIPT_DIALOG_ALERT:
+        break;
+    case WEBKIT_SCRIPT_DIALOG_PROMPT:
+        dialog->priv->dialog->text = gtk_entry_get_text(GTK_ENTRY(dialog->priv->entry));
+        break;
+    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
+    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
+        dialog->priv->dialog->confirmed = true;
+        break;
+    }
+    webkitScriptDialogImplClose(dialog);
+}
+
+void webkitScriptDialogImplSetEntryText(WebKitScriptDialogImpl* dialog, const String& text)
+{
+    if (dialog->priv->dialog->type != WEBKIT_SCRIPT_DIALOG_PROMPT)
+        return;
+
+    gtk_entry_set_text(GTK_ENTRY(dialog->priv->entry), text.utf8().data());
+}

Added: trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogImpl.h (0 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogImpl.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogImpl.h	2018-09-14 11:01:06 UTC (rev 236004)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "WebKitScriptDialog.h"
+#include "WebKitWebViewDialog.h"
+#include <wtf/text/WTFString.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_SCRIPT_DIALOG_IMPL            (webkit_script_dialog_impl_get_type())
+#define WEBKIT_SCRIPT_DIALOG_IMPL(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_SCRIPT_DIALOG_IMPL, WebKitScriptDialogImpl))
+#define WEBKIT_IS_SCRIPT_DIALOG_IMPL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_SCRIPT_DIALOG_IMPL))
+#define WEBKIT_SCRIPT_DIALOG_IMPL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_SCRIPT_DIALOG_IMPL, WebKitScriptDialogImplClass))
+#define WEBKIT_IS_SCRIPT_DIALOG_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_SCRIPT_DIALOG_IMPL))
+#define WEBKIT_SCRIPT_DIALOG_IMPL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_SCRIPT_DIALOG_IMPL, WebKitScriptDialogImplClass))
+
+typedef struct _WebKitScriptDialogImpl        WebKitScriptDialogImpl;
+typedef struct _WebKitScriptDialogImplClass   WebKitScriptDialogImplClass;
+typedef struct _WebKitScriptDialogImplPrivate WebKitScriptDialogImplPrivate;
+
+struct _WebKitScriptDialogImpl {
+    WebKitWebViewDialog parent;
+
+    WebKitScriptDialogImplPrivate* priv;
+};
+
+struct _WebKitScriptDialogImplClass {
+    WebKitWebViewDialogClass parentClass;
+};
+
+GType webkit_script_dialog_impl_get_type();
+GtkWidget* webkitScriptDialogImplNew(WebKitScriptDialog*, const char* title);
+void webkitScriptDialogImplCancel(WebKitScriptDialogImpl*);
+void webkitScriptDialogImplConfirm(WebKitScriptDialogImpl*);
+void webkitScriptDialogImplSetEntryText(WebKitScriptDialogImpl*, const String&);
+
+G_END_DECLS

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (236003 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2018-09-14 11:01:06 UTC (rev 236004)
@@ -41,7 +41,6 @@
 #include "WebEventFactory.h"
 #include "WebInspectorProxy.h"
 #include "WebKit2Initialize.h"
-#include "WebKitAuthenticationDialog.h"
 #include "WebKitWebViewBaseAccessible.h"
 #include "WebKitWebViewBasePrivate.h"
 #include "WebPageGroup.h"
@@ -167,7 +166,7 @@
     CString tooltipText;
     IntRect tooltipArea;
     GRefPtr<AtkObject> accessible;
-    GtkWidget* authenticationDialog { nullptr };
+    GtkWidget* dialog { nullptr };
     GtkWidget* inspectorView { nullptr };
     AttachmentSide inspectorAttachmentSide { AttachmentSide::Bottom };
     unsigned inspectorViewSize { 0 };
@@ -401,7 +400,7 @@
 static bool webkitWebViewChildIsInternalWidget(WebKitWebViewBase* webViewBase, GtkWidget* widget)
 {
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
-    return widget == priv->inspectorView || widget == priv->authenticationDialog;
+    return widget == priv->inspectorView || widget == priv->dialog;
 }
 
 static void webkitWebViewBaseContainerAdd(GtkContainer* container, GtkWidget* widget)
@@ -420,10 +419,10 @@
     gtk_widget_set_parent(widget, GTK_WIDGET(container));
 }
 
-void webkitWebViewBaseAddAuthenticationDialog(WebKitWebViewBase* webViewBase, GtkWidget* dialog)
+void webkitWebViewBaseAddDialog(WebKitWebViewBase* webViewBase, GtkWidget* dialog)
 {
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
-    priv->authenticationDialog = dialog;
+    priv->dialog = dialog;
     gtk_container_add(GTK_CONTAINER(webViewBase), dialog);
     gtk_widget_show(dialog);
 
@@ -459,8 +458,8 @@
     if (priv->inspectorView == widget) {
         priv->inspectorView = 0;
         priv->inspectorViewSize = 0;
-    } else if (priv->authenticationDialog == widget) {
-        priv->authenticationDialog = 0;
+    } else if (priv->dialog == widget) {
+        priv->dialog = nullptr;
     } else {
         ASSERT(priv->children.contains(widget));
         priv->children.remove(widget);
@@ -482,8 +481,8 @@
     if (includeInternals && priv->inspectorView)
         (*callback)(priv->inspectorView, callbackData);
 
-    if (includeInternals && priv->authenticationDialog)
-        (*callback)(priv->authenticationDialog, callbackData);
+    if (includeInternals && priv->dialog)
+        (*callback)(priv->dialog, callbackData);
 }
 
 void webkitWebViewBaseChildMoveResize(WebKitWebViewBase* webView, GtkWidget* child, const IntRect& childRect)
@@ -518,7 +517,7 @@
 
     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv;
     priv->pageClient = std::make_unique<PageClientImpl>(viewWidget);
-    priv->authenticationDialog = 0;
+    priv->dialog = nullptr;
 }
 
 static gboolean webkitWebViewBaseDraw(GtkWidget* widget, cairo_t* cr)
@@ -589,15 +588,15 @@
         gtk_widget_size_allocate(priv->inspectorView, &childAllocation);
     }
 
-    // The authentication dialog is centered in the view rect, which means that it
+    // The dialogs are centered in the view rect, which means that it
     // never overlaps the web inspector. Thus, we need to calculate the allocation here
     // after calculating the inspector allocation.
-    if (priv->authenticationDialog) {
+    if (priv->dialog) {
         GtkRequisition minimumSize;
-        gtk_widget_get_preferred_size(priv->authenticationDialog, &minimumSize, nullptr);
+        gtk_widget_get_preferred_size(priv->dialog, &minimumSize, nullptr);
 
         GtkAllocation childAllocation = { 0, 0, std::max(minimumSize.width, viewRect.width()), std::max(minimumSize.height, viewRect.height()) };
-        gtk_widget_size_allocate(priv->authenticationDialog, &childAllocation);
+        gtk_widget_size_allocate(priv->dialog, &childAllocation);
     }
 
     if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea()))
@@ -685,7 +684,7 @@
     }
 #endif
 
-    if (priv->authenticationDialog)
+    if (priv->dialog)
         return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, keyEvent);
 
 #if ENABLE(FULLSCREEN_API)
@@ -743,7 +742,7 @@
 static void webkitWebViewBaseHandleMouseEvent(WebKitWebViewBase* webViewBase, GdkEvent* event)
 {
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
-    ASSERT(!priv->authenticationDialog);
+    ASSERT(!priv->dialog);
 
     int clickCount = 0;
 
@@ -788,7 +787,7 @@
     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
 
-    if (priv->authenticationDialog)
+    if (priv->dialog)
         return GDK_EVENT_STOP;
 
     webkitWebViewBaseHandleMouseEvent(webViewBase, reinterpret_cast<GdkEvent*>(event));
@@ -801,7 +800,7 @@
     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
 
-    if (priv->authenticationDialog)
+    if (priv->dialog)
         return GDK_EVENT_STOP;
 
     webkitWebViewBaseHandleMouseEvent(webViewBase, reinterpret_cast<GdkEvent*>(event));
@@ -812,7 +811,7 @@
 static void webkitWebViewBaseHandleWheelEvent(WebKitWebViewBase* webViewBase, GdkEvent* event, std::optional<WebWheelEvent::Phase> phase = std::nullopt, std::optional<WebWheelEvent::Phase> momentum = std::nullopt)
 {
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
-    ASSERT(!priv->authenticationDialog);
+    ASSERT(!priv->dialog);
     if (phase)
         priv->pageProxy->handleWheelEvent(NativeWebWheelEvent(event, phase.value(), momentum.value_or(WebWheelEvent::Phase::PhaseNone)));
     else
@@ -827,7 +826,7 @@
     if (std::exchange(priv->shouldForwardNextWheelEvent, false))
         return GDK_EVENT_PROPAGATE;
 
-    if (priv->authenticationDialog)
+    if (priv->dialog)
         return GDK_EVENT_PROPAGATE;
 
     // Shift+Wheel scrolls in the perpendicular direction.
@@ -875,7 +874,7 @@
     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
 
-    if (priv->authenticationDialog) {
+    if (priv->dialog) {
         auto* widgetClass = GTK_WIDGET_CLASS(webkit_web_view_base_parent_class);
         return widgetClass->motion_notify_event ? widgetClass->motion_notify_event(widget, event) : GDK_EVENT_PROPAGATE;
     }
@@ -890,7 +889,7 @@
     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
 
-    if (priv->authenticationDialog)
+    if (priv->dialog)
         return GDK_EVENT_PROPAGATE;
 
 #if ENABLE(DEVELOPER_MODE)
@@ -985,7 +984,7 @@
     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
 
-    if (priv->authenticationDialog)
+    if (priv->dialog)
         return GDK_EVENT_STOP;
 
     GdkEvent* touchEvent = reinterpret_cast<GdkEvent*>(event);
@@ -1258,12 +1257,12 @@
 
 static gboolean webkitWebViewBaseFocus(GtkWidget* widget, GtkDirectionType direction)
 {
-    // If the authentication dialog is active, we need to forward focus events there. This
+    // If a dialog is active, we need to forward focus events there. This
     // ensures that you can tab between elements in the box.
     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
-    if (priv->authenticationDialog) {
+    if (priv->dialog) {
         gboolean returnValue;
-        g_signal_emit_by_name(priv->authenticationDialog, "focus", direction, &returnValue);
+        g_signal_emit_by_name(priv->dialog, "focus", direction, &returnValue);
         return returnValue;
     }
 
@@ -1273,8 +1272,8 @@
 static void webkitWebViewBaseDestroy(GtkWidget* widget)
 {
     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
-    if (priv->authenticationDialog)
-        gtk_widget_destroy(priv->authenticationDialog);
+    if (priv->dialog)
+        gtk_widget_destroy(priv->dialog);
 
     GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->destroy(widget);
 }

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h (236003 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h	2018-09-14 11:01:06 UTC (rev 236004)
@@ -61,8 +61,7 @@
 bool webkitWebViewBaseIsVisible(WebKitWebViewBase*);
 bool webkitWebViewBaseIsInWindow(WebKitWebViewBase*);
 
-void webkitWebViewBaseAddAuthenticationDialog(WebKitWebViewBase*, GtkWidget* authDialog);
-void webkitWebViewBaseCancelAuthenticationDialog(WebKitWebViewBase*);
+void webkitWebViewBaseAddDialog(WebKitWebViewBase*, GtkWidget*);
 void webkitWebViewBaseAddWebInspector(WebKitWebViewBase*, GtkWidget* inspector, WebKit::AttachmentSide);
 void webkitWebViewBaseResetClickCounter(WebKitWebViewBase*);
 void webkitWebViewBaseEnterAcceleratedCompositingMode(WebKitWebViewBase*, const WebKit::LayerTreeContext&);

Added: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewDialog.cpp (0 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewDialog.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewDialog.cpp	2018-09-14 11:01:06 UTC (rev 236004)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitWebViewDialog.h"
+
+#include <wtf/glib/GRefPtr.h>
+#include <wtf/glib/WTFGType.h>
+
+struct _WebKitWebViewDialogPrivate {
+#if !GTK_CHECK_VERSION(3, 20, 0)
+    GRefPtr<GtkStyleContext> styleContext;
+#endif
+};
+
+WEBKIT_DEFINE_ABSTRACT_TYPE(WebKitWebViewDialog, webkit_web_view_dialog, GTK_TYPE_EVENT_BOX)
+
+static gboolean webkitWebViewDialogDraw(GtkWidget* widget, cairo_t* cr)
+{
+    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+    cairo_set_source_rgba(cr, 0, 0, 0, 0.5);
+    cairo_paint(cr);
+
+    if (GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget))) {
+        GtkAllocation allocation;
+        gtk_widget_get_allocation(child, &allocation);
+
+#if GTK_CHECK_VERSION(3, 20, 0)
+        GtkStyleContext* styleContext = gtk_widget_get_style_context(widget);
+#else
+        GtkStyleContext* styleContext = WEBKIT_WEB_VIEW_DIALOG(widget)->priv->styleContext.get();
+#endif
+        gtk_style_context_save(styleContext);
+        gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BACKGROUND);
+        gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_TITLEBAR);
+        gtk_render_background(styleContext, cr, allocation.x, allocation.y, allocation.width, allocation.height);
+        gtk_style_context_restore(styleContext);
+    }
+
+    GTK_WIDGET_CLASS(webkit_web_view_dialog_parent_class)->draw(widget, cr);
+
+    return FALSE;
+}
+
+static void webkitWebViewDialogSizeAllocate(GtkWidget* widget, GtkAllocation* allocation)
+{
+    GTK_WIDGET_CLASS(webkit_web_view_dialog_parent_class)->size_allocate(widget, allocation);
+
+    GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget));
+    if (!child)
+        return;
+
+    GtkRequisition naturalSize;
+    gtk_widget_get_preferred_size(child, 0, &naturalSize);
+
+    GtkAllocation childAllocation;
+    gtk_widget_get_allocation(child, &childAllocation);
+
+    childAllocation.x += (allocation->width - naturalSize.width) / 2;
+    childAllocation.y += (allocation->height - naturalSize.height) / 2;
+    childAllocation.width = naturalSize.width;
+    childAllocation.height = naturalSize.height;
+    gtk_widget_size_allocate(child, &childAllocation);
+}
+
+static void webkitWebViewDialogConstructed(GObject* object)
+{
+    G_OBJECT_CLASS(webkit_web_view_dialog_parent_class)->constructed(object);
+
+#if GTK_CHECK_VERSION(3, 20, 0)
+    gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(object)), GTK_STYLE_CLASS_CSD);
+#else
+    WebKitWebViewDialogPrivate* priv = WEBKIT_WEB_VIEW_DIALOG(object)->priv;
+    priv->styleContext = adoptGRef(gtk_style_context_new());
+    GtkWidgetPath* path = gtk_widget_path_new();
+    gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
+    gtk_style_context_add_class(priv->styleContext.get(), GTK_STYLE_CLASS_BACKGROUND);
+    gtk_style_context_add_class(priv->styleContext.get(), GTK_STYLE_CLASS_TITLEBAR);
+    gtk_style_context_add_class(priv->styleContext.get(), GTK_STYLE_CLASS_CSD);
+    gtk_style_context_set_path(priv->styleContext.get(), path);
+    gtk_widget_path_free(path);
+#endif
+}
+
+static void webkit_web_view_dialog_class_init(WebKitWebViewDialogClass* klass)
+{
+    GObjectClass* objectClass = G_OBJECT_CLASS(klass);
+    objectClass->constructed = webkitWebViewDialogConstructed;
+
+    GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(klass);
+    widgetClass->draw = webkitWebViewDialogDraw;
+    widgetClass->size_allocate = webkitWebViewDialogSizeAllocate;
+
+#if GTK_CHECK_VERSION(3, 20, 0)
+    gtk_widget_class_set_css_name(widgetClass, "messagedialog");
+#endif
+}

Added: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewDialog.h (0 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewDialog.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewDialog.h	2018-09-14 11:01:06 UTC (rev 236004)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_WEB_VIEW_DIALOG            (webkit_web_view_dialog_get_type())
+#define WEBKIT_WEB_VIEW_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW_DIALOG, WebKitWebViewDialog))
+#define WEBKIT_IS_WEB_VIEW_DIALOG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW_DIALOG))
+#define WEBKIT_WEB_VIEW_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEB_VIEW_DIALOG, WebKitWebViewDialogClass))
+#define WEBKIT_IS_WEB_VIEW_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEB_VIEW_DIALOG))
+#define WEBKIT_WEB_VIEW_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEB_VIEW_DIALOG, WebKitWebViewDialogClass))
+
+typedef struct _WebKitWebViewDialog        WebKitWebViewDialog;
+typedef struct _WebKitWebViewDialogClass   WebKitWebViewDialogClass;
+typedef struct _WebKitWebViewDialogPrivate WebKitWebViewDialogPrivate;
+
+struct _WebKitWebViewDialog {
+    GtkEventBox parent;
+
+    WebKitWebViewDialogPrivate* priv;
+};
+
+struct _WebKitWebViewDialogClass {
+    GtkEventBoxClass parentClass;
+};
+
+GType webkit_web_view_dialog_get_type();
+
+G_END_DECLS

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp (236003 => 236004)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp	2018-09-14 07:20:01 UTC (rev 236003)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp	2018-09-14 11:01:06 UTC (rev 236004)
@@ -21,7 +21,7 @@
 #include "WebKitWebView.h"
 
 #include "WebKitAuthenticationDialog.h"
-#include "WebKitScriptDialogPrivate.h"
+#include "WebKitScriptDialogImpl.h"
 #include "WebKitWebViewBasePrivate.h"
 #include "WebKitWebViewPrivate.h"
 #include <WebCore/GtkUtilities.h>
@@ -33,7 +33,7 @@
 gboolean webkitWebViewAuthenticate(WebKitWebView* webView, WebKitAuthenticationRequest* request)
 {
     CredentialStorageMode credentialStorageMode = webkit_authentication_request_can_save_credentials(request) ? AllowPersistentStorage : DisallowPersistentStorage;
-    webkitWebViewBaseAddAuthenticationDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitAuthenticationDialogNew(request, credentialStorageMode));
+    webkitWebViewBaseAddDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitAuthenticationDialogNew(request, credentialStorageMode));
 
     return TRUE;
 }
@@ -40,7 +40,9 @@
 
 gboolean webkitWebViewScriptDialog(WebKitWebView* webView, WebKitScriptDialog* scriptDialog)
 {
-    webkitScriptDialogRun(scriptDialog, webView);
+    GUniquePtr<char> title(g_strdup_printf("_javascript_ - %s", webkitWebViewGetPage(webView).pageLoadState().url().utf8().data()));
+    webkitWebViewBaseAddDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitScriptDialogImplNew(scriptDialog, title.get()));
+
     return TRUE;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to