pidgin: 0305c99d: WebKit knows the current formatting of t...
qulogic at pidgin.im
qulogic at pidgin.im
Mon Feb 27 18:11:26 EST 2012
----------------------------------------------------------------------
Revision: 0305c99dc3cbe96a88f5df913e6d616c73e778c5
Parent: 399191b455275ea1846078765377597030ef8f60
Author: qulogic at pidgin.im
Date: 02/27/12 01:35:27
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/0305c99dc3cbe96a88f5df913e6d616c73e778c5
Changelog:
WebKit knows the current formatting of the selection better than we
do, so don't bother saving it ourselves.
Changes against parent 399191b455275ea1846078765377597030ef8f60
patched pidgin/gtkwebview.c
patched pidgin/gtkwebview.h
patched pidgin/gtkwebviewtoolbar.c
-------------- next part --------------
============================================================
--- pidgin/gtkwebview.c 803e2abf22b1d7477a1f9227064ffc86c6795708
+++ pidgin/gtkwebview.c 71dca9dbbec3b6f3c7306f9aa73d1e9ec93f295f
@@ -68,16 +68,7 @@ typedef struct _GtkWebViewPriv {
GtkWebViewButtons format_functions;
struct {
gboolean wbfo:1; /* Whole buffer formatting only. */
- gboolean bold:1;
- gboolean italic:1;
- gboolean underline:1;
- gboolean strike:1;
- gchar *forecolor;
- gchar *backcolor;
gchar *background;
- gchar *fontface;
- int fontsize;
- /*GtkTextTag *link;*/
} edit;
} GtkWebViewPriv;
@@ -319,21 +310,6 @@ webview_clear_formatting(GtkWebView *web
if (!webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview)))
return;
- priv->edit.bold = FALSE;
- priv->edit.italic = FALSE;
- priv->edit.underline = FALSE;
- priv->edit.strike = FALSE;
- priv->edit.fontsize = 0;
-
- g_free(priv->edit.fontface);
- priv->edit.fontface = NULL;
-
- g_free(priv->edit.forecolor);
- priv->edit.forecolor = NULL;
-
- g_free(priv->edit.backcolor);
- priv->edit.backcolor = NULL;
-
g_free(priv->edit.background);
priv->edit.background = NULL;
@@ -545,6 +521,7 @@ gtk_webview_quote_js_string(const char *
return g_string_free(str, FALSE);
}
+
void
gtk_webview_safe_execute_script(GtkWebView *webview, const char *script)
{
@@ -611,7 +588,8 @@ gtk_webview_scroll_to_end(GtkWebView *we
}
}
-void gtk_webview_page_up(GtkWebView *webview)
+void
+gtk_webview_page_up(GtkWebView *webview)
{
GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
GtkAdjustment *vadj = priv->vadj;
@@ -628,7 +606,8 @@ void gtk_webview_page_up(GtkWebView *web
gtk_adjustment_set_value(vadj, scroll_val);
}
-void gtk_webview_page_down(GtkWebView *webview)
+void
+gtk_webview_page_down(GtkWebView *webview)
{
GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
GtkAdjustment *vadj = priv->vadj;
@@ -657,12 +636,12 @@ gtk_webview_setup_entry(GtkWebView *webv
void
gtk_webview_setup_entry(GtkWebView *webview, PurpleConnectionFlags flags)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
GtkWebViewButtons buttons;
if (flags & PURPLE_CONNECTION_HTML) {
char color[8];
GdkColor fg_color, bg_color;
+ gboolean bold, italic, underline, strike;
buttons = GTK_WEBVIEW_ALL;
@@ -676,17 +655,19 @@ gtk_webview_setup_entry(GtkWebView *webv
if (flags & PURPLE_CONNECTION_NO_URLDESC)
buttons &= ~GTK_WEBVIEW_LINKDESC;
+ gtk_webview_get_current_format(webview, &bold, &italic, &underline, &strike);
+
gtk_webview_set_format_functions(webview, GTK_WEBVIEW_ALL);
- if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != priv->edit.bold)
+ if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != bold)
gtk_webview_toggle_bold(webview);
- if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != priv->edit.italic)
+ if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != italic)
gtk_webview_toggle_italic(webview);
- if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != priv->edit.underline)
+ if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != underline)
gtk_webview_toggle_underline(webview);
- if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike") != priv->edit.strike)
+ if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike") != strike)
gtk_webview_toggle_strike(webview);
gtk_webview_toggle_fontface(webview,
@@ -705,24 +686,26 @@ gtk_webview_setup_entry(GtkWebView *webv
{
gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"),
&fg_color);
- g_snprintf(color, sizeof(color), "#%02x%02x%02x",
- fg_color.red / 256,
- fg_color.green / 256,
- fg_color.blue / 256);
+ g_snprintf(color, sizeof(color),
+ "#%02x%02x%02x",
+ fg_color.red / 256,
+ fg_color.green / 256,
+ fg_color.blue / 256);
} else
strcpy(color, "");
gtk_webview_toggle_forecolor(webview, color);
- if(!(flags & PURPLE_CONNECTION_NO_BGCOLOR) &&
- strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"), "") != 0)
+ if (!(flags & PURPLE_CONNECTION_NO_BGCOLOR) &&
+ strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"), "") != 0)
{
gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"),
&bg_color);
- g_snprintf(color, sizeof(color), "#%02x%02x%02x",
- bg_color.red / 256,
- bg_color.green / 256,
- bg_color.blue / 256);
+ g_snprintf(color, sizeof(color),
+ "#%02x%02x%02x",
+ bg_color.red / 256,
+ bg_color.green / 256,
+ bg_color.blue / 256);
} else
strcpy(color, "");
@@ -777,50 +760,63 @@ gtk_webview_get_current_format(GtkWebVie
gboolean *italic, gboolean *underline,
gboolean *strike)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ WebKitDOMDocument *dom;
+ dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+
if (bold)
- *bold = priv->edit.bold;
+ *bold = webkit_dom_document_query_command_state(dom, "bold");
if (italic)
- *italic = priv->edit.italic;
+ *italic = webkit_dom_document_query_command_state(dom, "italic");
if (underline)
- *underline = priv->edit.underline;
+ *underline = webkit_dom_document_query_command_state(dom, "underline");
if (strike)
- *strike = priv->edit.strike;
+ *strike = webkit_dom_document_query_command_state(dom, "strikethrough");
}
-const char *
+char *
gtk_webview_get_current_fontface(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- return priv->edit.fontface;
+ WebKitDOMDocument *dom;
+ dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+ return webkit_dom_document_query_command_value(dom, "fontName");
}
-const char *
+char *
gtk_webview_get_current_forecolor(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- return priv->edit.forecolor;
+ WebKitDOMDocument *dom;
+ dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+ return webkit_dom_document_query_command_value(dom, "foreColor");
}
-const char *
+char *
gtk_webview_get_current_backcolor(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- return priv->edit.backcolor;
+ WebKitDOMDocument *dom;
+ dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+ return webkit_dom_document_query_command_value(dom, "backColor");
}
-const char *
+char *
gtk_webview_get_current_background(GtkWebView *webview)
{
GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- return priv->edit.background;
+ return g_strdup(priv->edit.background);
}
gint
gtk_webview_get_current_fontsize(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- return priv->edit.fontsize;
+ WebKitDOMDocument *dom;
+ gchar *text;
+ gint size;
+
+ dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+ text = webkit_dom_document_query_command_value(dom, "fontSize");
+ size = atoi(text);
+ g_free(text);
+
+ return size;
}
gboolean
@@ -845,11 +841,8 @@ gtk_webview_toggle_bold(GtkWebView *webv
void
gtk_webview_toggle_bold(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
- priv->edit.bold = !priv->edit.bold;
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
webkit_dom_document_exec_command(dom, "bold", FALSE, "");
}
@@ -857,11 +850,8 @@ gtk_webview_toggle_italic(GtkWebView *we
void
gtk_webview_toggle_italic(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
- priv->edit.italic = !priv->edit.italic;
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
webkit_dom_document_exec_command(dom, "italic", FALSE, "");
}
@@ -869,11 +859,8 @@ gtk_webview_toggle_underline(GtkWebView
void
gtk_webview_toggle_underline(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
- priv->edit.underline = !priv->edit.underline;
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
webkit_dom_document_exec_command(dom, "underline", FALSE, "");
}
@@ -881,11 +868,8 @@ gtk_webview_toggle_strike(GtkWebView *we
void
gtk_webview_toggle_strike(GtkWebView *webview)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
- priv->edit.strike = !priv->edit.strike;
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
webkit_dom_document_exec_command(dom, "strikethrough", FALSE, "");
}
@@ -893,14 +877,10 @@ gtk_webview_toggle_forecolor(GtkWebView
gboolean
gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
- g_free(priv->edit.forecolor);
- priv->edit.forecolor = g_strdup(color);
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
- webkit_dom_document_exec_command(dom, "forecolor", FALSE, color);
+ webkit_dom_document_exec_command(dom, "foreColor", FALSE, color);
return FALSE;
}
@@ -908,14 +888,10 @@ gtk_webview_toggle_backcolor(GtkWebView
gboolean
gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
- g_free(priv->edit.backcolor);
- priv->edit.backcolor = g_strdup(color);
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
- webkit_dom_document_exec_command(dom, "backcolor", FALSE, color);
+ webkit_dom_document_exec_command(dom, "backColor", FALSE, color);
return FALSE;
}
@@ -934,14 +910,10 @@ gtk_webview_toggle_fontface(GtkWebView *
gboolean
gtk_webview_toggle_fontface(GtkWebView *webview, const char *face)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
- g_free(priv->edit.fontface);
- priv->edit.fontface = g_strdup(face);
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
- webkit_dom_document_exec_command(dom, "fontname", FALSE, face);
+ webkit_dom_document_exec_command(dom, "fontName", FALSE, face);
return FALSE;
}
@@ -949,15 +921,12 @@ gtk_webview_font_set_size(GtkWebView *we
void
gtk_webview_font_set_size(GtkWebView *webview, gint size)
{
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
char *tmp;
- priv->edit.fontsize = size;
-
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
tmp = g_strdup_printf("%d", size);
- webkit_dom_document_exec_command(dom, "fontsize", FALSE, tmp);
+ webkit_dom_document_exec_command(dom, "fontSize", FALSE, tmp);
g_free(tmp);
}
@@ -966,13 +935,15 @@ gtk_webview_font_shrink(GtkWebView *webv
{
GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
+ gint fontsize;
char *tmp;
- priv->edit.fontsize = MAX(priv->edit.fontsize - 1, 1);
+ fontsize = gtk_webview_get_current_fontsize(webview);
+ fontsize = MAX(fontsize - 1, 1);
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
- tmp = g_strdup_printf("%d", priv->edit.fontsize);
- webkit_dom_document_exec_command(dom, "fontsize", FALSE, tmp);
+ tmp = g_strdup_printf("%d", fontsize);
+ webkit_dom_document_exec_command(dom, "fontSize", FALSE, tmp);
g_free(tmp);
}
@@ -981,13 +952,15 @@ gtk_webview_font_grow(GtkWebView *webvie
{
GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
WebKitDOMDocument *dom;
+ gint fontsize;
char *tmp;
- priv->edit.fontsize = MIN(priv->edit.fontsize + 1, MAX_FONT_SIZE);
+ fontsize = gtk_webview_get_current_fontsize(webview);
+ fontsize = MIN(fontsize + 1, MAX_FONT_SIZE);
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
- tmp = g_strdup_printf("%d", priv->edit.fontsize);
- webkit_dom_document_exec_command(dom, "fontsize", FALSE, tmp);
+ tmp = g_strdup_printf("%d", fontsize);
+ webkit_dom_document_exec_command(dom, "fontSize", FALSE, tmp);
g_free(tmp);
}
============================================================
--- pidgin/gtkwebview.h e46233d6e576081f295f21296f79ddce69fe3236
+++ pidgin/gtkwebview.h 6b3a64ffd30804f5df8132642539ae8a773c4eb5
@@ -242,7 +242,7 @@ void gtk_webview_get_current_format(GtkW
*
* @return A string containing the font face or @c NULL if none is set.
*/
-const char *gtk_webview_get_current_fontface(GtkWebView *webview);
+char *gtk_webview_get_current_fontface(GtkWebView *webview);
/**
* Returns a string containing the selected foreground color at the current
@@ -252,7 +252,7 @@ const char *gtk_webview_get_current_font
*
* @return A string containing the foreground color or @c NULL if none is set.
*/
-const char *gtk_webview_get_current_forecolor(GtkWebView *webview);
+char *gtk_webview_get_current_forecolor(GtkWebView *webview);
/**
* Returns a string containing the selected font background color at the current
@@ -262,7 +262,7 @@ const char *gtk_webview_get_current_fore
*
* @return A string containing the background color or @c NULL if none is set.
*/
-const char *gtk_webview_get_current_backcolor(GtkWebView *webview);
+char *gtk_webview_get_current_backcolor(GtkWebView *webview);
/**
* Returns a string containing the selected background color at the current
@@ -272,7 +272,7 @@ const char *gtk_webview_get_current_back
*
* @return A string containg the background color or @c NULL if none is set.
*/
-const char *gtk_webview_get_current_background(GtkWebView *webview);
+char *gtk_webview_get_current_background(GtkWebView *webview);
/**
* Returns a integer containing the selected HTML font size at the current
============================================================
--- pidgin/gtkwebviewtoolbar.c 1cb95230dfb25c02e5252eed1b17087fbed7c505
+++ pidgin/gtkwebviewtoolbar.c 5f779f8927584bb9386bb2abf7e252fa8cdc9077
@@ -253,7 +253,7 @@ toggle_font(GtkWidget *font, GtkWebViewT
priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(font))) {
- const char *fontname = gtk_webview_get_current_fontface(GTK_WEBVIEW(toolbar->webview));
+ char *fontname = gtk_webview_get_current_fontface(GTK_WEBVIEW(toolbar->webview));
if (!priv->font_dialog) {
priv->font_dialog = gtk_font_selection_dialog_new(_("Select Font"));
@@ -279,6 +279,8 @@ toggle_font(GtkWidget *font, GtkWebViewT
}
gtk_window_present(GTK_WINDOW(priv->font_dialog));
+
+ g_free(fontname);
} else {
cancel_toolbar_font(font, toolbar);
}
@@ -341,7 +343,7 @@ toggle_fg_color(GtkWidget *color, GtkWeb
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) {
GtkWidget *colorsel;
GdkColor fgcolor;
- const char *color = gtk_webview_get_current_forecolor(GTK_WEBVIEW(toolbar->webview));
+ char *color = gtk_webview_get_current_forecolor(GTK_WEBVIEW(toolbar->webview));
if (!priv->fgcolor_dialog) {
priv->fgcolor_dialog = gtk_color_selection_dialog_new(_("Select Text Color"));
@@ -360,6 +362,8 @@ toggle_fg_color(GtkWidget *color, GtkWeb
}
gtk_window_present(GTK_WINDOW(priv->fgcolor_dialog));
+
+ g_free(color);
} else {
cancel_toolbar_fgcolor(color, toolbar);
}
@@ -432,7 +436,7 @@ toggle_bg_color(GtkWidget *color, GtkWeb
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) {
GtkWidget *colorsel;
GdkColor bgcolor;
- const char *color = gtk_webview_get_current_backcolor(GTK_WEBVIEW(toolbar->webview));
+ char *color = gtk_webview_get_current_backcolor(GTK_WEBVIEW(toolbar->webview));
if (!priv->bgcolor_dialog) {
priv->bgcolor_dialog = gtk_color_selection_dialog_new(_("Select Background Color"));
@@ -451,6 +455,8 @@ toggle_bg_color(GtkWidget *color, GtkWeb
}
gtk_window_present(GTK_WINDOW(priv->bgcolor_dialog));
+
+ g_free(color);
} else {
cancel_toolbar_bgcolor(color, toolbar);
}
@@ -1098,8 +1104,7 @@ update_buttons(GtkWebViewToolbar *toolba
{
GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
gboolean bold, italic, underline, strike;
- const char *tmp;
- const char *tmp2;
+ char *tmp, *tmp2;
GtkLabel *label = GTK_LABEL(priv->font_label);
gtk_label_set_label(label, _("_Font"));
@@ -1158,6 +1163,7 @@ update_buttons(GtkWebViewToolbar *toolba
gtk_label_set_markup_with_mnemonic(label, markup);
g_free(markup);
}
+ g_free(tmp);
tmp = gtk_webview_get_current_forecolor(GTK_WEBVIEW(toolbar->webview));
toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->fgcolor),
@@ -1168,6 +1174,7 @@ update_buttons(GtkWebViewToolbar *toolba
gtk_label_set_markup_with_mnemonic(label, markup);
g_free(markup);
}
+ g_free(tmp);
tmp = gtk_webview_get_current_backcolor(GTK_WEBVIEW(toolbar->webview));
tmp2 = gtk_webview_get_current_background(GTK_WEBVIEW(toolbar->webview));
@@ -1179,6 +1186,8 @@ update_buttons(GtkWebViewToolbar *toolba
gtk_label_set_markup_with_mnemonic(label, markup);
g_free(markup);
}
+ g_free(tmp);
+ g_free(tmp2);
}
static void
More information about the Commits
mailing list