pidgin: b6651c27: JS-ify the markerline plugin.

qulogic at pidgin.im qulogic at pidgin.im
Thu Dec 29 03:07:09 EST 2011


----------------------------------------------------------------------
Revision: b6651c27e7f2bb373a232d2f43381c5649da5289
Parent:   b8635a4141575e5f53c7c087d35c4e3e45c7b9be
Author:   qulogic at pidgin.im
Date:     12/28/11 00:07:15
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b6651c27e7f2bb373a232d2f43381c5649da5289

Changelog: 

JS-ify the markerline plugin.

Changes against parent b8635a4141575e5f53c7c087d35c4e3e45c7b9be

  patched  pidgin/plugins/Makefile.am
  patched  pidgin/plugins/markerline.c

-------------- next part --------------
============================================================
--- pidgin/plugins/Makefile.am	63ff22d31146b62ff8dc632e5a80042abeeb5b53
+++ pidgin/plugins/Makefile.am	c114922bf5179a4142e4bde6997002c24783d901
@@ -38,6 +38,7 @@ iconaway_la_LDFLAGS         = -module -a
 gtkbuddynote_la_LDFLAGS     = -module -avoid-version
 history_la_LDFLAGS          = -module -avoid-version
 iconaway_la_LDFLAGS         = -module -avoid-version
+markerline_la_LDFLAGS       = -module -avoid-version
 notify_la_LDFLAGS           = -module -avoid-version
 pidginrc_la_LDFLAGS         = -module -avoid-version
 relnot_la_LDFLAGS           = -module -avoid-version
@@ -56,6 +57,7 @@ plugin_LTLIBRARIES = \
 	gtkbuddynote.la     \
 	history.la          \
 	iconaway.la         \
+	markerline.la       \
 	notify.la           \
 	pidginrc.la         \
 	relnot.la           \
@@ -80,6 +82,7 @@ iconaway_la_SOURCES         = iconaway.c
 gtkbuddynote_la_SOURCES     = gtkbuddynote.c
 history_la_SOURCES          = history.c
 iconaway_la_SOURCES         = iconaway.c
+markerline_la_SOURCES       = markerline.c
 notify_la_SOURCES           = notify.c
 pidginrc_la_SOURCES         = pidginrc.c
 relnot_la_SOURCES           = relnot.c
@@ -96,6 +99,7 @@ iconaway_la_LIBADD          = $(GTK_LIBS
 gtkbuddynote_la_LIBADD      = $(GTK_LIBS)
 history_la_LIBADD           = $(GTK_LIBS)
 iconaway_la_LIBADD          = $(GTK_LIBS)
+markerline_la_LIBADD        = $(GTK_LIBS) $(WEBKIT_LIBS)
 notify_la_LIBADD            = $(GTK_LIBS)
 pidginrc_la_LIBADD          = $(GTK_LIBS)
 relnot_la_LIBADD            = $(GLIB_LIBS)
============================================================
--- pidgin/plugins/markerline.c	2b60a4254e8361b0fd2e4592f611c7e3befebc6f
+++ pidgin/plugins/markerline.c	26cba006ad7a7f998d5026ae6b280842af0d9f02
@@ -33,81 +33,38 @@
 
 /* Purple headers */
 #include <gtkconv.h>
-#include <gtkimhtml.h>
 #include <gtkplugin.h>
+#include <gtkwebview.h>
 #include <version.h>
 
 #define PREF_PREFIX     "/plugins/gtk/" PLUGIN_ID
 #define PREF_IMS        PREF_PREFIX "/ims"
 #define PREF_CHATS      PREF_PREFIX "/chats"
 
-static int
-imhtml_expose_cb(GtkWidget *widget, GdkEventExpose *event, PidginConversation *gtkconv)
-{
-	int y, last_y, offset;
-	GdkRectangle visible_rect;
-	GtkTextIter iter;
-	GdkRectangle buf;
-	int pad;
-	PurpleConversation *conv = gtkconv->active_conv;
-	PurpleConversationType type = purple_conversation_get_type(conv);
-
-	if ((type == PURPLE_CONV_TYPE_CHAT && !purple_prefs_get_bool(PREF_CHATS)) ||
-			(type == PURPLE_CONV_TYPE_IM && !purple_prefs_get_bool(PREF_IMS)))
-		return FALSE;
-
-	gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &visible_rect);
-
-	offset = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "markerline"));
-	if (offset)
-	{
-		gtk_text_buffer_get_iter_at_offset(gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)),
-							&iter, offset);
-
-		gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &iter, &buf);
-		last_y = buf.y + buf.height;
-		pad = (gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(widget)) +
-				gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(widget))) / 2;
-		last_y += pad;
-	}
-	else
-		last_y = 0;
-
-	gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT,
-										0, last_y, 0, &y);
-
-	if (y >= event->area.y)
-	{
-		GdkColor red = {0, 0xffff, 0, 0};
-		cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(event->window));
-
-		gdk_cairo_set_source_color(cr, &red);
-		cairo_move_to(cr, 0.0, y + 0.5);
-		cairo_rel_line_to(cr, visible_rect.width, 0.0);
-		cairo_set_line_width(cr, 1.0);
-		cairo_stroke(cr);
-		cairo_destroy(cr);
-	}
-	return FALSE;
-}
-
 static void
 update_marker_for_gtkconv(PidginConversation *gtkconv)
 {
-	GtkTextIter iter;
-	GtkTextBuffer *buffer;
+	PurpleConversation *conv;
+	PurpleConversationType type;
+
 	g_return_if_fail(gtkconv != NULL);
 
-	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml));
+	conv = gtkconv->active_conv;
+	type = purple_conversation_get_type(conv);
 
