Title: [107947] trunk/Source/WebKit2
Revision
107947
Author
carlo...@webkit.org
Date
2012-02-16 09:10:58 -0800 (Thu, 16 Feb 2012)

Log Message

[GTK] Add WebKitPrintOperation to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=76448

Reviewed by Martin Robinson.

* GNUmakefile.am: Add new files to compilation.
* UIProcess/API/gtk/WebKitDefines.h:
* UIProcess/API/gtk/WebKitPrintOperation.cpp: Added.
(webViewDestroyed): Delete the print operation when the view
widget associated is destroyed.
(webkitPrintOperationConstructed): Connect to destroy signal of
associated web view.
(webkitPrintOperationGetProperty):
(webkitPrintOperationSetProperty):
(webkit_print_operation_init):
(webkit_print_operation_class_init):
(webkitPrintOperationRunDialogUnix): Use GtkPrintUnixDialog to
show the printing dialog in UNIX platforms.
(webkitPrintOperationRunDialogWin32): Empty, not implemented yet.
(drawPagesForPrintingCompleted): Callback called when printing
operation has finished in the web process.
(webkitPrintOperationRunDialogForFrame): Run the printing dialog
and start printing the given frame.
(webkit_print_operation_new): Create a new print operation for the
given web view.
(webkit_print_operation_get_print_settings):
(webkit_print_operation_set_print_settings):
(webkit_print_operation_get_page_setup):
(webkit_print_operation_set_page_setup):
(webkit_print_operation_run_dialog): Run the print dialog to print
the web view main frame.
* UIProcess/API/gtk/WebKitPrintOperation.h: Added.
* UIProcess/API/gtk/WebKitPrintOperationPrivate.h: Added.
* UIProcess/API/gtk/WebKitUIClient.cpp:
(printFrame): Call webkitWebViewPrintFrame.
(attachUIClientToView): Add implementation for
printFrame callback.
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_class_init): Add WebKitWebView::print-requested
signal.
(webkitWebViewPrintFrame): Emit print-requested and show the print
dialog to print the frame when not signal is not handled by user.
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/WebKitWebViewPrivate.h:
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for
WebKitPrintOperation.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
* UIProcess/API/gtk/tests/GNUmakefile.am:
* UIProcess/API/gtk/tests/TestPrinting.cpp: Added.
(testPrintOperationPrintSettings):
(webViewPrintRequestedCallback):
(testWebViewPrintRequested):
(beforeAll):
(afterAll):
* UIProcess/API/gtk/webkit2.h: Include WebKitPrintOperation.h.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (107946 => 107947)


--- trunk/Source/WebKit2/ChangeLog	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-16 17:10:58 UTC (rev 107947)
@@ -1,3 +1,61 @@
+2012-02-16  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitPrintOperation to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=76448
+
+        Reviewed by Martin Robinson.
+
+        * GNUmakefile.am: Add new files to compilation.
+        * UIProcess/API/gtk/WebKitDefines.h:
+        * UIProcess/API/gtk/WebKitPrintOperation.cpp: Added.
+        (webViewDestroyed): Delete the print operation when the view
+        widget associated is destroyed.
+        (webkitPrintOperationConstructed): Connect to destroy signal of
+        associated web view.
+        (webkitPrintOperationGetProperty):
+        (webkitPrintOperationSetProperty):
+        (webkit_print_operation_init):
+        (webkit_print_operation_class_init):
+        (webkitPrintOperationRunDialogUnix): Use GtkPrintUnixDialog to
+        show the printing dialog in UNIX platforms.
+        (webkitPrintOperationRunDialogWin32): Empty, not implemented yet.
+        (drawPagesForPrintingCompleted): Callback called when printing
+        operation has finished in the web process.
+        (webkitPrintOperationRunDialogForFrame): Run the printing dialog
+        and start printing the given frame.
+        (webkit_print_operation_new): Create a new print operation for the
+        given web view.
+        (webkit_print_operation_get_print_settings):
+        (webkit_print_operation_set_print_settings):
+        (webkit_print_operation_get_page_setup):
+        (webkit_print_operation_set_page_setup):
+        (webkit_print_operation_run_dialog): Run the print dialog to print
+        the web view main frame.
+        * UIProcess/API/gtk/WebKitPrintOperation.h: Added.
+        * UIProcess/API/gtk/WebKitPrintOperationPrivate.h: Added.
+        * UIProcess/API/gtk/WebKitUIClient.cpp:
+        (printFrame): Call webkitWebViewPrintFrame.
+        (attachUIClientToView): Add implementation for
+        printFrame callback.
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkit_web_view_class_init): Add WebKitWebView::print-requested
+        signal.
+        (webkitWebViewPrintFrame): Emit print-requested and show the print
+        dialog to print the frame when not signal is not handled by user.
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/WebKitWebViewPrivate.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for
+        WebKitPrintOperation.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
+        * UIProcess/API/gtk/tests/GNUmakefile.am:
+        * UIProcess/API/gtk/tests/TestPrinting.cpp: Added.
+        (testPrintOperationPrintSettings):
+        (webViewPrintRequestedCallback):
+        (testWebViewPrintRequested):
+        (beforeAll):
+        (afterAll):
+        * UIProcess/API/gtk/webkit2.h: Include WebKitPrintOperation.h.
+
 2012-02-16  Simon Hausmann  <simon.hausm...@nokia.com>
 
         [Gtk][Efl][Qt] Move OpenGLShims out of cairo/ subdirectory

