annotate pidgin/gtkwebview.c @ 32437:5dea9a26078d

Use internal.h for less (conditional) #includes.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 04 Jan 2012 00:14:51 +0000
parents 3e82cdc85a45
children 5022cf604d6e
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
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
54 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
55 get_image_filename_from_id(GtkWebView* view, int id)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
56 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
57 char *filename = NULL;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
58 FILE *file;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
59 PurpleStoredImage* img;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
60
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
61 if (!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
62 view->priv->images = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
63
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
64 filename = (char *)g_hash_table_lookup(view->priv->images, GINT_TO_POINTER(id));
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
65 if (filename)
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
66 return filename;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
67
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
68 /* else get from img 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
69 file = purple_mkstemp(&filename, TRUE);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
70
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
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
73 fwrite(purple_imgstore_get_data(img), purple_imgstore_get_size(img), 1, file);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
74 g_hash_table_insert(view->priv->images, GINT_TO_POINTER(id), filename);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
75 fclose(file);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
76 return filename;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
77 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
78
32122
1795afae76f2 Fix more white spaces issues.
masca@cpw.pidgin.im
parents: 32120
diff changeset
79 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
80 clear_single_image(gpointer key, gpointer value, gpointer userdata)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
81 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
82 g_unlink((char *)value);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
83 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
84
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
85 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
86 clear_images(GtkWebView *view)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
87 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
88 if (!view->priv->images)
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
89 return;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
90 g_hash_table_foreach(view->priv->images, clear_single_image, NULL);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
91 g_hash_table_unref(view->priv->images);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
92 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
93
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
94 /*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
95 * 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
96 * 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
97 * purple changes the way it works.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
98 */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
99 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
100 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
101 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
102 GString *buffer = g_string_sized_new(strlen(html));
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
103 const char* cur = html;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
104 char *id;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
105 int nid;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
106
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
107 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
108 const char *img = strstr(cur, "<img");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
109 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
110 g_string_append(buffer, cur);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
111 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
112 } 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
113 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
114
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 cur = strstr(img, "/>");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
116 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
117 cur = strstr(img, ">");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
118
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
119 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
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
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
124 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
125 g_string_printf(buffer, "%s", html);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
126 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
127 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
128
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
129 /*
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
130 * if this is valid HTML, then I can be sure that it
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
131 * has an id= and does not have an src=, since
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
132 * '=' cannot appear in parameters.
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
133 */
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
134
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
135 id = strstr(img, "id=") + 3;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
136
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
137 /* *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
138 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
139 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
140 else
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
141 nid = atoi(id + 1);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
142
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
143 /* 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
144 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
145
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
146 g_string_append_printf(buffer, " src='file://%s' ", get_image_filename_from_id(view, nid));
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
147 }
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
148
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
149 return g_string_free(buffer, FALSE);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
150 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
151
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
152 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
153 gtk_webview_finalize(GObject *view)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
154 {
32081
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32080
diff changeset
155 gpointer temp;
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32080
diff changeset
156
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
157 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
158 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
159 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
160
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
161 clear_images(GTK_WEBVIEW(view));
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
162 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
163 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
164 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
165
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
166 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
167 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
168 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
169 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
170 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
171 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
172
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
173 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
174 webview_link_clicked(WebKitWebView *view,
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
175 WebKitWebFrame *frame,
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
176 WebKitNetworkRequest *request,
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
177 WebKitWebNavigationAction *navigation_action,
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
178 WebKitWebPolicyDecision *policy_decision)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
179 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
180 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
181 WebKitWebNavigationReason reason;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
182
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
183 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
184 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
185
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
186 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
187 /* 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
188 * 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
189 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
190 } 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
191 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
192
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
193 return TRUE;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
194 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
195
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
196 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
197 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
198 {
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 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
200 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
201 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
202 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
203 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
204
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
205 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
206 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
207 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
208
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
209 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
210 }
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
32122
1795afae76f2 Fix more white spaces issues.
masca@cpw.pidgin.im
parents: 32120
diff changeset
212 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
213 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
214 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
215 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
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 /* 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
218 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
219 }
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
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 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
222 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
223 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
224 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
225 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
226 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
227 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
228 }
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
229
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
230 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
231 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
232 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
233 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
234 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
235 }
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
236
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
237 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
238 gtk_webview_init(GtkWebView *view, gpointer userdata)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
239 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
240 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
241 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
242 G_CALLBACK(webview_link_clicked),
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
243 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
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-started",
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_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
247 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
248
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
249 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
250 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
251 view);
32122
1795afae76f2 Fix more white spaces issues.
masca@cpw.pidgin.im
parents: 32120
diff changeset
252
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
253 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
254 view->priv->js_queue = g_queue_new();
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
255 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
256
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
257
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
258 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
259 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
260 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
261 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
262
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
263 clear_images(view);
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