pidgin/gtkwebview.c

Sun, 08 Jul 2012 23:49:44 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 08 Jul 2012 23:49:44 -0400
changeset 33084
1da63a04d506
parent 33083
e96acbe0e928
child 33097
acd0d7217593
child 33160
4ddceddab409
permissions
-rw-r--r--

Make sure the selection anchor is removed.

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

mercurial