Modified: trunk/Source/WebKit2/GNUmakefile.am (107946 => 107947)


--- trunk/Source/WebKit2/GNUmakefile.am	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/GNUmakefile.am	2012-02-16 17:10:58 UTC (rev 107947)
@@ -91,6 +91,7 @@
 	$(WebKit2)/UIProcess/API/gtk/WebKitHitTestResult.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitPolicyDecision.h \
+	$(WebKit2)/UIProcess/API/gtk/WebKitPrintOperation.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitResponsePolicyDecision.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitSettings.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitURIRequest.h \
@@ -553,6 +554,9 @@
 	Source/WebKit2/UIProcess/API/gtk/WebKitPolicyDecisionPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp \
+	Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperationPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp \

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h	2012-02-16 17:10:58 UTC (rev 107947)
@@ -32,6 +32,8 @@
 
 #include <glib.h>
 
+typedef struct _WebKitPrintOperation WebKitPrintOperation;
+
 #ifdef G_OS_WIN32
 #    ifdef BUILDING_WEBKIT
 #        define WEBKIT_API __declspec(dllexport)

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp (0 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp	2012-02-16 17:10:58 UTC (rev 107947)
@@ -0,0 +1,379 @@
+/*
+ * Copyright (C) 2012 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 "WebKitPrintOperation.h"
+
+#include "PrintInfo.h"
+#include "WebKitPrintOperationPrivate.h"
+#include "WebKitPrivate.h"
+#include "WebKitWebViewBasePrivate.h"
+#include "WebPageProxy.h"
+#include <WebCore/GtkUtilities.h>
+#include <WebCore/NotImplemented.h>
+#include <glib/gi18n-lib.h>
+#include <wtf/gobject/GRefPtr.h>
+
+#ifdef HAVE_GTK_UNIX_PRINTING
+#include <gtk/gtkunixprint.h>
+#endif
+
+using namespace WebKit;
+
+enum {
+    PROP_0,
+
+    PROP_WEB_VIEW,
+    PROP_PRINT_SETTINGS,
+    PROP_PAGE_SETUP
+};
+
+enum {
+    DONE,
+
+    LAST_SIGNAL
+};
+
+struct _WebKitPrintOperationPrivate {
+    WebKitWebView* webView;
+    gulong webViewDestroyedId;
+
+    GRefPtr<GtkPrintSettings> printSettings;
+    GRefPtr<GtkPageSetup> pageSetup;
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+G_DEFINE_TYPE(WebKitPrintOperation, webkit_print_operation, G_TYPE_OBJECT)
+
+static void webkitPrintOperationFinalize(GObject* object)
+{
+    WebKitPrintOperationPrivate* priv = WEBKIT_PRINT_OPERATION(object)->priv;
+    g_signal_handler_disconnect(priv->webView, priv->webViewDestroyedId);
+
+    priv->~WebKitPrintOperationPrivate();
+    G_OBJECT_CLASS(webkit_print_operation_parent_class)->finalize(object);
+}
+
+static void webViewDestroyed(GtkWidget* webView, GObject* printOperation)
+{
+    g_object_unref(printOperation);
+}
+
+static void webkitPrintOperationConstructed(GObject* object)
+{
+    WebKitPrintOperation* printOperation = WEBKIT_PRINT_OPERATION(object);
+    WebKitPrintOperationPrivate* priv = printOperation->priv;
+
+    if (G_OBJECT_CLASS(webkit_print_operation_parent_class)->constructed)
+        G_OBJECT_CLASS(webkit_print_operation_parent_class)->constructed(object);
+
+    priv->webViewDestroyedId = g_signal_connect(priv->webView, "destroy", G_CALLBACK(webViewDestroyed), printOperation);
+}
+
+static void webkitPrintOperationGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
+{
+    WebKitPrintOperation* printOperation = WEBKIT_PRINT_OPERATION(object);
+
+    switch (propId) {
+    case PROP_WEB_VIEW:
+        g_value_take_object(value, printOperation->priv->webView);
+        break;
+    case PROP_PRINT_SETTINGS:
+        g_value_set_object(value, printOperation->priv->printSettings.get());
+        break;
+    case PROP_PAGE_SETUP:
+        g_value_set_object(value, printOperation->priv->pageSetup.get());
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+    }
+}
+
+static void webkitPrintOperationSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
+{
+    WebKitPrintOperation* printOperation = WEBKIT_PRINT_OPERATION(object);
+
+    switch (propId) {
+    case PROP_WEB_VIEW:
+        printOperation->priv->webView = WEBKIT_WEB_VIEW(g_value_get_object(value));
+        break;
+    case PROP_PRINT_SETTINGS:
+        webkit_print_operation_set_print_settings(printOperation, GTK_PRINT_SETTINGS(g_value_get_object(value)));
+        break;
+    case PROP_PAGE_SETUP:
+        webkit_print_operation_set_page_setup(printOperation, GTK_PAGE_SETUP(g_value_get_object(value)));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+    }
+}
+
+static void webkit_print_operation_init(WebKitPrintOperation* printOperation)
+{
+    WebKitPrintOperationPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(printOperation, WEBKIT_TYPE_PRINT_OPERATION, WebKitPrintOperationPrivate);
+    printOperation->priv = priv;
+    new (priv) WebKitPrintOperationPrivate();
+}
+
+static void webkit_print_operation_class_init(WebKitPrintOperationClass* printOperationClass)
+{
+    GObjectClass* gObjectClass = G_OBJECT_CLASS(printOperationClass);
+    gObjectClass->finalize = webkitPrintOperationFinalize;
+    gObjectClass->constructed = webkitPrintOperationConstructed;
+    gObjectClass->get_property = webkitPrintOperationGetProperty;
+    gObjectClass->set_property = webkitPrintOperationSetProperty;
+
+    /**
+     * WebKitPrintOperation:web-view:
+     *
+     * The #WebKitWebView that will be printed.
+     */
+    g_object_class_install_property(gObjectClass,
+                                    PROP_WEB_VIEW,
+                                    g_param_spec_object("web-view",
+                                                        _("Web View"),
+                                                        _("The web view that will be printed"),
+                                                        WEBKIT_TYPE_WEB_VIEW,
+                                                        static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
+     * WebKitPrintOperation:print-settings:
+     *
+     * The initial #GtkPrintSettings for the print operation.
+     */
+    g_object_class_install_property(gObjectClass,
+                                    PROP_PRINT_SETTINGS,
+                                    g_param_spec_object("print-settings",
+                                                        _("Print Settings"),
+                                                        _("The initial print settings for the print operation"),
+                                                        GTK_TYPE_PRINT_SETTINGS,
+                                                        WEBKIT_PARAM_READWRITE));
+    /**
+     * WebKitPrintOperation:page-setup:
+     *
+     * The initial #GtkPageSetup for the print operation.
+     */
+    g_object_class_install_property(gObjectClass,
+                                     PROP_PAGE_SETUP,
+                                     g_param_spec_object("page-setup",
+                                                         _("Page Setup"),
+                                                         _("The initial page setup for the print operation"),
+                                                         GTK_TYPE_PAGE_SETUP,
+                                                         WEBKIT_PARAM_READWRITE));
+
+    /**
+     * WebKitPrintOperation::done:
+     * @print_operation: the #WebKitPrintOperation on which the signal was emitted
+     *
+     * Emitted when the print operation has finished doing everything
+     * required for printing.
+     */
+    signals[DONE] =
+        g_signal_new("done",
+                     G_TYPE_FROM_CLASS(gObjectClass),
+                     G_SIGNAL_RUN_LAST,
+                     0, 0, 0,
+                     g_cclosure_marshal_VOID__VOID,
+                     G_TYPE_NONE, 0);
+
+    g_type_class_add_private(printOperationClass, sizeof(WebKitPrintOperationPrivate));
+}
+
+#ifdef HAVE_GTK_UNIX_PRINTING
+static bool webkitPrintOperationRunDialogUnix(WebKitPrintOperation* printOperation, GtkWindow* parent)
+{
+    GtkPrintUnixDialog* printDialog = GTK_PRINT_UNIX_DIALOG(gtk_print_unix_dialog_new(0, parent));
+    gtk_print_unix_dialog_set_manual_capabilities(printDialog, static_cast<GtkPrintCapabilities>(0));
+
+    WebKitPrintOperationPrivate* priv = printOperation->priv;
+    if (priv->printSettings)
+        gtk_print_unix_dialog_set_settings(printDialog, priv->printSettings.get());
+
+    if (priv->pageSetup)
+        gtk_print_unix_dialog_set_page_setup(printDialog, priv->pageSetup.get());
+
+    gtk_print_unix_dialog_set_embed_page_setup(printDialog, TRUE);
+
+    bool returnValue = false;
+    if (gtk_dialog_run(GTK_DIALOG(printDialog)) == GTK_RESPONSE_OK) {
+        priv->printSettings = adoptGRef(gtk_print_unix_dialog_get_settings(printDialog));
+        priv->pageSetup = gtk_print_unix_dialog_get_page_setup(printDialog);
+        returnValue = true;
+    }
+
+    gtk_widget_destroy(GTK_WIDGET(printDialog));
+
+    return returnValue;
+}
+#endif // HAVE_GTK_UNIX_PRINTING
+
+#ifdef G_OS_WIN32
+static bool webkitPrintOperationRunDialogWin32(WebKitPrintOperation*, GtkWindow*)
+{
+    notImplemented();
+    return false;
+}
+#endif
+
+static void drawPagesForPrintingCompleted(WKErrorRef, void* context)
+{
+    WebKitPrintOperation* printOperation = WEBKIT_PRINT_OPERATION(context);
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView));
+    page->endPrinting();
+    g_signal_emit(printOperation, signals[DONE], 0, NULL);
+}
+
+void webkitPrintOperationRunDialogForFrame(WebKitPrintOperation* printOperation, GtkWindow* parent, WebFrameProxy* webFrame)
+{
+    WebKitPrintOperationPrivate* priv = printOperation->priv;
+    if (!parent) {
+        GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(priv->webView));
+        if (widgetIsOnscreenToplevelWindow(toplevel))
+            parent = GTK_WINDOW(toplevel);
+    }
+#ifdef HAVE_GTK_UNIX_PRINTING
+    bool shouldPrint = webkitPrintOperationRunDialogUnix(printOperation, parent);
+#endif
+#ifdef G_OS_WIN32
+    bool shouldPrint = webkitPrintOperationRunDialogWin32(printOperation, parent);
+#endif
+
+    if (!shouldPrint) {
+        g_signal_emit(printOperation, signals[DONE], 0, NULL);
+        return;
+    }
+
+    PrintInfo printInfo(priv->printSettings.get(), priv->pageSetup.get());
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(priv->webView));
+    page->drawPagesForPrinting(webFrame, printInfo, VoidCallback::create(printOperation, &drawPagesForPrintingCompleted));
+}
+
+/**
+ * webkit_print_operation_new:
+ * @web_view: a #WebKitWebView
+ *
+ * Create a new #WebKitPrintOperation to print @web_view contents.
+ *
+ * Returns: (transfer full): a new #WebKitPrintOperation.
+ */
+WebKitPrintOperation* webkit_print_operation_new(WebKitWebView* webView)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
+
+    return WEBKIT_PRINT_OPERATION(g_object_new(WEBKIT_TYPE_PRINT_OPERATION, "web-view", webView, NULL));
+}
+
+/**
+ * webkit_print_operation_get_print_settings:
+ * @print_operation: a #WebKitPrintOperation
+ *
+ * Return the current print settings of @print_operation. It returns %NULL until
+ * either webkit_print_operation_set_print_settings() or webkit_print_operation_run_dialog()
+ * have been called.
+ *
+ * Returns: (transfer none): the current #GtkPrintSettings of @print_operation.
+ */
+GtkPrintSettings* webkit_print_operation_get_print_settings(WebKitPrintOperation* printOperation)
+{
+    g_return_val_if_fail(WEBKIT_IS_PRINT_OPERATION(printOperation), 0);
+
+    return printOperation->priv->printSettings.get();
+}
+
+/**
+ * webkit_print_operation_set_print_settings:
+ * @print_operation: a #WebKitPrintOperation
+ * @print_settings: a #GtkPrintSettings to set
+ *
+ * Set the current print settings of @print_operation. Current print settings are used for
+ * the initial values of the print dialog when webkit_print_operation_run_dialog() is called.
+ */
+void webkit_print_operation_set_print_settings(WebKitPrintOperation* printOperation, GtkPrintSettings* printSettings)
+{
+    g_return_if_fail(WEBKIT_IS_PRINT_OPERATION(printOperation));
+    g_return_if_fail(GTK_IS_PRINT_SETTINGS(printSettings));
+
+    if (printOperation->priv->printSettings.get() == printSettings)
+        return;
+
+    printOperation->priv->printSettings = printSettings;
+    g_object_notify(G_OBJECT(printOperation), "print-settings");
+}
+
+/**
+ * webkit_print_operation_get_page_setup:
+ * @print_operation: a #WebKitPrintOperation
+ *
+ * Return the current page setup of @print_operation. It returns %NULL until
+ * either webkit_print_operation_set_print_settings() or webkit_print_operation_run_dialog()
+ * have been called.
+ *
+ * Returns: (transfer none): the current #GtkPageSetup of @print_operation.
+ */
+GtkPageSetup* webkit_print_operation_get_page_setup(WebKitPrintOperation* printOperation)
+{
+    g_return_val_if_fail(WEBKIT_IS_PRINT_OPERATION(printOperation), 0);
+
+    return printOperation->priv->pageSetup.get();
+}
+
+/**
+ * webkit_print_operation_set_page_setup:
+ * @print_operation: a #WebKitPrintOperation
+ * @page_setup: a #GtkPageSetup to set
+ *
+ * Set the current page setup of @print_operation. Current page setup is used for the
+ * initial values of the print dialog when webkit_print_operation_run_dialog() is called.
+ */
+void webkit_print_operation_set_page_setup(WebKitPrintOperation* printOperation, GtkPageSetup* pageSetup)
+{
+    g_return_if_fail(WEBKIT_IS_PRINT_OPERATION(printOperation));
+    g_return_if_fail(GTK_IS_PAGE_SETUP(pageSetup));
+
+    if (printOperation->priv->pageSetup.get() == pageSetup)
+        return;
+
+    printOperation->priv->pageSetup = pageSetup;
+    g_object_notify(G_OBJECT(printOperation), "page-setup");
+}
+
+/**
+ * webkit_print_operation_run_dialog:
+ * @print_operation: a #WebKitPrintOperation
+ * @parent: (allow-none): transient parent of the print dialog
+ *
+ * Run the print dialog using and start printing using the options selected by
+ * the user. This method returns when the print operation is closed.
+ * The WebKitPrintOperation::done signal is emitted when the printing
+ * operation finishes.
+ * Current print settings and page setup of @print_operation are updated with
+ * options selected by the user when Print button is pressed in print dialog.
+ * You can get the updated print settings and page setup by calling
+ * webkit_print_operation_get_print_settings() and webkit_print_operation_get_page_setup()
+ * after this method.
+ */
+void webkit_print_operation_run_dialog(WebKitPrintOperation* printOperation, GtkWindow* parent)
+{
+    g_return_if_fail(WEBKIT_IS_PRINT_OPERATION(printOperation));
+
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView));
+    webkitPrintOperationRunDialogForFrame(printOperation, parent, page->mainFrame());
+}
+

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h (0 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h	2012-02-16 17:10:58 UTC (rev 107947)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitPrintOperation_h
+#define WebKitPrintOperation_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitWebView.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_PRINT_OPERATION            (webkit_print_operation_get_type())
+#define WEBKIT_PRINT_OPERATION(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_PRINT_OPERATION, WebKitPrintOperation))
+#define WEBKIT_IS_PRINT_OPERATION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_PRINT_OPERATION))
+#define WEBKIT_PRINT_OPERATION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_PRINT_OPERATION, WebKitPrintOperationClass))
+#define WEBKIT_IS_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_PRINT_OPERATION))
+#define WEBKIT_PRINT_OPERATION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_PRINT_OPERATION, WebKitPrintOperationClass))
+
+typedef struct _WebKitPrintOperationClass   WebKitPrintOperationClass;
+typedef struct _WebKitPrintOperationPrivate WebKitPrintOperationPrivate;
+
+struct _WebKitPrintOperation {
+    GObject parent;
+
+    WebKitPrintOperationPrivate *priv;
+};
+
+struct _WebKitPrintOperationClass {
+    GObjectClass parent_class;
+};
+
+WEBKIT_API GType
+webkit_print_operation_get_type           (void);
+
+WEBKIT_API WebKitPrintOperation *
+webkit_print_operation_new                (WebKitWebView        *web_view);
+
+WEBKIT_API GtkPrintSettings *
+webkit_print_operation_get_print_settings (WebKitPrintOperation *print_operation);
+
+WEBKIT_API void
+webkit_print_operation_set_print_settings (WebKitPrintOperation *print_operation,
+                                           GtkPrintSettings     *print_settings);
+
+WEBKIT_API GtkPageSetup *
+webkit_print_operation_get_page_setup     (WebKitPrintOperation *print_operation);
+
+WEBKIT_API void
+webkit_print_operation_set_page_setup     (WebKitPrintOperation *print_operation,
+                                           GtkPageSetup         *page_setup);
+
+WEBKIT_API void
+webkit_print_operation_run_dialog         (WebKitPrintOperation *print_operation,
+                                           GtkWindow            *parent);
+
+G_END_DECLS
+
+#endif

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperationPrivate.h (0 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperationPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperationPrivate.h	2012-02-16 17:10:58 UTC (rev 107947)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#ifndef WebKitPrintOperationPrivate_h
+#define WebKitPrintOperationPrivate_h
+
+#include "WebFrameProxy.h"
+#include "WebKitPrintOperation.h"
+
+void webkitPrintOperationRunDialogForFrame(WebKitPrintOperation*, GtkWindow* parent, WebKit::WebFrameProxy*);
+
+#endif // WebKitPrintOperationPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp	2012-02-16 17:10:58 UTC (rev 107947)
@@ -131,6 +131,11 @@
     webkitWebViewMouseTargetChanged(WEBKIT_WEB_VIEW(clientInfo), hitTestResult, wkEventModifiersToGdkModifiers(modifiers));
 }
 
+static void printFrame(WKPageRef page, WKFrameRef frame, const void*)
+{
+    webkitWebViewPrintFrame(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()), frame);
+}
+
 void attachUIClientToView(WebKitWebView* webView)
 {
     WKPageUIClient wkUIClient = {
@@ -170,7 +175,7 @@
         0, // footerHeight
         0, // drawHeader
         0, // drawFooter
-        0, // printFrame
+        printFrame,
         0, // runModal
         0, // didCompleteRubberBandForMainFrame
         0, // saveDataToFileInDownloadsFolder

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2012-02-16 17:10:58 UTC (rev 107947)
@@ -28,6 +28,7 @@
 #include "WebKitLoaderClient.h"
 #include "WebKitMarshal.h"
 #include "WebKitPolicyClient.h"
+#include "WebKitPrintOperationPrivate.h"
 #include "WebKitPrivate.h"
 #include "WebKitSettingsPrivate.h"
 #include "WebKitUIClient.h"
@@ -62,6 +63,8 @@
 
     MOUSE_TARGET_CHANGED,
 
+    PRINT_REQUESTED,
+
     LAST_SIGNAL
 };
 
@@ -647,6 +650,33 @@
                       G_TYPE_NONE, 2,
                       WEBKIT_TYPE_HIT_TEST_RESULT,
                       G_TYPE_UINT);
