[evolution/webkit: 92/196] Implement status-message and popup-event signals to EMailDisplay



commit 8e2ba42c4acb91f7d04a38758980c35d81c7b027
Author: Dan VrÃtil <dvratil redhat com>
Date:   Wed Jan 4 12:05:54 2012 +0100

    Implement status-message and popup-event signals to EMailDisplay
    
    And update EMailShellView to use the new signals from EMailDisplay.
    
     - added e_mail_display_scroll to port 'magic spacebar' scrolling
    
    The gtkhtml's signal "scroll" handler has not yet been ported because
    it is not clear to me what it is supposed to do.

 mail/e-mail-display.c                    |  125 +++++++++++++++++++++++++++---
 mail/e-mail-display.h                    |   13 +++-
 modules/mail/e-mail-shell-view-actions.c |    9 +--
 modules/mail/e-mail-shell-view-private.c |   16 ++--
 4 files changed, 136 insertions(+), 27 deletions(-)
---
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 694f766..4c25d81 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -28,7 +28,9 @@
 #include "e-mail-display.h"
 
 #include <glib/gi18n.h>
+#include <gdk/gdk.h>
 
+#include "e-util/e-marshal.h"
 #include "e-util/e-util.h"
 #include "e-util/e-plugin-ui.h"
 #include "mail/em-composer-utils.h"
@@ -60,6 +62,8 @@ struct _EMailDisplayPrivate {
 	gboolean headers_collapsed;
 
 	GList *webviews;
+
+        GtkWidget *current_webview;
 };
 
 enum {
@@ -67,9 +71,17 @@ enum {
 	PROP_FORMATTER,
 	PROP_MODE,
 	PROP_HEADERS_COLLAPSABLE,
-	PROP_HEADERS_COLLAPSED
+	PROP_HEADERS_COLLAPSED,
+};
+
+enum {
+	POPUP_EVENT,
+	STATUS_MESSAGE,
+        LAST_SIGNAL
 };
 
+static gint signals[LAST_SIGNAL];
+
 static gpointer parent_class;
 
 static CamelDataCache *emd_global_http_cache = 0;
@@ -133,6 +145,23 @@ static GtkActionEntry mailto_entries[] = {
 	  NULL }
 };
 
+static gboolean
+mail_display_webview_enter_notify_event (GtkWidget *widget,
+                                         GdkEvent *event,
+                                         gpointer user_data)
+{
+      EMailDisplay *display = user_data;
+
+      /* This handler should always be connected to EWebView
+       * signals only! */
+      g_return_val_if_fail (E_IS_WEB_VIEW (widget), FALSE);
+
+      if (event->crossing.mode == GDK_CROSSING_NORMAL)
+              display->priv->current_webview = widget;
+
+      return FALSE;
+}
+
 static void
 formatter_image_loading_policy_changed_cb (GObject *object,
                                            GParamSpec *pspec,
@@ -300,6 +329,30 @@ mail_display_style_set (GtkWidget *widget,
 	e_mail_display_reload (display);
 }
 
+static void
+mail_display_emit_status_message (EWebView *web_view,
+				  const gchar *message,
+				  gpointer user_data)
+{
+	EMailDisplay *display = user_data;
+
+	g_signal_emit (display, signals[STATUS_MESSAGE], 0, message);
+}
+
+static gboolean
+mail_display_emit_popup_event (EWebView *web_view,
+			       GdkEventButton *event,
+			       const gchar *uri,
+			       gpointer user_data)
+{
+	EMailDisplay *display = user_data;
+	gboolean event_handled;
+
+	g_signal_emit (display, signals[POPUP_EVENT], 0, event, uri, &event_handled);
+
+	return event_handled;
+}
+
 static gboolean
 mail_display_process_mailto (EWebView *web_view,
                              const gchar *mailto_uri,
@@ -573,6 +626,13 @@ mail_display_setup_webview (EMailDisplay *display,
 		G_CALLBACK (mail_display_process_mailto), display);
 	g_signal_connect (web_view, "notify::load-status",
 		G_CALLBACK (mail_display_webkit_finished), NULL);
+	g_signal_connect (web_view, "status-message",
+		G_CALLBACK (mail_display_emit_status_message), display);
+	g_signal_connect (web_view, "popup-event",
+		G_CALLBACK (mail_display_emit_popup_event), display);
+        g_signal_connect (web_view, "enter-notify-event",
+                G_CALLBACK (mail_display_webview_enter_notify_event), display);
+
 
         settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (web_view));
         /* When webviews holds headers or attached image then the can_load_images option
@@ -591,7 +651,7 @@ mail_display_setup_webview (EMailDisplay *display,
 	 * EMailReader handles them.  How devious is that? */
 	gtk_action_group_add_actions (
 		action_group, mailto_entries,
-		G_N_ELEMENTS (mailto_entries), display);
+		G_N_ELEMENTS (mailto_entries), web_view);
 
 	/* Because we are loading from a hard-coded string, there is
 	 * no chance of I/O errors.  Failure here implies a malformed
@@ -626,6 +686,7 @@ mail_display_insert_web_view (EMailDisplay *display,
 {
 	GtkWidget *scrolled_window;
 	GtkAdjustment *web_view_vadjustment;
+        GdkWindow *window;
 
 	display->priv->webviews = g_list_append (display->priv->webviews, web_view);
 	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
@@ -649,6 +710,13 @@ mail_display_insert_web_view (EMailDisplay *display,
         gtk_box_pack_start (GTK_BOX (display->priv->box), scrolled_window, FALSE, TRUE, 0);
 	gtk_widget_show_all (scrolled_window);
 
+        /* Enable enter-notify event */
+        window = gtk_widget_get_window (GTK_WIDGET (web_view));
+        if (!(gdk_window_get_events (window) & GDK_ENTER_NOTIFY_MASK)) {
+              gdk_window_set_events (window,
+                      gdk_window_get_events (window) | GDK_ENTER_NOTIFY_MASK);
+        }
+
         return scrolled_window;
 }
 
