[evolution/webkit: 114/154] Add zoom-level change proxying to EMailDisplay



commit acdeb950b9b8ebab203539ea546fa3cea8a7fe90
Author: Dan VrÃtil <dvratil redhat com>
Date:   Tue Jan 10 13:16:01 2012 +0100

    Add zoom-level change proxying to EMailDisplay

 mail/e-mail-display.c     |  116 +++++++++++++++++++++++++--------------------
 mail/e-mail-reader.c      |    5 +-
 widgets/misc/e-web-view.c |   64 ++++++++++++++++---------
 widgets/misc/e-web-view.h |    6 ++
 4 files changed, 114 insertions(+), 77 deletions(-)
---
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index d18a5bc..6be0936 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -69,6 +69,9 @@ struct _EMailDisplayPrivate {
         GtkActionGroup *images_actions;
 
         guint caret_mode:1;
+	gfloat zoom_level;
+
+	WebKitWebSettings *settings;
 };
 
 enum {
@@ -78,6 +81,7 @@ enum {
 	PROP_HEADERS_COLLAPSABLE,
 	PROP_HEADERS_COLLAPSED,
         PROP_CARET_MODE,
+	PROP_ZOOM_LEVEL
 };
 
 enum {
@@ -92,8 +96,6 @@ static gpointer parent_class;
 
 static CamelDataCache *emd_global_http_cache = 0;
 
-typedef void (*WebViewActionFunc) (EWebView *web_view);
-
 static const gchar *ui =
 "<ui>"
 "  <popup name='context'>"
@@ -279,6 +281,8 @@ mail_display_set_property (GObject *object,
                            const GValue *value,
                            GParamSpec *pspec)
 {
+	EMailDisplayPrivate *priv = E_MAIL_DISPLAY (object)->priv;
+
 	switch (property_id) {
 		case PROP_FORMATTER:
 			e_mail_display_set_formatter (
@@ -301,10 +305,11 @@ mail_display_set_property (GObject *object,
 				g_value_get_boolean (value));
 			return;
                 case PROP_CARET_MODE:
-                        e_mail_display_set_caret_mode (
-                                E_MAIL_DISPLAY (object),
-                                g_value_get_boolean (value));
+			priv->caret_mode = g_value_get_boolean (value);
                         return;
+		case PROP_ZOOM_LEVEL:
+			priv->zoom_level = g_value_get_float (value);
+			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -316,6 +321,8 @@ mail_display_get_property (GObject *object,
                            GValue *value,
                            GParamSpec *pspec)
 {
+	EMailDisplayPrivate *priv = E_MAIL_DISPLAY (object)->priv;
+
 	switch (property_id) {
 		case PROP_FORMATTER:
 			g_value_set_object (
@@ -338,10 +345,11 @@ mail_display_get_property (GObject *object,
 				E_MAIL_DISPLAY (object)));
 			return;
                 case PROP_CARET_MODE:
-                        g_value_set_boolean (
-                                value, e_mail_display_get_caret_mode(
-                                E_MAIL_DISPLAY (object)));
+                        g_value_set_boolean (value, priv->caret_mode);
                         return;
+		case PROP_ZOOM_LEVEL:
+			g_value_set_float (value, priv->zoom_level);
+			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -369,6 +377,11 @@ mail_display_dispose (GObject *object)
 		priv->webviews = NULL;
 	}
 
+	if (priv->settings) {
+		g_object_unref (priv->settings);
+		priv->settings = NULL;
+	}
+
 	/* Chain up to parent's dispose() method. */
 	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -679,6 +692,7 @@ mail_display_setup_webview (EMailDisplay *display,
 	GError *error = NULL;
 
 	web_view = E_WEB_VIEW (e_web_view_new ());
+	e_web_view_set_settings (web_view, display->priv->settings);
 
 	g_signal_connect (web_view, "navigation-policy-decision-requested",
 		G_CALLBACK (mail_display_link_clicked), display);
@@ -699,17 +713,19 @@ mail_display_setup_webview (EMailDisplay *display,
         g_signal_connect (web_view, "update-actions",
                 G_CALLBACK (mail_display_webview_update_actions), display);
 
-	g_object_bind_property (web_view, "caret-mode",
-		display, "caret-mode", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+	g_object_bind_property (web_view, "zoom-level", display, "zoom-level", 
+		G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
 
-        settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (web_view));
+//        settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (web_view));
         /* When webviews holds headers or attached image then the can_load_images option
            does not apply */
+/*
         if (em_format_html_can_load_images (display->priv->formatter) || is_header)
                 g_object_set (G_OBJECT (settings), "auto-load-images", TRUE, NULL);
         else
                 g_object_set (G_OBJECT (settings), "auto-load-images", FALSE, NULL);
-
+*/
 
 	/* Because we are loading from a hard-coded string, there is
 	 * no chance of I/O errors.  Failure here implies a malformed
@@ -1056,6 +1072,19 @@ mail_display_class_init (EMailDisplayClass *class)
                         FALSE,
                         G_PARAM_READWRITE));
 
+	g_object_class_install_property (
+		object_class,
+		PROP_ZOOM_LEVEL,
+		g_param_spec_float (
+			"zoom-level",
+			"Zoom Level",
+			NULL,
+			G_MINFLOAT,
+			G_MAXFLOAT,
+			1.0,
+			G_PARAM_READWRITE));
+			
+
 	signals[POPUP_EVENT] = g_signal_new (
 		"popup-event",
 		G_TYPE_FROM_CLASS (class),
@@ -1087,6 +1116,12 @@ mail_display_init (EMailDisplay *display)
 
 	display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
 
+	display->priv->settings = e_web_view_get_default_settings (GTK_WIDGET (display));
+	g_object_bind_property (display, "caret-mode",
+		display->priv->settings, "enable-caret-browsing", 
+		G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+	
+
 	display->priv->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
         gtk_container_set_reallocate_redraws (GTK_CONTAINER (display->priv->box), TRUE);
 	gtk_container_add (GTK_CONTAINER (display), display->priv->box);
@@ -1441,66 +1476,43 @@ e_mail_display_get_selection_plain_text (EMailDisplay *display,
 }
 
 void
-e_mail_display_set_caret_mode (EMailDisplay *display,
-			       gboolean caret_mode)
+e_mail_display_zoom_100 (EMailDisplay *display)
 {
 	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
-	if (display->priv->caret_mode == caret_mode)
-		return;
+	display->priv->zoom_level = 1.0;
 
-	display->priv->caret_mode = caret_mode;
-
-	g_object_notify (G_OBJECT (display), "caret-mode");
+	g_object_notify (G_OBJECT (display), "zoom-level");
 }
 
-gboolean
-e_mail_display_get_caret_mode (EMailDisplay *display)
+void
+e_mail_display_zoom_in (EMailDisplay *display)
 {
-	g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), FALSE);
+	gfloat step;
 
-	return display->priv->caret_mode;
-}
+	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
+	g_object_get (G_OBJECT (display->priv->settings), 
+		"zoom-step", &step, NULL);
 
+	display->priv->zoom_level += step;
 
-static void
-webview_action (GtkWidget *widget, WebViewActionFunc func)
-{
-	/*
-	 * It's not a critical error to pass other then EWebView
-	 * widgets.
-	 */
-	if (E_IS_WEB_VIEW (widget)) {
-		func (E_WEB_VIEW (widget));
-	}
+	g_object_notify (G_OBJECT (display), "zoom-level");
 }
 
 void
-e_mail_display_zoom_100 (EMailDisplay *display)
+e_mail_display_zoom_out (EMailDisplay *display)
 {
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
+	float step;
 
-	gtk_container_foreach (GTK_CONTAINER (display),
-			(GtkCallback) webview_action, e_web_view_zoom_100);
-}
-
-void
-e_mail_display_zoom_in (EMailDisplay *display)
-{
 	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
-	gtk_container_foreach (GTK_CONTAINER (display),
-			(GtkCallback) webview_action, e_web_view_zoom_in);
-}
+	g_object_get (G_OBJECT (display->priv->settings),
+		"zoom-step", &step, NULL);
 
-void
-e_mail_display_zoom_out (EMailDisplay *display)
-{
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
+	display->priv->zoom_level -= step;
 
-	gtk_container_foreach (GTK_CONTAINER (display),
-			(GtkCallback) webview_action, e_web_view_zoom_out);
+	g_object_notify (G_OBJECT (display), "zoom-level");
 }
 
 static void
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 58117c1..18b0d68 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -3967,13 +3967,12 @@ e_mail_reader_init (EMailReader *reader,
 	action_name = "mail-caret-mode";
 	action = e_mail_reader_get_action (reader, action_name);
 
-	/* FIXME WEBKIT
 	g_object_bind_property (
 		action, "active",
-		web_view, "caret-mode",
+		display, "caret-mode",
 		G_BINDING_BIDIRECTIONAL |
 		G_BINDING_SYNC_CREATE);
-	*/
+
 connect_signals:
 
 	if (!connect_signals)
diff --git a/widgets/misc/e-web-view.c b/widgets/misc/e-web-view.c
index 44497a6..6d633c8 100644
--- a/widgets/misc/e-web-view.c
+++ b/widgets/misc/e-web-view.c
@@ -1540,8 +1540,6 @@ e_web_view_init (EWebView *web_view)
 	WebKitWebSettings *web_settings;
 	const gchar *domain = GETTEXT_PACKAGE;
 	const gchar *id;
-	GtkStyleContext *context;
-	const PangoFontDescription *font;
 	GError *error = NULL;
 
 	web_view->priv = E_WEB_VIEW_GET_PRIVATE (web_view);
@@ -1569,26 +1567,9 @@ e_web_view_init (EWebView *web_view)
 		ui_manager, "connect-proxy",
 		G_CALLBACK (web_view_connect_proxy_cb), web_view);
 
-	web_settings = webkit_web_view_get_settings (
-		WEBKIT_WEB_VIEW (web_view));
-
-	/* Use same font-size as rest of Evolution */
-	context = gtk_widget_get_style_context (GTK_WIDGET (web_view));
-	font = gtk_style_context_get_font (context, GTK_STATE_FLAG_NORMAL);
-	g_object_set (G_OBJECT (web_settings),
-		"default-font-size", (pango_font_description_get_size (font) / PANGO_SCALE),
-		"default-monospace-font-size", (pango_font_description_get_size (font) / PANGO_SCALE),
-		NULL);
-
-	/* Force frames to be as high as their content (e.g. no scrolling) */
-	g_object_set (G_OBJECT (web_settings), "enable-frame-flattening",
-		TRUE, NULL);
-
-	g_object_bind_property (
-		web_view, "caret-mode",
-		web_settings, "enable-caret-browsing",
-		G_BINDING_BIDIRECTIONAL |
-		G_BINDING_SYNC_CREATE);
+	web_settings = e_web_view_get_default_settings (GTK_WIDGET (web_view));
+	e_web_view_set_settings (web_view, web_settings);
+	g_object_unref (web_settings);
 
 	action_group = gtk_action_group_new ("uri");
 	gtk_action_group_set_translation_domain (action_group, domain);
@@ -2657,3 +2638,42 @@ e_web_view_get_selection_html (EWebView *web_view)
 
         return webkit_dom_html_element_get_inner_html (element);
 }
+
+void
+e_web_view_set_settings (EWebView *web_view,
+			 WebKitWebSettings *settings)
+{
+	g_return_if_fail (E_IS_WEB_VIEW (web_view));
+
+	if (settings == webkit_web_view_get_settings (WEBKIT_WEB_VIEW (web_view)))
+		return;
+
+	g_object_bind_property (settings, "enable-caret-browsing", web_view, "caret-mode",
+		G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+	webkit_web_view_set_settings (WEBKIT_WEB_VIEW (web_view), settings);
+}
+
+
+WebKitWebSettings*
+e_web_view_get_default_settings(GtkWidget *parent_widget)
+{
+	GtkStyleContext *context;
+	const PangoFontDescription *font;
+	WebKitWebSettings *settings;
+
+	g_return_val_if_fail (GTK_IS_WIDGET (parent_widget), NULL);
+
+	settings = webkit_web_settings_new ();
+
+	/* Use same font-size as rest of Evolution */
+	context = gtk_widget_get_style_context (parent_widget);
+	font = gtk_style_context_get_font (context, GTK_STATE_FLAG_NORMAL);
+
+	g_object_set (G_OBJECT (settings),
+		      "default-font-size", (pango_font_description_get_size (font) / PANGO_SCALE),
+		      "default-monospace-font-size", (pango_font_description_get_size (font) / PANGO_SCALE),
+		      "enable-frame-flattening", TRUE, NULL);
+
+	return settings;	
+}
diff --git a/widgets/misc/e-web-view.h b/widgets/misc/e-web-view.h
index 9e31ab9..a54d53e 100644
--- a/widgets/misc/e-web-view.h
+++ b/widgets/misc/e-web-view.h
@@ -216,6 +216,12 @@ void		e_web_view_update_actions	(EWebView *web_view);
 
 gchar*          e_web_view_get_selection_html   (EWebView *web_view);
 
+void		e_web_view_set_settings		(EWebView *web_view,
+						 WebKitWebSettings *settings);
+
+WebKitWebSettings*
+		e_web_view_get_default_settings ();
+
 G_END_DECLS
 
 #endif /* E_WEB_VIEW_H */



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