pidgin: 74973123: Add a changed signal shortcut for editab...

qulogic at pidgin.im qulogic at pidgin.im
Mon Jun 4 04:25:49 EDT 2012


----------------------------------------------------------------------
Revision: 7497312392274aa4f4be0007aaa34c34e8c18d3c
Parent:   ac4e17d54aff8b9275bd29092a2c23bc9f132028
Author:   qulogic at pidgin.im
Date:     06/03/12 15:40:55
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/7497312392274aa4f4be0007aaa34c34e8c18d3c

Changelog: 

Add a changed signal shortcut for editable webview changes.

Changes against parent ac4e17d54aff8b9275bd29092a2c23bc9f132028

  patched  pidgin/gtkwebview.c
  patched  pidgin/gtkwebview.h

-------------- next part --------------
============================================================
--- pidgin/gtkwebview.c	8cbb4c8b795ee7287a2d92cb7a811a6c3a495671
+++ pidgin/gtkwebview.c	42177a8738e01ce95784d765017739ec527bfd52
@@ -43,6 +43,7 @@ enum {
 	TOGGLE_FORMAT,
 	CLEAR_FORMAT,
 	UPDATE_FORMAT,
+	CHANGED,
 	LAST_SIGNAL
 };
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -343,6 +344,12 @@ webview_toggle_format(GtkWebView *webvie
 	}
 }
 
+static void
+editable_input_cb(GtkWebView *webview, WebKitDOMEvent *event, void *data)
+{
+	g_signal_emit(webview, signals[CHANGED], 0);
+}
+
 /******************************************************************************
  * GObject Stuff
  *****************************************************************************/
@@ -404,6 +411,12 @@ gtk_webview_class_init(GtkWebViewClass *
 	                                      G_STRUCT_OFFSET(GtkWebViewClass, update_format),
 	                                      NULL, 0, g_cclosure_marshal_VOID__VOID,
 	                                      G_TYPE_NONE, 0);
+	signals[CHANGED] = g_signal_new("changed",
+	                                G_TYPE_FROM_CLASS(gobject_class),
+	                                G_SIGNAL_RUN_FIRST,
+	                                G_STRUCT_OFFSET(GtkWebViewClass, changed),
+	                                NULL, NULL, g_cclosure_marshal_VOID__VOID,
+	                                G_TYPE_NONE, 0);
 
 	klass->toggle_format = webview_toggle_format;
 	klass->clear_format = webview_clear_formatting;
@@ -625,7 +638,20 @@ gtk_webview_set_editable(GtkWebView *web
 void
 gtk_webview_set_editable(GtkWebView *webview, gboolean editable)
 {
+	WebKitDOMDocument *doc;
+
 	webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview), editable);
+
+	doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	if (editable) {
+		webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(doc),
+	    	                                       "input", G_CALLBACK(editable_input_cb),
+	    	                                       FALSE, NULL);
+	} else {
+		webkit_dom_event_target_remove_event_listener(WEBKIT_DOM_EVENT_TARGET(doc),
+		                                              "input", G_CALLBACK(editable_input_cb),
+		                                              FALSE);
+	}
 }
 
 void
============================================================
--- pidgin/gtkwebview.h	1f05634edfb3596dfa86f7aa6546594bae69bb76
+++ pidgin/gtkwebview.h	14436066899232f2a864bd2099e3f7b83626d75a
@@ -74,6 +74,7 @@ struct _GtkWebViewClass
 	void (*toggle_format)(GtkWebView *, GtkWebViewButtons);
 	void (*clear_format)(GtkWebView *);
 	void (*update_format)(GtkWebView *);
+	void (*changed)(GtkWebView *);
 };
 
 G_BEGIN_DECLS


More information about the Commits mailing list