Changeset 108068 in webkit


Ignore:
Timestamp:
Feb 17, 2012 6:25:58 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add webkit_print_operation_print() to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=76536

Reviewed by Gustavo Noronha Silva.

  • UIProcess/API/gtk/WebKitPrintOperation.cpp:

(webkitPrintOperationPrintPagesForFrame): Helper function to call
WebPageProxy::drawPagesForPrinting using the given
GtkPrintSettings and GtkPageSetup.
(webkitPrintOperationRunDialogForFrame): Use
webkitPrintOperationPrintPagesForFrame().
(webkit_print_operation_print): Print directly using current
GtkPrintSettings and GtkPageSetup without showing the print
dialog.

  • UIProcess/API/gtk/WebKitPrintOperation.h:
  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
  • UIProcess/API/gtk/tests/GNUmakefile.am:
  • UIProcess/API/gtk/tests/TestPrinting.cpp:

(testPrintOperationPrintLoadChanged):
(testPrintOperationPrintDone):
(testPrintOperationPrintPrinter):
(testPrintOperationPrint):
(beforeAll):
(afterAll):

Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r108055 r108068  
     12012-02-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add webkit_print_operation_print() to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=76536
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        * UIProcess/API/gtk/WebKitPrintOperation.cpp:
     9        (webkitPrintOperationPrintPagesForFrame): Helper function to call
     10        WebPageProxy::drawPagesForPrinting using the given
     11        GtkPrintSettings and GtkPageSetup.
     12        (webkitPrintOperationRunDialogForFrame): Use
     13        webkitPrintOperationPrintPagesForFrame().
     14        (webkit_print_operation_print): Print directly using current
     15        GtkPrintSettings and GtkPageSetup without showing the print
     16        dialog.
     17        * UIProcess/API/gtk/WebKitPrintOperation.h:
     18        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
     19        * UIProcess/API/gtk/tests/GNUmakefile.am:
     20        * UIProcess/API/gtk/tests/TestPrinting.cpp:
     21        (testPrintOperationPrintLoadChanged):
     22        (testPrintOperationPrintDone):
     23        (testPrintOperationPrintPrinter):
     24        (testPrintOperationPrint):
     25        (beforeAll):
     26        (afterAll):
     27
    1282012-02-17  No'am Rosenthal  <noam.rosenthal@nokia.com>
    229
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp

    r108040 r108068  
    241241}
    242242
     243static void webkitPrintOperationPrintPagesForFrame(WebKitPrintOperation* printOperation, WebFrameProxy* webFrame, GtkPrintSettings* printSettings, GtkPageSetup* pageSetup)
     244{
     245    PrintInfo printInfo(printSettings, pageSetup);
     246    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView));
     247    page->drawPagesForPrinting(webFrame, printInfo, VoidCallback::create(g_object_ref(printOperation), &drawPagesForPrintingCompleted));
     248}
     249
    243250void webkitPrintOperationRunDialogForFrame(WebKitPrintOperation* printOperation, GtkWindow* parent, WebFrameProxy* webFrame)
    244251{
     
    261268    }
    262269
    263     PrintInfo printInfo(priv->printSettings.get(), priv->pageSetup.get());
    264     WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(priv->webView));
    265     page->drawPagesForPrinting(webFrame, printInfo, VoidCallback::create(g_object_ref(printOperation), &drawPagesForPrintingCompleted));
     270    webkitPrintOperationPrintPagesForFrame(printOperation, webFrame, priv->printSettings.get(), priv->pageSetup.get());
    266271}
    267272
     
    378383}
    379384
     385/**
     386 * webkit_print_operation_print:
     387 * @print_operation: a #WebKitPrintOperation
     388 *
     389 * Start a print operation using current print settings and page setup
     390 * without showing the print dialog. If either print settings or page setup
     391 * are not set with webkit_print_operation_set_print_settings() and
     392 * webkit_print_operation_set_page_setup(), the default options will be used
     393 * and the print job will be sent to the default printer.
     394 */
     395void webkit_print_operation_print(WebKitPrintOperation* printOperation)
     396{
     397    g_return_if_fail(WEBKIT_IS_PRINT_OPERATION(printOperation));
     398
     399    WebKitPrintOperationPrivate* priv = printOperation->priv;
     400    GRefPtr<GtkPrintSettings> printSettings = priv->printSettings ? priv->printSettings : adoptGRef(gtk_print_settings_new());
     401    GRefPtr<GtkPageSetup> pageSetup = priv->pageSetup ? priv->pageSetup : adoptGRef(gtk_page_setup_new());
     402
     403    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(printOperation->priv->webView));
     404    webkitPrintOperationPrintPagesForFrame(printOperation, page->mainFrame(), printSettings.get(), pageSetup.get());
     405}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h

    r107947 r108068  
    7575                                           GtkWindow            *parent);
    7676
     77WEBKIT_API void
     78webkit_print_operation_print              (WebKitPrintOperation *print_operation);
     79
    7780G_END_DECLS
    7881
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r107947 r108068  
    427427webkit_print_operation_set_page_setup
    428428webkit_print_operation_run_dialog
     429webkit_print_operation_print
    429430
    430431<SUBSECTION Standard>
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am

    r107947 r108068  
    123123Programs_WebKit2APITests_TestPrinting_SOURCES = \
    124124        Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp
    125 Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags)
    126 Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd)
     125Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags) $(GTK_UNIX_PRINTING_CFLAGS)
     126Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd) $(GTK_UNIX_PRINTING_LIBS)
    127127Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags)
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp

    r107947 r108068  
    2020#include "config.h"
    2121#include "WebViewTest.h"
     22#include <glib/gstdio.h>
    2223#include <wtf/gobject/GRefPtr.h>
     24
     25#ifdef HAVE_GTK_UNIX_PRINTING
     26#include <gtk/gtkunixprint.h>
     27#endif
     28
     29static char* kTempDirectory;
    2330
    2431static void testPrintOperationPrintSettings(WebViewTest* test, gconstpointer)
     
    6572}
    6673
     74#ifdef HAVE_GTK_UNIX_PRINTING
     75static void testPrintOperationPrintLoadChanged(WebKitWebView*, WebKitLoadEvent loadEvent, WebViewTest* test)
     76{
     77    if (loadEvent != WEBKIT_LOAD_FINISHED)
     78        return;
     79    g_main_loop_quit(test->m_mainLoop);
     80}
     81
     82static void testPrintOperationPrintDone(WebKitPrintOperation* printOperation, WebViewTest* test)
     83{
     84    g_object_unref(printOperation);
     85    g_main_loop_quit(test->m_mainLoop);
     86}
     87
     88static gboolean testPrintOperationPrintPrinter(GtkPrinter* printer, gpointer userData)
     89{
     90    if (strcmp(gtk_printer_get_name(printer), "Print to File"))
     91        return FALSE;
     92
     93    GtkPrinter** foundPrinter = static_cast<GtkPrinter**>(userData);
     94    *foundPrinter = static_cast<GtkPrinter*>(g_object_ref(printer));
     95    return TRUE;
     96}
     97
     98static void testPrintOperationPrint(WebViewTest* test, gconstpointer)
     99{
     100    g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(testPrintOperationPrintLoadChanged), test);
     101    test->loadHtml("<html><body>WebKitGTK+ printing test</body></html>", 0);
     102    g_main_loop_run(test->m_mainLoop);
     103
     104    GtkPrinter* printer = 0;
     105    gtk_enumerate_printers(testPrintOperationPrintPrinter, &printer, 0, TRUE);
     106    if (!printer) {
     107        g_message("%s", "Cannot test WebKitPrintOperation/print: no suitable printer found");
     108        return;
     109    }
     110
     111    GOwnPtr<char> outputFilename(g_build_filename(kTempDirectory, "webkit-print.pdf", NULL));
     112    GRefPtr<GFile> outputFile = adoptGRef(g_file_new_for_path(outputFilename.get()));
     113    GOwnPtr<char> outputURI(g_file_get_uri(outputFile.get()));
     114
     115    GRefPtr<GtkPrintSettings> printSettings = adoptGRef(gtk_print_settings_new());
     116    gtk_print_settings_set_printer(printSettings.get(), gtk_printer_get_name(printer));
     117    gtk_print_settings_set(printSettings.get(), GTK_PRINT_SETTINGS_OUTPUT_URI, outputURI.get());
     118    g_object_unref(printer);
     119
     120    GRefPtr<WebKitPrintOperation> printOperation = webkit_print_operation_new(test->m_webView);
     121    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printOperation.get()));
     122    g_signal_connect(printOperation.get(), "done", G_CALLBACK(testPrintOperationPrintDone), test);
     123    webkit_print_operation_set_print_settings(printOperation.get(), printSettings.get());
     124    webkit_print_operation_print(printOperation.get());
     125    g_main_loop_run(test->m_mainLoop);
     126
     127    GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(outputFile.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE","G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
     128                                                              static_cast<GFileQueryInfoFlags>(0), 0, 0));
     129    g_assert(fileInfo.get());
     130    g_assert_cmpint(g_file_info_get_size(fileInfo.get()), >, 0);
     131    g_assert_cmpstr(g_file_info_get_content_type(fileInfo.get()), ==, "application/pdf");
     132
     133    g_file_delete(outputFile.get(), 0, 0);
     134}
     135#endif // HAVE_GTK_UNIX_PRINTING
     136
    67137void beforeAll()
    68138{
     139    kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0);
     140    g_assert(kTempDirectory);
     141
    69142    WebViewTest::add("WebKitPrintOperation", "printing-settings", testPrintOperationPrintSettings);
    70143    WebViewTest::add("WebKitWebView", "print-requested", testWebViewPrintRequested);
     144#ifdef HAVE_GTK_UNIX_PRINTING
     145    WebViewTest::add("WebKitPrintOperation", "print", testPrintOperationPrint);
     146#endif
    71147}
    72148
    73149void afterAll()
    74150{
     151    g_rmdir(kTempDirectory);
    75152}
Note: See TracChangeset for help on using the changeset viewer.