+    /**
+     * WebKitWebView::print-requested:
+     * @web_view: the #WebKitWebView on which the signal is emitted
+     * @print_operation: the #WebKitPrintOperation that will handle the print request
+     *
+     * Emitted when printing is requested on @web_view, usually by a _javascript_ call,
+     * before the print dialog is shown. This signal can be used to set the initial
+     * print settings and page setup of @print_operation to be used as default values in
+     * the print dialog. You can call webkit_print_operation_set_print_settings() and
+     * webkit_print_operation_set_page_setup() and then return %FALSE to propagate the
+     * event so that the print dialog is shown.
+     *
+     * You can connect to this signal and return %TRUE to cancel the print operation
+     * or implement your own print dialog.
+     *
+     * Returns: %TRUE to stop other handlers from being invoked for the event.
+     *    %FALSE to propagate the event further.
+     */
+    signals[PRINT_REQUESTED] =
+        g_signal_new("print-requested",
+                     G_TYPE_FROM_CLASS(webViewClass),
+                     G_SIGNAL_RUN_LAST,
+                     G_STRUCT_OFFSET(WebKitWebViewClass, print_requested),
+                     g_signal_accumulator_true_handled, 0,
+                     webkit_marshal_BOOLEAN__OBJECT,
+                     G_TYPE_BOOLEAN, 1,
+                     WEBKIT_TYPE_PRINT_OPERATION);
 }
 
 void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent)
