Commit b39ae22c authored by kov@webkit.org's avatar kov@webkit.org

2009-04-13 Gustavo Noronha Silva <gns@gnome.org>

        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:

git-svn-id: svn://svn.chromium.org/blink/trunk@42435 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b770a0af
2009-04-13 Gustavo Noronha Silva <gns@gnome.org>
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:
2009-04-10 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk> 2009-04-10 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>
Reviewed by Holger Freyther. Reviewed by Holger Freyther.
......
...@@ -404,7 +404,14 @@ void ChromeClient::setToolTip(const String& toolTip) ...@@ -404,7 +404,14 @@ void ChromeClient::setToolTip(const String& toolTip)
void ChromeClient::print(Frame* frame) void ChromeClient::print(Frame* frame)
{ {
webkit_web_frame_print(kit(frame)); WebKitWebFrame* webFrame = kit(frame);
gboolean isHandled = false;
g_signal_emit_by_name(m_webView, "print-requested", webFrame, &isHandled);
if (isHandled)
return;
webkit_web_frame_print(webFrame);
} }
void ChromeClient::exceededDatabaseQuota(Frame* frame, const String&) void ChromeClient::exceededDatabaseQuota(Frame* frame, const String&)
......
...@@ -176,9 +176,6 @@ extern "C" { ...@@ -176,9 +176,6 @@ extern "C" {
WEBKIT_API gchar* WEBKIT_API gchar*
webkit_web_frame_get_inner_text (WebKitWebFrame* frame); webkit_web_frame_get_inner_text (WebKitWebFrame* frame);
WEBKIT_API void
webkit_web_frame_print (WebKitWebFrame* frame);
WEBKIT_API gchar* WEBKIT_API gchar*
webkit_web_frame_dump_render_tree (WebKitWebFrame* frame); webkit_web_frame_dump_render_tree (WebKitWebFrame* frame);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Copyright (C) 2008 Collabora Ltd. * Copyright (C) 2008 Collabora Ltd.
* Copyright (C) 2008 Nuanti Ltd. * Copyright (C) 2008 Nuanti Ltd.
* Copyright (C) 2009 Jan Alonzo <jmalonzo@gmail.com> * Copyright (C) 2009 Jan Alonzo <jmalonzo@gmail.com>
* Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
...@@ -611,7 +612,7 @@ gchar* webkit_web_frame_dump_render_tree(WebKitWebFrame* frame) ...@@ -611,7 +612,7 @@ gchar* webkit_web_frame_dump_render_tree(WebKitWebFrame* frame)
return g_strdup(string.utf8().data()); return g_strdup(string.utf8().data());
} }
static void begin_print(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data) static void begin_print_callback(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data)
{ {
PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data);
...@@ -629,7 +630,7 @@ static void begin_print(GtkPrintOperation* op, GtkPrintContext* context, gpointe ...@@ -629,7 +630,7 @@ static void begin_print(GtkPrintOperation* op, GtkPrintContext* context, gpointe
gtk_print_operation_set_n_pages(op, printContext->pageCount()); gtk_print_operation_set_n_pages(op, printContext->pageCount());
} }
static void draw_page(GtkPrintOperation* op, GtkPrintContext* context, gint page_nr, gpointer user_data) static void draw_page_callback(GtkPrintOperation* op, GtkPrintContext* context, gint page_nr, gpointer user_data)
{ {
PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data);
...@@ -639,34 +640,72 @@ static void draw_page(GtkPrintOperation* op, GtkPrintContext* context, gint page ...@@ -639,34 +640,72 @@ static void draw_page(GtkPrintOperation* op, GtkPrintContext* context, gint page
printContext->spoolPage(ctx, page_nr, width); printContext->spoolPage(ctx, page_nr, width);
} }
static void end_print(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data) static void end_print_callback(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data)
{ {
PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data);
printContext->end(); printContext->end();
} }
void webkit_web_frame_print(WebKitWebFrame* frame) /**
* webkit_web_frame_print_full:
* @frame: a #WebKitWebFrame to be printed
* @operation: the #GtkPrintOperation to be carried
* @action: the #GtkPrintOperationAction to be performed
* @error: #GError for error return
*
* Prints the given #WebKitFrame, using the given #GtkPrintOperation
* and #GtkPrintOperationAction. This function wraps a call to
* gtk_print_operation_run() for printing the contents of the
* #WebKitWebFrame.
*
* Since: 1.1.5
*/
GtkPrintOperationResult webkit_web_frame_print_full(WebKitWebFrame* frame, GtkPrintOperation* operation, GtkPrintOperationAction action, GError** error)
{ {
g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), GTK_PRINT_OPERATION_RESULT_ERROR);
g_return_val_if_fail(GTK_IS_PRINT_OPERATION(operation), GTK_PRINT_OPERATION_RESULT_ERROR);
GtkWidget* topLevel = gtk_widget_get_toplevel(GTK_WIDGET(webkit_web_frame_get_web_view(frame))); GtkWidget* topLevel = gtk_widget_get_toplevel(GTK_WIDGET(webkit_web_frame_get_web_view(frame)));
if (!GTK_WIDGET_TOPLEVEL(topLevel)) if (!GTK_WIDGET_TOPLEVEL(topLevel))
topLevel = NULL; topLevel = NULL;
Frame* coreFrame = core(frame); Frame* coreFrame = core(frame);
if (!coreFrame) if (!coreFrame)
return; return GTK_PRINT_OPERATION_RESULT_ERROR;
PrintContext printContext(coreFrame); PrintContext printContext(coreFrame);
GtkPrintOperation* op = gtk_print_operation_new(); g_signal_connect(operation, "begin-print", G_CALLBACK(begin_print_callback), &printContext);
g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), &printContext); g_signal_connect(operation, "draw-page", G_CALLBACK(draw_page_callback), &printContext);
g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), &printContext); g_signal_connect(operation, "end-print", G_CALLBACK(end_print_callback), &printContext);
g_signal_connect(op, "end-print", G_CALLBACK(end_print), &printContext);
GError *error = NULL; return gtk_print_operation_run(operation, action, GTK_WINDOW(topLevel), error);
gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(topLevel), &error); }
g_object_unref(op);
/**
* webkit_web_frame_print:
* @frame: a #WebKitWebFrame
*
* Prints the given #WebKitFrame, by presenting a print dialog to the
* user. If you need more control over the printing process, see
* webkit_web_frame_print_full().
*
* Since: 1.1.5
*/
void webkit_web_frame_print(WebKitWebFrame* frame)
{
g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
WebKitWebFramePrivate* priv = frame->priv;
GtkPrintOperation* operation = gtk_print_operation_new();
GError* error = 0;
webkit_web_frame_print_full(frame, operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error);
g_object_unref(operation);
if (error) { if (error) {
GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(topLevel), GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(priv->webView));
GtkWidget* dialog = gtk_message_dialog_new(GTK_WIDGET_TOPLEVEL(window) ? GTK_WINDOW(window) : 0,
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define WEBKIT_WEB_FRAME_H #define WEBKIT_WEB_FRAME_H
#include <glib-object.h> #include <glib-object.h>
#include <gtk/gtk.h>
#include <JavaScriptCore/JSBase.h> #include <JavaScriptCore/JSBase.h>
#include <webkit/webkitdefines.h> #include <webkit/webkitdefines.h>
...@@ -108,6 +110,15 @@ webkit_web_frame_find_frame (WebKitWebFrame *frame, ...@@ -108,6 +110,15 @@ webkit_web_frame_find_frame (WebKitWebFrame *frame,
WEBKIT_API JSGlobalContextRef WEBKIT_API JSGlobalContextRef
webkit_web_frame_get_global_context (WebKitWebFrame *frame); webkit_web_frame_get_global_context (WebKitWebFrame *frame);
WEBKIT_API GtkPrintOperationResult
webkit_web_frame_print_full (WebKitWebFrame *frame,
GtkPrintOperation *operation,
GtkPrintOperationAction action,
GError **error);
WEBKIT_API void
webkit_web_frame_print (WebKitWebFrame *frame);
G_END_DECLS G_END_DECLS
#endif #endif
...@@ -139,6 +139,7 @@ enum { ...@@ -139,6 +139,7 @@ enum {
CUT_CLIPBOARD, CUT_CLIPBOARD,
DOWNLOAD_REQUESTED, DOWNLOAD_REQUESTED,
MOVE_CURSOR, MOVE_CURSOR,
PRINT_REQUESTED,
LAST_SIGNAL LAST_SIGNAL
}; };
...@@ -1375,6 +1376,35 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) ...@@ -1375,6 +1376,35 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
GTK_TYPE_MENU); GTK_TYPE_MENU);
/**
* WebKitWebView::print-requested
* @web_view: the object in which the signal is emitted
* @web_frame: the frame that is requesting to be printed
* @return: %TRUE if the print request has been handled, %FALSE if
* the default handler should run
*
* Emitted when printing is requested by the frame, usually
* because of a javascript call. When handling this signal you
* should call webkit_web_frame_print_full() or
* webkit_web_frame_print() to do the actual printing.
*
* The default handler will present a print dialog and carry a
* print operation. Notice that this means that if you intend to
* ignore a print request you must connect to this signal, and
* return %TRUE.
*
* Since: 1.1.5
*/
webkit_web_view_signals[PRINT_REQUESTED] = g_signal_new("print-requested",
G_TYPE_FROM_CLASS(webViewClass),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
0,
g_signal_accumulator_true_handled,
NULL,
webkit_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN, 1,
WEBKIT_TYPE_WEB_FRAME);
webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed", webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed",
G_TYPE_FROM_CLASS(webViewClass), G_TYPE_FROM_CLASS(webViewClass),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment