Changeset 107947 in webkit


Ignore:
Timestamp:
Feb 16, 2012 9:10:58 AM (12 years ago)
Author:
Carlos Garcia Campos
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.
Location:
trunk/Source/WebKit2
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r107945 r107947  
     12012-02-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add WebKitPrintOperation to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=76448
     5
     6        Reviewed by Martin Robinson.
     7
     8        * GNUmakefile.am: Add new files to compilation.
     9        * UIProcess/API/gtk/WebKitDefines.h:
     10        * UIProcess/API/gtk/WebKitPrintOperation.cpp: Added.
     11        (webViewDestroyed): Delete the print operation when the view
     12        widget associated is destroyed.
     13        (webkitPrintOperationConstructed): Connect to destroy signal of
     14        associated web view.
     15        (webkitPrintOperationGetProperty):
     16        (webkitPrintOperationSetProperty):
     17        (webkit_print_operation_init):
     18        (webkit_print_operation_class_init):
     19        (webkitPrintOperationRunDialogUnix): Use GtkPrintUnixDialog to
     20        show the printing dialog in UNIX platforms.
     21        (webkitPrintOperationRunDialogWin32): Empty, not implemented yet.
     22        (drawPagesForPrintingCompleted): Callback called when printing
     23        operation has finished in the web process.
     24        (webkitPrintOperationRunDialogForFrame): Run the printing dialog
     25        and start printing the given frame.
     26        (webkit_print_operation_new): Create a new print operation for the
     27        given web view.
     28        (webkit_print_operation_get_print_settings):
     29        (webkit_print_operation_set_print_settings):
     30        (webkit_print_operation_get_page_setup):
     31        (webkit_print_operation_set_page_setup):
     32        (webkit_print_operation_run_dialog): Run the print dialog to print
     33        the web view main frame.
     34        * UIProcess/API/gtk/WebKitPrintOperation.h: Added.
     35        * UIProcess/API/gtk/WebKitPrintOperationPrivate.h: Added.
     36        * UIProcess/API/gtk/WebKitUIClient.cpp:
     37        (printFrame): Call webkitWebViewPrintFrame.
     38        (attachUIClientToView): Add implementation for
     39        printFrame callback.
     40        * UIProcess/API/gtk/WebKitWebView.cpp:
     41        (webkit_web_view_class_init): Add WebKitWebView::print-requested
     42        signal.
     43        (webkitWebViewPrintFrame): Emit print-requested and show the print
     44        dialog to print the frame when not signal is not handled by user.
     45        * UIProcess/API/gtk/WebKitWebView.h:
     46        * UIProcess/API/gtk/WebKitWebViewPrivate.h:
     47        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for
     48        WebKitPrintOperation.
     49        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
     50        * UIProcess/API/gtk/tests/GNUmakefile.am:
     51        * UIProcess/API/gtk/tests/TestPrinting.cpp: Added.
     52        (testPrintOperationPrintSettings):
     53        (webViewPrintRequestedCallback):
     54        (testWebViewPrintRequested):
     55        (beforeAll):
     56        (afterAll):
     57        * UIProcess/API/gtk/webkit2.h: Include WebKitPrintOperation.h.
     58
    1592012-02-16  Simon Hausmann  <simon.hausmann@nokia.com>
    260
  • trunk/Source/WebKit2/GNUmakefile.am

    r107250 r107947  
    9292        $(WebKit2)/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h \
    9393        $(WebKit2)/UIProcess/API/gtk/WebKitPolicyDecision.h \
     94        $(WebKit2)/UIProcess/API/gtk/WebKitPrintOperation.h \
    9495        $(WebKit2)/UIProcess/API/gtk/WebKitResponsePolicyDecision.h \
    9596        $(WebKit2)/UIProcess/API/gtk/WebKitSettings.h \
     
    554555        Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp \
    555556        Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.h \
     557        Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp \
     558        Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h \
     559        Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperationPrivate.h \
    556560        Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h \
    557561        Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.cpp \
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h

    r103938 r107947  
    3333#include <glib.h>
    3434
     35typedef struct _WebKitPrintOperation WebKitPrintOperation;
     36
    3537#ifdef G_OS_WIN32
    3638#    ifdef BUILDING_WEBKIT
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp

    r107250 r107947  
    132132}
    133133
     134static void printFrame(WKPageRef page, WKFrameRef frame, const void*)
     135{
     136    webkitWebViewPrintFrame(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()), frame);
     137}
     138
    134139void attachUIClientToView(WebKitWebView* webView)
    135140{
     
    171176        0, // drawHeader
    172177        0, // drawFooter
    173         0, // printFrame
     178        printFrame,
    174179        0, // runModal
    175180        0, // didCompleteRubberBandForMainFrame
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r107904 r107947  
    2929#include "WebKitMarshal.h"
    3030#include "WebKitPolicyClient.h"
     31#include "WebKitPrintOperationPrivate.h"
    3132#include "WebKitPrivate.h"
    3233#include "WebKitSettingsPrivate.h"
     
    6263
    6364    MOUSE_TARGET_CHANGED,
     65
     66    PRINT_REQUESTED,
    6467
    6568    LAST_SIGNAL
     
    648651                      WEBKIT_TYPE_HIT_TEST_RESULT,
    649652                      G_TYPE_UINT);
     653    /**
     654     * WebKitWebView::print-requested:
     655     * @web_view: the #WebKitWebView on which the signal is emitted
     656     * @print_operation: the #WebKitPrintOperation that will handle the print request
     657     *
     658     * Emitted when printing is requested on @web_view, usually by a javascript call,
     659     * before the print dialog is shown. This signal can be used to set the initial
     660     * print settings and page setup of @print_operation to be used as default values in
     661     * the print dialog. You can call webkit_print_operation_set_print_settings() and
     662     * webkit_print_operation_set_page_setup() and then return %FALSE to propagate the
     663     * event so that the print dialog is shown.
     664     *
     665     * You can connect to this signal and return %TRUE to cancel the print operation
     666     * or implement your own print dialog.
     667     *
     668     * Returns: %TRUE to stop other handlers from being invoked for the event.
     669     *    %FALSE to propagate the event further.
     670     */
     671    signals[PRINT_REQUESTED] =
     672        g_signal_new("print-requested",
     673                     G_TYPE_FROM_CLASS(webViewClass),
     674                     G_SIGNAL_RUN_LAST,
     675                     G_STRUCT_OFFSET(WebKitWebViewClass, print_requested),
     676                     g_signal_accumulator_true_handled, 0,
     677                     webkit_marshal_BOOLEAN__OBJECT,
     678                     G_TYPE_BOOLEAN, 1,
     679                     WEBKIT_TYPE_PRINT_OPERATION);
    650680}
    651681
     
    770800    priv->mouseTargetHitTestResult = adoptGRef(webkitHitTestResultCreate(wkHitTestResult));
    771801    g_signal_emit(webView, signals[MOUSE_TARGET_CHANGED], 0, priv->mouseTargetHitTestResult.get(), modifiers);
     802}
     803
     804void webkitWebViewPrintFrame(WebKitWebView* webView, WKFrameRef wkFrame)
     805{
     806    GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(webkit_print_operation_new(webView));
     807    gboolean returnValue;
     808    g_signal_emit(webView, signals[PRINT_REQUESTED], 0, printOperation.get(), &returnValue);
     809    if (returnValue)
     810        return;
     811
     812    g_signal_connect(printOperation.get(), "done", G_CALLBACK(g_object_unref), 0);
     813    webkitPrintOperationRunDialogForFrame(printOperation.leakRef(), 0, toImpl(wkFrame));
    772814}
    773815
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r107250 r107947  
    3232#include <webkit2/WebKitDefines.h>
    3333#include <webkit2/WebKitHitTestResult.h>
    34 #include <webkit2/WebKitWebContext.h>
    3534#include <webkit2/WebKitSettings.h>
    3635#include <webkit2/WebKitURIRequest.h>
     36#include <webkit2/WebKitWebContext.h>
    3737#include <webkit2/WebKitWebViewBase.h>
    3838#include <webkit2/WebKitWindowProperties.h>
     
    140140    gboolean   (* decide_policy)        (WebKitWebView             *web_view,
    141141                                         WebKitPolicyDecision      *decision,
    142                                          WebKitPolicyDecisionType  type);
    143     void       (* mouse_target_changed) (WebKitWebView            *web_view,
    144                                          WebKitHitTestResult      *hit_test_result,
    145                                          guint                     modifiers);
     142                                         WebKitPolicyDecisionType   type);
     143    void       (* mouse_target_changed) (WebKitWebView             *web_view,
     144                                         WebKitHitTestResult       *hit_test_result,
     145                                         guint                      modifiers);
     146    gboolean   (* print_requested)      (WebKitWebView             *web_view,
     147                                         WebKitPrintOperation      *print_operation);
    146148
    147149    /* Padding for future expansion */
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h

    r107250 r107947  
    4545void webkitWebViewMakePolicyDecision(WebKitWebView*, WebKitPolicyDecisionType, WebKitPolicyDecision*);
    4646void webkitWebViewMouseTargetChanged(WebKitWebView*, WKHitTestResultRef, unsigned modifiers);
     47void webkitWebViewPrintFrame(WebKitWebView*, WKFrameRef);
    4748
    4849#endif // WebKitWebViewPrivate_h
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml

    r107250 r107947  
    2626    <xi:include href="xml/WebKitResponsePolicyDecision.xml"/>
    2727    <xi:include href="xml/WebKitHitTestResult.xml"/>
     28    <xi:include href="xml/WebKitPrintOperation.xml"/>
    2829    <xi:include href="xml/WebKitError.xml"/>
    2930  </chapter>
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r107250 r107947  
    419419
    420420<SECTION>
     421<FILE>WebKitPrintOperation</FILE>
     422WebKitPrintOperation
     423webkit_print_operation_new
     424webkit_print_operation_get_print_settings
     425webkit_print_operation_set_print_settings
     426webkit_print_operation_get_page_setup
     427webkit_print_operation_set_page_setup
     428webkit_print_operation_run_dialog
     429
     430<SUBSECTION Standard>
     431WebKitPrintOperationClass
     432WEBKIT_TYPE_PRINT_OPERATION
     433WEBKIT_PRINT_OPERATION
     434WEBKIT_IS_PRINT_OPERATION
     435WEBKIT_PRINT_OPERATION_CLASS
     436WEBKIT_IS_PRINT_OPERATION_CLASS
     437WEBKIT_PRINT_OPERATION_GET_CLASS
     438
     439<SUBSECTION Private>
     440WebKitPrintOperationPrivate
     441webkit_print_operation_get_type
     442</SECTION>
     443
     444<SECTION>
    421445<FILE>WebKitError</FILE>
    422446WEBKIT_NETWORK_ERROR
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am

    r106961 r107947  
    77        Programs/WebKit2APITests/TestDownloads \
    88        Programs/WebKit2APITests/TestWebKitPolicyClient \
    9         Programs/WebKit2APITests/TestWebViewEditor
     9        Programs/WebKit2APITests/TestWebViewEditor \
     10        Programs/WebKit2APITests/TestPrinting
    1011
    1112noinst_PROGRAMS += $(TEST_PROGS)
     
    119120Programs_WebKit2APITests_TestWebViewEditor_LDADD = $(webkit2_tests_ldadd)
    120121Programs_WebKit2APITests_TestWebViewEditor_LDFLAGS = $(webkit2_tests_ldflags)
     122
     123Programs_WebKit2APITests_TestPrinting_SOURCES = \
     124        Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp
     125Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags)
     126Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd)
     127Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags)
  • trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h

    r107250 r107947  
    3232#include <webkit2/WebKitError.h>
    3333#include <webkit2/WebKitHitTestResult.h>
     34#include <webkit2/WebKitPrintOperation.h>
    3435#include <webkit2/WebKitSettings.h>
    3536#include <webkit2/WebKitURIRequest.h>
Note: See TracChangeset for help on using the changeset viewer.