@@ -771,6 +801,18 @@
     g_signal_emit(webView, signals[MOUSE_TARGET_CHANGED], 0, priv->mouseTargetHitTestResult.get(), modifiers);
 }
 
+void webkitWebViewPrintFrame(WebKitWebView* webView, WKFrameRef wkFrame)
+{
+    GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(webkit_print_operation_new(webView));
+    gboolean returnValue;
+    g_signal_emit(webView, signals[PRINT_REQUESTED], 0, printOperation.get(), &returnValue);
+    if (returnValue)
+        return;
+
+    g_signal_connect(printOperation.get(), "done", G_CALLBACK(g_object_unref), 0);
+    webkitPrintOperationRunDialogForFrame(printOperation.leakRef(), 0, toImpl(wkFrame));
+}
+
 /**
  * webkit_web_view_new:
  *

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2012-02-16 17:10:58 UTC (rev 107947)
@@ -31,9 +31,9 @@
 #include <webkit2/WebKitBackForwardList.h>
 #include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitHitTestResult.h>
-#include <webkit2/WebKitWebContext.h>
 #include <webkit2/WebKitSettings.h>
 #include <webkit2/WebKitURIRequest.h>
+#include <webkit2/WebKitWebContext.h>
 #include <webkit2/WebKitWebViewBase.h>
 #include <webkit2/WebKitWindowProperties.h>
 #include <webkit2/WebKitPolicyDecision.h>
@@ -139,10 +139,12 @@
                                          gchar                    **text);
     gboolean   (* decide_policy)        (WebKitWebView             *web_view,
                                          WebKitPolicyDecision      *decision,
-                                         WebKitPolicyDecisionType  type);
-    void       (* mouse_target_changed) (WebKitWebView            *web_view,
-                                         WebKitHitTestResult      *hit_test_result,
-                                         guint                     modifiers);
+                                         WebKitPolicyDecisionType   type);
+    void       (* mouse_target_changed) (WebKitWebView             *web_view,
+                                         WebKitHitTestResult       *hit_test_result,
+                                         guint                      modifiers);
+    gboolean   (* print_requested)      (WebKitWebView             *web_view,
+                                         WebKitPrintOperation      *print_operation);
 
     /* Padding for future expansion */
     void (*_webkit_reserved0) (void);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h	2012-02-16 17:10:58 UTC (rev 107947)
