pidgin/gtkwebview.c

Sun, 12 Aug 2012 04:00:19 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 12 Aug 2012 04:00:19 -0400
changeset 33249
92a0135ceb96
parent 33248
565884eb4354
child 33250
84e141f1bfed
permissions
-rw-r--r--

Don't focus the entry when getting the Menu key.

32445
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
1 /*
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
2 * @file gtkwebview.c GTK+ WebKitWebView wrapper class.
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
3 * @ingroup pidgin
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
4 */
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
5
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
6 /* pidgin
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
7 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
8 * Pidgin is the legal property of its developers, whose names are too numerous
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
10 * source distribution.
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
11 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
12 * This program is free software; you can redistribute it and/or modify
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
13 * it under the terms of the GNU General Public License as published by
32445
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
15 * (at your option) any later version.
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
16 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
17 * This program is distributed in the hope that it will be useful,
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
20 * GNU General Public License for more details.
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
21 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
22 * You should have received a copy of the GNU General Public License
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
23 * along with this program; if not, write to the Free Software
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
25 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
26 */
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
27
32791
a2dc8d3ee1b8 Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32774
diff changeset
28 #include "internal.h"
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
29 #include "debug.h"
32791
a2dc8d3ee1b8 Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32774
diff changeset
30 #include "pidgin.h"
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
31
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
32 #include <gdk/gdkkeysyms.h>
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
33 #include "gtkutils.h"
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
34 #include "gtkwebview.h"
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
35
33170
ce4447562d64 Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33167
diff changeset
36 #include "gtk3compat.h"
ce4447562d64 Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33167
diff changeset
37
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
38 #define MAX_FONT_SIZE 7
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
39 #define MAX_SCROLL_TIME 0.4 /* seconds */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
40 #define SCROLL_DELAY 33 /* milliseconds */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
41
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
42 #define GTK_WEBVIEW_GET_PRIVATE(obj) \
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
43 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GTK_TYPE_WEBVIEW, GtkWebViewPriv))
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
44
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
45 enum {
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
46 LOAD_HTML,
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
47 LOAD_JS
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
48 };
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
49
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
50 enum {
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
51 BUTTONS_UPDATE,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
52 TOGGLE_FORMAT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
53 CLEAR_FORMAT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
54 UPDATE_FORMAT,
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
55 CHANGED,
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
56 HTML_APPENDED,
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
57 LAST_SIGNAL
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
58 };
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
59 static guint signals[LAST_SIGNAL] = { 0 };
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
60
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
61 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
62 * Structs
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
63 *****************************************************************************/
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
64
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
65 typedef struct {
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
66 WebKitWebInspector *inspector;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
67 WebKitDOMNode *node;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
68 } GtkWebViewInspectData;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
69
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
70 typedef struct {
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
71 char *name;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
72 int length;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
73
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
74 gboolean (*activate)(GtkWebView *webview, const char *uri);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
75 gboolean (*context_menu)(GtkWebView *webview, WebKitDOMHTMLAnchorElement *link, GtkWidget *menu);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
76 } GtkWebViewProtocol;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
77
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
78 typedef struct _GtkWebViewPriv {
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
79 /* Processing queues */
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
80 gboolean is_loading;
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
81 GQueue *load_queue;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
82 guint loader;
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
83
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
84 /* Scroll adjustments */
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
85 GtkAdjustment *vadj;
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
86 gboolean autoscroll;
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
87 guint scroll_src;
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
88 GTimer *scroll_time;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
89
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
90 /* Format options */
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
91 GtkWebViewButtons format_functions;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
92 struct {
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
93 gboolean wbfo:1; /* Whole buffer formatting only. */
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
94 gboolean block_changed:1;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
95 } edit;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
96
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
97 } GtkWebViewPriv;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
98
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
99 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
100 * Globals
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
101 *****************************************************************************/
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
102
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
103 static WebKitWebViewClass *parent_class = NULL;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
104
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
105 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
106 * Helpers
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
107 *****************************************************************************/
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
108
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
109 static void
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
110 webview_resource_loading(WebKitWebView *webview,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
111 WebKitWebFrame *frame,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
112 WebKitWebResource *resource,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
113 WebKitNetworkRequest *request,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
114 WebKitNetworkResponse *response,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
115 gpointer user_data)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
116 {
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
117 const gchar *uri;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
118
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
119 uri = webkit_network_request_get_uri(request);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
120 if (purple_str_has_prefix(uri, PURPLE_STORED_IMAGE_PROTOCOL)) {
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
121 int id;
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
122 PurpleStoredImage *img;
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
123 const char *filename;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
124
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
125 uri += sizeof(PURPLE_STORED_IMAGE_PROTOCOL) - 1;
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
126 id = strtoul(uri, NULL, 10);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
127
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
128 img = purple_imgstore_find_by_id(id);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
129 if (!img)
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
130 return;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
131
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
132 filename = purple_imgstore_get_filename(img);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
133 if (filename && g_path_is_absolute(filename)) {
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
134 char *tmp = g_strdup_printf("file://%s", filename);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
135 webkit_network_request_set_uri(request, tmp);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
136 g_free(tmp);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
137 } else {
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
138 char *b64 = purple_base64_encode(purple_imgstore_get_data(img),
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
139 purple_imgstore_get_size(img));
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
140 const char *type = purple_imgstore_get_extension(img);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
141 char *tmp = g_strdup_printf("data:image/%s;base64,%s", type, b64);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
142 webkit_network_request_set_uri(request, tmp);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
143 g_free(b64);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
144 g_free(tmp);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
145 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
146 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
147 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
148
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
149 static gboolean
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
150 process_load_queue(GtkWebView *webview)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
151 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
152 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
153 int type;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
154 char *str;
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
155 WebKitDOMDocument *doc;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
156 WebKitDOMHTMLElement *body;
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
157 WebKitDOMNode *start, *end;
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
158 WebKitDOMRange *range;
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
159 gboolean require_scroll = FALSE;
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
160
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
161 if (priv->is_loading) {
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
162 priv->loader = 0;
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
163 return FALSE;
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
164 }
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
165 if (!priv->load_queue || g_queue_is_empty(priv->load_queue)) {
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
166 priv->loader = 0;
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
167 return FALSE;
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
168 }
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
169
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
170 type = GPOINTER_TO_INT(g_queue_pop_head(priv->load_queue));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
171 str = g_queue_pop_head(priv->load_queue);
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
172
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
173 switch (type) {
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
174 case LOAD_HTML:
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
175 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
176 body = webkit_dom_document_get_body(doc);
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
177 start = webkit_dom_node_get_last_child(WEBKIT_DOM_NODE(body));
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
178
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
179 if (priv->autoscroll) {
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
180 require_scroll = (gtk_adjustment_get_value(priv->vadj)
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
181 >= (gtk_adjustment_get_upper(priv->vadj) -
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
182 gtk_adjustment_get_page_size(priv->vadj)));
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
183 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
184
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
185 webkit_dom_html_element_insert_adjacent_html(body, "beforeend",
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
186 str, NULL);
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
187
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
188 range = webkit_dom_document_create_range(doc);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
189 if (start) {
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
190 end = webkit_dom_node_get_last_child(WEBKIT_DOM_NODE(body));
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
191 webkit_dom_range_set_start_after(range,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
192 WEBKIT_DOM_NODE(start),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
193 NULL);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
194 webkit_dom_range_set_end_after(range,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
195 WEBKIT_DOM_NODE(end),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
196 NULL);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
197 } else {
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
198 webkit_dom_range_select_node_contents(range,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
199 WEBKIT_DOM_NODE(body),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
200 NULL);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
201 }
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
202
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
203 if (require_scroll) {
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
204 if (start)
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
205 webkit_dom_element_scroll_into_view(WEBKIT_DOM_ELEMENT(start),
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
206 TRUE);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
207 else
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
208 webkit_dom_element_scroll_into_view(WEBKIT_DOM_ELEMENT(body),
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
209 TRUE);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
210 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
211
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
212 g_signal_emit(webview, signals[HTML_APPENDED], 0, range);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
213
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
214 break;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
215
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
216 case LOAD_JS:
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
217 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(webview), str);
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
218 break;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
219
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
220 default:
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
221 purple_debug_error("webview",
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
222 "Got unknown loading queue type: %d\n", type);
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
223 break;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
224 }
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
225
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
226 g_free(str);
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
227
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
228 return TRUE;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
229 }
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
230
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
231 static void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
232 webview_load_started(WebKitWebView *webview, WebKitWebFrame *frame,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
233 gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
234 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
235 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
236
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
237 /* is there a better way to test for is_loading? */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
238 priv->is_loading = TRUE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
239 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
240
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
241 static void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
242 webview_load_finished(WebKitWebView *webview, WebKitWebFrame *frame,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
243 gpointer userdata)
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
244 {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
245 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
246
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
247 priv->is_loading = FALSE;
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
248 if (priv->loader == 0)
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
249 priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
250 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
251
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
252 static void
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
253 webview_show_inspector_cb(GtkWidget *item, GtkWebViewInspectData *data)
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
254 {
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
255 webkit_web_inspector_inspect_node(data->inspector, data->node);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
256 }
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
257
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
258 static GtkWebViewProtocol *
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
259 webview_find_protocol(const char *url, gboolean reverse)
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
260 {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
261 GtkWebViewClass *klass;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
262 GList *iter;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
263 GtkWebViewProtocol *proto = NULL;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
264 int length = reverse ? strlen(url) : -1;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
265
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
266 klass = g_type_class_ref(GTK_TYPE_WEBVIEW);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
267 for (iter = klass->protocols; iter; iter = iter->next) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
268 proto = iter->data;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
269 if (g_ascii_strncasecmp(url, proto->name, reverse ? MIN(length, proto->length) : proto->length) == 0) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
270 g_type_class_unref(klass);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
271 return proto;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
272 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
273 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
274
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
275 g_type_class_unref(klass);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
276 return NULL;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
277 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
278
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
279 static gboolean
33226
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
280 webview_navigation_decision(WebKitWebView *webview,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
281 WebKitWebFrame *frame,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
282 WebKitNetworkRequest *request,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
283 WebKitWebNavigationAction *navigation_action,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
284 WebKitWebPolicyDecision *policy_decision,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
285 gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
286 {
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
287 const gchar *uri;
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
288 WebKitWebNavigationReason reason;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
289
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
290 uri = webkit_network_request_get_uri(request);
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
291 reason = webkit_web_navigation_action_get_reason(navigation_action);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
292
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
293 if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
294 GtkWebViewProtocol *proto = webview_find_protocol(uri, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
295 if (proto) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
296 /* XXX: Do something with the return value? */
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
297 proto->activate(GTK_WEBVIEW(webview), uri);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
298 }
32800
67649fafdb51 If we handle a navigation request, then we should tell WebKit
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32799
diff changeset
299 webkit_web_policy_decision_ignore(policy_decision);
32803
a2d80b30be13 We don't want WebKit to process a Refresh, or Back/Forward
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32800
diff changeset
300 } else if (reason == WEBKIT_WEB_NAVIGATION_REASON_OTHER)
32523
2d37b68228b6 Let webview manage the navigation ONLY if the reason is the user clicked a link.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32513
diff changeset
301 webkit_web_policy_decision_use(policy_decision);
32803
a2d80b30be13 We don't want WebKit to process a Refresh, or Back/Forward
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32800
diff changeset
302 else
a2d80b30be13 We don't want WebKit to process a Refresh, or Back/Forward
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32800
diff changeset
303 webkit_web_policy_decision_ignore(policy_decision);
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
304
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
305 return TRUE;
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
306 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
307
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
308 static void
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
309 do_popup_menu(WebKitWebView *webview, int button, int time, int context,
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
310 WebKitDOMNode *node, const char *uri)
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
311 {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
312 GtkWidget *menu;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
313 GtkWidget *cut, *copy, *paste, *delete, *select;
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
314 WebKitWebSettings *settings;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
315 gboolean inspector;
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
316
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
317 menu = gtk_menu_new();
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
318 g_signal_connect(menu, "selection-done",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
319 G_CALLBACK(gtk_widget_destroy), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
320
33233
26a3100b451e Don't show link context menu when it's part of the selection.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33232
diff changeset
321 if ((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
26a3100b451e Don't show link context menu when it's part of the selection.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33232
diff changeset
322 && !(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION)) {
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
323 GtkWebViewProtocol *proto = NULL;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
324 GList *children;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
325
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
326 while (node && !WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT(node)) {
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
327 node = webkit_dom_node_get_parent_node(node);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
328 }
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
329
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
330 if (uri && node)
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
331 proto = webview_find_protocol(uri, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
332
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
333 if (proto && proto->context_menu) {
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
334 proto->context_menu(GTK_WEBVIEW(webview),
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
335 WEBKIT_DOM_HTML_ANCHOR_ELEMENT(node), menu);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
336 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
337
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
338 children = gtk_container_get_children(GTK_CONTAINER(menu));
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
339 if (!children) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
340 GtkWidget *item = gtk_menu_item_new_with_label(_("No actions available"));
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
341 gtk_widget_show(item);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
342 gtk_widget_set_sensitive(item, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
343 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
344 } else {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
345 g_list_free(children);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
346 }
33232
a572083f80ef Register protocols with GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33231
diff changeset
347 gtk_widget_show_all(menu);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
348
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
349 } else {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
350 /* Using connect_swapped means we don't need any wrapper functions */
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
351 cut = pidgin_new_item_from_stock(menu, _("Cu_t"), GTK_STOCK_CUT,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
352 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
353 g_signal_connect_swapped(G_OBJECT(cut), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
354 G_CALLBACK(webkit_web_view_cut_clipboard),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
355 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
356
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
357 copy = pidgin_new_item_from_stock(menu, _("_Copy"), GTK_STOCK_COPY,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
358 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
359 g_signal_connect_swapped(G_OBJECT(copy), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
360 G_CALLBACK(webkit_web_view_copy_clipboard),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
361 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
362
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
363 paste = pidgin_new_item_from_stock(menu, _("_Paste"), GTK_STOCK_PASTE,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
364 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
365 g_signal_connect_swapped(G_OBJECT(paste), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
366 G_CALLBACK(webkit_web_view_paste_clipboard),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
367 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
368
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
369 delete = pidgin_new_item_from_stock(menu, _("_Delete"), GTK_STOCK_DELETE,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
370 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
371 g_signal_connect_swapped(G_OBJECT(delete), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
372 G_CALLBACK(webkit_web_view_delete_selection),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
373 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
374
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
375 pidgin_separator(menu);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
376
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
377 select = pidgin_new_item_from_stock(menu, _("Select _All"),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
378 GTK_STOCK_SELECT_ALL,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
379 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
380 g_signal_connect_swapped(G_OBJECT(select), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
381 G_CALLBACK(webkit_web_view_select_all),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
382 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
383
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
384 gtk_widget_set_sensitive(cut,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
385 webkit_web_view_can_cut_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
386 gtk_widget_set_sensitive(copy,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
387 webkit_web_view_can_copy_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
388 gtk_widget_set_sensitive(paste,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
389 webkit_web_view_can_paste_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
390 gtk_widget_set_sensitive(delete,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
391 webkit_web_view_can_cut_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
392 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
393
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
394 settings = webkit_web_view_get_settings(webview);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
395 g_object_get(G_OBJECT(settings), "enable-developer-extras", &inspector, NULL);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
396 if (inspector) {
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
397 GtkWidget *inspect;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
398 GtkWebViewInspectData *data;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
399
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
400 data = g_new0(GtkWebViewInspectData, 1);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
401 data->inspector = webkit_web_view_get_inspector(webview);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
402 data->node = node;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
403
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
404 pidgin_separator(menu);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
405
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
406 inspect = pidgin_new_item_from_stock(menu, _("Inspect _Element"), NULL,
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
407 NULL, NULL, 0, 0, NULL);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
408 g_signal_connect_data(G_OBJECT(inspect), "activate",
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
409 G_CALLBACK(webview_show_inspector_cb),
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
410 data, (GClosureNotify)g_free, 0);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
411 }
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
412
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
413 g_signal_emit_by_name(G_OBJECT(webview), "populate-popup", menu);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
414
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
415 gtk_menu_attach_to_widget(GTK_MENU(menu), GTK_WIDGET(webview), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
416 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, time);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
417 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
418
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
419 static gboolean
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
420 webview_popup_menu(WebKitWebView *webview)
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
421 {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
422 do_popup_menu(webview, 0, gtk_get_current_event_time(),
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
423 WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
424 NULL, NULL);
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
425 return TRUE;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
426 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
427
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
428 static gboolean
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
429 webview_button_pressed(WebKitWebView *webview, GdkEventButton *event)
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
430 {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
431 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
432 WebKitHitTestResult *hit;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
433 int context;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
434 WebKitDOMNode *node;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
435 char *uri;
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
436
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
437 hit = webkit_web_view_get_hit_test_result(webview, event);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
438 g_object_get(G_OBJECT(hit),
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
439 "context", &context,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
440 "inner-node", &node,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
441 "link-uri", &uri,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
442 NULL);
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
443
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
444 do_popup_menu(webview, event->button, event->time, context,
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
445 node, uri);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
446
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
447 g_free(uri);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
448
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
449 return TRUE;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
450 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
451
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
452 return FALSE;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
453 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
454
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
455 /*
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
456 * Smoothly scroll a WebView.
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
457 *
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
458 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom.
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
459 */
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
460 static gboolean
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
461 smooth_scroll_cb(gpointer data)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
462 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
463 GtkWebViewPriv *priv = data;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
464 GtkAdjustment *adj;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
465 gdouble max_val;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
466 gdouble scroll_val;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
467
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
468 g_return_val_if_fail(priv->scroll_time != NULL, FALSE);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
469
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
470 adj = priv->vadj;
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
471 max_val = gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
472 scroll_val = gtk_adjustment_get_value(adj) +
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
473 ((max_val - gtk_adjustment_get_value(adj)) / 3);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
474
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
475 if (g_timer_elapsed(priv->scroll_time, NULL) > MAX_SCROLL_TIME
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
476 || scroll_val >= max_val) {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
477 /* time's up. jump to the end and kill the timer */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
478 gtk_adjustment_set_value(adj, max_val);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
479 g_timer_destroy(priv->scroll_time);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
480 priv->scroll_time = NULL;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
481 priv->scroll_src = 0;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
482 return FALSE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
483 }
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
484
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
485 /* scroll by 1/3rd the remaining distance */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
486 gtk_adjustment_set_value(adj, scroll_val);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
487 return TRUE;
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
488 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
489
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
490 static gboolean
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
491 scroll_idle_cb(gpointer data)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
492 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
493 GtkWebViewPriv *priv = data;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
494 GtkAdjustment *adj = priv->vadj;
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
495 gdouble max_val;
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
496
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
497 if (adj) {
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
498 max_val = gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj);
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
499 gtk_adjustment_set_value(adj, max_val);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
500 }
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
501
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
502 priv->scroll_src = 0;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
503 return FALSE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
504 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
505
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
506 static void
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
507 emit_format_signal(GtkWebView *webview, GtkWebViewButtons buttons)
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
508 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
509 g_object_ref(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
510 g_signal_emit(webview, signals[TOGGLE_FORMAT], 0, buttons);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
511 g_object_unref(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
512 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
513
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
514 static void
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
515 do_formatting(GtkWebView *webview, const char *name, const char *value)
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
516 {
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
517 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
518 WebKitDOMDocument *dom;
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
519 WebKitDOMDOMWindow *win;
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
520 WebKitDOMDOMSelection *sel = NULL;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
521 WebKitDOMRange *range = NULL;
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
522
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
523 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
524
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
525 if (priv->edit.wbfo) {
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
526 win = webkit_dom_document_get_default_view(dom);
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
527 sel = webkit_dom_dom_window_get_selection(win);
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
528 if (webkit_dom_dom_selection_get_range_count(sel) > 0)
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
529 range = webkit_dom_dom_selection_get_range_at(sel, 0, NULL);
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
530 webkit_web_view_select_all(WEBKIT_WEB_VIEW(webview));
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
531 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
532
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
533 priv->edit.block_changed = TRUE;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
534 webkit_dom_document_exec_command(dom, name, FALSE, value);
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
535 priv->edit.block_changed = FALSE;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
536
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
537 if (priv->edit.wbfo) {
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
538 if (range) {
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
539 webkit_dom_dom_selection_remove_all_ranges(sel);
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
540 webkit_dom_dom_selection_add_range(sel, range);
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
541 } else {
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
542 webkit_dom_dom_selection_collapse_to_end(sel, NULL);
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
543 }
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
544 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
545 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
546
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
547 static void
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
548 webview_font_shrink(GtkWebView *webview)
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
549 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
550 gint fontsize;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
551 char *tmp;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
552
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
553 fontsize = gtk_webview_get_current_fontsize(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
554 fontsize = MAX(fontsize - 1, 1);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
555
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
556 tmp = g_strdup_printf("%d", fontsize);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
557 do_formatting(webview, "fontSize", tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
558 g_free(tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
559 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
560
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
561 static void
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
562 webview_font_grow(GtkWebView *webview)
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
563 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
564 gint fontsize;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
565 char *tmp;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
566
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
567 fontsize = gtk_webview_get_current_fontsize(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
568 fontsize = MIN(fontsize + 1, MAX_FONT_SIZE);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
569
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
570 tmp = g_strdup_printf("%d", fontsize);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
571 do_formatting(webview, "fontSize", tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
572 g_free(tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
573 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
574
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
575 static void
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
576 webview_clear_formatting(GtkWebView *webview)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
577 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
578 if (!webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview)))
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
579 return;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
580
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
581 do_formatting(webview, "removeFormat", "");
33020
03c013f8990c Remove links and background colours on format-clear.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33018
diff changeset
582 do_formatting(webview, "unlink", "");
03c013f8990c Remove links and background colours on format-clear.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33018
diff changeset
583 do_formatting(webview, "backColor", "inherit");
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
584 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
585
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
586 static void
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
587 webview_toggle_format(GtkWebView *webview, GtkWebViewButtons buttons)
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
588 {
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
589 /* since this function is the handler for the formatting keystrokes,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
590 we need to check here that the formatting attempted is permitted */
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
591 buttons &= gtk_webview_get_format_functions(webview);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
592
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
593 switch (buttons) {
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
594 case GTK_WEBVIEW_BOLD:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
595 do_formatting(webview, "bold", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
596 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
597 case GTK_WEBVIEW_ITALIC:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
598 do_formatting(webview, "italic", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
599 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
600 case GTK_WEBVIEW_UNDERLINE:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
601 do_formatting(webview, "underline", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
602 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
603 case GTK_WEBVIEW_STRIKE:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
604 do_formatting(webview, "strikethrough", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
605 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
606 case GTK_WEBVIEW_SHRINK:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
607 webview_font_shrink(webview);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
608 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
609 case GTK_WEBVIEW_GROW:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
610 webview_font_grow(webview);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
611 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
612 default:
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
613 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
614 }
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
615 }
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
616
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
617 static void
33028
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
618 editable_input_cb(GtkWebView *webview, gpointer data)
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
619 {
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
620 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33030
4114ce42d094 Don't emit changed signal when a webview is insensitive.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33028
diff changeset
621 if (!priv->edit.block_changed && gtk_widget_is_sensitive(GTK_WIDGET(webview)))
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
622 g_signal_emit(webview, signals[CHANGED], 0);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
623 }
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
624
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
625 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
626 * GObject Stuff
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
627 *****************************************************************************/
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
628
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
629 GtkWidget *
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
630 gtk_webview_new(void)
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
631 {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
632 return GTK_WIDGET(g_object_new(gtk_webview_get_type(), NULL));
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
633 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
634
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
635 static void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
636 gtk_webview_finalize(GObject *webview)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
637 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
638 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
639 gpointer temp;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
640
33227
2541e55ae19d Only remove source if non-zero.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33226
diff changeset
641 if (priv->loader)
2541e55ae19d Only remove source if non-zero.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33226
diff changeset
642 g_source_remove(priv->loader);
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
643
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
644 while (!g_queue_is_empty(priv->load_queue)) {
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
645 temp = g_queue_pop_head(priv->load_queue);
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
646 temp = g_queue_pop_head(priv->load_queue);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
647 g_free(temp);
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
648 }
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
649 g_queue_free(priv->load_queue);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
650
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
651 G_OBJECT_CLASS(parent_class)->finalize(G_OBJECT(webview));
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
652 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
653
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
654 static void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
655 gtk_webview_class_init(GtkWebViewClass *klass, gpointer userdata)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
656 {
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
657 GObjectClass *gobject_class;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
658 GtkBindingSet *binding_set;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
659
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
660 parent_class = g_type_class_ref(webkit_web_view_get_type());
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
661 gobject_class = G_OBJECT_CLASS(klass);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
662
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
663 g_type_class_add_private(klass, sizeof(GtkWebViewPriv));
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
664
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
665 signals[BUTTONS_UPDATE] = g_signal_new("allowed-formats-updated",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
666 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
667 G_SIGNAL_RUN_FIRST,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
668 G_STRUCT_OFFSET(GtkWebViewClass, buttons_update),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
669 NULL, 0, g_cclosure_marshal_VOID__INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
670 G_TYPE_NONE, 1, G_TYPE_INT);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
671 signals[TOGGLE_FORMAT] = g_signal_new("format-toggled",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
672 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
673 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
674 G_STRUCT_OFFSET(GtkWebViewClass, toggle_format),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
675 NULL, 0, g_cclosure_marshal_VOID__INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
676 G_TYPE_NONE, 1, G_TYPE_INT);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
677 signals[CLEAR_FORMAT] = g_signal_new("format-cleared",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
678 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
679 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
680 G_STRUCT_OFFSET(GtkWebViewClass, clear_format),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
681 NULL, 0, g_cclosure_marshal_VOID__VOID,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
682 G_TYPE_NONE, 0);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
683 signals[UPDATE_FORMAT] = g_signal_new("format-updated",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
684 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
685 G_SIGNAL_RUN_FIRST,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
686 G_STRUCT_OFFSET(GtkWebViewClass, update_format),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
687 NULL, 0, g_cclosure_marshal_VOID__VOID,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
688 G_TYPE_NONE, 0);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
689 signals[CHANGED] = g_signal_new("changed",
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
690 G_TYPE_FROM_CLASS(gobject_class),
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
691 G_SIGNAL_RUN_FIRST,
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
692 G_STRUCT_OFFSET(GtkWebViewClass, changed),
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
693 NULL, NULL, g_cclosure_marshal_VOID__VOID,
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
694 G_TYPE_NONE, 0);
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
695 signals[HTML_APPENDED] = g_signal_new("html-appended",
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
696 G_TYPE_FROM_CLASS(gobject_class),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
697 G_SIGNAL_RUN_FIRST,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
698 G_STRUCT_OFFSET(GtkWebViewClass, html_appended),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
699 NULL, NULL,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
700 g_cclosure_marshal_VOID__OBJECT,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
701 G_TYPE_NONE, 1, WEBKIT_TYPE_DOM_RANGE,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
702 NULL);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
703
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
704 klass->toggle_format = webview_toggle_format;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
705 klass->clear_format = webview_clear_formatting;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
706
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
707 gobject_class->finalize = gtk_webview_finalize;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
708
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
709 binding_set = gtk_binding_set_by_class(parent_class);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
710 gtk_binding_entry_add_signal(binding_set, GDK_KEY_b, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
711 "format-toggled", 1, G_TYPE_INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
712 GTK_WEBVIEW_BOLD);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
713 gtk_binding_entry_add_signal(binding_set, GDK_KEY_i, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
714 "format-toggled", 1, G_TYPE_INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
715 GTK_WEBVIEW_ITALIC);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
716 gtk_binding_entry_add_signal(binding_set, GDK_KEY_u, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
717 "format-toggled", 1, G_TYPE_INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
718 GTK_WEBVIEW_UNDERLINE);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
719 gtk_binding_entry_add_signal(binding_set, GDK_KEY_plus, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
720 "format-toggled", 1, G_TYPE_INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
721 GTK_WEBVIEW_GROW);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
722 gtk_binding_entry_add_signal(binding_set, GDK_KEY_equal, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
723 "format-toggled", 1, G_TYPE_INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
724 GTK_WEBVIEW_GROW);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
725 gtk_binding_entry_add_signal(binding_set, GDK_KEY_minus, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
726 "format-toggled", 1, G_TYPE_INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
727 GTK_WEBVIEW_SHRINK);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
728
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
729 binding_set = gtk_binding_set_by_class(klass);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
730 gtk_binding_entry_add_signal(binding_set, GDK_KEY_r, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
731 "format-cleared", 0);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
732 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
733
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
734 static void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
735 gtk_webview_init(GtkWebView *webview, gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
736 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
737 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
738
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
739 priv->load_queue = g_queue_new();
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
740
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
741 g_signal_connect(G_OBJECT(webview), "button-press-event",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
742 G_CALLBACK(webview_button_pressed), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
743
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
744 g_signal_connect(G_OBJECT(webview), "popup-menu",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
745 G_CALLBACK(webview_popup_menu), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
746
33223
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
747 g_signal_connect(G_OBJECT(webview), "navigation-policy-decision-requested",
33226
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
748 G_CALLBACK(webview_navigation_decision), NULL);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
749
33223
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
750 g_signal_connect(G_OBJECT(webview), "load-started",
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
751 G_CALLBACK(webview_load_started), NULL);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
752
33223
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
753 g_signal_connect(G_OBJECT(webview), "load-finished",
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
754 G_CALLBACK(webview_load_finished), NULL);
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
755
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
756 g_signal_connect(G_OBJECT(webview), "resource-request-starting",
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
757 G_CALLBACK(webview_resource_loading), NULL);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
758 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
759
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
760 GType
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
761 gtk_webview_get_type(void)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
762 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
763 static GType mview_type = 0;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
764 if (G_UNLIKELY(mview_type == 0)) {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
765 static const GTypeInfo mview_info = {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
766 sizeof(GtkWebViewClass),
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
767 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
768 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
769 (GClassInitFunc)gtk_webview_class_init,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
770 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
771 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
772 sizeof(GtkWebView),
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
773 0,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
774 (GInstanceInitFunc)gtk_webview_init,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
775 NULL
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
776 };
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
777 mview_type = g_type_register_static(webkit_web_view_get_type(),
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
778 "GtkWebView", &mview_info, 0);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
779 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
780 return mview_type;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
781 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
782
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
783 /*****************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
784 * Public API functions
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
785 *****************************************************************************/
32793
db876e8e41ac Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32791
diff changeset
786
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
787 char *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
788 gtk_webview_quote_js_string(const char *text)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
789 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
790 GString *str = g_string_new("\"");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
791 const char *cur = text;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
792
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
793 while (cur && *cur) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
794 switch (*cur) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
795 case '\\':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
796 g_string_append(str, "\\\\");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
797 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
798 case '\"':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
799 g_string_append(str, "\\\"");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
800 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
801 case '\r':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
802 g_string_append(str, "<br/>");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
803 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
804 case '\n':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
805 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
806 default:
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
807 g_string_append_c(str, *cur);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
808 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
809 cur++;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
810 }
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
811
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
812 g_string_append_c(str, '"');
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
813
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
814 return g_string_free(str, FALSE);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
815 }
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
816
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
817 void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
818 gtk_webview_safe_execute_script(GtkWebView *webview, const char *script)
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
819 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
820 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
821
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
822 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
823
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
824 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
825 g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(LOAD_JS));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
826 g_queue_push_tail(priv->load_queue, g_strdup(script));
33224
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
827 if (!priv->is_loading && priv->loader == 0)
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
828 priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
829 }
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
830
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
831 void
32993
d6da54acf528 Remove _with_imgstore suffix on this function. There isn't a version
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32898
diff changeset
832 gtk_webview_load_html_string(GtkWebView *webview, const char *html)
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
833 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
834 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
835
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
836 webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html, NULL, NULL,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
837 "file:///");
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
838 }
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
839
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
840 void
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
841 gtk_webview_load_html_string_with_selection(GtkWebView *webview, const char *html)
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
842 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
843 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
844
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
845 gtk_webview_load_html_string(webview, html);
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
846 gtk_webview_safe_execute_script(webview,
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
847 "var s = window.getSelection();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
848 "var r = document.createRange();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
849 "var n = document.getElementById('caret');"
33084
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
850 "r.selectNodeContents(n);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
851 "var f = r.extractContents();"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
852 "r.selectNode(n);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
853 "r.insertNode(f);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
854 "n.parentNode.removeChild(n);"
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
855 "s.removeAllRanges();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
856 "s.addRange(r);");
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
857 }
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
858
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
859 void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
860 gtk_webview_append_html(GtkWebView *webview, const char *html)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
861 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
862 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
863
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
864 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
865
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
866 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
867 g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(LOAD_HTML));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
868 g_queue_push_tail(priv->load_queue, g_strdup(html));
33224
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
869 if (!priv->is_loading && priv->loader == 0)
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
870 priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
871 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
872
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
873 void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
874 gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj)
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
875 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
876 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
877
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
878 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
879
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
880 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
881 priv->vadj = vadj;
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
882 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
883
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
884 void
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
885 gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth)
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
886 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
887 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
888
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
889 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
890
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
891 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
892 if (priv->scroll_time)
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
893 g_timer_destroy(priv->scroll_time);
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
894 if (priv->scroll_src)
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
895 g_source_remove(priv->scroll_src);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
896 if (smooth) {
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
897 priv->scroll_time = g_timer_new();
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
898 priv->scroll_src = g_timeout_add_full(G_PRIORITY_LOW, SCROLL_DELAY, smooth_scroll_cb, priv, NULL);
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
899 } else {
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
900 priv->scroll_time = NULL;
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
901 priv->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, priv, NULL);
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
902 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
903 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
904
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
905 void
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
906 gtk_webview_set_autoscroll(GtkWebView *webview, gboolean scroll)
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
907 {
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
908 GtkWebViewPriv *priv;
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
909
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
910 g_return_if_fail(webview != NULL);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
911
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
912 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
913 priv->autoscroll = scroll;
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
914 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
915
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
916 gboolean
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
917 gtk_webview_get_autoscroll(GtkWebView *webview)
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
918 {
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
919 GtkWebViewPriv *priv;
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
920
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
921 g_return_val_if_fail(webview != NULL, FALSE);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
922
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
923 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
924 return priv->autoscroll;
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
925 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
926
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
927 void
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
928 gtk_webview_page_up(GtkWebView *webview)
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
929 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
930 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
931 GtkAdjustment *vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
932 gdouble scroll_val;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
933
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
934 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
935
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
936 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
937 vadj = priv->vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
938 scroll_val = gtk_adjustment_get_value(vadj) - gtk_adjustment_get_page_size(vadj);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
939 scroll_val = MAX(scroll_val, gtk_adjustment_get_lower(vadj));
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
940
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
941 gtk_adjustment_set_value(vadj, scroll_val);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
942 }
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
943
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
944 void
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
945 gtk_webview_page_down(GtkWebView *webview)
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
946 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
947 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
948 GtkAdjustment *vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
949 gdouble scroll_val;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
950 gdouble page_size;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
951
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
952 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
953
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
954 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
955 vadj = priv->vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
956 page_size = gtk_adjustment_get_page_size(vadj);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
957 scroll_val = gtk_adjustment_get_value(vadj) + page_size;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
958 scroll_val = MIN(scroll_val, gtk_adjustment_get_upper(vadj) - page_size);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
959
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
960 gtk_adjustment_set_value(vadj, scroll_val);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
961 }
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
962
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
963 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
964 gtk_webview_set_editable(GtkWebView *webview, gboolean editable)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
965 {
33197
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
966 GtkWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
967 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
968
33197
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
969 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
970 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview), editable);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
971
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
972 if (editable) {
33028
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
973 g_signal_connect(G_OBJECT(webview), "user-changed-contents",
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
974 G_CALLBACK(editable_input_cb), NULL);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
975 } else {
33028
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
976 g_signal_handlers_disconnect_by_func(G_OBJECT(webview),
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
977 G_CALLBACK(editable_input_cb),
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
978 NULL);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
979 }
33197
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
980
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
981 priv->format_functions = GTK_WEBVIEW_ALL;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
982 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
983
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
984 void
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
985 gtk_webview_setup_entry(GtkWebView *webview, PurpleConnectionFlags flags)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
986 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
987 GtkWebViewButtons buttons;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
988
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
989 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
990
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
991 if (flags & PURPLE_CONNECTION_HTML) {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
992 gboolean bold, italic, underline, strike;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
993
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
994 buttons = GTK_WEBVIEW_ALL;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
995
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
996 if (flags & PURPLE_CONNECTION_NO_BGCOLOR)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
997 buttons &= ~GTK_WEBVIEW_BACKCOLOR;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
998 if (flags & PURPLE_CONNECTION_NO_FONTSIZE)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
999 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1000 buttons &= ~GTK_WEBVIEW_GROW;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1001 buttons &= ~GTK_WEBVIEW_SHRINK;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1002 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1003 if (flags & PURPLE_CONNECTION_NO_URLDESC)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1004 buttons &= ~GTK_WEBVIEW_LINKDESC;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1005
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1006 gtk_webview_get_current_format(webview, &bold, &italic, &underline, &strike);
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1007
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1008 gtk_webview_set_format_functions(webview, GTK_WEBVIEW_ALL);
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1009 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != bold)
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1010 gtk_webview_toggle_bold(webview);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1011
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1012 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != italic)
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1013 gtk_webview_toggle_italic(webview);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1014
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1015 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != underline)
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1016 gtk_webview_toggle_underline(webview);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1017
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1018 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike") != strike)
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1019 gtk_webview_toggle_strike(webview);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1020
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1021 gtk_webview_toggle_fontface(webview,
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1022 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/font_face"));
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1023
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1024 if (!(flags & PURPLE_CONNECTION_NO_FONTSIZE))
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1025 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1026 int size = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size");
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1027
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1028 /* 3 is the default. */
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1029 if (size != 3)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1030 gtk_webview_font_set_size(webview, size);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1031 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1032
33025
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1033 gtk_webview_toggle_forecolor(webview,
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1034 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"));
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1035
33025
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1036 if (!(flags & PURPLE_CONNECTION_NO_BGCOLOR)) {
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1037 gtk_webview_toggle_backcolor(webview,
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1038 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"));
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1039 } else {
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1040 gtk_webview_toggle_backcolor(webview, "");
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1041 }
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1042
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1043 if (flags & PURPLE_CONNECTION_FORMATTING_WBFO)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1044 gtk_webview_set_whole_buffer_formatting_only(webview, TRUE);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1045 else
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1046 gtk_webview_set_whole_buffer_formatting_only(webview, FALSE);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1047 } else {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1048 buttons = GTK_WEBVIEW_SMILEY | GTK_WEBVIEW_IMAGE;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1049 webview_clear_formatting(webview);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1050 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1051
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1052 if (flags & PURPLE_CONNECTION_NO_IMAGES)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1053 buttons &= ~GTK_WEBVIEW_IMAGE;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1054
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1055 if (flags & PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY)
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1056 buttons |= GTK_WEBVIEW_CUSTOM_SMILEY;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1057 else
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1058 buttons &= ~GTK_WEBVIEW_CUSTOM_SMILEY;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1059
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1060 gtk_webview_set_format_functions(webview, buttons);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1061 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1062
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1063 void
33021
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1064 pidgin_webview_set_spellcheck(GtkWebView *webview, gboolean enable)
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1065 {
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1066 WebKitWebSettings *settings;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1067
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1068 g_return_if_fail(webview != NULL);
33021
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1069
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1070 settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1071 g_object_set(G_OBJECT(settings), "enable-spell-checking", enable, NULL);
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1072 webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webview), settings);
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1073 }
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1074
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1075 void
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1076 gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview, gboolean wbfo)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1077 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1078 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1079
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1080 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1081
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1082 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1083 priv->edit.wbfo = wbfo;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1084 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1085
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1086 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1087 gtk_webview_set_format_functions(GtkWebView *webview, GtkWebViewButtons buttons)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1088 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1089 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1090 GObject *object;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1091
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1092 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1093
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1094 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1095 object = g_object_ref(G_OBJECT(webview));
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1096 priv->format_functions = buttons;
32812
5be5c09c86de Emit the allowed-formats-updated signal when the set_format_functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32811
diff changeset
1097 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons);
5be5c09c86de Emit the allowed-formats-updated signal when the set_format_functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32811
diff changeset
1098 g_object_unref(object);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1099 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1100
33231
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1101 void
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1102 gtk_webview_activate_anchor(WebKitDOMHTMLAnchorElement *link)
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1103 {
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1104 WebKitDOMDocument *doc;
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1105 WebKitDOMEvent *event;
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1106
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1107 doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(link));
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1108 event = webkit_dom_document_create_event(doc, "MouseEvent", NULL);
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1109 webkit_dom_event_init_event(event, "click", TRUE, TRUE);
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1110 webkit_dom_node_dispatch_event(WEBKIT_DOM_NODE(link), event, NULL);
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1111 }
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1112
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1113 gboolean
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1114 gtk_webview_class_register_protocol(const char *name,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1115 gboolean (*activate)(GtkWebView *webview, const char *uri),
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1116 gboolean (*context_menu)(GtkWebView *webview, WebKitDOMHTMLAnchorElement *link, GtkWidget *menu))
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1117 {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1118 GtkWebViewClass *klass;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1119 GtkWebViewProtocol *proto;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1120
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1121 g_return_val_if_fail(name, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1122
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1123 klass = g_type_class_ref(GTK_TYPE_WEBVIEW);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1124 g_return_val_if_fail(klass, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1125
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1126 if ((proto = webview_find_protocol(name, TRUE))) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1127 if (activate) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1128 return FALSE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1129 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1130 klass->protocols = g_list_remove(klass->protocols, proto);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1131 g_free(proto->name);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1132 g_free(proto);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1133 return TRUE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1134 } else if (!activate) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1135 return FALSE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1136 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1137
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1138 proto = g_new0(GtkWebViewProtocol, 1);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1139 proto->name = g_strdup(name);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1140 proto->length = strlen(name);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1141 proto->activate = activate;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1142 proto->context_menu = context_menu;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1143 klass->protocols = g_list_prepend(klass->protocols, proto);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1144
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1145 return TRUE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1146 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1147
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1148 gchar *
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1149 gtk_webview_get_head_html(GtkWebView *webview)
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1150 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1151 WebKitDOMDocument *doc;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1152 WebKitDOMHTMLHeadElement *head;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1153 gchar *html;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1154
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1155 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1156
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1157 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1158 head = webkit_dom_document_get_head(doc);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1159 html = webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(head));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1160
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1161 return html;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1162 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1163
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1164 gchar *
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1165 gtk_webview_get_body_html(GtkWebView *webview)
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1166 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1167 WebKitDOMDocument *doc;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1168 WebKitDOMHTMLElement *body;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1169 gchar *html;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1170
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1171 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1172
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1173 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1174 body = webkit_dom_document_get_body(doc);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1175 html = webkit_dom_html_element_get_inner_html(body);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1176
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1177 return html;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1178 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1179
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1180 gchar *
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1181 gtk_webview_get_body_text(GtkWebView *webview)
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1182 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1183 WebKitDOMDocument *doc;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1184 WebKitDOMHTMLElement *body;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1185 gchar *text;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1186
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1187 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1188
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1189 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1190 body = webkit_dom_document_get_body(doc);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1191 text = webkit_dom_html_element_get_inner_text(body);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1192
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1193 return text;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1194 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1195
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1196 gchar *
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1197 gtk_webview_get_selected_text(GtkWebView *webview)
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1198 {
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1199 WebKitDOMDocument *dom;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1200 WebKitDOMDOMWindow *win;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1201 WebKitDOMDOMSelection *sel;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1202 WebKitDOMRange *range;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1203
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1204 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1205
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1206 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1207 win = webkit_dom_document_get_default_view(dom);
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1208 sel = webkit_dom_dom_window_get_selection(win);
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1209 range = webkit_dom_dom_selection_get_range_at(sel, 0, NULL);
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1210
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1211 return webkit_dom_range_get_text(range);
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1212 }
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1213
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1214 GtkWebViewButtons
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1215 gtk_webview_get_format_functions(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1216 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1217 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1218
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1219 g_return_val_if_fail(webview != NULL, 0);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1220
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1221 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1222 return priv->format_functions;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1223 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1224
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1225 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1226 gtk_webview_get_current_format(GtkWebView *webview, gboolean *bold,
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1227 gboolean *italic, gboolean *underline,
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1228 gboolean *strike)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1229 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1230 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1231
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1232 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1233
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1234 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1235
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1236 if (bold)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1237 *bold = webkit_dom_document_query_command_state(dom, "bold");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1238 if (italic)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1239 *italic = webkit_dom_document_query_command_state(dom, "italic");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1240 if (underline)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1241 *underline = webkit_dom_document_query_command_state(dom, "underline");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1242 if (strike)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1243 *strike = webkit_dom_document_query_command_state(dom, "strikethrough");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1244 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1245
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1246 char *
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1247 gtk_webview_get_current_fontface(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1248 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1249 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1250
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1251 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1252
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1253 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1254 return webkit_dom_document_query_command_value(dom, "fontName");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1255 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1256
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1257 char *
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1258 gtk_webview_get_current_forecolor(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1259 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1260 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1261
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1262 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1263
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1264 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1265 return webkit_dom_document_query_command_value(dom, "foreColor");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1266 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1267
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1268 char *
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1269 gtk_webview_get_current_backcolor(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1270 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1271 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1272
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1273 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1274
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1275 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1276 return webkit_dom_document_query_command_value(dom, "backColor");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1277 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1278
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1279 gint
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1280 gtk_webview_get_current_fontsize(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1281 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1282 WebKitDOMDocument *dom;
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1283 gchar *text;
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1284 gint size;
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1285
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1286 g_return_val_if_fail(webview != NULL, 0);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1287
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1288 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1289 text = webkit_dom_document_query_command_value(dom, "fontSize");
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1290 size = atoi(text);
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1291 g_free(text);
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1292
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1293 return size;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1294 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1295
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1296 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1297 gtk_webview_get_editable(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1298 {
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1299 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview));
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1300 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1301
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1302 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1303 gtk_webview_clear_formatting(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1304 {
32813
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1305 GObject *object;
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1306
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1307 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1308
32813
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1309 object = g_object_ref(G_OBJECT(webview));
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1310 g_signal_emit(object, signals[CLEAR_FORMAT], 0);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1311 g_object_unref(object);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1312 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1313
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1314 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1315 gtk_webview_toggle_bold(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1316 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1317 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1318 emit_format_signal(webview, GTK_WEBVIEW_BOLD);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1319 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1320
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1321 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1322 gtk_webview_toggle_italic(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1323 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1324 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1325 emit_format_signal(webview, GTK_WEBVIEW_ITALIC);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1326 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1327
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1328 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1329 gtk_webview_toggle_underline(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1330 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1331 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1332 emit_format_signal(webview, GTK_WEBVIEW_UNDERLINE);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1333 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1334
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1335 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1336 gtk_webview_toggle_strike(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1337 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1338 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1339 emit_format_signal(webview, GTK_WEBVIEW_STRIKE);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1340 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1341
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1342 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1343 gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1344 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1345 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1346
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1347 do_formatting(webview, "foreColor", color);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1348 emit_format_signal(webview, GTK_WEBVIEW_FORECOLOR);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
1349
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1350 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1351 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1352
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1353 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1354 gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1355 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1356 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1357
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1358 do_formatting(webview, "backColor", color);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1359 emit_format_signal(webview, GTK_WEBVIEW_BACKCOLOR);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
1360
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1361 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1362 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1363
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1364 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1365 gtk_webview_toggle_fontface(GtkWebView *webview, const char *face)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1366 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1367 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1368
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1369 do_formatting(webview, "fontName", face);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1370 emit_format_signal(webview, GTK_WEBVIEW_FACE);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
1371
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1372 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1373 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1374
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1375 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1376 gtk_webview_font_set_size(GtkWebView *webview, gint size)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1377 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1378 char *tmp;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1379
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1380 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1381
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1382 tmp = g_strdup_printf("%d", size);
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1383 do_formatting(webview, "fontSize", tmp);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1384 emit_format_signal(webview, GTK_WEBVIEW_SHRINK|GTK_WEBVIEW_GROW);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
1385 g_free(tmp);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1386 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1387
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1388 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1389 gtk_webview_font_shrink(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1390 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1391 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1392 emit_format_signal(webview, GTK_WEBVIEW_SHRINK);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1393 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1394
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1395 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1396 gtk_webview_font_grow(GtkWebView *webview)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1397 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1398 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1399 emit_format_signal(webview, GTK_WEBVIEW_GROW);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1400 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1401
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1402 void
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1403 gtk_webview_insert_hr(GtkWebView *webview)
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1404 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1405 GtkWebViewPriv *priv;
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1406 WebKitDOMDocument *dom;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1407
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1408 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1409
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1410 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1411 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1412
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1413 priv->edit.block_changed = TRUE;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1414 webkit_dom_document_exec_command(dom, "insertHorizontalRule", FALSE, "");
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1415 priv->edit.block_changed = FALSE;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1416 }
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1417
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1418 void
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1419 gtk_webview_insert_link(GtkWebView *webview, const char *url, const char *desc)
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1420 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1421 GtkWebViewPriv *priv;
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1422 WebKitDOMDocument *dom;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1423 char *link;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1424
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1425 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1426
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1427 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1428 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
33016
509c717fcf6e The URL probably needs to be quoted.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33014
diff changeset
1429 link = g_strdup_printf("<a href='%s'>%s</a>", url, desc ? desc : url);
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1430
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1431 priv->edit.block_changed = TRUE;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1432 webkit_dom_document_exec_command(dom, "insertHTML", FALSE, link);
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1433 priv->edit.block_changed = FALSE;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1434 g_free(link);
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1435 }
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1436
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1437 void
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1438 gtk_webview_insert_image(GtkWebView *webview, int id)
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1439 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1440 GtkWebViewPriv *priv;
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1441 WebKitDOMDocument *dom;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1442 char *img;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1443
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1444 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1445
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1446 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1447 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
1448 img = g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'/>",
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
1449 id);
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1450
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1451 priv->edit.block_changed = TRUE;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1452 webkit_dom_document_exec_command(dom, "insertHTML", FALSE, img);
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1453 priv->edit.block_changed = FALSE;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1454 g_free(img);
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1455 }
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1456

mercurial