-	if (!gtk_text_buffer_get_char_count(buffer))
+	if ((type == PURPLE_CONV_TYPE_CHAT && !purple_prefs_get_bool(PREF_CHATS)) ||
+	    (type == PURPLE_CONV_TYPE_IM && !purple_prefs_get_bool(PREF_IMS)))
 		return;
 
-	gtk_text_buffer_get_end_iter(buffer, &iter);
-
-	g_object_set_data(G_OBJECT(gtkconv->imhtml), "markerline",
-						GINT_TO_POINTER(gtk_text_iter_get_offset(&iter)));
-	gtk_widget_queue_draw(gtkconv->imhtml);
+	gtk_webview_safe_execute_script(GTK_WEBVIEW(gtkconv->webview),
+		"var mhr = document.getElementById(\"markerhr\");"
+		"if (!mhr) {"
+			"mhr = document.createElement(\"hr\");"
+			"mhr.setAttribute(\"id\", \"markerhr\");"
+			"mhr.setAttribute(\"color\", \"#ff0000\");"
+			"mhr.setAttribute(\"size\", \"1\");"
+		"}"
+		"document.getElementById(\"Chat\").appendChild(mhr);");
 }
 
 static gboolean
@@ -125,28 +82,6 @@ focus_removed(GtkWidget *widget, GdkEven
 	return FALSE;
 }
 
-#if 0
-static gboolean
-window_resized(GtkWidget *w, GdkEventConfigure *event, PidginWindow *win)
-{
-	GList *list;
-
-	list = pidgin_conv_window_get_gtkconvs(win);
-
-	for (; list; list = list->next)
-		update_marker_for_gtkconv(list->data);
-
-	return FALSE;
-}
-
-static gboolean
-imhtml_resize_cb(GtkWidget *w, GtkAllocation *allocation, PidginConversation *gtkconv)
-{
-	gtk_widget_queue_draw(w);
-	return FALSE;
-}
-#endif
-
 static void
 page_switched(GtkWidget *widget, GtkWidget *page, gint num, PidginWindow *win)
 {
@@ -156,7 +91,9 @@ detach_from_gtkconv(PidginConversation *
 static void
 detach_from_gtkconv(PidginConversation *gtkconv, gpointer null)
 {
-	g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->imhtml), imhtml_expose_cb, gtkconv);
+	gtk_webview_safe_execute_script(GTK_WEBVIEW(gtkconv->webview),
+		"var mhr = document.getElementById(\"markerhr\");"
+		"if (mhr) mhr.parentNode.removeChild(mhr);");
 }
 
 static void
@@ -165,16 +102,13 @@ detach_from_pidgin_window(PidginWindow *
 	g_list_foreach(pidgin_conv_window_get_gtkconvs(win), (GFunc)detach_from_gtkconv, NULL);
 	g_signal_handlers_disconnect_by_func(G_OBJECT(win->notebook), page_switched, win);
 	g_signal_handlers_disconnect_by_func(G_OBJECT(win->window), focus_removed, win);
-
-	gtk_widget_queue_draw(win->window);
 }
 
 static void
 attach_to_gtkconv(PidginConversation *gtkconv, gpointer null)
 {
 	detach_from_gtkconv(gtkconv, NULL);
-	g_signal_connect(G_OBJECT(gtkconv->imhtml), "expose_event",
-					 G_CALLBACK(imhtml_expose_cb), gtkconv);
+	update_marker_for_gtkconv(gtkconv);
 }
 
 static void
@@ -187,8 +121,6 @@ attach_to_pidgin_window(PidginWindow *wi
 
 	g_signal_connect(G_OBJECT(win->notebook), "switch_page",
 					G_CALLBACK(page_switched), win);
-
-	gtk_widget_queue_draw(win->window);
 }
 
 static void
@@ -220,15 +152,15 @@ jump_to_markerline(PurpleConversation *c
 jump_to_markerline(PurpleConversation *conv, gpointer null)
 {
 	PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
-	int offset;
-	GtkTextIter iter;
 
 	if (!gtkconv)
 		return;
 
-	offset = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkconv->imhtml), "markerline"));
-	gtk_text_buffer_get_iter_at_offset(GTK_IMHTML(gtkconv->imhtml)->text_buffer, &iter, offset);
-	gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(gtkconv->imhtml), &iter, 0, TRUE, 0, 0);
+	gtk_webview_safe_execute_script(GTK_WEBVIEW(gtkconv->webview),
+		"var mhr = document.getElementById(\"markerhr\");"
+		"if (mhr) {"
+			"window.scroll(0, mhr.offsetTop);"
+		"}");
 }
 
 static void


More information about the Commits mailing list