@@ -44,5 +44,6 @@
 WKStringRef webkitWebViewRunJavaScriptPrompt(WebKitWebView*, const CString& message, const CString& defaultText);
 void webkitWebViewMakePolicyDecision(WebKitWebView*, WebKitPolicyDecisionType, WebKitPolicyDecision*);
 void webkitWebViewMouseTargetChanged(WebKitWebView*, WKHitTestResultRef, unsigned modifiers);
+void webkitWebViewPrintFrame(WebKitWebView*, WKFrameRef);
 
 #endif // WebKitWebViewPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2012-02-16 17:10:58 UTC (rev 107947)
@@ -25,6 +25,7 @@
     <xi:include href=""
     <xi:include href=""
     <xi:include href=""
+    <xi:include href=""
     <xi:include href=""
   </chapter>
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-02-16 17:10:58 UTC (rev 107947)
@@ -418,6 +418,30 @@
 </SECTION>
 
 <SECTION>
+<FILE>WebKitPrintOperation</FILE>
+WebKitPrintOperation
+webkit_print_operation_new
+webkit_print_operation_get_print_settings
+webkit_print_operation_set_print_settings
+webkit_print_operation_get_page_setup
+webkit_print_operation_set_page_setup
+webkit_print_operation_run_dialog
+
+<SUBSECTION Standard>
+WebKitPrintOperationClass
+WEBKIT_TYPE_PRINT_OPERATION
+WEBKIT_PRINT_OPERATION
+WEBKIT_IS_PRINT_OPERATION
+WEBKIT_PRINT_OPERATION_CLASS
+WEBKIT_IS_PRINT_OPERATION_CLASS
+WEBKIT_PRINT_OPERATION_GET_CLASS
+
+<SUBSECTION Private>
+WebKitPrintOperationPrivate
+webkit_print_operation_get_type
+</SECTION>
+
+<SECTION>
 <FILE>WebKitError</FILE>
 WEBKIT_NETWORK_ERROR
 WEBKIT_PLUGIN_ERROR

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am	2012-02-16 17:10:58 UTC (rev 107947)
@@ -6,7 +6,8 @@
 	Programs/WebKit2APITests/TestBackForwardList \
 	Programs/WebKit2APITests/TestDownloads \
 	Programs/WebKit2APITests/TestWebKitPolicyClient \