@@ -906,6 +974,27 @@ mail_display_class_init (EMailDisplayClass *class)
 			NULL,
 			FALSE,
 			G_PARAM_READWRITE));
+
+	signals[POPUP_EVENT] = g_signal_new (
+		"popup-event",
+		G_TYPE_FROM_CLASS (class),
+		G_SIGNAL_RUN_LAST,
+		G_STRUCT_OFFSET (EMailDisplayClass, popup_event),
+		g_signal_accumulator_true_handled, NULL,
+		e_marshal_BOOLEAN__BOXED_STRING,
+		G_TYPE_BOOLEAN, 2,
+		GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
+		G_TYPE_STRING);
+
+	signals[STATUS_MESSAGE] = g_signal_new (
+		"status-message",
+		G_TYPE_FROM_CLASS (class),
+		G_SIGNAL_RUN_LAST,
+		G_STRUCT_OFFSET (EMailDisplayClass, status_message),
+		NULL, NULL,
+		g_cclosure_marshal_VOID__STRING,
+		G_TYPE_NONE, 1,
+		G_TYPE_STRING);
 }
 
 static void
@@ -1141,16 +1230,9 @@ e_mail_display_reload (EMailDisplay *display)
 EWebView*
 e_mail_display_get_current_web_view (EMailDisplay *display)
 {
-	GtkWidget *widget;
-
 	g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), NULL);
 
-	widget = gtk_container_get_focus_child (GTK_CONTAINER (display));
-
-	if (E_IS_WEB_VIEW (widget))
-		return E_WEB_VIEW (widget);
-	else
-		return NULL;
+        return E_WEB_VIEW (display->priv->current_webview);
 }
 
 void
@@ -1316,3 +1398,26 @@ e_mail_display_load_images (EMailDisplay * display)
         gtk_container_foreach (GTK_CONTAINER (display->priv->box),
                         (GtkCallback) load_images, NULL);
 }
