annotate pidgin/gtkwebview.c @ 32440:1809d65d4f92

This strlen seems redundant.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 04 Jan 2012 01:21:28 +0000
parents 5022cf604d6e
children fb8447f6649c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32065
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
1 /*
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
2 * @file gtkwebview.c GTK+ WebKitWebView wrapper class.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
3 * @ingroup pidgin
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
4 */
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
5
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
6 /* pidgin
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
7 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
8 * Pidgin is the legal property of its developers, whose names are too numerous
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
10 * source distribution.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
11 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
12 * This program is free software; you can redistribute it and/or modify
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
13 * it under the terms of the GNU General Public License as published by
32065
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
15 * (at your option) any later version.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
16 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
17 * This program is distributed in the hope that it will be useful,
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
20 * GNU General Public License for more details.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
21 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
22 * You should have received a copy of the GNU General Public License
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
23 * along with this program; if not, write to the Free Software
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
25 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
26 */
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
27
32437
5dea9a26078d Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32421
diff changeset
28 #include "internal.h"
5dea9a26078d Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32421
diff changeset
29 #include "pidgin.h"
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
30
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
31 #include "gtkwebview.h"
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
32
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
33 static WebKitWebViewClass *parent_class = NULL;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
34
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
35 struct GtkWebViewPriv {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
36 GHashTable *images; /**< a map from id to temporary file for the image */
32199
68fe7b5211a7 Mark webkit-related missing functionality with "TODO WEBKIT" instead of
Mark Doliner <mark@kingant.net>
parents: 32143
diff changeset
37 gboolean empty; /**< whether anything has been appended **/
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
38
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
39 /* JS execute queue */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
40 GQueue *js_queue;
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
41 gboolean is_loading;
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
42 GtkAdjustment *vadj;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
43 guint scroll_src;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
44 GTimer *scroll_time;
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
45 };
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
46
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
47 GtkWidget *
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
48 gtk_webview_new(void)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
49 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
50 GtkWebView* ret = GTK_WEBVIEW(g_object_new(gtk_webview_get_type(), NULL));
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
51 return GTK_WIDGET(ret);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
52 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
53
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
54 static const char *
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
55 get_image_src_from_id(GtkWebView* view, int id)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
56 {
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
57 char *src;
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
58 PurpleStoredImage *img;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
59
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
60 if (view->priv->images) {
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
61 /* Check for already loaded image */
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
62 src = (char *)g_hash_table_lookup(view->priv->images, GINT_TO_POINTER(id));
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
63 if (src)
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
64 return src;
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
65 } else {
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
66 view->priv->images = g_hash_table_new_full(g_direct_hash, g_direct_equal,
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
67 NULL, g_free);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
68 }
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
69
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
70 /* Find image in store */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
71 img = purple_imgstore_find_by_id(id);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
72
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
73 src = (char *)purple_imgstore_get_filename(img);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
74 if (src) {
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
75 src = g_strdup_printf("file://%s", src);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
76 } else {
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
77 char *tmp;
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
78 tmp = purple_base64_encode(purple_imgstore_get_data(img),
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
79 purple_imgstore_get_size(img));
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
80 src = g_strdup_printf("data:base64,%s", tmp);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
81 g_free(tmp);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
82 }
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
83
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
84 g_hash_table_insert(view->priv->images, GINT_TO_POINTER(id), src);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
85
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
86 return src;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
87 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
88
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
89 /*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
90 * Replace all <img id=""> tags with <img src="">. I hoped to never
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
91 * write any HTML parsing code, but I'm forced to do this, until
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
92 * purple changes the way it works.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
93 */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
94 static char *
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
95 replace_img_id_with_src(GtkWebView *view, const char *html)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
96 {
32440
1809d65d4f92 This strlen seems redundant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32439
diff changeset
97 GString *buffer = g_string_new(NULL);
1809d65d4f92 This strlen seems redundant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32439
diff changeset
98 const char *cur = html;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
99 char *id;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
100 int nid;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
101
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
102 while (*cur) {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
103 const char *img = strstr(cur, "<img");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
104 if (!img) {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
105 g_string_append(buffer, cur);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
106 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
107 } else
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
108 g_string_append_len(buffer, cur, img - cur);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
109
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
110 cur = strstr(img, "/>");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
111 if (!cur)
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
112 cur = strstr(img, ">");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
113
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
114 if (!cur) { /* invalid html? */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
115 g_string_printf(buffer, "%s", html);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
116 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
117 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
118
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
119 if (strstr(img, "src=") || !strstr(img, "id=")) {
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
120 g_string_printf(buffer, "%s", html);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
121 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
122 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
123
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
124 /*
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
125 * if this is valid HTML, then I can be sure that it
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
126 * has an id= and does not have an src=, since
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
127 * '=' cannot appear in parameters.
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
128 */
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
129
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
130 id = strstr(img, "id=") + 3;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
131
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
132 /* *id can't be \0, since a ">" appears after this */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
133 if (isdigit(*id))
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
134 nid = atoi(id);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
135 else
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
136 nid = atoi(id + 1);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
137
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
138 /* let's dump this, tag and then dump the src information */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
139 g_string_append_len(buffer, img, cur - img);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
140
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
141 g_string_append_printf(buffer, " src='%s' ", get_image_src_from_id(view, nid));
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
142 }
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
143
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
144 return g_string_free(buffer, FALSE);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
145 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
146
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
147 static void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
148 gtk_webview_finalize(GObject *view)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
149 {
32081
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32080
diff changeset
150 gpointer temp;
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32080
diff changeset
151
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
152 while ((temp = g_queue_pop_head(GTK_WEBVIEW(view)->priv->js_queue)))
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
153 g_free(temp);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
154 g_queue_free(GTK_WEBVIEW(view)->priv->js_queue);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
155
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
156 if (GTK_WEBVIEW(view)->priv->images)
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
157 g_hash_table_unref(GTK_WEBVIEW(view)->priv->images);
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
158 g_free(GTK_WEBVIEW(view)->priv);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
159 G_OBJECT_CLASS(parent_class)->finalize(G_OBJECT(view));
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
160 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
161
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
162 static void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
163 gtk_webview_class_init(GtkWebViewClass *klass, gpointer userdata)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
164 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
165 parent_class = g_type_class_ref(webkit_web_view_get_type());
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
166 G_OBJECT_CLASS(klass)->finalize = gtk_webview_finalize;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
167 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
168
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
169 static gboolean
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
170 webview_link_clicked(WebKitWebView *view,
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
171 WebKitWebFrame *frame,
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
172 WebKitNetworkRequest *request,
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
173 WebKitWebNavigationAction *navigation_action,
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
174 WebKitWebPolicyDecision *policy_decision)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
175 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
176 const gchar *uri;
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
177 WebKitWebNavigationReason reason;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
178
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
179 uri = webkit_network_request_get_uri(request);
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
180 reason = webkit_web_navigation_action_get_reason(navigation_action);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
181
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
182 if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
183 /* the gtk imhtml way was to create an idle cb, not sure
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
184 * why, so right now just using purple_notify_uri directly */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
185 purple_notify_uri(NULL, uri);
32143
e7eba7a6a989 Let webview manage the navigation ONLY if the reason is the user clicked a link.
masca@cpw.pidgin.im
parents: 32133
diff changeset
186 } else
e7eba7a6a989 Let webview manage the navigation ONLY if the reason is the user clicked a link.
masca@cpw.pidgin.im
parents: 32133
diff changeset
187 webkit_web_policy_decision_use(policy_decision);
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
188
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
189 return TRUE;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
190 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
191
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
192 static gboolean
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
193 process_js_script_queue(GtkWebView *view)
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
194 {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
195 char *script;
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
196 if (view->priv->is_loading)
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
197 return FALSE; /* we will be called when loaded */
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
198 if (!view->priv->js_queue || g_queue_is_empty(view->priv->js_queue))
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
199 return FALSE; /* nothing to do! */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
200
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
201 script = g_queue_pop_head(view->priv->js_queue);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
202 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(view), script);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
203 g_free(script);
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
204
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
205 return TRUE; /* there may be more for now */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
206 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
207
32122
1795afae76f2 Fix more white spaces issues.
masca@cpw.pidgin.im
parents: 32120
diff changeset
208 static void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
209 webview_load_started(WebKitWebView *view,
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
210 WebKitWebFrame *frame,
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
211 gpointer userdata)
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
212 {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
213 /* is there a better way to test for is_loading? */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
214 GTK_WEBVIEW(view)->priv->is_loading = TRUE;
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
215 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
216
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
217 static void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
218 webview_load_finished(WebKitWebView *view,
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
219 WebKitWebFrame *frame,
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
220 gpointer userdata)
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
221 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
222 GTK_WEBVIEW(view)->priv->is_loading = FALSE;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
223 g_idle_add((GSourceFunc)process_js_script_queue, view);
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
224 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
225
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
226 void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
227 gtk_webview_safe_execute_script(GtkWebView *view, const char *script)
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
228 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
229 g_queue_push_tail(view->priv->js_queue, g_strdup(script));
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
230 g_idle_add((GSourceFunc)process_js_script_queue, view);
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
231 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
232
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
233 static void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
234 gtk_webview_init(GtkWebView *view, gpointer userdata)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
235 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
236 view->priv = g_new0(struct GtkWebViewPriv, 1);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
237 g_signal_connect(view, "navigation-policy-decision-requested",
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
238 G_CALLBACK(webview_link_clicked),
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
239 view);
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
240
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
241 g_signal_connect(view, "load-started",
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
242 G_CALLBACK(webview_load_started),
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
243 view);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
244
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
245 g_signal_connect(view, "load-finished",
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
246 G_CALLBACK(webview_load_finished),
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
247 view);
32122
1795afae76f2 Fix more white spaces issues.
masca@cpw.pidgin.im
parents: 32120
diff changeset
248
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
249 view->priv->empty = TRUE;
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
250 view->priv->js_queue = g_queue_new();
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
251 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
252
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
253
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
254 void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
255 gtk_webview_load_html_string_with_imgstore(GtkWebView *view, const char *html)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
256 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
257 char *html_imged;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
258
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
259 if (view->priv->images) {
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
260 g_hash_table_unref(view->priv->images);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
261 view->priv->images = NULL;
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
262 }
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
263
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
264 html_imged = replace_img_id_with_src(view, html);
32421
3e82cdc85a45 webkit_web_view_load_html_string is superceded by webkit_web_view_load_string as of 1.1.1 (which we require)
Daniel Atallah <daniel.atallah@gmail.com>
parents: 32419
diff changeset
265 webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), html_imged, NULL, NULL, "file:///");
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
266 g_free(html_imged);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
267 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
268
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
269 char *
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
270 gtk_webview_quote_js_string(const char *text)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
271 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
272 GString *str = g_string_new("\"");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
273 const char *cur = text;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
274
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
275 while (cur && *cur) {
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
276 switch (*cur) {
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
277 case '\\':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
278 g_string_append(str, "\\\\");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
279 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
280 case '\"':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
281 g_string_append(str, "\\\"");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
282 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
283 case '\r':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
284 g_string_append(str, "<br/>");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
285 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
286 case '\n':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
287 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
288 default:
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
289 g_string_append_c(str, *cur);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
290 }
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
291 cur++;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
292 }
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
293 g_string_append_c(str, '"');
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
294 return g_string_free(str, FALSE);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
295 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
296
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
297 void
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
298 gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj)
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
299 {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
300 webview->priv->vadj = vadj;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
301 }
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
302
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
303 /* this is a "hack", my plan is to eventually handle this
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
304 * correctly using a signals and a plugin: the plugin will have
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
305 * the information as to what javascript function to call. It seems
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
306 * wrong to hardcode that here.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
307 */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
308 void
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
309 gtk_webview_append_html(GtkWebView *view, const char *html)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
310 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
311 char *escaped = gtk_webview_quote_js_string(html);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
312 char *script = g_strdup_printf("document.write(%s)", escaped);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
313 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(view), script);
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
314 view->priv->empty = FALSE;
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
315 gtk_webview_scroll_to_end(view, TRUE);
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
316 g_free(script);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
317 g_free(escaped);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
318 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
319
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
320 gboolean
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
321 gtk_webview_is_empty(GtkWebView *view)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
322 {
32080
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32066
diff changeset
323 return view->priv->empty;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
324 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
325
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
326 #define MAX_SCROLL_TIME 0.4 /* seconds */
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
327 #define SCROLL_DELAY 33 /* milliseconds */
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
328
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
329 /*
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
330 * Smoothly scroll a WebView.
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
331 *
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
332 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom.
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
333 */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
334 static gboolean
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
335 smooth_scroll_cb(gpointer data)
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
336 {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
337 struct GtkWebViewPriv *priv = data;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
338 GtkAdjustment *adj = priv->vadj;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
339 gdouble max_val = adj->upper - adj->page_size;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
340 gdouble scroll_val = gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
341
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
342 g_return_val_if_fail(priv->scroll_time != NULL, FALSE);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
343
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
344 if (g_timer_elapsed(priv->scroll_time, NULL) > MAX_SCROLL_TIME || scroll_val >= max_val) {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
345 /* time's up. jump to the end and kill the timer */
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
346 gtk_adjustment_set_value(adj, max_val);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
347 g_timer_destroy(priv->scroll_time);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
348 priv->scroll_time = NULL;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
349 g_source_remove(priv->scroll_src);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
350 priv->scroll_src = 0;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
351 return FALSE;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
352 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
353
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
354 /* scroll by 1/3rd the remaining distance */
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
355 gtk_adjustment_set_value(adj, scroll_val);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
356 return TRUE;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
357 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
358
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
359 static gboolean
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
360 scroll_idle_cb(gpointer data)
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
361 {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
362 struct GtkWebViewPriv *priv = data;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
363 GtkAdjustment *adj = priv->vadj;
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
364 if (adj) {
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
365 gtk_adjustment_set_value(adj, adj->upper - adj->page_size);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
366 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
367 priv->scroll_src = 0;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
368 return FALSE;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
369 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
370
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
371 void
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
372 gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth)
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
373 {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
374 struct GtkWebViewPriv *priv = webview->priv;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
375 if (priv->scroll_time)
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
376 g_timer_destroy(priv->scroll_time);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
377 if (priv->scroll_src)
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
378 g_source_remove(priv->scroll_src);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
379 if(smooth) {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
380 priv->scroll_time = g_timer_new();
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
381 priv->scroll_src = g_timeout_add_full(G_PRIORITY_LOW, SCROLL_DELAY, smooth_scroll_cb, priv, NULL);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
382 } else {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
383 priv->scroll_time = NULL;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
384 priv->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, priv, NULL);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
385 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
386 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
387
32419
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
388 void gtk_webview_page_up(GtkWebView *webview)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
389 {
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
390 GtkAdjustment *vadj = webview->priv->vadj;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
391 gdouble scroll_val;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
392
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
393 #if GTK_CHECK_VERSION(2,14,0)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
394 scroll_val = gtk_adjustment_get_value(vadj) - gtk_adjustment_get_page_size(vadj);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
395 scroll_val = MAX(scroll_val, gtk_adjustment_get_lower(vadj));
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
396 #else
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
397 scroll_val = gtk_adjustment_get_value(vadj) - vadj->page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
398 scroll_val = MAX(scroll_val, vadj->lower);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
399 #endif
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
400
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
401 gtk_adjustment_set_value(vadj, scroll_val);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
402 }
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
403
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
404 void gtk_webview_page_down(GtkWebView *webview)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
405 {
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
406 GtkAdjustment *vadj = webview->priv->vadj;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
407 gdouble scroll_val;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
408 gdouble page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
409
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
410 #if GTK_CHECK_VERSION(2,14,0)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
411 page_size = gtk_adjustment_get_page_size(vadj);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
412 scroll_val = gtk_adjustment_get_value(vadj) + page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
413 scroll_val = MIN(scroll_val, gtk_adjustment_get_upper(vadj) - page_size);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
414 #else
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
415 page_size = vadj->page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
416 scroll_val = gtk_adjustment_get_value(vadj) + page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
417 scroll_val = MIN(scroll_val, vadj->upper - page_size);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
418 #endif
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
419
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
420 gtk_adjustment_set_value(vadj, scroll_val);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
421 }
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
422
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
423 GType
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
424 gtk_webview_get_type(void)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
425 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
426 static GType mview_type = 0;
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
427 if (G_UNLIKELY(mview_type == 0)) {
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
428 static const GTypeInfo mview_info = {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
429 sizeof(GtkWebViewClass),
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
430 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
431 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
432 (GClassInitFunc) gtk_webview_class_init,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
433 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
434 NULL,
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
435 sizeof(GtkWebView),
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
436 0,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
437 (GInstanceInitFunc) gtk_webview_init,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
438 NULL
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
439 };
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
440 mview_type = g_type_register_static(webkit_web_view_get_type(),
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
441 "GtkWebView", &mview_info, 0);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
442 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
443 return mview_type;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
444 }
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
445