-	Programs/WebKit2APITests/TestWebViewEditor
+	Programs/WebKit2APITests/TestWebViewEditor \
+	Programs/WebKit2APITests/TestPrinting
 
 noinst_PROGRAMS += $(TEST_PROGS)
 
@@ -118,3 +119,9 @@
 Programs_WebKit2APITests_TestWebViewEditor_CPPFLAGS = $(webkit2_tests_cppflags)
 Programs_WebKit2APITests_TestWebViewEditor_LDADD = $(webkit2_tests_ldadd)
 Programs_WebKit2APITests_TestWebViewEditor_LDFLAGS = $(webkit2_tests_ldflags)
+
+Programs_WebKit2APITests_TestPrinting_SOURCES = \
+        Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp
+Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags)
+Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd)
+Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags)

Added: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp (0 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp	2012-02-16 17:10:58 UTC (rev 107947)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 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 "WebViewTest.h"
+#include <wtf/gobject/GRefPtr.h>
+
+static void testPrintOperationPrintSettings(WebViewTest* test, gconstpointer)
+{
+    GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(webkit_print_operation_new(test->m_webView));
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printOperation.get()));
+
+    g_assert(!webkit_print_operation_get_print_settings(printOperation.get()));
+    g_assert(!webkit_print_operation_get_page_setup(printOperation.get()));
+
+    GRefPtr<GtkPrintSettings> printSettings = adoptGRef(gtk_print_settings_new());
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printSettings.get()));
+
+    GRefPtr<GtkPageSetup> pageSetup = adoptGRef(gtk_page_setup_new());
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(pageSetup.get()));
+
+    webkit_print_operation_set_print_settings(printOperation.get(), printSettings.get());
+    webkit_print_operation_set_page_setup(printOperation.get(), pageSetup.get());
+
+    g_assert(webkit_print_operation_get_print_settings(printOperation.get()) == printSettings.get());
+    g_assert(webkit_print_operation_get_page_setup(printOperation.get()) == pageSetup.get());
+}
+
+static gboolean webViewPrintRequestedCallback(WebKitWebView* webView, WebKitPrintOperation* printOperation, WebViewTest* test)
+{
+    g_assert(webView == test->m_webView);
+
+    g_assert(WEBKIT_IS_PRINT_OPERATION(printOperation));
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printOperation));
+
+    g_assert(!webkit_print_operation_get_print_settings(printOperation));
+    g_assert(!webkit_print_operation_get_page_setup(printOperation));
+
+    g_main_loop_quit(test->m_mainLoop);
+
+    return TRUE;
+}
+
+static void testWebViewPrintRequested(WebViewTest* test, gconstpointer)
+{
+    g_signal_connect(test->m_webView, "print-requested", G_CALLBACK(webViewPrintRequestedCallback), test);
+    test->loadHtml("<html><body _onLoad_=\"print();\">WebKitGTK+ printing test</body></html>", 0);
+    g_main_loop_run(test->m_mainLoop);
+}
+
+void beforeAll()
+{
+    WebViewTest::add("WebKitPrintOperation", "printing-settings", testPrintOperationPrintSettings);
+    WebViewTest::add("WebKitWebView", "print-requested", testWebViewPrintRequested);
+}
+
+void afterAll()
+{
+}

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h (107946 => 107947)


--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-02-16 17:09:49 UTC (rev 107946)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-02-16 17:10:58 UTC (rev 107947)
@@ -31,6 +31,7 @@
 #include <webkit2/WebKitEnumTypes.h>
 #include <webkit2/WebKitError.h>
 #include <webkit2/WebKitHitTestResult.h>
+#include <webkit2/WebKitPrintOperation.h>
 #include <webkit2/WebKitSettings.h>
 #include <webkit2/WebKitURIRequest.h>
 #include <webkit2/WebKitURIResponse.h>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to