Changeset 42435 in webkit


Ignore:
Timestamp:
Apr 13, 2009 9:26:52 AM (15 years ago)
Author:
kov@webkit.org
Message:

2009-04-13 Gustavo Noronha Silva <Gustavo Noronha Silva>

Reviewed by Holger Freyther.

https://bugs.webkit.org/show_bug.cgi?id=22898
[GTK] need proper API for printing

Implement proper printing API, using the GTK+ printing API.

  • WebCoreSupport/ChromeClientGtk.cpp: (WebKit::ChromeClient::print):
  • webkit/webkitprivate.h:
  • webkit/webkitwebframe.cpp:
  • webkit/webkitwebframe.h:
  • webkit/webkitwebview.cpp:
Location:
trunk/WebKit/gtk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r42391 r42435  
     12009-04-13  Gustavo Noronha Silva  <gns@gnome.org>
     2
     3        Reviewed by Holger Freyther.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=22898
     6        [GTK] need proper API for printing
     7
     8        Implement proper printing API, using the GTK+ printing API.
     9
     10        * WebCoreSupport/ChromeClientGtk.cpp:
     11        (WebKit::ChromeClient::print):
     12        * webkit/webkitprivate.h:
     13        * webkit/webkitwebframe.cpp:
     14        * webkit/webkitwebframe.h:
     15        * webkit/webkitwebview.cpp:
     16
    1172009-04-10  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
    218
  • trunk/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp

    r42251 r42435  
    405405void ChromeClient::print(Frame* frame)
    406406{
    407     webkit_web_frame_print(kit(frame));
     407    WebKitWebFrame* webFrame = kit(frame);
     408    gboolean isHandled = false;
     409    g_signal_emit_by_name(m_webView, "print-requested", webFrame, &isHandled);
     410
     411    if (isHandled)
     412        return;
     413
     414    webkit_web_frame_print(webFrame);
    408415}
    409416
  • trunk/WebKit/gtk/webkit/webkitprivate.h

    r41522 r42435  
    177177    webkit_web_frame_get_inner_text (WebKitWebFrame* frame);
    178178
    179     WEBKIT_API void
    180     webkit_web_frame_print (WebKitWebFrame* frame);
    181 
    182179    WEBKIT_API gchar*
    183180    webkit_web_frame_dump_render_tree (WebKitWebFrame* frame);
  • trunk/WebKit/gtk/webkit/webkitwebframe.cpp

    r42251 r42435  
    77 * Copyright (C) 2008 Nuanti Ltd.
    88 * Copyright (C) 2009 Jan Alonzo <jmalonzo@gmail.com>
     9 * Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
    910 *
    1011 * This library is free software; you can redistribute it and/or
     
    612613}
    613614
    614 static void begin_print(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data)
     615static void begin_print_callback(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data)
    615616{
    616617    PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data);
     
    630631}
    631632
    632 static void draw_page(GtkPrintOperation* op, GtkPrintContext* context, gint page_nr, gpointer user_data)
     633static void draw_page_callback(GtkPrintOperation* op, GtkPrintContext* context, gint page_nr, gpointer user_data)
    633634{
    634635    PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data);
     
    640641}
    641642
    642 static void end_print(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data)
     643static void end_print_callback(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data)
    643644{
    644645    PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data);
     
    646647}
    647648
    648 void webkit_web_frame_print(WebKitWebFrame* frame)
    649 {
     649/**
     650 * webkit_web_frame_print_full:
     651 * @frame: a #WebKitWebFrame to be printed
     652 * @operation: the #GtkPrintOperation to be carried
     653 * @action: the #GtkPrintOperationAction to be performed
     654 * @error: #GError for error return
     655 *
     656 * Prints the given #WebKitFrame, using the given #GtkPrintOperation
     657 * and #GtkPrintOperationAction. This function wraps a call to
     658 * gtk_print_operation_run() for printing the contents of the
     659 * #WebKitWebFrame.
     660 *
     661 * Since: 1.1.5
     662 */
     663GtkPrintOperationResult webkit_web_frame_print_full(WebKitWebFrame* frame, GtkPrintOperation* operation, GtkPrintOperationAction action, GError** error)
     664{
     665    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), GTK_PRINT_OPERATION_RESULT_ERROR);
     666    g_return_val_if_fail(GTK_IS_PRINT_OPERATION(operation), GTK_PRINT_OPERATION_RESULT_ERROR);
     667
    650668    GtkWidget* topLevel = gtk_widget_get_toplevel(GTK_WIDGET(webkit_web_frame_get_web_view(frame)));
    651669    if (!GTK_WIDGET_TOPLEVEL(topLevel))
     
    654672    Frame* coreFrame = core(frame);
    655673    if (!coreFrame)
    656         return;
     674        return GTK_PRINT_OPERATION_RESULT_ERROR;
    657675
    658676    PrintContext printContext(coreFrame);
    659677
    660     GtkPrintOperation* op = gtk_print_operation_new();
    661     g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), &printContext);
    662     g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), &printContext);
    663     g_signal_connect(op, "end-print", G_CALLBACK(end_print), &printContext);
    664     GError *error = NULL;
    665     gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(topLevel), &error);
    666     g_object_unref(op);
     678    g_signal_connect(operation, "begin-print", G_CALLBACK(begin_print_callback), &printContext);
     679    g_signal_connect(operation, "draw-page", G_CALLBACK(draw_page_callback), &printContext);
     680    g_signal_connect(operation, "end-print", G_CALLBACK(end_print_callback), &printContext);
     681
     682    return gtk_print_operation_run(operation, action, GTK_WINDOW(topLevel), error);
     683}
     684
     685/**
     686 * webkit_web_frame_print:
     687 * @frame: a #WebKitWebFrame
     688 *
     689 * Prints the given #WebKitFrame, by presenting a print dialog to the
     690 * user. If you need more control over the printing process, see
     691 * webkit_web_frame_print_full().
     692 *
     693 * Since: 1.1.5
     694 */
     695void webkit_web_frame_print(WebKitWebFrame* frame)
     696{
     697    g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
     698
     699    WebKitWebFramePrivate* priv = frame->priv;
     700    GtkPrintOperation* operation = gtk_print_operation_new();
     701    GError* error = 0;
     702
     703    webkit_web_frame_print_full(frame, operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error);
     704    g_object_unref(operation);
    667705
    668706    if (error) {
    669         GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(topLevel),
     707        GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(priv->webView));
     708        GtkWidget* dialog = gtk_message_dialog_new(GTK_WIDGET_TOPLEVEL(window) ? GTK_WINDOW(window) : 0,
    670709                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
    671710                                                   GTK_MESSAGE_ERROR,
  • trunk/WebKit/gtk/webkit/webkitwebframe.h

    r40918 r42435  
    2323
    2424#include <glib-object.h>
     25#include <gtk/gtk.h>
     26
    2527#include <JavaScriptCore/JSBase.h>
    2628
     
    109111webkit_web_frame_get_global_context (WebKitWebFrame       *frame);
    110112
     113WEBKIT_API GtkPrintOperationResult
     114webkit_web_frame_print_full         (WebKitWebFrame       *frame,
     115                                     GtkPrintOperation    *operation,
     116                                     GtkPrintOperationAction action,
     117                                     GError              **error);
     118
     119WEBKIT_API void
     120webkit_web_frame_print              (WebKitWebFrame       *frame);
     121
    111122G_END_DECLS
    112123
  • trunk/WebKit/gtk/webkit/webkitwebview.cpp

    r42391 r42435  
    140140    DOWNLOAD_REQUESTED,
    141141    MOVE_CURSOR,
     142    PRINT_REQUESTED,
    142143    LAST_SIGNAL
    143144};
     
    13751376            G_TYPE_NONE, 1,
    13761377            GTK_TYPE_MENU);
     1378
     1379    /**
     1380     * WebKitWebView::print-requested
     1381     * @web_view: the object in which the signal is emitted
     1382     * @web_frame: the frame that is requesting to be printed
     1383     * @return: %TRUE if the print request has been handled, %FALSE if
     1384     * the default handler should run
     1385     *
     1386     * Emitted when printing is requested by the frame, usually
     1387     * because of a javascript call. When handling this signal you
     1388     * should call webkit_web_frame_print_full() or
     1389     * webkit_web_frame_print() to do the actual printing.
     1390     *
     1391     * The default handler will present a print dialog and carry a
     1392     * print operation. Notice that this means that if you intend to
     1393     * ignore a print request you must connect to this signal, and
     1394     * return %TRUE.
     1395     *
     1396     * Since: 1.1.5
     1397     */
     1398    webkit_web_view_signals[PRINT_REQUESTED] = g_signal_new("print-requested",
     1399            G_TYPE_FROM_CLASS(webViewClass),
     1400            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
     1401            0,
     1402            g_signal_accumulator_true_handled,
     1403            NULL,
     1404            webkit_marshal_BOOLEAN__OBJECT,
     1405            G_TYPE_BOOLEAN, 1,
     1406            WEBKIT_TYPE_WEB_FRAME);
    13771407
    13781408    webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed",
Note: See TracChangeset for help on using the changeset viewer.