pidgin/gtkwebview.c

Sun, 29 Jul 2012 11:36:05 +0200

author
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
date
Sun, 29 Jul 2012 11:36:05 +0200
changeset 33212
970a460e74fa
parent 33197
151a6a5a0521
child 33221
0215244831ec
permissions
-rw-r--r--

Fix compilation for GTK2

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"
a2dc8d3ee1b8 Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32774
diff changeset
29 #include "pidgin.h"
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
30
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
31 #include <gdk/gdkkeysyms.h>
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
32 #include "gtkwebview.h"
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
33
33170
ce4447562d64 Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33167
diff changeset
34 #include "gtk3compat.h"
ce4447562d64 Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33167
diff changeset
35
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
36 #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
37 #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
38 #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
39
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
40 #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
41 (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
42
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
43 enum {
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
44 BUTTONS_UPDATE,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
45 TOGGLE_FORMAT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
46 CLEAR_FORMAT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
47 UPDATE_FORMAT,
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
48 CHANGED,
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
49 LAST_SIGNAL
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
50 };
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
51 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
52
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
53 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
54 * Structs
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
55 *****************************************************************************/
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
56
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
57 typedef struct _GtkWebViewPriv {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
58 gboolean empty; /**< whether anything has been appended **/
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
59
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
60 /* Processing queues */
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
61 GQueue *html_queue;
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
62 GQueue *js_queue;
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
63 gboolean is_loading;
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
64
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
65 /* Scroll adjustments */
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
66 GtkAdjustment *vadj;
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
67 guint scroll_src;
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
68 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
69
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
70 /* Format options */
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
71 GtkWebViewButtons format_functions;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
72 struct {
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
73 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
74 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
75 } edit;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
76
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
77 } GtkWebViewPriv;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
78
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
79 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
80 * Globals
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
81 *****************************************************************************/
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
82
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
83 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
84
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
85 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
86 * Helpers
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
87 *****************************************************************************/
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
88
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
89 static void
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
90 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
91 WebKitWebFrame *frame,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
92 WebKitWebResource *resource,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
93 WebKitNetworkRequest *request,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
94 WebKitNetworkResponse *response,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
95 gpointer user_data)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
96 {
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
97 const gchar *uri;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
98
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
99 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
100 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
101 int id;
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
102 PurpleStoredImage *img;
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
103 const char *filename;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
104
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
105 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
106 id = strtoul(uri, NULL, 10);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
107
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
108 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
109 if (!img)
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
110 return;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
111
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
112 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
113 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
114 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
115 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
116 g_free(tmp);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
117 } else {
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
118 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
119 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
120 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
121 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
122 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
123 g_free(b64);
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
124 g_free(tmp);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
125 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
126 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
127 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
128
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
129 static gboolean
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
130 process_js_script_queue(GtkWebView *webview)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
131 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
132 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
133 char *script;
32461
72fe247cc953 Yep, tested, and changed some code from previous commit. This is a hard
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32460
diff changeset
134
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
135 if (priv->is_loading)
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
136 return FALSE; /* we will be called when loaded */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
137 if (!priv->js_queue || g_queue_is_empty(priv->js_queue))
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
138 return FALSE; /* nothing to do! */
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
139
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
140 script = g_queue_pop_head(priv->js_queue);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
141 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(webview), script);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
142 g_free(script);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
143
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
144 return TRUE; /* there may be more for now */
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
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
147 static gboolean
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
148 process_html_queue(GtkWebView *webview)
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
149 {
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
150 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
151 char *html;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
152 WebKitDOMDocument *doc;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
153 WebKitDOMHTMLElement *body;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
154
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
155 if (priv->is_loading)
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
156 return FALSE;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
157 if (!priv->html_queue || g_queue_is_empty(priv->html_queue))
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
158 return FALSE;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
159
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
160 html = g_queue_pop_head(priv->html_queue);
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
161 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
162 body = webkit_dom_document_get_body(doc);
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
163 webkit_dom_html_element_insert_adjacent_html(body, "beforeend", html, NULL);
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
164 g_free(html);
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
165 priv->empty = FALSE;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
166
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
167 return TRUE;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
168 }
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
169
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
170 static void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
171 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
172 gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
173 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
174 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
175
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
176 /* 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
177 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
178 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
179
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
180 static void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
181 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
182 gpointer userdata)
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
183 {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
184 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
185
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
186 priv->is_loading = FALSE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
187 g_idle_add((GSourceFunc)process_js_script_queue, webview);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
188 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
189
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
190 static gboolean
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
191 webview_link_clicked(WebKitWebView *webview,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
192 WebKitWebFrame *frame,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
193 WebKitNetworkRequest *request,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
194 WebKitWebNavigationAction *navigation_action,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
195 WebKitWebPolicyDecision *policy_decision,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
196 gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
197 {
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
198 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
199 WebKitWebNavigationReason reason;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
200
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
201 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
202 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
203
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
204 if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
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
205 /* the gtk imhtml way was to create an idle cb, not sure
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
206 * why, so right now just using purple_notify_uri directly */
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
207 purple_notify_uri(NULL, uri);
32800
67649fafdb51 If we handle a navigation request, then we should tell WebKit
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32799
diff changeset
208 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
209 } 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
210 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
211 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
212 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
213
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
214 return TRUE;
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
215 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
216
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
217 /*
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
218 * 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
219 *
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
220 * @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
221 */
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
222 static gboolean
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
223 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
224 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
225 GtkWebViewPriv *priv = data;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
226 GtkAdjustment *adj;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
227 gdouble max_val;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
228 gdouble scroll_val;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
229
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
230 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
231
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
232 adj = priv->vadj;
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
233 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
234 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
235 ((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
236
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
237 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
238 || 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
239 /* 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
240 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
241 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
242 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
243 g_source_remove(priv->scroll_src);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
244 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
245 return FALSE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
246 }
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
247
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
248 /* 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
249 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
250 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
251 }
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
252
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
253 static gboolean
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
254 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
255 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
256 GtkWebViewPriv *priv = data;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
257 GtkAdjustment *adj = priv->vadj;
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
258 gdouble max_val;
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
259
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
260 if (adj) {
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
261 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
262 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
263 }
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
264
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
265 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
266 return FALSE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
267 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
268
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
269 static void
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
270 emit_format_signal(GtkWebView *webview, GtkWebViewButtons buttons)
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
271 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
272 g_object_ref(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
273 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
274 g_object_unref(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
275 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
276
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
277 static void
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
278 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
279 {
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
280 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
281 WebKitDOMDocument *dom;
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
282 WebKitDOMDOMWindow *win;
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
283 WebKitDOMDOMSelection *sel = NULL;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
284 WebKitDOMRange *range = NULL;
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
285
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
286 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
287
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
288 if (priv->edit.wbfo) {
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
289 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
290 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
291 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
292 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
293 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
294 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
295
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
296 priv->edit.block_changed = TRUE;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
297 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
298 priv->edit.block_changed = FALSE;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
299
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
300 if (priv->edit.wbfo) {
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
301 if (range) {
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
302 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
303 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
304 } else {
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
305 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
306 }
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
307 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
308 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
309
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
310 static void
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
311 webview_font_shrink(GtkWebView *webview)
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
312 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
313 gint fontsize;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
314 char *tmp;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
315
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
316 fontsize = gtk_webview_get_current_fontsize(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
317 fontsize = MAX(fontsize - 1, 1);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
318
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
319 tmp = g_strdup_printf("%d", fontsize);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
320 do_formatting(webview, "fontSize", tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
321 g_free(tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
322 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
323
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
324 static void
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
325 webview_font_grow(GtkWebView *webview)
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
326 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
327 gint fontsize;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
328 char *tmp;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
329
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
330 fontsize = gtk_webview_get_current_fontsize(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
331 fontsize = MIN(fontsize + 1, MAX_FONT_SIZE);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
332
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
333 tmp = g_strdup_printf("%d", fontsize);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
334 do_formatting(webview, "fontSize", tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
335 g_free(tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
336 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
337
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
338 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
339 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
340 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
341 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
342 return;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
343
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
344 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
345 do_formatting(webview, "unlink", "");
03c013f8990c Remove links and background colours on format-clear.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33018
diff changeset
346 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
347 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
348
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
349 static void
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
350 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
351 {
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
352 /* 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
353 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
354 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
355
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
356 switch (buttons) {
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
357 case GTK_WEBVIEW_BOLD:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
358 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
359 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
360 case GTK_WEBVIEW_ITALIC:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
361 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
362 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
363 case GTK_WEBVIEW_UNDERLINE:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
364 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
365 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
366 case GTK_WEBVIEW_STRIKE:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
367 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
368 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
369 case GTK_WEBVIEW_SHRINK:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
370 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
371 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
372 case GTK_WEBVIEW_GROW:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
373 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
374 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
375 default:
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
376 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
377 }
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
378 }
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
379
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
380 static void
33028
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
381 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
382 {
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
383 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
384 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
385 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
386 }
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
387
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
388 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
389 * GObject Stuff
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
390 *****************************************************************************/
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
391
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
392 GtkWidget *
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
393 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
394 {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
395 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
396 }
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
397
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
398 static void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
399 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
400 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
401 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
402 gpointer temp;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
403
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
404 while ((temp = g_queue_pop_head(priv->html_queue)))
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
405 g_free(temp);
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
406 g_queue_free(priv->html_queue);
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
407
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
408 while ((temp = g_queue_pop_head(priv->js_queue)))
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
409 g_free(temp);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
410 g_queue_free(priv->js_queue);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
411
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
412 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
413 }
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
414
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
415 static void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
416 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
417 {
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
418 GObjectClass *gobject_class;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
419 GtkBindingSet *binding_set;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
420
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
421 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
422 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
423
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
424 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
425
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
426 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
427 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
428 G_SIGNAL_RUN_FIRST,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439 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
440 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
441 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
442 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
443 G_TYPE_NONE, 0);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
444 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
445 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
446 G_SIGNAL_RUN_FIRST,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
447 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
448 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
449 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
450 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
451 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
452 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
453 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
454 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
455 G_TYPE_NONE, 0);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
456
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
457 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
458 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
459
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
460 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
461
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
462 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
463 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
464 "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
465 GTK_WEBVIEW_BOLD);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
466 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
467 "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
468 GTK_WEBVIEW_ITALIC);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
469 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
470 "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
471 GTK_WEBVIEW_UNDERLINE);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
472 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
473 "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
474 GTK_WEBVIEW_GROW);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
475 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
476 "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
477 GTK_WEBVIEW_GROW);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
478 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
479 "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
480 GTK_WEBVIEW_SHRINK);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
481
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
482 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
483 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
484 "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
485 }
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
486
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
487 static void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
488 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
489 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
490 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
491
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
492 priv->empty = TRUE;
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
493 priv->html_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
494 priv->js_queue = g_queue_new();
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
495
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
496 g_signal_connect(webview, "navigation-policy-decision-requested",
32799
918d0fc9a651 Passing the webview as userdata when the webview is the object
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32797
diff changeset
497 G_CALLBACK(webview_link_clicked), 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
498
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
499 g_signal_connect(webview, "load-started",
32799
918d0fc9a651 Passing the webview as userdata when the webview is the object
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32797
diff changeset
500 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
501
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
502 g_signal_connect(webview, "load-finished",
32799
918d0fc9a651 Passing the webview as userdata when the webview is the object
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32797
diff changeset
503 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
504
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
505 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
506 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
507 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
508
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
509 GType
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
510 gtk_webview_get_type(void)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
511 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
512 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
513 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
514 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
515 sizeof(GtkWebViewClass),
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
516 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
517 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
518 (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
519 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
520 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
521 sizeof(GtkWebView),
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
522 0,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
523 (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
524 NULL
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
525 };
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
526 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
527 "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
528 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
529 return mview_type;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
530 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
531
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
532 /*****************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
533 * Public API functions
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
534 *****************************************************************************/
32793
db876e8e41ac Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32791
diff changeset
535
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
536 gboolean
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
537 gtk_webview_is_empty(GtkWebView *webview)
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
538 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
539 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
540
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
541 g_return_val_if_fail(webview != NULL, TRUE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
542
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
543 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
544 return priv->empty;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
545 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
546
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
547 char *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
548 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
549 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
550 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
551 const char *cur = text;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
552
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
553 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
554 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
555 case '\\':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
556 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
557 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
558 case '\"':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
559 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
560 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
561 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
562 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
563 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
564 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
565 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
566 default:
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
567 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
568 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
569 cur++;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
570 }
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
571
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
572 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
573
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
574 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
575 }
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
576
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
577 void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
578 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
579 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
580 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
581
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
582 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
583
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
584 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
585 g_queue_push_tail(priv->js_queue, g_strdup(script));
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
586 g_idle_add((GSourceFunc)process_js_script_queue, webview);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
587 }
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
588
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
589 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
590 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
591 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
592 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
593
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
594 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
595 "file:///");
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
596 }
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
597
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
598 void
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
599 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
600 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
601 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
602
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
603 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
604 gtk_webview_safe_execute_script(webview,
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
605 "var s = window.getSelection();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
606 "var r = document.createRange();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
607 "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
608 "r.selectNodeContents(n);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
609 "var f = r.extractContents();"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
610 "r.selectNode(n);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
611 "r.insertNode(f);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
612 "n.parentNode.removeChild(n);"
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
613 "s.removeAllRanges();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
614 "s.addRange(r);");
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
615 }
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
616
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
617 void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
618 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
619 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
620 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
621
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
622 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
623
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
624 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
625 g_queue_push_tail(priv->html_queue, g_strdup(html));
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
626 g_idle_add((GSourceFunc)process_html_queue, webview);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
627 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
628
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
629 void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
630 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
631 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
632 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
633
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
634 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
635
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
636 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
637 priv->vadj = vadj;
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
638 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
639
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
640 void
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
641 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
642 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
643 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
644
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
645 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
646
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
647 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
648 if (priv->scroll_time)
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
649 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
650 if (priv->scroll_src)
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
651 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
652 if (smooth) {
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
653 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
654 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
655 } else {
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
656 priv->scroll_time = NULL;
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
657 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
658 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
659 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
660
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
661 void
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
662 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
663 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
664 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
665 GtkAdjustment *vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
666 gdouble scroll_val;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
667
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
668 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
669
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
670 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
671 vadj = priv->vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
672 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
673 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
674
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
675 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
676 }
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
677
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
678 void
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
679 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
680 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
681 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
682 GtkAdjustment *vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
683 gdouble scroll_val;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
684 gdouble page_size;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
685
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
686 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
687
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
688 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
689 vadj = priv->vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
690 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
691 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
692 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
693
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
694 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
695 }
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
696
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
697 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
698 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
699 {
33197
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
700 GtkWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
701 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
702
33197
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
703 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
704 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
705
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
706 if (editable) {
33028
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
707 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
708 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
709 } else {
33028
2a61ad7ca6b6 Apparently, there's an object signal for this.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33025
diff changeset
710 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
711 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
712 NULL);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
713 }
33197
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
714
151a6a5a0521 The default editing flags should enable everything.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33170
diff changeset
715 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
716 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
717
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
718 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
719 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
720 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
721 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
722
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
723 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
724
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
725 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
726 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
727
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
728 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
729
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
730 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
731 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
732 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
733 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
734 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
735 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
736 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
737 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
738 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
739
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
740 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
741
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
742 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
743 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
744 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
745
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
746 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
747 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
748
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
749 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
750 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
751
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
752 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
753 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
754
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
755 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
756 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
757
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
758 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
759 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
760 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
761
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
762 /* 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
763 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
764 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
765 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
766
33025
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
767 gtk_webview_toggle_forecolor(webview,
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
768 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
769
33025
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
770 if (!(flags & PURPLE_CONNECTION_NO_BGCOLOR)) {
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
771 gtk_webview_toggle_backcolor(webview,
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
772 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
773 } else {
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
774 gtk_webview_toggle_backcolor(webview, "");
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
775 }
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
776
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
777 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
778 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
779 else
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
780 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
781 } else {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
782 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
783 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
784 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
785
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
786 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
787 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
788
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
789 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
790 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
791 else
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
792 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
793
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
794 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
795 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
796
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
797 void
33021
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
798 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
799 {
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
800 WebKitWebSettings *settings;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
801
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
802 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
803
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
804 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
805 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
806 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
807 }
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
808
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
809 void
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
810 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
811 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
812 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
813
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
814 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
815
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
816 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
817 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
818 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
819
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
820 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
821 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
822 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
823 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
824 GObject *object;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
825
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
826 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
827
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
828 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
829 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
830 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
831 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
832 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
833 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
834
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
835 gchar *
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
836 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
837 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
838 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
839 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
840 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
841
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
842 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
843
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
844 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
845 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
846 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
847
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
848 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
849 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
850
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
851 gchar *
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
852 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
853 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
854 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
855 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
856 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
857
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
858 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
859
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
860 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
861 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
862 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
863
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
864 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
865 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
866
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
867 gchar *
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
868 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
869 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
870 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
871 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
872 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
873
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
874 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
875
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
876 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
877 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
878 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
879
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
880 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
881 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
882
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
883 gchar *
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
884 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
885 {
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
886 WebKitDOMDocument *dom;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
887 WebKitDOMDOMWindow *win;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
888 WebKitDOMDOMSelection *sel;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
889 WebKitDOMRange *range;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
890
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
891 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
892
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
893 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
894 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
895 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
896 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
897
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
898 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
899 }
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
900
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
901 GtkWebViewButtons
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
902 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
903 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
904 GtkWebViewPriv *priv;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
905
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
906 g_return_val_if_fail(webview != NULL, 0);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
907
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
908 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
909 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
910 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
911
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
912 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
913 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
914 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
915 gboolean *strike)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
916 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
917 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
918
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
919 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
920
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
921 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
922
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
923 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
924 *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
925 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
926 *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
927 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
928 *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
929 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
930 *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
931 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
932
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
933 char *
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
934 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
935 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
936 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
937
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
938 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
939
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
940 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
941 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
942 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
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 char *
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
945 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
946 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
947 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
948
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
949 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
950
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
951 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
952 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
953 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
954
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
955 char *
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
956 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
957 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
958 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
959
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
960 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
961
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
962 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
963 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
964 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
965
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
966 gint
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
967 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
968 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
969 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
970 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
971 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
972
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
973 g_return_val_if_fail(webview != NULL, 0);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
974
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
975 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
976 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
977 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
978 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
979
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
980 return size;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
981 }
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 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
984 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
985 {
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
986 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
987 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
988
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
989 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
990 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
991 {
32813
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
992 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
993
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
994 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
995
32813
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
996 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
997 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
998 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
999 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1000
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1001 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1002 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
1003 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1004 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1005 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
1006 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1007
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1008 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1009 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
1010 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1011 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1012 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
1013 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1014
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1015 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1016 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
1017 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1018 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1019 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
1020 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1021
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1022 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1023 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
1024 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1025 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1026 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
1027 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1028
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1029 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1030 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
1031 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1032 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1033
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1034 do_formatting(webview, "foreColor", color);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1035 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
1036
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1037 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1038 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1039
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1040 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1041 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
1042 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1043 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1044
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1045 do_formatting(webview, "backColor", color);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1046 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
1047
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1048 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1049 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1050
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1051 gboolean
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1052 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
1053 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1054 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1055
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1056 do_formatting(webview, "fontName", face);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1057 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
1058
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1059 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1060 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1061
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1062 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1063 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
1064 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1065 char *tmp;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1066
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1067 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1068
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1069 tmp = g_strdup_printf("%d", size);
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1070 do_formatting(webview, "fontSize", tmp);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1071 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
1072 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
1073 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1074
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1075 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1076 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
1077 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1078 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1079 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
1080 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1081
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1082 void
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1083 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
1084 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1085 g_return_if_fail(webview != NULL);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1086 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
1087 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1088
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1089 void
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1090 gtk_webview_insert_hr(GtkWebView *webview)
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1091 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1092 GtkWebViewPriv *priv;
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1093 WebKitDOMDocument *dom;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1094
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1095 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1096
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1097 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1098 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
1099
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1100 priv->edit.block_changed = TRUE;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1101 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
1102 priv->edit.block_changed = FALSE;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1103 }
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
1104
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1105 void
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1106 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
1107 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1108 GtkWebViewPriv *priv;
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1109 WebKitDOMDocument *dom;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1110 char *link;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1111
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1112 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1113
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1114 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1115 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
1116 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
1117
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1118 priv->edit.block_changed = TRUE;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1119 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
1120 priv->edit.block_changed = FALSE;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1121 g_free(link);
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1122 }
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
1123
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1124 void
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1125 gtk_webview_insert_image(GtkWebView *webview, int id)
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1126 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1127 GtkWebViewPriv *priv;
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1128 WebKitDOMDocument *dom;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1129 char *img;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1130
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1131 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1132
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1133 priv = GTK_WEBVIEW_GET_PRIVATE(webview);
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1134 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
1135 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
1136 id);
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1137
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1138 priv->edit.block_changed = TRUE;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1139 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
1140 priv->edit.block_changed = FALSE;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1141 g_free(img);
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1142 }
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
1143

mercurial