3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #ifndef _PIDGIN_WEBVIEW_H_
24 #define _PIDGIN_WEBVIEW_H_
27 * @section_id: pidgin-gtkwebview
28 * @short_description: <filename>gtkwebview.h</filename>
29 * @title: WebKitWebView Wrapper
31 * Wrapper over the Gtk WebKitWebView component.
36 #include <webkit/webkit.h>
38 #define PIDGIN_TYPE_WEBVIEW (pidgin_webview_get_type())
39 #define PIDGIN_WEBVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PIDGIN_TYPE_WEBVIEW, PidginWebView))
40 #define PIDGIN_WEBVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PIDGIN_TYPE_WEBVIEW, PidginWebViewClass))
41 #define PIDGIN_IS_WEBVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PIDGIN_TYPE_WEBVIEW))
42 #define PIDGIN_IS_WEBVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PIDGIN_TYPE_WEBVIEW))
43 #define PIDGIN_WEBVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PIDGIN_TYPE_WEBVIEW, PidginWebViewClass))
46 /*salinasv: this are partially magic numbers, we need to find how to get them from the DOM */
47 #define WEBVIEW_DOM_FONT_PADDING 3
48 #define WEBVIEW_DOM_TEXT_PADDING 16
51 PIDGIN_WEBVIEW_BOLD
= 1 << 0,
52 PIDGIN_WEBVIEW_ITALIC
= 1 << 1,
53 PIDGIN_WEBVIEW_UNDERLINE
= 1 << 2,
54 PIDGIN_WEBVIEW_GROW
= 1 << 3,
55 PIDGIN_WEBVIEW_SHRINK
= 1 << 4,
56 PIDGIN_WEBVIEW_FACE
= 1 << 5,
57 PIDGIN_WEBVIEW_FORECOLOR
= 1 << 6,
58 PIDGIN_WEBVIEW_BACKCOLOR
= 1 << 7,
59 PIDGIN_WEBVIEW_LINK
= 1 << 8,
60 PIDGIN_WEBVIEW_IMAGE
= 1 << 9,
61 PIDGIN_WEBVIEW_SMILEY
= 1 << 10,
62 PIDGIN_WEBVIEW_LINKDESC
= 1 << 11,
63 PIDGIN_WEBVIEW_STRIKE
= 1 << 12,
64 /* Show custom smileys when appropriate. */
65 PIDGIN_WEBVIEW_CUSTOM_SMILEY
= 1 << 13,
66 PIDGIN_WEBVIEW_ALL
= -1
67 } PidginWebViewButtons
;
70 PIDGIN_WEBVIEW_ACTION_BOLD
,
71 PIDGIN_WEBVIEW_ACTION_ITALIC
,
72 PIDGIN_WEBVIEW_ACTION_UNDERLINE
,
73 PIDGIN_WEBVIEW_ACTION_STRIKE
,
74 PIDGIN_WEBVIEW_ACTION_LARGER
,
76 PIDGIN_WEBVIEW_ACTION_NORMAL
,
78 PIDGIN_WEBVIEW_ACTION_SMALLER
,
79 PIDGIN_WEBVIEW_ACTION_FONTFACE
,
80 PIDGIN_WEBVIEW_ACTION_FGCOLOR
,
81 PIDGIN_WEBVIEW_ACTION_BGCOLOR
,
82 PIDGIN_WEBVIEW_ACTION_CLEAR
,
83 PIDGIN_WEBVIEW_ACTION_IMAGE
,
84 PIDGIN_WEBVIEW_ACTION_LINK
,
85 PIDGIN_WEBVIEW_ACTION_HR
,
86 PIDGIN_WEBVIEW_ACTION_SMILEY
,
87 PIDGIN_WEBVIEW_ACTION_ATTENTION
88 } PidginWebViewAction
;
90 typedef struct _PidginWebView PidginWebView
;
91 typedef struct _PidginWebViewClass PidginWebViewClass
;
98 struct _PidginWebViewClass
100 WebKitWebViewClass parent
;
104 void (*buttons_update
)(PidginWebView
*, PidginWebViewButtons
);
105 void (*toggle_format
)(PidginWebView
*, PidginWebViewButtons
);
106 void (*clear_format
)(PidginWebView
*);
107 void (*update_format
)(PidginWebView
*);
108 void (*changed
)(PidginWebView
*);
109 void (*html_appended
)(PidginWebView
*, WebKitDOMRange
*);
110 gboolean (*insert_image
)(PidginWebView
*, PurpleImage
*);
116 * pidgin_webview_get_type:
118 * Returns: The #GType for #PidginWebView widget
120 GType
pidgin_webview_get_type(void);
123 * pidgin_webview_new:
124 * @editable: Whether this PidginWebView will be user-editable
126 * Create a new PidginWebView object
128 * Returns: A GtkWidget corresponding to the PidginWebView object
130 GtkWidget
*pidgin_webview_new(gboolean editable
);
133 * pidgin_webview_append_html:
134 * @webview: The PidginWebView object
135 * @markup: The html markup to append
137 * A very basic routine to append html, which can be considered
138 * equivalent to a "document.write" using JavaScript.
140 void pidgin_webview_append_html(PidginWebView
*webview
, const char *markup
);
143 * pidgin_webview_load_html_string:
144 * @webview: The PidginWebView object
145 * @html: The HTML content to load
147 * Requests loading of the given content.
149 void pidgin_webview_load_html_string(PidginWebView
*webview
, const char *html
);
152 * pidgin_webview_load_html_string_with_selection:
153 * @webview: The PidginWebView object
154 * @html: The HTML content to load
156 * Requests loading of the given content and sets the selection. You must
157 * include an anchor tag with id='caret' in the HTML string, which will be
158 * used to set the selection. This tag is then removed so that querying the
159 * WebView's HTML contents will no longer return it.
161 void pidgin_webview_load_html_string_with_selection(PidginWebView
*webview
, const char *html
);
164 * pidgin_webview_safe_execute_script:
165 * @webview: The PidginWebView object
166 * @script: The script to execute
168 * Execute the JavaScript only after the webkit_webview_load_string
169 * loads completely. We also guarantee that the scripts are executed
170 * in the order they are called here. This is useful to avoid race
171 * conditions when calling JS functions immediately after opening the
174 void pidgin_webview_safe_execute_script(PidginWebView
*webview
, const char *script
);
177 * pidgin_webview_quote_js_string:
178 * @str: The string to escape and quote
180 * A convenience routine to quote a string for use as a JavaScript
181 * string. For instance, "hello 'world'" becomes "'hello \\'world\\''"
183 * Returns: The quoted string
185 char *pidgin_webview_quote_js_string(const char *str
);
188 * pidgin_webview_set_vadjustment:
189 * @webview: The PidginWebView object
190 * @vadj: The GtkAdjustment that control the webview
192 * Set the vertical adjustment for the PidginWebView.
194 void pidgin_webview_set_vadjustment(PidginWebView
*webview
, GtkAdjustment
*vadj
);
197 * pidgin_webview_scroll_to_end:
198 * @webview: The PidginWebView object
199 * @smooth: A boolean indicating if smooth scrolling should be used
201 * Scrolls the Webview to the end of its contents.
203 void pidgin_webview_scroll_to_end(PidginWebView
*webview
, gboolean smooth
);
206 * pidgin_webview_set_autoscroll:
207 * @webview: The PidginWebView object
208 * @scroll: Whether to automatically scroll
210 * Set whether the PidginWebView stays at its end when HTML content is appended. If
211 * not already at the end before appending, then scrolling will not occur.
213 void pidgin_webview_set_autoscroll(PidginWebView
*webview
, gboolean scroll
);
216 * pidgin_webview_get_autoscroll:
217 * @webview: The PidginWebView object
219 * Set whether the PidginWebView stays at its end when HTML content is appended. If
220 * not already at the end before appending, then scrolling will not occur.
222 * Returns: Whether to automatically scroll
224 gboolean
pidgin_webview_get_autoscroll(PidginWebView
*webview
);
227 * pidgin_webview_page_up:
228 * @webview: The PidginWebView.
230 * Scrolls a PidginWebView up by one page.
232 void pidgin_webview_page_up(PidginWebView
*webview
);
235 * pidgin_webview_page_down:
236 * @webview: The PidginWebView.
238 * Scrolls a PidginWebView down by one page.
240 void pidgin_webview_page_down(PidginWebView
*webview
);
243 * pidgin_webview_setup_entry:
244 * @webview: The PidginWebView.
245 * @flags: The connection flags describing the allowed formatting.
247 * Setup formatting for a PidginWebView depending on the flags specified.
249 void pidgin_webview_setup_entry(PidginWebView
*webview
, PurpleConnectionFlags flags
);
252 * pidgin_webview_set_spellcheck:
253 * @webview: The PidginWebView.
254 * @enable: Whether to enable or disable spell-checking.
256 * Setup spell-checking on a PidginWebView.
258 void pidgin_webview_set_spellcheck(PidginWebView
*webview
, gboolean enable
);
261 * pidgin_webview_set_whole_buffer_formatting_only:
262 * @webview: The PidginWebView
263 * @wbfo: %TRUE to enable the mode, or %FALSE otherwise.
265 * Enables or disables whole buffer formatting only (wbfo) in a PidginWebView.
266 * In this mode formatting options to the buffer take effect for the entire
267 * buffer instead of specific text.
269 void pidgin_webview_set_whole_buffer_formatting_only(PidginWebView
*webview
,
273 * pidgin_webview_set_format_functions:
274 * @webview: The PidginWebView
275 * @buttons: A PidginWebViewButtons bitmask indicating which functions to use
277 * Indicates which formatting functions to enable and disable in a PidginWebView.
279 void pidgin_webview_set_format_functions(PidginWebView
*webview
,
280 PidginWebViewButtons buttons
);
283 * pidgin_webview_activate_anchor:
284 * @link: The WebKitDOMHTMLAnchorElement object
286 * Activates a WebKitDOMHTMLAnchorElement object. This triggers the navigation
287 * signals, and marks the link as visited (when possible).
289 void pidgin_webview_activate_anchor(WebKitDOMHTMLAnchorElement
*link
);
292 * pidgin_webview_class_register_protocol:
293 * @name: The name of the protocol (e.g. http://)
294 * @activate: The callback to trigger when the protocol text is clicked.
295 * Removes any current protocol definition if %NULL. The
296 * callback should return %TRUE if the link was activated
297 * properly, %FALSE otherwise.
298 * @context_menu: The callback to trigger when the context menu is popped
299 * up on the protocol text. The callback should return
300 * %TRUE if the request for context menu was processed
301 * successfully, %FALSE otherwise.
303 * Register a protocol with the PidginWebView widget. Registering a protocol would
304 * allow certain text to be clickable.
306 * Returns: %TRUE if the protocol was successfully registered
307 * (or unregistered, when \a activate is %NULL)
309 gboolean
pidgin_webview_class_register_protocol(const char *name
,
310 gboolean (*activate
)(PidginWebView
*webview
, const char *uri
),
311 gboolean (*context_menu
)(PidginWebView
*webview
, WebKitDOMHTMLAnchorElement
*link
, GtkWidget
*menu
));
314 * pidgin_webview_get_format_functions:
315 * @webview: The PidginWebView
317 * Returns which formatting functions are enabled in a PidginWebView.
319 * Returns: A PidginWebViewButtons bitmask indicating which functions to are enabled
321 PidginWebViewButtons
pidgin_webview_get_format_functions(PidginWebView
*webview
);
324 * pidgin_webview_get_current_format:
325 * @webview: The PidginWebView
326 * @bold: The boolean to set for bold or %NULL.
327 * @italic: The boolean to set for italic or %NULL.
328 * @underline: The boolean to set for underline or %NULL.
329 * @strikethrough: The boolean to set for strikethrough or %NULL.
331 * Sets each boolean to %TRUE or %FALSE to indicate if that formatting
332 * option is enabled at the current position in a PidginWebView.
334 void pidgin_webview_get_current_format(PidginWebView
*webview
, gboolean
*bold
,
335 gboolean
*italic
, gboolean
*underline
,
336 gboolean
*strikethrough
);
339 * pidgin_webview_get_current_fontface:
340 * @webview: The PidginWebView
342 * Returns a string containing the selected font face at the current position
343 * in a PidginWebView.
345 * Returns: A string containing the font face or %NULL if none is set.
347 char *pidgin_webview_get_current_fontface(PidginWebView
*webview
);
350 * pidgin_webview_get_current_forecolor:
351 * @webview: The PidginWebView
353 * Returns a string containing the selected foreground color at the current
354 * position in a PidginWebView.
356 * Returns: A string containing the foreground color or %NULL if none is set.
358 char *pidgin_webview_get_current_forecolor(PidginWebView
*webview
);
361 * pidgin_webview_get_current_backcolor:
362 * @webview: The PidginWebView
364 * Returns a string containing the selected font background color at the current
365 * position in a PidginWebView.
367 * Returns: A string containing the background color or %NULL if none is set.
369 char *pidgin_webview_get_current_backcolor(PidginWebView
*webview
);
372 * pidgin_webview_get_current_fontsize:
373 * @webview: The PidginWebView
375 * Returns a integer containing the selected HTML font size at the current
376 * position in a PidginWebView.
378 * Returns: The HTML font size.
380 gint
pidgin_webview_get_current_fontsize(PidginWebView
*webview
);
383 * pidgin_webview_get_head_html:
384 * @webview: The PidginWebView
386 * Gets the content of the head element of a PidginWebView as HTML.
388 * Returns: The HTML from the head element.
390 gchar
*pidgin_webview_get_head_html(PidginWebView
*webview
);
393 * pidgin_webview_get_body_html:
394 * @webview: The PidginWebView
396 * Gets the HTML content of a PidginWebView.
398 * Returns: The HTML that is currently displayed.
400 gchar
*pidgin_webview_get_body_html(PidginWebView
*webview
);
403 * pidgin_webview_get_body_text:
404 * @webview: The PidginWebView
406 * Gets the text content of a PidginWebView.
408 * Returns: The HTML-free text that is currently displayed.
410 gchar
*pidgin_webview_get_body_text(PidginWebView
*webview
);
413 * pidgin_webview_get_selected_text:
414 * @webview: The PidginWebView
416 * Gets the selected text of a PidginWebView.
418 * Returns: The HTML-free text that is currently selected, or NULL if nothing is
419 * currently selected.
421 gchar
*pidgin_webview_get_selected_text(PidginWebView
*webview
);
424 * pidgin_webview_is_empty:
425 * @webview: the PidginWebView.
427 * Checks, if the @webview is empty.
429 * Returns %TRUES, if the @webview is empty, %FALSE otherwise.
432 pidgin_webview_is_empty(PidginWebView
*webview
);
435 * pidgin_webview_get_caret:
436 * @webview: The PidginWebView
437 * @container_ret: A pointer to a pointer to a WebKitDOMNode. This pointer
438 * will be set to the container the caret is in. Set to
439 * %NULL if a range is selected.
440 * @pos_ret: A pointer to a glong. This value will be set to the
441 * position of the caret in the container. Set to -1 if a
444 * Gets the container of the caret, along with its position in the container
445 * from a PidginWebView.
447 void pidgin_webview_get_caret(PidginWebView
*webview
, WebKitDOMNode
**container_ret
,
451 * pidgin_webview_set_caret:
452 * @webview: The PidginWebView
453 * @container: The WebKitDOMNode to set the caret in
454 * @pos: The position of the caret in the container
456 * Sets the caret position in container, in a PidginWebView.
458 void pidgin_webview_set_caret(PidginWebView
*webview
, WebKitDOMNode
*container
,
462 * pidgin_webview_clear_formatting:
463 * @webview: The PidginWebView
465 * Clear all the formatting on a PidginWebView.
467 void pidgin_webview_clear_formatting(PidginWebView
*webview
);
470 * pidgin_webview_toggle_bold:
471 * @webview: The PidginWebView
473 * Toggles bold at the cursor location or selection in a PidginWebView.
475 void pidgin_webview_toggle_bold(PidginWebView
*webview
);
478 * pidgin_webview_toggle_italic:
479 * @webview: The PidginWebView
481 * Toggles italic at the cursor location or selection in a PidginWebView.
483 void pidgin_webview_toggle_italic(PidginWebView
*webview
);
486 * pidgin_webview_toggle_underline:
487 * @webview: The PidginWebView
489 * Toggles underline at the cursor location or selection in a PidginWebView.
491 void pidgin_webview_toggle_underline(PidginWebView
*webview
);
494 * pidgin_webview_toggle_strike:
495 * @webview: The PidginWebView
497 * Toggles strikethrough at the cursor location or selection in a PidginWebView.
499 void pidgin_webview_toggle_strike(PidginWebView
*webview
);
502 * pidgin_webview_toggle_forecolor:
503 * @webview: The PidginWebView
504 * @color: The HTML-style color, or %NULL or "" to clear the color.
506 * Toggles a foreground color at the current location or selection in a
509 * Returns: %TRUE if a color was set, or %FALSE if it was cleared.
511 gboolean
pidgin_webview_toggle_forecolor(PidginWebView
*webview
, const char *color
);
514 * pidgin_webview_toggle_backcolor:
515 * @webview: The PidginWebView
516 * @color: The HTML-style color, or %NULL or "" to clear the color.
518 * Toggles a background color at the current location or selection in a
521 * Returns: %TRUE if a color was set, or %FALSE if it was cleared.
523 gboolean
pidgin_webview_toggle_backcolor(PidginWebView
*webview
, const char *color
);
526 * pidgin_webview_toggle_fontface:
527 * @webview: The PidginWebView
528 * @face: The font face name, or %NULL or "" to clear the font.
530 * Toggles a font face at the current location or selection in a PidginWebView.
532 * Returns: %TRUE if a font name was set, or %FALSE if it was cleared.
534 gboolean
pidgin_webview_toggle_fontface(PidginWebView
*webview
, const char *face
);
537 * pidgin_webview_font_set_size:
538 * @webview: The PidginWebView
539 * @size: The HTML font size to use.
541 * Sets the font size at the current location or selection in a PidginWebView.
543 void pidgin_webview_font_set_size(PidginWebView
*webview
, gint size
);
546 * pidgin_webview_font_shrink:
547 * @webview: The PidginWebView
549 * Decreases the font size by 1 at the current location or selection in a
552 void pidgin_webview_font_shrink(PidginWebView
*webview
);
555 * pidgin_webview_font_grow:
556 * @webview: The PidginWebView
558 * Increases the font size by 1 at the current location or selection in a
561 void pidgin_webview_font_grow(PidginWebView
*webview
);
564 * pidgin_webview_insert_hr:
565 * @webview: The PidginWebView
567 * Inserts a horizontal rule at the current location or selection in a
570 void pidgin_webview_insert_hr(PidginWebView
*webview
);
573 * pidgin_webview_insert_link:
574 * @webview: The PidginWebView
575 * @url: The URL of the link
576 * @desc: The text description of the link. If not supplied, the URL is
579 * Inserts a link at the current location or selection in a PidginWebView.
581 void pidgin_webview_insert_link(PidginWebView
*webview
, const char *url
, const char *desc
);
584 * pidgin_webview_insert_image:
585 * @webview: the PidginWebView.
586 * @image: the PurpleImage.
588 * Inserts an image at the current location or selection in a PidginWebView.
591 pidgin_webview_insert_image(PidginWebView
*webview
, PurpleImage
*image
);
594 * pidgin_webview_get_DOM_height:
595 * @webview: the PidginWebView.
597 * Look for the calculated height for the DOM on the webview.
599 * Returns the total height of the DOM in the webview.
602 pidgin_webview_get_DOM_height(PidginWebView
*webview
);
605 * pidgin_webview_get_DOM_height:
606 * @webview: the PidginWebView.
608 * Look for the font size used on the current webview
610 * Returns the font size for the webview.
613 pidgin_webview_get_font_size(PidginWebView
*webview
);
616 * pidgin_webview_get_protocol_name:
617 * @webview: The PidginWebView
619 * Gets the protocol name associated with this PidginWebView.
621 const char *pidgin_webview_get_protocol_name(PidginWebView
*webview
);
624 * pidgin_webview_show_toolbar:
625 * @webview: The PidginWebView.
627 * Makes the toolbar associated with a PidginWebView visible.
629 void pidgin_webview_show_toolbar(PidginWebView
*webview
);
632 * pidgin_webview_hide_toolbar:
633 * @webview: The PidginWebView.
635 * Makes the toolbar associated with a PidginWebView invisible.
637 void pidgin_webview_hide_toolbar(PidginWebView
*webview
);
640 * pidgin_webview_activate_toolbar:
641 * @webview: The PidginWebView
642 * @action: The PidginWebViewAction
644 * Activate an action on the toolbar associated with a PidginWebView.
646 void pidgin_webview_activate_toolbar(PidginWebView
*webview
, PidginWebViewAction action
);
649 * pidgin_webview_switch_active_conversation:
650 * @webview: The PidginWebView
651 * @conv: The conversation.
653 * Updates the webview for a new active #PurpleConversation.
656 pidgin_webview_switch_active_conversation(PidginWebView
*webview
,
657 PurpleConversation
*conv
);
659 /* Do not use. TODO: rename to _pidgin and move to gtkinternal.h */
661 pidgin_webview_set_toolbar(PidginWebView
*webview
, GtkWidget
*toolbar
);
664 * pidgin_webview_get_toolbar:
665 * @webview: The PidginWebView
667 * Returns the toolbar associated with the webview.
669 * Returns: the toolbar.
672 pidgin_webview_get_toolbar(PidginWebView
*webview
);
676 #endif /* _PIDGIN_WEBVIEW_H_ */