+
+
+void
+e_mail_display_scroll (EMailDisplay* display,
+                       GdkScrollDirection direction)
+{
+        GtkAdjustment *vadjustment;
+        gint d;
+        gdouble step;
+
+        g_return_if_fail (E_IS_MAIL_DISPLAY (display));
+        g_return_if_fail ((direction == GDK_SCROLL_UP) || (direction == GDK_SCROLL_DOWN));
+
+        vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (display));
+
+        if (gtk_adjustment_get_upper (vadjustment) == 0)
+                return;
+
+        d = (direction == GDK_SCROLL_DOWN) ? 1 : -1;
+        step = d * gtk_adjustment_get_page_increment (vadjustment);
+        gtk_adjustment_set_value (vadjustment,
+                gtk_adjustment_get_value (vadjustment) + step);
+}
diff --git a/mail/e-mail-display.h b/mail/e-mail-display.h
index 8d13d18..2cbbb40 100644
--- a/mail/e-mail-display.h
+++ b/mail/e-mail-display.h
@@ -59,11 +59,15 @@ struct _EMailDisplay {
 struct _EMailDisplayClass {
 	GtkViewportClass parent_class;
 
-	/* TODO WEBKIT: popup-event signal */
-	/* TODO WEBKIT: status-message signal */
+	void		(*status_message)		(EMailDisplay *display,
+							 const gchar *message);
+
+	gboolean	(*popup_event)			(EMailDisplay *display,
+							 GdkEventButton *event,
+							 const gchar *uri);
 };
 
-GType			e_mail_display_get_type			(void);
+GType			e_mail_display_get_type		(void);
 EMFormatHTML *		e_mail_display_get_formatter	(EMailDisplay *display);
 void			e_mail_display_set_formatter	(EMailDisplay *display,
 						 	 EMFormatHTML *formatter);
@@ -108,6 +112,9 @@ void			e_mail_display_zoom_out		(EMailDisplay *display);
 
 void                    e_mail_display_load_images      (EMailDisplay *display);
 
+void                    e_mail_display_scroll           (EMailDisplay *display,
+                                                         GdkScrollDirection direction);
+
 G_END_DECLS
 
 #endif /* E_MAIL_DISPLAY_H */
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index 7621fa5..d74e7b0 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -922,9 +922,7 @@ action_mail_smart_backward_cb (GtkAction *action,
 	toggle_action = GTK_TOGGLE_ACTION (ACTION (MAIL_CARET_MODE));
 	caret_mode = gtk_toggle_action_get_active (toggle_action);
 
-	/* FIXME WEBKIT FUCKING IMPLEMENT
-	gtk_scrolled_window_scroll (display, GTK_MOVEMENT_PAGES, -1);
-	*/
+        e_mail_display_scroll (display, GDK_SCROLL_UP);
 
 	if (caret_mode || !magic_spacebar)
 		return;
@@ -960,7 +958,6 @@ action_mail_smart_forward_cb (GtkAction *action,
 	EMailShellContent *mail_shell_content;
 	EMailShellSidebar *mail_shell_sidebar;
 	EMFolderTree *folder_tree;
-	EMFormatHTML *formatter;
 	EMailReader *reader;
 	EMailView *mail_view;
 	GtkWidget *message_list;
@@ -992,9 +989,7 @@ action_mail_smart_forward_cb (GtkAction *action,
 	toggle_action = GTK_TOGGLE_ACTION (ACTION (MAIL_CARET_MODE));
 	caret_mode = gtk_toggle_action_get_active (toggle_action);
 
-	/* FIXME WEBKIT: Fucking implement
-	gtk_scolled_window_scroll (display, GTK_MOVEMENT_PAGES, 1);
-	*/
+        e_mail_display_scroll (display, GDK_SCROLL_DOWN);
 
 
 	if (caret_mode || !magic_spacebar)
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c
index 9519df3..c8ab233 100644
--- a/modules/mail/e-mail-shell-view-private.c
+++ b/modules/mail/e-mail-shell-view-private.c
@@ -344,7 +344,6 @@ mail_shell_view_popup_event_cb (EMailShellView *mail_shell_view,
 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 
-	/* FIXME WEBKIT: Probably does not do what we want it to */
 	reader = E_MAIL_READER (mail_view);
 	display = e_mail_reader_get_mail_display (reader);
 	web_view = e_mail_display_get_current_web_view (display);
@@ -462,7 +461,6 @@ mail_shell_view_reader_changed_cb (EMailShellView *mail_shell_view,
 		G_CALLBACK (mail_shell_view_message_list_right_click_cb),
 		mail_shell_view, G_CONNECT_SWAPPED);
 
-	/* FIXME WEBKIT EMailDisplay does not have these signals (yet)
 	g_signal_connect_object (
 		display, "key-press-event",
 		G_CALLBACK (mail_shell_view_key_press_event_cb),
@@ -473,17 +471,19 @@ mail_shell_view_reader_changed_cb (EMailShellView *mail_shell_view,
 		G_CALLBACK (mail_shell_view_popup_event_cb),
 		mail_shell_view, G_CONNECT_SWAPPED);
 
+        /* FIXME WEBKIT: Not sure if this event has ever worked
+         *      (GtkHTML does not seem to emit the signal at all)
 	g_signal_connect_object (
-		display, "scroll",
+                display, "scroll",
 		G_CALLBACK (mail_shell_view_scroll_cb),
 		mail_shell_view,
-		G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+                G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+        */
 
 	g_signal_connect_object (
 		display, "status-message",
 		G_CALLBACK (e_shell_taskbar_set_message),
 		shell_taskbar, G_CONNECT_SWAPPED);
-	*/
 }
 
 static void
@@ -781,7 +781,6 @@ e_mail_shell_view_private_constructed (EMailShellView *mail_shell_view)
 		G_CALLBACK (e_mail_shell_view_update_search_filter),
 		mail_shell_view, G_CONNECT_SWAPPED);
 
-	/* FIXME WEBKIT: EMailDisplay does no have these signals (for now)
 	g_signal_connect_object (
 		display, "key-press-event",
 		G_CALLBACK (mail_shell_view_key_press_event_cb),
@@ -792,17 +791,20 @@ e_mail_shell_view_private_constructed (EMailShellView *mail_shell_view)
 		G_CALLBACK (mail_shell_view_popup_event_cb),
 		mail_shell_view, G_CONNECT_SWAPPED);
 
+        /* FIXME WEBKIT: Not sure if this event has ever worked
+         *      (GtkHTML does not seem to emit the signal at all)
 	g_signal_connect_object (
 		display, "scroll",
 		G_CALLBACK (mail_shell_view_scroll_cb),
 		mail_shell_view,
 		G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+	*/
 
 	g_signal_connect_object (
 		display, "status-message",
 		G_CALLBACK (e_shell_taskbar_set_message),
 		shell_taskbar, G_CONNECT_SWAPPED);
-	*/
+
 	g_signal_connect_object (
 		mail_shell_view, "toggled",
 		G_CALLBACK (e_mail_shell_view_update_send_receive_menus),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]