pidgin/gtkwebview.c

Wed, 16 Apr 2014 22:40:44 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Wed, 16 Apr 2014 22:40:44 +0200
changeset 35859
3d157ce203ed
parent 35841
56e1ef289cbb
child 35911
e173a6f9a021
permissions
-rw-r--r--

cross-win32: make libpidgin and libfinch shared, disable hacky libpidgin loading code. Pidgin runs now

32445
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
1 /* pidgin
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
2 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
3 * Pidgin is the legal property of its developers, whose names are too numerous
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
5 * source distribution.
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
6 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
7 * This program is free software; you can redistribute it and/or modify
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
8 * it under the terms of the GNU General Public License as published by
32445
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
10 * (at your option) any later version.
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
11 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
12 * This program is distributed in the hope that it will be useful,
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
15 * GNU General Public License for more details.
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
16 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
17 * You should have received a copy of the GNU General Public License
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
18 * along with this program; if not, write to the Free Software
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
20 *
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
21 */
a14d94db0df0 cleaning up code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32441
diff changeset
22
32791
a2dc8d3ee1b8 Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32774
diff changeset
23 #include "internal.h"
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
24 #include "debug.h"
35194
9a0203562da5 pidgin: Fix build and warnings with glib 2.24
Ankit Vani <a@nevitus.org>
parents: 35129
diff changeset
25 #include "glibcompat.h"
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
26 #include "image-store.h"
32791
a2dc8d3ee1b8 Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32774
diff changeset
27 #include "pidgin.h"
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
28 #include "pidginstock.h"
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
29
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
30 #include <gdk/gdkkeysyms.h>
35194
9a0203562da5 pidgin: Fix build and warnings with glib 2.24
Ankit Vani <a@nevitus.org>
parents: 35129
diff changeset
31
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
32 #include "gtkutils.h"
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
33 #include "gtksmiley-manager.h"
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
34 #include "gtkwebview.h"
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
35 #include "gtkwebviewtoolbar.h"
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
36
34490
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
37 #include "gtkinternal.h"
33170
ce4447562d64 Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33167
diff changeset
38 #include "gtk3compat.h"
ce4447562d64 Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33167
diff changeset
39
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
40 #define MAX_FONT_SIZE 7
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
41 #define MAX_SCROLL_TIME 0.4 /* seconds */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
42 #define SCROLL_DELAY 33 /* milliseconds */
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
43 #define PIDGIN_WEBVIEW_MAX_PROCESS_TIME 100000 /* microseconds */
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
44
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
45 #define PIDGIN_WEBVIEW_GET_PRIVATE(obj) \
35506
4252b2882889 Fix some remaining GTK_* macros as Elliott noticed
Ankit Vani <a@nevitus.org>
parents: 35500
diff changeset
46 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PIDGIN_TYPE_WEBVIEW, PidginWebViewPriv))
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
47
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
48 enum {
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
49 LOAD_HTML,
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
50 LOAD_JS
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
51 };
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
52
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
53 enum {
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
54 BUTTONS_UPDATE,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
55 TOGGLE_FORMAT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
56 CLEAR_FORMAT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
57 UPDATE_FORMAT,
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
58 CHANGED,
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
59 HTML_APPENDED,
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
60 LAST_SIGNAL
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
61 };
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
62 static guint signals[LAST_SIGNAL] = { 0 };
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
63
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
64 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
65 * Structs
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
66 *****************************************************************************/
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
67
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
68 typedef struct {
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
69 WebKitWebInspector *inspector;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
70 WebKitDOMNode *node;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
71 } PidginWebViewInspectData;
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
72
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
73 typedef struct {
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
74 WebKitWebView *webview;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
75 gunichar ch;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
76 } PidginWebViewInsertData;
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
77
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
78 typedef struct {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
79 const char *label;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
80 gunichar ch;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
81 } GtkUnicodeMenuEntry;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
82
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
83 typedef struct {
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
84 char *name;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
85 int length;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
86
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
87 gboolean (*activate)(PidginWebView *webview, const char *uri);
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
88 gboolean (*context_menu)(PidginWebView *webview, WebKitDOMHTMLAnchorElement *link, GtkWidget *menu);
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
89 } PidginWebViewProtocol;
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
90
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
91 typedef struct _PidginWebViewPriv {
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
92 /* Processing queues */
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
93 gboolean is_loading;
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
94 GQueue *load_queue;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
95 guint loader;
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
96
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
97 /* Scroll adjustments */
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
98 GtkAdjustment *vadj;
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
99 gboolean autoscroll;
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
100 guint scroll_src;
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
101 GTimer *scroll_time;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
102
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
103 /* Format options */
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
104 PidginWebViewButtons format_functions;
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
105 PidginWebViewToolbar *toolbar;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
106 struct {
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
107 gboolean wbfo:1; /* Whole buffer formatting only. */
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
108 gboolean block_changed:1;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
109 } edit;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
110
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
111 /* WebKit inspector */
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
112 WebKitWebView *inspector_view;
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
113 GtkWindow *inspector_win;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
114 } PidginWebViewPriv;
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
115
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
116 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
117 * Globals
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
118 *****************************************************************************/
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
119
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
120 static WebKitWebViewClass *parent_class = NULL;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
121
35796
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
122 static GRegex *smileys_re = NULL;
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
123 static GRegex *empty_html_re = NULL;
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
124
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
125 /* Resources cache.
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
126 *
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
127 * It's global, because gtkwebkit calls "resource-load-finished" only once
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
128 * for each static resource.
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
129 */
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
130 static GHashTable *globally_loaded_images = NULL;
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
131 guint globally_loaded_images_refcnt = 0;
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
132
35671
d1cc97d667a2 Box PidginSmiley and PidginWebViewSmiley
Ankit Vani <a@nevitus.org>
parents: 35648
diff changeset
133
33256
2bf06f291ff7 Add some smiley stuff to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33254
diff changeset
134 /******************************************************************************
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
135 * Helpers
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
136 *****************************************************************************/
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
137
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
138 static void
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
139 webview_resource_loading(WebKitWebView *webview,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
140 WebKitWebFrame *frame,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
141 WebKitWebResource *resource,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
142 WebKitNetworkRequest *request,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
143 WebKitNetworkResponse *response,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
144 gpointer user_data)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
145 {
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
146 const gchar *uri;
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
147 PurpleImage *img = NULL;
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
148 const gchar *path;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
149
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
150 uri = webkit_network_request_get_uri(request);
35831
86b7a6d3d267 PurpleImage: use purple_image_store_get_from_uri where possible
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35830
diff changeset
151 if ((img = purple_image_store_get_from_uri(uri)) != NULL) {
86b7a6d3d267 PurpleImage: use purple_image_store_get_from_uri where possible
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35830
diff changeset
152 /* noop */
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
153 } else if (purple_str_has_prefix(uri, PURPLE_IMAGE_STORE_STOCK_PROTOCOL)) {
34490
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
154 gchar *p_uri, *found;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
155 const gchar *domain, *stock_name;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
156
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
157 uri += sizeof(PURPLE_IMAGE_STORE_STOCK_PROTOCOL) - 1;
34490
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
158
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
159 p_uri = g_strdup(uri);
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
160 found = strchr(p_uri, '/');
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
161 if (!found) {
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
162 purple_debug_warning("webview", "Invalid purple stock "
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
163 "image uri: %s", uri);
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
164 return;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
165 }
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
166
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
167 found[0] = '\0';
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
168 domain = p_uri;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
169 stock_name = found + 1;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
170
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
171 if (g_strcmp0(domain, "e2ee") == 0) {
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
172 img = _pidgin_e2ee_stock_icon_get(stock_name);
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
173 if (!img)
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
174 return;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
175 } else {
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
176 purple_debug_warning("webview", "Invalid purple stock "
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
177 "image domain: %s", domain);
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
178 return;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
179 }
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
180 } else
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
181 return;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
182
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
183 if (img != NULL) {
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
184 path = purple_image_get_path(img);
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
185 if (path) {
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
186 gchar *uri = g_filename_to_uri(path, NULL, NULL);
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
187 webkit_network_request_set_uri(request, uri);
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
188 g_free(uri);
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
189 } else {
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
190 gchar *b64, *src;
34490
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
191 const gchar *type;
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
192
4825e8b34919 E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
193 b64 = purple_base64_encode(
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
194 purple_image_get_data(img),
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
195 purple_image_get_size(img));
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
196 type = purple_image_get_mimetype(img);
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
197 src = g_strdup_printf("data:%s;base64,%s", type, b64);
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
198 g_free(b64);
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
199 webkit_network_request_set_uri(request, src);
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
200 g_free(src);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
201 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
202 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
203 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
204
33535
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
205 static void
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
206 webview_resource_loaded(WebKitWebView *web_view, WebKitWebFrame *web_frame,
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
207 WebKitWebResource *web_resource, gpointer user_data)
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
208 {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
209 const gchar *uri;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
210 GString *data;
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
211 PurpleImage *image = NULL;
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
212
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
213 if (!purple_str_has_caseprefix(
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
214 webkit_web_resource_get_mime_type(web_resource), "image/"))
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
215 {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
216 return;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
217 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
218
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
219 uri = webkit_web_resource_get_uri(web_resource);
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
220 if (g_hash_table_lookup(globally_loaded_images, uri))
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
221 return;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
222
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
223 data = webkit_web_resource_get_data(web_resource);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
224 if (data->len == 0)
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
225 return;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
226
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
227 image = purple_image_store_get_from_uri(uri);
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
228 if (image) {
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
229 g_object_ref(image);
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
230 } else {
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
231 image = purple_image_new_from_data(
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
232 g_memdup(data->str, data->len), data->len);
35841
56e1ef289cbb Webkit: preserve file names for inline images and smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35831
diff changeset
233 if (purple_str_has_prefix(uri, "file:"))
56e1ef289cbb Webkit: preserve file names for inline images and smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35831
diff changeset
234 purple_image_set_friendly_filename(image, uri);
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
235 g_return_if_fail(image != NULL);
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
236 }
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
237
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
238 g_hash_table_insert(globally_loaded_images, g_strdup(uri), image);
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
239 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
240
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
241 static PurpleImage *
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
242 webview_resource_get_loaded(WebKitWebView *web_view, const gchar *uri)
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
243 {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
244 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(web_view);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
245
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
246 g_return_val_if_fail(priv != NULL, NULL);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
247
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
248 return g_hash_table_lookup(globally_loaded_images, uri);
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
249 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
250
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
251 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
252 process_load_queue_element(PidginWebView *webview)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
253 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
254 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
255 int type;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
256 char *str;
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
257 WebKitDOMDocument *doc;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
258 WebKitDOMHTMLElement *body;
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
259 WebKitDOMNode *start, *end;
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
260 WebKitDOMRange *range;
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
261 gboolean require_scroll = FALSE;
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
262
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
263 type = GPOINTER_TO_INT(g_queue_pop_head(priv->load_queue));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
264 str = g_queue_pop_head(priv->load_queue);
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
265
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
266 switch (type) {
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
267 case LOAD_HTML:
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
268 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
269 body = webkit_dom_document_get_body(doc);
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
270 start = webkit_dom_node_get_last_child(WEBKIT_DOM_NODE(body));
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
271
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
272 if (priv->autoscroll) {
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
273 require_scroll = (gtk_adjustment_get_value(priv->vadj)
33253
716af5e03402 Tweak autoscrolling limits to get filtered debug window to work.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33250
diff changeset
274 >= (gtk_adjustment_get_upper(priv->vadj) -
716af5e03402 Tweak autoscrolling limits to get filtered debug window to work.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33250
diff changeset
275 1.5*gtk_adjustment_get_page_size(priv->vadj)));
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
276 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
277
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
278 webkit_dom_html_element_insert_adjacent_html(body, "beforeend",
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
279 str, NULL);
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
280
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
281 range = webkit_dom_document_create_range(doc);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
282 if (start) {
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
283 end = webkit_dom_node_get_last_child(WEBKIT_DOM_NODE(body));
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
284 webkit_dom_range_set_start_after(range,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
285 WEBKIT_DOM_NODE(start),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
286 NULL);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
287 webkit_dom_range_set_end_after(range,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
288 WEBKIT_DOM_NODE(end),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
289 NULL);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
290 } else {
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
291 webkit_dom_range_select_node_contents(range,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
292 WEBKIT_DOM_NODE(body),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
293 NULL);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
294 }
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
295
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
296 if (require_scroll) {
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
297 if (start)
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
298 webkit_dom_element_scroll_into_view(WEBKIT_DOM_ELEMENT(start),
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
299 TRUE);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
300 else
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
301 webkit_dom_element_scroll_into_view(WEBKIT_DOM_ELEMENT(body),
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
302 TRUE);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
303 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
304
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
305 g_signal_emit(webview, signals[HTML_APPENDED], 0, range);
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
306
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
307 break;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
308
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
309 case LOAD_JS:
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
310 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(webview), str);
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
311 break;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
312
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
313 default:
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
314 purple_debug_error("webview",
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
315 "Got unknown loading queue type: %d\n", type);
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
316 break;
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
317 }
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
318
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
319 g_free(str);
33535
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
320 }
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
321
33535
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
322 static gboolean
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
323 process_load_queue(PidginWebView *webview)
33535
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
324 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
325 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33535
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
326 gint64 start_time;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
327
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
328 if (priv->is_loading) {
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
329 priv->loader = 0;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
330 return FALSE;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
331 }
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
332 if (!priv->load_queue || g_queue_is_empty(priv->load_queue)) {
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
333 priv->loader = 0;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
334 return FALSE;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
335 }
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
336
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
337 start_time = g_get_monotonic_time();
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
338 while (!g_queue_is_empty(priv->load_queue)) {
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
339 process_load_queue_element(webview);
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
340 if (g_get_monotonic_time() - start_time >
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
341 PIDGIN_WEBVIEW_MAX_PROCESS_TIME)
33535
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
342 break;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
343 }
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
344
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
345 if (g_queue_is_empty(priv->load_queue)) {
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
346 priv->loader = 0;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
347 return FALSE;
e03ae42cf793 Faster webkit webview - process elements from queue until timeout is hit
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33500
diff changeset
348 }
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
349 return TRUE;
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
350 }
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
351
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
352 static void
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
353 webview_load_started(WebKitWebView *webview, WebKitWebFrame *frame,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
354 gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
355 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
356 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
357
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
358 /* is there a better way to test for is_loading? */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
359 priv->is_loading = TRUE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
360 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
361
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
362 static void
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
363 webview_load_finished(WebKitWebView *webview, WebKitWebFrame *frame,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
364 gpointer userdata)
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
365 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
366 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
367
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
368 priv->is_loading = FALSE;
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
369 if (priv->loader == 0)
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
370 priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
371 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
372
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
373 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
374 webview_inspector_inspect_element(GtkWidget *item, PidginWebViewInspectData *data)
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
375 {
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
376 webkit_web_inspector_inspect_node(data->inspector, data->node);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
377 }
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
378
34464
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
379 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
380 webview_inspector_destroy(GtkWindow *window, PidginWebViewPriv *priv)
34464
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
381 {
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
382 g_return_if_fail(priv->inspector_win == window);
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
383
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
384 priv->inspector_win = NULL;
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
385 priv->inspector_view = NULL;
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
386 }
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
387
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
388 static WebKitWebView *
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
389 webview_inspector_create(WebKitWebInspector *inspector,
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
390 WebKitWebView *webview, gpointer _unused)
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
391 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
392 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
393
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
394 if (priv->inspector_view != NULL)
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
395 return priv->inspector_view;
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
396
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
397 priv->inspector_win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
398 gtk_window_set_title(priv->inspector_win, _("WebKit inspector"));
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
399 gtk_window_set_default_size(priv->inspector_win, 600, 400);
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
400
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
401 priv->inspector_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
402 gtk_container_add(GTK_CONTAINER(priv->inspector_win),
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
403 GTK_WIDGET(priv->inspector_view));
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
404
34464
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
405 g_signal_connect(priv->inspector_win, "destroy",
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
406 G_CALLBACK(webview_inspector_destroy), priv);
8755f8900cb4 Gtk webview inspector: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34308
diff changeset
407
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
408 return priv->inspector_view;
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
409 }
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
410
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
411 static gboolean
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
412 webview_inspector_show(WebKitWebInspector *inspector, GtkWidget *webview)
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
413 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
414 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
415
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
416 gtk_widget_show_all(GTK_WIDGET(priv->inspector_win));
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
417
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
418 return TRUE;
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
419 }
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
420
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
421 static PidginWebViewProtocol *
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
422 webview_find_protocol(const char *url, gboolean reverse)
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
423 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
424 PidginWebViewClass *klass;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
425 GList *iter;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
426 PidginWebViewProtocol *proto = NULL;
34308
cdb187c27360 Fix the rest of Pidgin's warnings about -Wsign-compare; remove -Wno-sign-compare from cflags
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34299
diff changeset
427 gssize length = reverse ? (gssize)strlen(url) : -1;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
428
35506
4252b2882889 Fix some remaining GTK_* macros as Elliott noticed
Ankit Vani <a@nevitus.org>
parents: 35500
diff changeset
429 klass = g_type_class_ref(PIDGIN_TYPE_WEBVIEW);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
430 for (iter = klass->protocols; iter; iter = iter->next) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
431 proto = iter->data;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
432 if (g_ascii_strncasecmp(url, proto->name, reverse ? MIN(length, proto->length) : proto->length) == 0) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
433 g_type_class_unref(klass);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
434 return proto;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
435 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
436 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
437
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
438 g_type_class_unref(klass);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
439 return NULL;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
440 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
441
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
442 static gboolean
33226
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
443 webview_navigation_decision(WebKitWebView *webview,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
444 WebKitWebFrame *frame,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
445 WebKitNetworkRequest *request,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
446 WebKitWebNavigationAction *navigation_action,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
447 WebKitWebPolicyDecision *policy_decision,
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
448 gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
449 {
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
450 const gchar *uri;
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
451 WebKitWebNavigationReason reason;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
452
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
453 uri = webkit_network_request_get_uri(request);
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
454 reason = webkit_web_navigation_action_get_reason(navigation_action);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
455
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
456 if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
457 PidginWebViewProtocol *proto = webview_find_protocol(uri, FALSE);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
458 if (proto) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
459 /* XXX: Do something with the return value? */
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
460 proto->activate(PIDGIN_WEBVIEW(webview), uri);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
461 }
32800
67649fafdb51 If we handle a navigation request, then we should tell WebKit
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32799
diff changeset
462 webkit_web_policy_decision_ignore(policy_decision);
32803
a2d80b30be13 We don't want WebKit to process a Refresh, or Back/Forward
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32800
diff changeset
463 } else if (reason == WEBKIT_WEB_NAVIGATION_REASON_OTHER)
32523
2d37b68228b6 Let webview manage the navigation ONLY if the reason is the user clicked a link.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32513
diff changeset
464 webkit_web_policy_decision_use(policy_decision);
32803
a2d80b30be13 We don't want WebKit to process a Refresh, or Back/Forward
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32800
diff changeset
465 else
a2d80b30be13 We don't want WebKit to process a Refresh, or Back/Forward
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32800
diff changeset
466 webkit_web_policy_decision_ignore(policy_decision);
32506
74d884939a2c Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32502
diff changeset
467
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
468 return TRUE;
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
469 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
470
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
471 static GtkWidget *
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
472 get_input_methods_menu(WebKitWebView *webview)
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
473 {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
474 GtkSettings *settings;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
475 gboolean show = TRUE;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
476 GtkWidget *item;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
477 GtkWidget *menu;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
478 GtkIMContext *im;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
479
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
480 settings = webview ? gtk_widget_get_settings(GTK_WIDGET(webview)) : gtk_settings_get_default();
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
481
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
482 if (settings)
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
483 g_object_get(settings, "gtk-show-input-method-menu", &show, NULL);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
484 if (!show)
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
485 return NULL;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
486
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
487 item = gtk_image_menu_item_new_with_mnemonic(_("Input _Methods"));
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
488
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
489 g_object_get(webview, "im-context", &im, NULL);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
490 menu = gtk_menu_new();
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
491 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(im),
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
492 GTK_MENU_SHELL(menu));
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
493 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
494
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
495 return item;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
496 }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
497
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
498 /* Values taken from gtktextutil.c */
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
499 static const GtkUnicodeMenuEntry bidi_menu_entries[] = {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
500 { N_("LRM _Left-to-right mark"), 0x200E },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
501 { N_("RLM _Right-to-left mark"), 0x200F },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
502 { N_("LRE Left-to-right _embedding"), 0x202A },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
503 { N_("RLE Right-to-left e_mbedding"), 0x202B },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
504 { N_("LRO Left-to-right _override"), 0x202D },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
505 { N_("RLO Right-to-left o_verride"), 0x202E },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
506 { N_("PDF _Pop directional formatting"), 0x202C },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
507 { N_("ZWS _Zero width space"), 0x200B },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
508 { N_("ZWJ Zero width _joiner"), 0x200D },
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
509 { N_("ZWNJ Zero width _non-joiner"), 0x200C }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
510 };
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
511
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
512 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
513 insert_control_character_cb(GtkMenuItem *item, PidginWebViewInsertData *data)
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
514 {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
515 WebKitWebView *webview = data->webview;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
516 gunichar ch = data->ch;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
517 PidginWebViewPriv *priv;
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
518 WebKitDOMDocument *dom;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
519 char buf[6];
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
520
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
521 priv = PIDGIN_WEBVIEW_GET_PRIVATE(PIDGIN_WEBVIEW(webview));
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
522 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
523
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
524 g_unichar_to_utf8(ch, buf);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
525 priv->edit.block_changed = TRUE;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
526 webkit_dom_document_exec_command(dom, "insertHTML", FALSE, buf);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
527 priv->edit.block_changed = FALSE;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
528 }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
529
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
530 static GtkWidget *
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
531 get_unicode_menu(WebKitWebView *webview)
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
532 {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
533 GtkSettings *settings;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
534 gboolean show = TRUE;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
535 GtkWidget *menuitem;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
536 GtkWidget *menu;
34308
cdb187c27360 Fix the rest of Pidgin's warnings about -Wsign-compare; remove -Wno-sign-compare from cflags
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34299
diff changeset
537 gsize i;
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
538
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
539 settings = webview ? gtk_widget_get_settings(GTK_WIDGET(webview)) : gtk_settings_get_default();
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
540
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
541 if (settings)
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
542 g_object_get(settings, "gtk-show-unicode-menu", &show, NULL);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
543 if (!show)
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
544 return NULL;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
545
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
546 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Insert Unicode Control Character"));
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
547
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
548 menu = gtk_menu_new();
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
549 for (i = 0; i < G_N_ELEMENTS(bidi_menu_entries); i++) {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
550 PidginWebViewInsertData *data;
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
551 GtkWidget *item;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
552
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
553 data = g_new0(PidginWebViewInsertData, 1);
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
554 data->webview = webview;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
555 data->ch = bidi_menu_entries[i].ch;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
556
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
557 item = gtk_menu_item_new_with_mnemonic(_(bidi_menu_entries[i].label));
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
558 g_signal_connect_data(item, "activate",
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
559 G_CALLBACK(insert_control_character_cb), data,
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
560 (GClosureNotify)g_free, 0);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
561 gtk_widget_show(item);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
562 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
563 }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
564
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
565 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
566
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
567 return menuitem;
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
568 }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
569
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
570 static void
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
571 webview_image_saved(GtkWidget *dialog, gint response, gpointer _unused)
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
572 {
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
573 PurpleImage *image;
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
574 gchar *filename;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
575
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
576 if (response != GTK_RESPONSE_ACCEPT) {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
577 gtk_widget_destroy(dialog);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
578 return;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
579 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
580
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
581 image = g_object_get_data(G_OBJECT(dialog), "pidgin-gtkwebview-image");
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
582 g_return_if_fail(image != NULL);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
583
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
584 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
585 g_return_if_fail(filename != NULL);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
586 g_return_if_fail(filename[0] != '\0');
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
587
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
588 if (!purple_image_save(image, filename)) {
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
589 purple_debug_error("gtkwebview", "Failed saving image");
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
590 /* TODO: we should display a notification here */
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
591 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
592
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
593 g_free(filename);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
594 gtk_widget_destroy(dialog);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
595 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
596
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
597 static void
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
598 webview_image_save(GtkWidget *item, WebKitDOMHTMLImageElement *image_node)
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
599 {
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
600 const gchar *src;
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
601 WebKitWebView *webview;
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
602 PurpleImage *image;
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
603 GtkFileChooserDialog *dialog;
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35814
diff changeset
604 const gchar *filename;
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
605 GtkWidget *parent;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
606
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
607 webview = g_object_get_data(G_OBJECT(image_node), "pidgin-gtkwebview");
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
608 g_return_if_fail(webview != NULL);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
609
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
610 src = webkit_dom_html_image_element_get_src(image_node); /* XXX: a leak or not? */
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
611 image = webview_resource_get_loaded(webview, src);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
612 g_return_if_fail(image != NULL);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
613
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
614 parent = gtk_widget_get_ancestor(item, GTK_TYPE_WINDOW);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
615 dialog = GTK_FILE_CHOOSER_DIALOG(gtk_file_chooser_dialog_new(
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
616 _("Save Image"),
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
617 parent ? GTK_WINDOW(parent) : NULL,
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
618 GTK_FILE_CHOOSER_ACTION_SAVE,
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
619 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
620 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
621 NULL));
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
622 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
623 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
624
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35814
diff changeset
625 filename = purple_image_get_friendly_filename(image);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35814
diff changeset
626 g_warn_if_fail(filename != NULL);
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
627 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
628
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
629 g_signal_connect(G_OBJECT(dialog), "response",
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
630 G_CALLBACK(webview_image_saved), NULL);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
631
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
632 g_object_ref(image);
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
633 g_object_set_data_full(G_OBJECT(dialog), "pidgin-gtkwebview-image",
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
634 image, g_object_unref);
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
635
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
636 gtk_widget_show(GTK_WIDGET(dialog));
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
637 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
638
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
639 static void
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
640 webview_image_add_smiley(GtkWidget *item, WebKitDOMHTMLImageElement *image_node)
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
641 {
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
642 const gchar *src;
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
643 WebKitWebView *webview;
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
644 PurpleImage *image;
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
645
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
646 src = webkit_dom_html_image_element_get_src(image_node);
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
647 webview = g_object_get_data(G_OBJECT(image_node), "pidgin-gtkwebview");
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
648 g_return_if_fail(webview != NULL);
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
649
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
650 image = webview_resource_get_loaded(webview, src);
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
651 g_return_if_fail(image != NULL);
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
652
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
653 pidgin_smiley_manager_add(image,
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
654 webkit_dom_html_image_element_get_alt(image_node));
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
655 }
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
656
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
657 static void
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
658 do_popup_menu(WebKitWebView *webview, int button, int time, int context,
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
659 WebKitDOMNode *node, const char *uri)
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
660 {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
661 GtkWidget *menu;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
662 GtkWidget *cut, *copy, *paste, *delete, *select;
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
663 gboolean show_clipboard = TRUE;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
664 WebKitDOMHTMLImageElement *image_node = NULL;
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
665
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
666 menu = gtk_menu_new();
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
667 g_signal_connect(menu, "selection-done",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
668 G_CALLBACK(gtk_widget_destroy), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
669
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
670 if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
671 PidginWebViewProtocol *proto = NULL;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
672 GList *children;
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
673 WebKitDOMNode *link_node = node;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
674
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
675 while (link_node && !WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT(link_node)) {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
676 link_node = webkit_dom_node_get_parent_node(node);
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
677 }
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
678
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
679 if (uri && link_node)
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
680 proto = webview_find_protocol(uri, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
681
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
682 if (proto && proto->context_menu) {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
683 proto->context_menu(PIDGIN_WEBVIEW(webview),
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
684 WEBKIT_DOM_HTML_ANCHOR_ELEMENT(link_node), menu);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
685 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
686
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
687 children = gtk_container_get_children(GTK_CONTAINER(menu));
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
688 if (!children) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
689 GtkWidget *item = gtk_menu_item_new_with_label(_("No actions available"));
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
690 gtk_widget_show(item);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
691 gtk_widget_set_sensitive(item, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
692 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
693 } else {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
694 g_list_free(children);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
695 }
33232
a572083f80ef Register protocols with GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33231
diff changeset
696 gtk_widget_show_all(menu);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
697
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
698 show_clipboard = FALSE;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
699 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
700
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
701 if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE) {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
702 WebKitDOMNode *_image_node = node;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
703
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
704 while (_image_node && !WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT(_image_node)) {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
705 _image_node = webkit_dom_node_get_parent_node(_image_node);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
706 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
707 if (_image_node)
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
708 image_node = WEBKIT_DOM_HTML_IMAGE_ELEMENT(_image_node);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
709 /* don't do it on our theme smileys */
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
710 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
711 if (image_node && webkit_dom_html_image_element_get_complete(image_node)) {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
712 GtkWidget *menu_item;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
713 int width, height;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
714
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
715 width = webkit_dom_html_image_element_get_width(image_node);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
716 height = webkit_dom_html_image_element_get_height(image_node);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
717
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
718 /* XXX */
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
719 g_object_set_data(G_OBJECT(image_node), "pidgin-gtkwebview", webview);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
720
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
721 menu_item = gtk_image_menu_item_new_with_mnemonic(
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
722 _("_Save Image..."));
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
723 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
724 gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU));
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
725 g_signal_connect_object(G_OBJECT(menu_item), "activate",
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
726 G_CALLBACK(webview_image_save), image_node, 0);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
727 gtk_widget_show(menu_item);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
728 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
729
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
730 /* TODO: check, if it's not *our* custom smiley (use css) */
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
731 if (width <= 96 && height <= 96) {
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
732 menu_item = gtk_image_menu_item_new_with_mnemonic(
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
733 _("_Add Custom Smiley..."));
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
734 gtk_image_menu_item_set_image(
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
735 GTK_IMAGE_MENU_ITEM(menu_item),
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
736 gtk_image_new_from_stock(GTK_STOCK_ADD,
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
737 GTK_ICON_SIZE_MENU));
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
738 g_signal_connect_object(G_OBJECT(menu_item), "activate",
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
739 G_CALLBACK(webview_image_add_smiley),
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
740 image_node, 0);
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
741 gtk_widget_show(menu_item);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
742 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
743 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
744
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
745 show_clipboard = FALSE;
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
746 }
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
747
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
748 if (show_clipboard) {
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
749 /* Using connect_swapped means we don't need any wrapper functions */
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
750 cut = pidgin_new_item_from_stock(menu, _("Cu_t"), GTK_STOCK_CUT,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
751 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
752 g_signal_connect_swapped(G_OBJECT(cut), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
753 G_CALLBACK(webkit_web_view_cut_clipboard),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
754 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
755
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
756 copy = pidgin_new_item_from_stock(menu, _("_Copy"), GTK_STOCK_COPY,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
757 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
758 g_signal_connect_swapped(G_OBJECT(copy), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
759 G_CALLBACK(webkit_web_view_copy_clipboard),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
760 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
761
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
762 paste = pidgin_new_item_from_stock(menu, _("_Paste"), GTK_STOCK_PASTE,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
763 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
764 g_signal_connect_swapped(G_OBJECT(paste), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
765 G_CALLBACK(webkit_web_view_paste_clipboard),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
766 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
767
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
768 delete = pidgin_new_item_from_stock(menu, _("_Delete"), GTK_STOCK_DELETE,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
769 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
770 g_signal_connect_swapped(G_OBJECT(delete), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
771 G_CALLBACK(webkit_web_view_delete_selection),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
772 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
773
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
774 pidgin_separator(menu);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
775
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
776 select = pidgin_new_item_from_stock(menu, _("Select _All"),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
777 GTK_STOCK_SELECT_ALL,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
778 NULL, NULL, 0, 0, NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
779 g_signal_connect_swapped(G_OBJECT(select), "activate",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
780 G_CALLBACK(webkit_web_view_select_all),
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
781 webview);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
782
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
783 gtk_widget_set_sensitive(cut,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
784 webkit_web_view_can_cut_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
785 gtk_widget_set_sensitive(copy,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
786 webkit_web_view_can_copy_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
787 gtk_widget_set_sensitive(paste,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
788 webkit_web_view_can_paste_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
789 gtk_widget_set_sensitive(delete,
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
790 webkit_web_view_can_cut_clipboard(webview));
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
791 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
792
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
793 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
794 "/webview/inspector_enabled"))
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
795 {
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
796 WebKitWebSettings *settings;
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
797 GtkWidget *inspect;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
798 PidginWebViewInspectData *data;
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
799
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
800 settings = webkit_web_view_get_settings(webview);
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
801 g_object_set(G_OBJECT(settings), "enable-developer-extras", TRUE, NULL);
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
802
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
803 data = g_new0(PidginWebViewInspectData, 1);
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
804 data->inspector = webkit_web_view_get_inspector(webview);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
805 data->node = node;
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
806
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
807 pidgin_separator(menu);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
808
35785
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
809 inspect = pidgin_new_item_from_stock(menu, _("Inspect _Element"),
65ced7f8beaa Fix regression: saving small WebView images as a custom smileys
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35784
diff changeset
810 PIDGIN_STOCK_DEBUG, NULL, NULL, 0, 0, NULL);
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
811 g_signal_connect_data(G_OBJECT(inspect), "activate",
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
812 G_CALLBACK(webview_inspector_inspect_element),
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
813 data, (GClosureNotify)g_free, 0);
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
814 }
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
815
33262
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
816 if (webkit_web_view_get_editable(webview)) {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
817 GtkWidget *im = get_input_methods_menu(webview);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
818 GtkWidget *unicode = get_unicode_menu(webview);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
819
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
820 if (im || unicode)
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
821 pidgin_separator(menu);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
822
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
823 if (im) {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
824 gtk_menu_shell_append(GTK_MENU_SHELL(menu), im);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
825 gtk_widget_show(im);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
826 }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
827
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
828 if (unicode) {
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
829 gtk_menu_shell_append(GTK_MENU_SHELL(menu), unicode);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
830 gtk_widget_show(unicode);
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
831 }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
832 }
ec6997a4258c Copy the input-method and unicode menus from a regular WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33256
diff changeset
833
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
834 g_signal_emit_by_name(G_OBJECT(webview), "populate-popup", menu);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
835
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
836 gtk_menu_attach_to_widget(GTK_MENU(menu), GTK_WIDGET(webview), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
837 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, time);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
838 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
839
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
840 static gboolean
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
841 webview_popup_menu(WebKitWebView *webview)
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
842 {
33250
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
843 WebKitDOMDocument *doc;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
844 WebKitDOMElement *active;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
845 WebKitDOMElement *link;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
846 int context;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
847 char *uri;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
848
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
849 context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
850 uri = NULL;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
851
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
852 doc = webkit_web_view_get_dom_document(webview);
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
853 active = webkit_dom_html_document_get_active_element(WEBKIT_DOM_HTML_DOCUMENT(doc));
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
854
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
855 link = active;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
856 while (link && !WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT(link))
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
857 link = webkit_dom_node_get_parent_element(WEBKIT_DOM_NODE(link));
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
858 if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT(link)) {
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
859 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK;
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
860 uri = webkit_dom_html_anchor_element_get_href(WEBKIT_DOM_HTML_ANCHOR_ELEMENT(link));
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
861 }
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
862
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
863 do_popup_menu(webview, 0, gtk_get_current_event_time(),
33250
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
864 context, WEBKIT_DOM_NODE(active), uri);
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
865
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
866 g_free(uri);
84e141f1bfed Add some context when using the keyboard to open a popup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33248
diff changeset
867
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
868 return TRUE;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
869 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
870
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
871 static gboolean
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
872 webview_button_pressed(WebKitWebView *webview, GdkEventButton *event)
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
873 {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
874 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
875 WebKitHitTestResult *hit;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
876 int context;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
877 WebKitDOMNode *node;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
878 char *uri;
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
879
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
880 hit = webkit_web_view_get_hit_test_result(webview, event);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
881 g_object_get(G_OBJECT(hit),
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
882 "context", &context,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
883 "inner-node", &node,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
884 "link-uri", &uri,
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
885 NULL);
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
886
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
887 do_popup_menu(webview, event->button, event->time, context,
33248
565884eb4354 Restore "Inspect Element" menu item.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33247
diff changeset
888 node, uri);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
889
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
890 g_free(uri);
33500
d6de39919ac3 Fix leak of the WebKitHitTestResult.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33265
diff changeset
891 g_object_unref(hit);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
892
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
893 return TRUE;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
894 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
895
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
896 return FALSE;
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
897 }
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
898
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
899 /*
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
900 * Smoothly scroll a WebView.
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
901 *
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
902 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom.
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
903 */
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
904 static gboolean
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
905 smooth_scroll_cb(gpointer data)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
906 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
907 PidginWebViewPriv *priv = data;
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
908 GtkAdjustment *adj;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
909 gdouble max_val;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
910 gdouble scroll_val;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
911
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
912 g_return_val_if_fail(priv->scroll_time != NULL, FALSE);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
913
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
914 adj = priv->vadj;
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
915 max_val = gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
916 scroll_val = gtk_adjustment_get_value(adj) +
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
917 ((max_val - gtk_adjustment_get_value(adj)) / 3);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
918
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
919 if (g_timer_elapsed(priv->scroll_time, NULL) > MAX_SCROLL_TIME
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
920 || scroll_val >= max_val) {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
921 /* time's up. jump to the end and kill the timer */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
922 gtk_adjustment_set_value(adj, max_val);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
923 g_timer_destroy(priv->scroll_time);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
924 priv->scroll_time = NULL;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
925 priv->scroll_src = 0;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
926 return FALSE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
927 }
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
928
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
929 /* scroll by 1/3rd the remaining distance */
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
930 gtk_adjustment_set_value(adj, scroll_val);
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
931 return TRUE;
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
932 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
933
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
934 static gboolean
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
935 scroll_idle_cb(gpointer data)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
936 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
937 PidginWebViewPriv *priv = data;
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
938 GtkAdjustment *adj = priv->vadj;
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
939 gdouble max_val;
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
940
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
941 if (adj) {
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
942 max_val = gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj);
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
943 gtk_adjustment_set_value(adj, max_val);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
944 }
32797
3fe407409ec2 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32796
diff changeset
945
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
946 priv->scroll_src = 0;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
947 return FALSE;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
948 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
949
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
950 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
951 emit_format_signal(PidginWebView *webview, PidginWebViewButtons buttons)
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
952 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
953 g_object_ref(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
954 g_signal_emit(webview, signals[TOGGLE_FORMAT], 0, buttons);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
955 g_object_unref(webview);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
956 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
957
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
958 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
959 do_formatting(PidginWebView *webview, const char *name, const char *value)
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
960 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
961 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
962 WebKitDOMDocument *dom;
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
963 WebKitDOMDOMWindow *win;
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
964 WebKitDOMDOMSelection *sel = NULL;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
965 WebKitDOMRange *range = NULL;
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
966
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
967 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
968
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
969 if (priv->edit.wbfo) {
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
970 win = webkit_dom_document_get_default_view(dom);
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
971 sel = webkit_dom_dom_window_get_selection(win);
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
972 if (webkit_dom_dom_selection_get_range_count(sel) > 0)
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
973 range = webkit_dom_dom_selection_get_range_at(sel, 0, NULL);
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
974 webkit_web_view_select_all(WEBKIT_WEB_VIEW(webview));
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
975 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
976
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
977 priv->edit.block_changed = TRUE;
35194
9a0203562da5 pidgin: Fix build and warnings with glib 2.24
Ankit Vani <a@nevitus.org>
parents: 35129
diff changeset
978 webkit_dom_document_exec_command(dom, (gchar *)name, FALSE, (gchar *)value);
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
979 priv->edit.block_changed = FALSE;
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
980
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
981 if (priv->edit.wbfo) {
33022
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
982 if (range) {
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
983 webkit_dom_dom_selection_remove_all_ranges(sel);
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
984 webkit_dom_dom_selection_add_range(sel, range);
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
985 } else {
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
986 webkit_dom_dom_selection_collapse_to_end(sel, NULL);
87c277f64c4e Avoid some asserts with WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33021
diff changeset
987 }
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
988 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
989 }
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
990
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
991 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
992 webview_font_shrink(PidginWebView *webview)
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
993 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
994 gint fontsize;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
995 char *tmp;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
996
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
997 fontsize = pidgin_webview_get_current_fontsize(webview);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
998 fontsize = MAX(fontsize - 1, 1);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
999
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1000 tmp = g_strdup_printf("%d", fontsize);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1001 do_formatting(webview, "fontSize", tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1002 g_free(tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1003 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1004
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1005 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1006 webview_font_grow(PidginWebView *webview)
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1007 {
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1008 gint fontsize;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1009 char *tmp;
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1010
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1011 fontsize = pidgin_webview_get_current_fontsize(webview);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1012 fontsize = MIN(fontsize + 1, MAX_FONT_SIZE);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1013
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1014 tmp = g_strdup_printf("%d", fontsize);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1015 do_formatting(webview, "fontSize", tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1016 g_free(tmp);
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1017 }
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1019 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1020 webview_clear_formatting(PidginWebView *webview)
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1021 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1022 if (!webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview)))
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1023 return;
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1024
33009
364b314b125a Clear formatting should also obey WBFO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33008
diff changeset
1025 do_formatting(webview, "removeFormat", "");
33020
03c013f8990c Remove links and background colours on format-clear.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33018
diff changeset
1026 do_formatting(webview, "unlink", "");
03c013f8990c Remove links and background colours on format-clear.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33018
diff changeset
1027 do_formatting(webview, "backColor", "inherit");
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1028 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1029
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1030 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1031 webview_toggle_format(PidginWebView *webview, PidginWebViewButtons buttons)
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1032 {
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1033 /* since this function is the handler for the formatting keystrokes,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1034 we need to check here that the formatting attempted is permitted */
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1035 buttons &= pidgin_webview_get_format_functions(webview);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1036
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1037 switch (buttons) {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1038 case PIDGIN_WEBVIEW_BOLD:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1039 do_formatting(webview, "bold", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1040 break;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1041 case PIDGIN_WEBVIEW_ITALIC:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1042 do_formatting(webview, "italic", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1043 break;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1044 case PIDGIN_WEBVIEW_UNDERLINE:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1045 do_formatting(webview, "underline", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1046 break;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1047 case PIDGIN_WEBVIEW_STRIKE:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1048 do_formatting(webview, "strikethrough", "");
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1049 break;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1050 case PIDGIN_WEBVIEW_SHRINK:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1051 webview_font_shrink(webview);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1052 break;
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1053 case PIDGIN_WEBVIEW_GROW:
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1054 webview_font_grow(webview);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1055 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1056 default:
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1057 break;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1058 }
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1059 }
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1060
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1061 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1062 editable_input_cb(PidginWebView *webview, gpointer data)
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1063 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1064 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33030
4114ce42d094 Don't emit changed signal when a webview is insensitive.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33028
diff changeset
1065 if (!priv->edit.block_changed && gtk_widget_is_sensitive(GTK_WIDGET(webview)))
33010
aa658ddce5ec Don't emit the changed signal when modifying the webview ourselves.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33009
diff changeset
1066 g_signal_emit(webview, signals[CHANGED], 0);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1067 }
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1068
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1069 /******************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1070 * GObject Stuff
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1071 *****************************************************************************/
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1072
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1073 GtkWidget *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1074 pidgin_webview_new(gboolean editable)
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1075 {
34276
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1076 GtkWidget *result;
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1077 WebKitWebView *webview;
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1078 WebKitWebSettings *settings;
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1079
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1080 result = g_object_new(pidgin_webview_get_type(), NULL);
34276
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1081 webview = WEBKIT_WEB_VIEW(result);
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1082 settings = webkit_web_view_get_settings(webview);
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1083
33877
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1084 g_object_set(G_OBJECT(settings), "default-encoding", "utf-8", NULL);
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1085 #ifdef _WIN32
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1086 /* XXX: win32 WebKitGTK replaces backslash with yen sign for
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1087 * "sans-serif" font. We should figure out, how to disable this
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1088 * behavior, but for now I will just apply this simple hack (using other
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1089 * font family).
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1090 */
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1091 g_object_set(G_OBJECT(settings), "default-font-family", "Verdana", NULL);
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1092 #endif
d33b4fa5ea06 win32: hack for webkit's feature of replacing backslash with yen sign; silencing some warnings in gtkconv.c; consistent messages in proxy.c
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33857
diff changeset
1093 webkit_web_view_set_settings(webview, settings);
34276
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1094
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1095 if (editable) {
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1096 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview), editable);
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1097
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1098 g_signal_connect(G_OBJECT(webview), "user-changed-contents",
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1099 G_CALLBACK(editable_input_cb), NULL);
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1100 }
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1101
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1102 return result;
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1103 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1104
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1105 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1106 pidgin_webview_finalize(GObject *webview)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1107 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1108 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1109
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1110 if (priv->inspector_win != NULL)
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1111 gtk_widget_destroy(GTK_WIDGET(priv->inspector_win));
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1112
33227
2541e55ae19d Only remove source if non-zero.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33226
diff changeset
1113 if (priv->loader)
2541e55ae19d Only remove source if non-zero.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33226
diff changeset
1114 g_source_remove(priv->loader);
33112
f3236514cb26 Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33097
diff changeset
1115
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1116 while (!g_queue_is_empty(priv->load_queue)) {
35689
1e257009ac10 Fix Pidgin clang scan-build warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35671
diff changeset
1117 g_queue_pop_head(priv->load_queue);
1e257009ac10 Fix Pidgin clang scan-build warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35671
diff changeset
1118 g_free(g_queue_pop_head(priv->load_queue));
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1119 }
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1120 g_queue_free(priv->load_queue);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1121
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1122 if (--globally_loaded_images_refcnt == 0) {
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1123 g_assert(globally_loaded_images != NULL);
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1124 g_hash_table_destroy(globally_loaded_images);
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1125 globally_loaded_images = NULL;
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1126 }
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
1127
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1128 G_OBJECT_CLASS(parent_class)->finalize(G_OBJECT(webview));
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1129 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1130
35648
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1131 enum {
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1132 PROP_0,
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1133 PROP_EXPAND
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1134 };
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1135
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1136 static void
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1137 pidgin_webview_set_property(GObject *object, guint prop_id, const GValue *value,
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1138 GParamSpec *pspec)
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1139 {
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1140 g_return_if_fail(PIDGIN_IS_WEBVIEW(object));
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1141
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1142 switch (prop_id) {
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1143 case PROP_EXPAND:
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1144 purple_debug_misc("webview",
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1145 "Ignored expand property (set to %d)",
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1146 g_value_get_boolean(value));
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1147 break;
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1148 default:
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1149 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id,
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1150 pspec);
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1151 }
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1152 }
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1153
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1154 static void
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1155 pidgin_webview_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1156 {
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1157 g_return_if_fail(PIDGIN_IS_WEBVIEW(object));
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1158
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1159 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1160 }
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1161
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1162 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1163 pidgin_webview_class_init(PidginWebViewClass *klass, gpointer userdata)
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1164 {
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1165 GObjectClass *gobject_class;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1166 GtkBindingSet *binding_set;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1167
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1168 parent_class = g_type_class_ref(webkit_web_view_get_type());
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1169 gobject_class = G_OBJECT_CLASS(klass);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1170
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1171 g_type_class_add_private(klass, sizeof(PidginWebViewPriv));
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1172
34276
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1173 /* Signals */
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1174
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1175 signals[BUTTONS_UPDATE] = g_signal_new("allowed-formats-updated",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1176 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1177 G_SIGNAL_RUN_FIRST,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1178 G_STRUCT_OFFSET(PidginWebViewClass, buttons_update),
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1179 NULL, 0, g_cclosure_marshal_VOID__INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1180 G_TYPE_NONE, 1, G_TYPE_INT);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1181 signals[TOGGLE_FORMAT] = g_signal_new("format-toggled",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1182 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1183 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1184 G_STRUCT_OFFSET(PidginWebViewClass, toggle_format),
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1185 NULL, 0, g_cclosure_marshal_VOID__INT,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1186 G_TYPE_NONE, 1, G_TYPE_INT);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1187 signals[CLEAR_FORMAT] = g_signal_new("format-cleared",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1188 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1189 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1190 G_STRUCT_OFFSET(PidginWebViewClass, clear_format),
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1191 NULL, 0, g_cclosure_marshal_VOID__VOID,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1192 G_TYPE_NONE, 0);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1193 signals[UPDATE_FORMAT] = g_signal_new("format-updated",
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1194 G_TYPE_FROM_CLASS(gobject_class),
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1195 G_SIGNAL_RUN_FIRST,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1196 G_STRUCT_OFFSET(PidginWebViewClass, update_format),
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1197 NULL, 0, g_cclosure_marshal_VOID__VOID,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1198 G_TYPE_NONE, 0);
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1199 signals[CHANGED] = g_signal_new("changed",
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1200 G_TYPE_FROM_CLASS(gobject_class),
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1201 G_SIGNAL_RUN_FIRST,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1202 G_STRUCT_OFFSET(PidginWebViewClass, changed),
33007
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1203 NULL, NULL, g_cclosure_marshal_VOID__VOID,
78b670090850 Add a changed signal shortcut for editable webview changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33006
diff changeset
1204 G_TYPE_NONE, 0);
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
1205 signals[HTML_APPENDED] = g_signal_new("html-appended",
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
1206 G_TYPE_FROM_CLASS(gobject_class),
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
1207 G_SIGNAL_RUN_FIRST,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1208 G_STRUCT_OFFSET(PidginWebViewClass, html_appended),
33241
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
1209 NULL, NULL,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
1210 g_cclosure_marshal_VOID__OBJECT,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
1211 G_TYPE_NONE, 1, WEBKIT_TYPE_DOM_RANGE,
d5a07f1ea70b Add a signal for when HTML is appended to a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33233
diff changeset
1212 NULL);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1213
34276
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1214 /* Class Methods */
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1215
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1216 klass->toggle_format = webview_toggle_format;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1217 klass->clear_format = webview_clear_formatting;
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1218
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1219 gobject_class->finalize = pidgin_webview_finalize;
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1220
34276
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1221 /* Key Bindings */
2b602f67f875 Make editable-ness a construct-only property of the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34274
diff changeset
1222
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1223 binding_set = gtk_binding_set_by_class(parent_class);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1224 gtk_binding_entry_add_signal(binding_set, GDK_KEY_b, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1225 "format-toggled", 1, G_TYPE_INT,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1226 PIDGIN_WEBVIEW_BOLD);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1227 gtk_binding_entry_add_signal(binding_set, GDK_KEY_i, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1228 "format-toggled", 1, G_TYPE_INT,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1229 PIDGIN_WEBVIEW_ITALIC);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1230 gtk_binding_entry_add_signal(binding_set, GDK_KEY_u, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1231 "format-toggled", 1, G_TYPE_INT,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1232 PIDGIN_WEBVIEW_UNDERLINE);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1233 gtk_binding_entry_add_signal(binding_set, GDK_KEY_plus, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1234 "format-toggled", 1, G_TYPE_INT,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1235 PIDGIN_WEBVIEW_GROW);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1236 gtk_binding_entry_add_signal(binding_set, GDK_KEY_equal, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1237 "format-toggled", 1, G_TYPE_INT,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1238 PIDGIN_WEBVIEW_GROW);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1239 gtk_binding_entry_add_signal(binding_set, GDK_KEY_minus, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1240 "format-toggled", 1, G_TYPE_INT,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1241 PIDGIN_WEBVIEW_SHRINK);
32811
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1242
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1243 binding_set = gtk_binding_set_by_class(klass);
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1244 gtk_binding_entry_add_signal(binding_set, GDK_KEY_r, GDK_CONTROL_MASK,
87c1f3bb5461 Add some formatting signals to webview from imhtml.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32810
diff changeset
1245 "format-cleared", 0);
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1246
35648
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1247 /* properties */
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1248
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1249 G_OBJECT_CLASS(klass)->set_property = pidgin_webview_set_property;
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1250 G_OBJECT_CLASS(klass)->get_property = pidgin_webview_get_property;
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1251
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1252 if (!g_object_class_find_property(G_OBJECT_CLASS(klass), "expand")) {
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1253 /* webkitgtk for gtk2 doesn't seems to have this */
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1254 g_object_class_install_property(G_OBJECT_CLASS(klass),
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1255 PROP_EXPAND, g_param_spec_boolean("expand", "Expand Both",
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1256 "Whether widget wants to expand in both directions",
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1257 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1258 }
6283b3708b03 Re-commit improved 3a61567
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35646
diff changeset
1259
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1260 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/webview");
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1261 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/webview/inspector_enabled", FALSE);
35796
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1262
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1263 g_return_if_fail(smileys_re == NULL);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1264 g_return_if_fail(empty_html_re == NULL);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1265 smileys_re = g_regex_new("<img[^>]* class=\"emoticon "
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1266 "[^\"^>]*\"[^>]*alt=\"([^\"^>]+)\"[^>]*>",
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1267 G_REGEX_DOTALL | G_REGEX_OPTIMIZE, 0, NULL);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1268 empty_html_re = g_regex_new("<(?!img)[^>]*>",
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1269 G_REGEX_DOTALL | G_REGEX_OPTIMIZE, 0, NULL);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1270 }
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1271
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1272 static void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1273 pidgin_webview_init(PidginWebView *webview, gpointer userdata)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1274 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1275 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1276 WebKitWebInspector *inspector;
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1277
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1278 priv->load_queue = g_queue_new();
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1279
33228
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
1280 g_signal_connect(G_OBJECT(webview), "button-press-event",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
1281 G_CALLBACK(webview_button_pressed), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
1282
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
1283 g_signal_connect(G_OBJECT(webview), "popup-menu",
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
1284 G_CALLBACK(webview_popup_menu), NULL);
a5943b35eb77 Override the WebKitWebView default context menu.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33227
diff changeset
1285
33223
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
1286 g_signal_connect(G_OBJECT(webview), "navigation-policy-decision-requested",
33226
ae332a3316c7 Give webview signal callback a more relevant name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33225
diff changeset
1287 G_CALLBACK(webview_navigation_decision), NULL);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1288
33223
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
1289 g_signal_connect(G_OBJECT(webview), "load-started",
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
1290 G_CALLBACK(webview_load_started), NULL);
32460
5771be5530d8 safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32446
diff changeset
1291
33223
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
1292 g_signal_connect(G_OBJECT(webview), "load-finished",
8bc668d886f4 Make some lines consistent with others.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33222
diff changeset
1293 G_CALLBACK(webview_load_finished), NULL);
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
1294
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
1295 g_signal_connect(G_OBJECT(webview), "resource-request-starting",
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
1296 G_CALLBACK(webview_resource_loading), NULL);
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1297
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
1298 g_signal_connect(G_OBJECT(webview), "resource-load-finished",
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
1299 G_CALLBACK(webview_resource_loaded), NULL);
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
1300
34299
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1301 inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview));
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1302 g_signal_connect(G_OBJECT(inspector), "inspect-web-view",
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1303 G_CALLBACK(webview_inspector_create), NULL);
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1304 g_signal_connect(G_OBJECT(inspector), "show-window",
419c033e46b9 Enable WebKit inspector for all widgets, not only conversation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34276
diff changeset
1305 G_CALLBACK(webview_inspector_show), webview);
35784
247f6f06531f Fix regression: saving WebView images
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35733
diff changeset
1306
35830
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1307 if (globally_loaded_images_refcnt++ == 0) {
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1308 g_assert(globally_loaded_images == NULL);
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1309 globally_loaded_images = g_hash_table_new_full(g_str_hash,
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1310 g_str_equal, g_free, g_object_unref);
fb32647ef2f3 PurpleImage: better reference management
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35829
diff changeset
1311 }
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1312 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1313
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1314 GType
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1315 pidgin_webview_get_type(void)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1316 {
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1317 static GType mview_type = 0;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1318 if (G_UNLIKELY(mview_type == 0)) {
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1319 static const GTypeInfo mview_info = {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1320 sizeof(PidginWebViewClass),
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1321 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1322 NULL,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1323 (GClassInitFunc)pidgin_webview_class_init,
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1324 NULL,
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1325 NULL,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1326 sizeof(PidginWebView),
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1327 0,
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1328 (GInstanceInitFunc)pidgin_webview_init,
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1329 NULL
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1330 };
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1331 mview_type = g_type_register_static(webkit_web_view_get_type(),
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1332 "PidginWebView", &mview_info, 0);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1333 }
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1334 return mview_type;
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1335 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1336
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1337 /*****************************************************************************
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1338 * Public API functions
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1339 *****************************************************************************/
32793
db876e8e41ac Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32791
diff changeset
1340
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1341 char *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1342 pidgin_webview_quote_js_string(const char *text)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1343 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1344 GString *str = g_string_new("\"");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1345 const char *cur = text;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1346
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1347 while (cur && *cur) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1348 switch (*cur) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1349 case '\\':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1350 g_string_append(str, "\\\\");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1351 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1352 case '\"':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1353 g_string_append(str, "\\\"");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1354 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1355 case '\r':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1356 g_string_append(str, "<br/>");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1357 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1358 case '\n':
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1359 break;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1360 default:
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1361 g_string_append_c(str, *cur);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1362 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1363 cur++;
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1364 }
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1365
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1366 g_string_append_c(str, '"');
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1367
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1368 return g_string_free(str, FALSE);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1369 }
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1370
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1371 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1372 pidgin_webview_safe_execute_script(PidginWebView *webview, const char *script)
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1373 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1374 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1375
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1376 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1377
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1378 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1379 g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(LOAD_JS));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1380 g_queue_push_tail(priv->load_queue, g_strdup(script));
33224
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
1381 if (!priv->is_loading && priv->loader == 0)
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
1382 priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1383 }
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1384
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1385 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1386 pidgin_webview_load_html_string(PidginWebView *webview, const char *html)
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1387 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1388 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1389
33054
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
1390 webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html, NULL, NULL,
177359654a3d Update the webview to use the new image sources.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33030
diff changeset
1391 "file:///");
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1392 }
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1393
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1394 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1395 pidgin_webview_load_html_string_with_selection(PidginWebView *webview, const char *html)
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1396 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1397 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1398
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1399 pidgin_webview_load_html_string(webview, html);
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1400 pidgin_webview_safe_execute_script(webview,
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1401 "var s = window.getSelection();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1402 "var r = document.createRange();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1403 "var n = document.getElementById('caret');"
33084
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
1404 "r.selectNodeContents(n);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
1405 "var f = r.extractContents();"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
1406 "r.selectNode(n);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
1407 "r.insertNode(f);"
1da63a04d506 Make sure the selection anchor is removed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33083
diff changeset
1408 "n.parentNode.removeChild(n);"
33083
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1409 "s.removeAllRanges();"
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1410 "s.addRange(r);");
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1411 }
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1412
e96acbe0e928 Move caret selection into GtkWebView code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33054
diff changeset
1413 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1414 pidgin_webview_append_html(PidginWebView *webview, const char *html)
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1415 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1416 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1417
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1418 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1419
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1420 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33222
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1421 g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(LOAD_HTML));
868965128ec8 Combine HTML and JS loading queues.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33221
diff changeset
1422 g_queue_push_tail(priv->load_queue, g_strdup(html));
33224
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
1423 if (!priv->is_loading && priv->loader == 0)
4bb64c5ef111 Ensure queue processing function is only added once.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33223
diff changeset
1424 priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
32441
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1425 }
8a015ca299f9 Apparently I missed these in my previous commit.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
1426
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1427 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1428 pidgin_webview_set_vadjustment(PidginWebView *webview, GtkAdjustment *vadj)
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1429 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1430 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1431
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1432 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1433
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1434 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1435 priv->vadj = vadj;
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1436 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1437
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32506
diff changeset
1438 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1439 pidgin_webview_scroll_to_end(PidginWebView *webview, gboolean smooth)
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1440 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1441 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1442
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1443 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1444
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1445 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1446 if (priv->scroll_time)
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1447 g_timer_destroy(priv->scroll_time);
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1448 if (priv->scroll_src)
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1449 g_source_remove(priv->scroll_src);
32796
34f384b0d75f Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32794
diff changeset
1450 if (smooth) {
32500
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1451 priv->scroll_time = g_timer_new();
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1452 priv->scroll_src = g_timeout_add_full(G_PRIORITY_LOW, SCROLL_DELAY, smooth_scroll_cb, priv, NULL);
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1453 } else {
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1454 priv->scroll_time = NULL;
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1455 priv->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, priv, NULL);
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1456 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1457 }
d8aa742c6288 webkit: Scroll to end when appending html.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents: 32489
diff changeset
1458
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1459 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1460 pidgin_webview_set_autoscroll(PidginWebView *webview, gboolean scroll)
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1461 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1462 PidginWebViewPriv *priv;
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1463
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1464 g_return_if_fail(webview != NULL);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1465
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1466 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1467 priv->autoscroll = scroll;
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1468 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1469
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1470 gboolean
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1471 pidgin_webview_get_autoscroll(PidginWebView *webview)
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1472 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1473 PidginWebViewPriv *priv;
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1474
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1475 g_return_val_if_fail(webview != NULL, FALSE);
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1476
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1477 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33247
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1478 return priv->autoscroll;
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1479 }
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1480
d8d6e87ce594 Add autoscrolling for the debug window.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33241
diff changeset
1481 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1482 pidgin_webview_page_up(PidginWebView *webview)
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1483 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1484 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1485 GtkAdjustment *vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1486 gdouble scroll_val;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1487
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1488 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1489
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1490 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1491 vadj = priv->vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1492 scroll_val = gtk_adjustment_get_value(vadj) - gtk_adjustment_get_page_size(vadj);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1493 scroll_val = MAX(scroll_val, gtk_adjustment_get_lower(vadj));
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1494
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1495 gtk_adjustment_set_value(vadj, scroll_val);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1496 }
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1497
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1498 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1499 pidgin_webview_page_down(PidginWebView *webview)
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1500 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1501 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1502 GtkAdjustment *vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1503 gdouble scroll_val;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1504 gdouble page_size;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1505
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1506 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1507
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1508 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1509 vadj = priv->vadj;
32772
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1510 page_size = gtk_adjustment_get_page_size(vadj);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1511 scroll_val = gtk_adjustment_get_value(vadj) + page_size;
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1512 scroll_val = MIN(scroll_val, gtk_adjustment_get_upper(vadj) - page_size);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1513
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1514 gtk_adjustment_set_value(vadj, scroll_val);
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1515 }
9d79ccaeedfe Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32577
diff changeset
1516
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1517 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1518 pidgin_webview_setup_entry(PidginWebView *webview, PurpleConnectionFlags flags)
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1519 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1520 PidginWebViewButtons buttons;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1521
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1522 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1523
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1524 if (flags & PURPLE_CONNECTION_FLAG_HTML) {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1525 gboolean bold, italic, underline, strike;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1526
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1527 buttons = PIDGIN_WEBVIEW_ALL;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1528
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1529 if (flags & PURPLE_CONNECTION_FLAG_NO_BGCOLOR)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1530 buttons &= ~PIDGIN_WEBVIEW_BACKCOLOR;
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1531 if (flags & PURPLE_CONNECTION_FLAG_NO_FONTSIZE)
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1532 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1533 buttons &= ~PIDGIN_WEBVIEW_GROW;
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1534 buttons &= ~PIDGIN_WEBVIEW_SHRINK;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1535 }
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1536 if (flags & PURPLE_CONNECTION_FLAG_NO_URLDESC)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1537 buttons &= ~PIDGIN_WEBVIEW_LINKDESC;
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1538
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1539 pidgin_webview_get_current_format(webview, &bold, &italic, &underline, &strike);
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1540
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1541 pidgin_webview_set_format_functions(webview, PIDGIN_WEBVIEW_ALL);
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1542 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != bold)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1543 pidgin_webview_toggle_bold(webview);
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1544
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1545 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != italic)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1546 pidgin_webview_toggle_italic(webview);
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1547
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1548 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != underline)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1549 pidgin_webview_toggle_underline(webview);
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1550
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1551 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike") != strike)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1552 pidgin_webview_toggle_strike(webview);
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1553
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1554 pidgin_webview_toggle_fontface(webview,
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1555 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/font_face"));
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1556
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1557 if (!(flags & PURPLE_CONNECTION_FLAG_NO_FONTSIZE))
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1558 {
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1559 int size = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size");
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1560
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1561 /* 3 is the default. */
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1562 if (size != 3)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1563 pidgin_webview_font_set_size(webview, size);
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1564 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1565
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1566 pidgin_webview_toggle_forecolor(webview,
33025
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1567 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"));
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1568
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1569 if (!(flags & PURPLE_CONNECTION_FLAG_NO_BGCOLOR)) {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1570 pidgin_webview_toggle_backcolor(webview,
33025
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1571 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"));
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1572 } else {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1573 pidgin_webview_toggle_backcolor(webview, "");
33025
74cd56966dbc This colour parsing seems unnecessary now.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33024
diff changeset
1574 }
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1575
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1576 if (flags & PURPLE_CONNECTION_FLAG_FORMATTING_WBFO)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1577 pidgin_webview_set_whole_buffer_formatting_only(webview, TRUE);
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1578 else
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1579 pidgin_webview_set_whole_buffer_formatting_only(webview, FALSE);
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1580 } else {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1581 buttons = PIDGIN_WEBVIEW_SMILEY | PIDGIN_WEBVIEW_IMAGE;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1582 webview_clear_formatting(webview);
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1583 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1584
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1585 if (flags & PURPLE_CONNECTION_FLAG_NO_IMAGES)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1586 buttons &= ~PIDGIN_WEBVIEW_IMAGE;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1587
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 33877
diff changeset
1588 if (flags & PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY)
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1589 buttons |= PIDGIN_WEBVIEW_CUSTOM_SMILEY;
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1590 else
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1591 buttons &= ~PIDGIN_WEBVIEW_CUSTOM_SMILEY;
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1592
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1593 pidgin_webview_set_format_functions(webview, buttons);
32810
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1594 }
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1595
17dceb2423c2 Add a function for setting a WebView entry based on the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32805
diff changeset
1596 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1597 pidgin_webview_set_spellcheck(PidginWebView *webview, gboolean enable)
33021
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1598 {
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1599 WebKitWebSettings *settings;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1600
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1601 g_return_if_fail(webview != NULL);
33021
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1602
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1603 settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1604 g_object_set(G_OBJECT(settings), "enable-spell-checking", enable, NULL);
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1605 webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webview), settings);
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1606 }
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1607
3dc4b2cdba7f Enable spell checking in an editable webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33020
diff changeset
1608 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1609 pidgin_webview_set_whole_buffer_formatting_only(PidginWebView *webview, gboolean wbfo)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1610 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1611 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1612
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1613 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1614
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1615 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1616 priv->edit.wbfo = wbfo;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1617 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1618
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1619 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1620 pidgin_webview_set_format_functions(PidginWebView *webview, PidginWebViewButtons buttons)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1621 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1622 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1623 GObject *object;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1624
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1625 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1626
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1627 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1628 object = g_object_ref(G_OBJECT(webview));
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1629 priv->format_functions = buttons;
32812
5be5c09c86de Emit the allowed-formats-updated signal when the set_format_functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32811
diff changeset
1630 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons);
5be5c09c86de Emit the allowed-formats-updated signal when the set_format_functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32811
diff changeset
1631 g_object_unref(object);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1632 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1633
33231
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1634 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1635 pidgin_webview_activate_anchor(WebKitDOMHTMLAnchorElement *link)
33231
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1636 {
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1637 WebKitDOMDocument *doc;
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1638 WebKitDOMEvent *event;
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1639
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1640 doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(link));
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1641 event = webkit_dom_document_create_event(doc, "MouseEvent", NULL);
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1642 webkit_dom_event_init_event(event, "click", TRUE, TRUE);
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1643 webkit_dom_node_dispatch_event(WEBKIT_DOM_NODE(link), event, NULL);
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1644 }
ab65d36fd975 Add a convenience function to activate a WebKit anchor element.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33229
diff changeset
1645
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1646 gboolean
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1647 pidgin_webview_class_register_protocol(const char *name,
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1648 gboolean (*activate)(PidginWebView *webview, const char *uri),
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1649 gboolean (*context_menu)(PidginWebView *webview, WebKitDOMHTMLAnchorElement *link, GtkWidget *menu))
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1650 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1651 PidginWebViewClass *klass;
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1652 PidginWebViewProtocol *proto;
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1653
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1654 g_return_val_if_fail(name, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1655
35506
4252b2882889 Fix some remaining GTK_* macros as Elliott noticed
Ankit Vani <a@nevitus.org>
parents: 35500
diff changeset
1656 klass = g_type_class_ref(PIDGIN_TYPE_WEBVIEW);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1657 g_return_val_if_fail(klass, FALSE);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1658
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1659 if ((proto = webview_find_protocol(name, TRUE))) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1660 if (activate) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1661 return FALSE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1662 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1663 klass->protocols = g_list_remove(klass->protocols, proto);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1664 g_free(proto->name);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1665 g_free(proto);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1666 return TRUE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1667 } else if (!activate) {
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1668 return FALSE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1669 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1670
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1671 proto = g_new0(PidginWebViewProtocol, 1);
33229
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1672 proto->name = g_strdup(name);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1673 proto->length = strlen(name);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1674 proto->activate = activate;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1675 proto->context_menu = context_menu;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1676 klass->protocols = g_list_prepend(klass->protocols, proto);
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1677
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1678 return TRUE;
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1679 }
f9503bfa54a4 Add protocol registration on a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33228
diff changeset
1680
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1681 gchar *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1682 pidgin_webview_get_head_html(PidginWebView *webview)
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1683 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1684 WebKitDOMDocument *doc;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1685 WebKitDOMHTMLHeadElement *head;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1686 gchar *html;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1687
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1688 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1689
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1690 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1691 head = webkit_dom_document_get_head(doc);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1692 html = webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(head));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1693
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1694 return html;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1695 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1696
35796
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1697 static gchar *
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1698 pidgin_webview_strip_smileys(const gchar *text)
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1699 {
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1700 return g_regex_replace(smileys_re, text, -1, 0, "\\1", 0, NULL);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1701 }
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1702
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1703 gchar *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1704 pidgin_webview_get_body_html(PidginWebView *webview)
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1705 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1706 WebKitDOMDocument *doc;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1707 WebKitDOMHTMLElement *body;
35796
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1708 gchar *html, *stripped;
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1709
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1710 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1711
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1712 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1713 body = webkit_dom_document_get_body(doc);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1714 html = webkit_dom_html_element_get_inner_html(body);
35796
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1715 stripped = pidgin_webview_strip_smileys(html);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1716 g_free(html);
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1717
35796
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1718 return stripped;
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1719 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1720
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1721 gchar *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1722 pidgin_webview_get_body_text(PidginWebView *webview)
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1723 {
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1724 WebKitDOMDocument *doc;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1725 WebKitDOMHTMLElement *body;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1726 gchar *text;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1727
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1728 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1729
33004
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1730 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1731 body = webkit_dom_document_get_body(doc);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1732 text = webkit_dom_html_element_get_inner_text(body);
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1733
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1734 return text;
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1735 }
2a86ad923464 Add some convenience functions to get the contents of a GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32994
diff changeset
1736
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1737 gchar *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1738 pidgin_webview_get_selected_text(PidginWebView *webview)
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1739 {
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1740 WebKitDOMDocument *dom;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1741 WebKitDOMDOMWindow *win;
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1742 WebKitDOMDOMSelection *sel;
33254
88b2504d0acf Fix an warning with selections. Selections are weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33253
diff changeset
1743 WebKitDOMRange *range = NULL;
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1744
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1745 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1746
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1747 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1748 win = webkit_dom_document_get_default_view(dom);
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1749 sel = webkit_dom_dom_window_get_selection(win);
33254
88b2504d0acf Fix an warning with selections. Selections are weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33253
diff changeset
1750 if (webkit_dom_dom_selection_get_range_count(sel))
88b2504d0acf Fix an warning with selections. Selections are weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33253
diff changeset
1751 range = webkit_dom_dom_selection_get_range_at(sel, 0, NULL);
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1752
33254
88b2504d0acf Fix an warning with selections. Selections are weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33253
diff changeset
1753 if (range)
88b2504d0acf Fix an warning with selections. Selections are weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33253
diff changeset
1754 return webkit_dom_range_get_text(range);
88b2504d0acf Fix an warning with selections. Selections are weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33253
diff changeset
1755 else
88b2504d0acf Fix an warning with selections. Selections are weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33253
diff changeset
1756 return NULL;
33014
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1757 }
2f8a83007ab9 Set up the link description from the already selected text.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33013
diff changeset
1758
35796
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1759 static gchar *
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1760 pidgin_webview_strip_empty_html(const gchar *text)
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1761 {
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1762 return g_regex_replace(empty_html_re, text, -1, 0, "", 0, NULL);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1763 }
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1764
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1765 gboolean
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1766 pidgin_webview_is_empty(PidginWebView *webview)
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1767 {
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1768 gchar *html, *tmp;
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1769 gboolean is_empty;
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1770
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1771 g_return_val_if_fail(webview != NULL, TRUE);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1772
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1773 html = pidgin_webview_get_body_html(webview);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1774 tmp = purple_strreplace(html, "&nbsp;", " ");
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1775 g_free(html);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1776 html = tmp;
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1777
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1778 tmp = pidgin_webview_strip_empty_html(html);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1779 g_free(html);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1780 html = tmp;
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1781
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1782 g_strstrip(html);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1783 is_empty = (html[0] == '\0');
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1784 g_free(html);
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1785
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1786 return is_empty;
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1787 }
bc5253318167 Show smiley images in the input entry and fix some smiley and inline image issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35785
diff changeset
1788
35129
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1789 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1790 pidgin_webview_get_caret(PidginWebView *webview, WebKitDOMNode **container_ret,
35129
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1791 glong *pos_ret)
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1792 {
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1793 WebKitDOMDocument *dom;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1794 WebKitDOMDOMWindow *win;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1795 WebKitDOMDOMSelection *sel;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1796 WebKitDOMRange *range = NULL;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1797 WebKitDOMNode *start_container, *end_container;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1798 glong start, end;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1799
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1800 g_return_if_fail(webview && container_ret && pos_ret);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1801
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1802 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1803 win = webkit_dom_document_get_default_view(dom);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1804 sel = webkit_dom_dom_window_get_selection(win);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1805 if (webkit_dom_dom_selection_get_range_count(sel))
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1806 range = webkit_dom_dom_selection_get_range_at(sel, 0, NULL);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1807
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1808 if (range) {
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1809 start_container = webkit_dom_range_get_start_container(range, NULL);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1810 start = webkit_dom_range_get_start_offset(range, NULL);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1811 end_container = webkit_dom_range_get_end_container(range, NULL);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1812 end = webkit_dom_range_get_end_offset(range, NULL);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1813
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1814 if (start == end &&
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1815 webkit_dom_node_is_same_node(start_container, end_container)) {
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1816
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1817 *container_ret = start_container;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1818 *pos_ret = start;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1819 return;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1820 }
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1821 }
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1822
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1823 *container_ret = NULL;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1824 *pos_ret = -1;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1825 }
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1826
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1827 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1828 pidgin_webview_set_caret(PidginWebView *webview, WebKitDOMNode *container, glong pos)
35129
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1829 {
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1830 WebKitDOMDocument *dom;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1831 WebKitDOMDOMWindow *win;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1832 WebKitDOMDOMSelection *sel;
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1833
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1834 g_return_if_fail(webview && container && pos >= 0);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1835
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1836 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1837 win = webkit_dom_document_get_default_view(dom);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1838 sel = webkit_dom_dom_window_get_selection(win);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1839
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1840 webkit_dom_dom_selection_set_position(sel, container, pos, NULL);
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1841 }
22dca763eeef Tab completion
Ankit Vani <a@nevitus.org>
parents: 35047
diff changeset
1842
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1843 PidginWebViewButtons
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1844 pidgin_webview_get_format_functions(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1845 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1846 PidginWebViewPriv *priv;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1847
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1848 g_return_val_if_fail(webview != NULL, 0);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1849
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1850 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1851 return priv->format_functions;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1852 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1853
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1854 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1855 pidgin_webview_get_current_format(PidginWebView *webview, gboolean *bold,
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1856 gboolean *italic, gboolean *underline,
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1857 gboolean *strike)
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1858 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1859 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1860
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1861 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1862
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1863 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1864
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1865 if (bold)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1866 *bold = webkit_dom_document_query_command_state(dom, "bold");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1867 if (italic)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1868 *italic = webkit_dom_document_query_command_state(dom, "italic");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1869 if (underline)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1870 *underline = webkit_dom_document_query_command_state(dom, "underline");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1871 if (strike)
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1872 *strike = webkit_dom_document_query_command_state(dom, "strikethrough");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1873 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1874
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1875 char *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1876 pidgin_webview_get_current_fontface(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1877 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1878 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1879
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1880 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1881
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1882 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1883 return webkit_dom_document_query_command_value(dom, "fontName");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1884 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1885
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1886 char *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1887 pidgin_webview_get_current_forecolor(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1888 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1889 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1890
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1891 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1892
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1893 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1894 return webkit_dom_document_query_command_value(dom, "foreColor");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1895 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1896
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1897 char *
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1898 pidgin_webview_get_current_backcolor(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1899 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1900 WebKitDOMDocument *dom;
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1901
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1902 g_return_val_if_fail(webview != NULL, NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1903
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1904 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1905 return webkit_dom_document_query_command_value(dom, "backColor");
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1906 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1907
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1908 gint
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1909 pidgin_webview_get_current_fontsize(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1910 {
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1911 WebKitDOMDocument *dom;
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1912 gchar *text;
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1913 gint size;
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1914
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1915 g_return_val_if_fail(webview != NULL, 0);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1916
32895
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1917 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1918 text = webkit_dom_document_query_command_value(dom, "fontSize");
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1919 size = atoi(text);
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1920 g_free(text);
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1921
fbd3b11e535a WebKit knows the current formatting of the selection better than we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32894
diff changeset
1922 return size;
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1923 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1924
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1925 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1926 pidgin_webview_clear_formatting(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1927 {
32813
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1928 GObject *object;
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1929
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1930 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1931
32813
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1932 object = g_object_ref(G_OBJECT(webview));
d1dc6f667a34 Emit the format-cleared signal when the webview format is cleared.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32812
diff changeset
1933 g_signal_emit(object, signals[CLEAR_FORMAT], 0);
33018
cfa94708af72 Emit formatting toggle signals.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33017
diff changeset
1934 g_object_unref(object);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1935 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1936
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1937 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1938 pidgin_webview_toggle_bold(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1939 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1940 g_return_if_fail(webview != NULL);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1941 emit_format_signal(webview, PIDGIN_WEBVIEW_BOLD);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1942 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1943
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1944 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1945 pidgin_webview_toggle_italic(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1946 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1947 g_return_if_fail(webview != NULL);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1948 emit_format_signal(webview, PIDGIN_WEBVIEW_ITALIC);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1949 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1950
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1951 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1952 pidgin_webview_toggle_underline(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1953 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1954 g_return_if_fail(webview != NULL);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1955 emit_format_signal(webview, PIDGIN_WEBVIEW_UNDERLINE);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1956 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1957
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1958 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1959 pidgin_webview_toggle_strike(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1960 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1961 g_return_if_fail(webview != NULL);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1962 emit_format_signal(webview, PIDGIN_WEBVIEW_STRIKE);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1963 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1964
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1965 gboolean
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1966 pidgin_webview_toggle_forecolor(PidginWebView *webview, const char *color)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1967 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1968 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1969
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1970 do_formatting(webview, "foreColor", color);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1971 emit_format_signal(webview, PIDGIN_WEBVIEW_FORECOLOR);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
1972
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1973 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1974 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1975
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1976 gboolean
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1977 pidgin_webview_toggle_backcolor(PidginWebView *webview, const char *color)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1978 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1979 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1980
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1981 do_formatting(webview, "backColor", color);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1982 emit_format_signal(webview, PIDGIN_WEBVIEW_BACKCOLOR);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
1983
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1984 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1985 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1986
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1987 gboolean
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1988 pidgin_webview_toggle_fontface(PidginWebView *webview, const char *face)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1989 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1990 g_return_val_if_fail(webview != NULL, FALSE);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
1991
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
1992 do_formatting(webview, "fontName", face);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1993 emit_format_signal(webview, PIDGIN_WEBVIEW_FACE);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
1994
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1995 return FALSE;
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1996 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1997
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
1998 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
1999 pidgin_webview_font_set_size(PidginWebView *webview, gint size)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2000 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2001 char *tmp;
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2002
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2003 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2004
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2005 tmp = g_strdup_printf("%d", size);
33006
86765d2f6f3b Setup WBFO in a WebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33004
diff changeset
2006 do_formatting(webview, "fontSize", tmp);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2007 emit_format_signal(webview, PIDGIN_WEBVIEW_SHRINK|PIDGIN_WEBVIEW_GROW);
32823
f179695f60cb Add some code for manipulating the WebView in edit-mode. Thanks to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32813
diff changeset
2008 g_free(tmp);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2009 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2010
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2011 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2012 pidgin_webview_font_shrink(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2013 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2014 g_return_if_fail(webview != NULL);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2015 emit_format_signal(webview, PIDGIN_WEBVIEW_SHRINK);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2016 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2017
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2018 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2019 pidgin_webview_font_grow(PidginWebView *webview)
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2020 {
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2021 g_return_if_fail(webview != NULL);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2022 emit_format_signal(webview, PIDGIN_WEBVIEW_GROW);
32805
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2023 }
57f914c32dc4 Copy some editing functions from GtkIMHtml. These are incomplete.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32803
diff changeset
2024
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2025 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2026 pidgin_webview_insert_hr(PidginWebView *webview)
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2027 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2028 PidginWebViewPriv *priv;
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2029 WebKitDOMDocument *dom;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2030
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2031 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2032
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2033 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33012
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2034 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2035
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2036 priv->edit.block_changed = TRUE;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2037 webkit_dom_document_exec_command(dom, "insertHorizontalRule", FALSE, "");
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2038 priv->edit.block_changed = FALSE;
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2039 }
3a742f00a0f4 Restore Insert Horizontal Rule functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33010
diff changeset
2040
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2041 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2042 pidgin_webview_insert_link(PidginWebView *webview, const char *url, const char *desc)
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2043 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2044 PidginWebViewPriv *priv;
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2045 WebKitDOMDocument *dom;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2046 char *link;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2047
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2048 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2049
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2050 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2051 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
33016
509c717fcf6e The URL probably needs to be quoted.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33014
diff changeset
2052 link = g_strdup_printf("<a href='%s'>%s</a>", url, desc ? desc : url);
33013
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2053
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2054 priv->edit.block_changed = TRUE;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2055 webkit_dom_document_exec_command(dom, "insertHTML", FALSE, link);
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2056 priv->edit.block_changed = FALSE;
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2057 g_free(link);
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2058 }
f62232fb738a Restore "Insert Link" functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33012
diff changeset
2059
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2060 void
35812
48c6ee645ca1 Imgstore vs PurpleImage: rip and fix
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35798
diff changeset
2061 pidgin_webview_insert_image(PidginWebView *webview, PurpleImage *image)
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2062 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2063 PidginWebViewPriv *priv;
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2064 WebKitDOMDocument *dom;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2065 char *img;
35812
48c6ee645ca1 Imgstore vs PurpleImage: rip and fix
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35798
diff changeset
2066 guint id;
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2067
33097
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2068 g_return_if_fail(webview != NULL);
acd0d7217593 Prevent crashing and stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33084
diff changeset
2069
35812
48c6ee645ca1 Imgstore vs PurpleImage: rip and fix
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35798
diff changeset
2070 id = purple_image_store_add(image);
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2071 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2072 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
35814
8d99745b6214 imgstore: rip from Pidgin (mostly gtkwebview)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35812
diff changeset
2073 img = g_strdup_printf("<img src='" PURPLE_IMAGE_STORE_PROTOCOL
35812
48c6ee645ca1 Imgstore vs PurpleImage: rip and fix
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35798
diff changeset
2074 "%u'/>", id);
33017
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2075
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2076 priv->edit.block_changed = TRUE;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2077 webkit_dom_document_exec_command(dom, "insertHTML", FALSE, img);
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2078 priv->edit.block_changed = FALSE;
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2079 g_free(img);
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2080 }
d21ab88ad911 Fixup Insert Image functionality.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33016
diff changeset
2081
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2082 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2083 pidgin_webview_set_toolbar(PidginWebView *webview, GtkWidget *toolbar)
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2084 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2085 PidginWebViewPriv *priv;
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2086
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2087 g_return_if_fail(webview != NULL);
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2088
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2089 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2090 priv->toolbar = PIDGIN_WEBVIEWTOOLBAR(toolbar);
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2091 }
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2092
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2093 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2094 pidgin_webview_show_toolbar(PidginWebView *webview)
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2095 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2096 PidginWebViewPriv *priv;
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2097
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2098 g_return_if_fail(webview != NULL);
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2099
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2100 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2101 g_return_if_fail(priv->toolbar != NULL);
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2102
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2103 gtk_widget_show(GTK_WIDGET(priv->toolbar));
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2104 }
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2105
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2106 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2107 pidgin_webview_hide_toolbar(PidginWebView *webview)
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2108 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2109 PidginWebViewPriv *priv;
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2110
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2111 g_return_if_fail(webview != NULL);
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2112
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2113 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2114 g_return_if_fail(priv->toolbar != NULL);
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2115
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2116 gtk_widget_hide(GTK_WIDGET(priv->toolbar));
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2117 }
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2118
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2119 void
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2120 pidgin_webview_activate_toolbar(PidginWebView *webview, PidginWebViewAction action)
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2121 {
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2122 PidginWebViewPriv *priv;
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2123
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2124 g_return_if_fail(webview != NULL);
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2125
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2126 priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2127 g_return_if_fail(priv->toolbar != NULL);
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2128
35500
ae6432ea326f Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
2129 pidgin_webviewtoolbar_activate(priv->toolbar, action);
34274
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2130 }
9169710b5af5 Hide GtkWebViewToolbar stuff within the GtkWebView.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33877
diff changeset
2131
35713
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2132 void
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2133 pidgin_webview_switch_active_conversation(PidginWebView *webview,
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2134 PurpleConversation *conv)
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2135 {
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2136 PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2137
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2138 g_return_if_fail(priv != NULL);
35716
80bedd712883 Custom smileys: parse and display in toolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35714
diff changeset
2139 if (priv->toolbar == NULL)
80bedd712883 Custom smileys: parse and display in toolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35714
diff changeset
2140 return;
35713
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2141
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2142 pidgin_webviewtoolbar_switch_active_conversation(priv->toolbar, conv);
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35648
diff changeset
2143 }

mercurial