Fwd: Gtkconv webview entry regression

Jorge Villaseñor salinasv at gmail.com
Wed Jun 17 22:53:30 EDT 2015


Third attempt! Yeeii!

---------- Forwarded message ----------
From: Jorge Villaseñor <salinasv at gmail.com>
Date: Wed, Jun 17, 2015 at 7:42 PM
Subject: Fwd: Gtkconv webview entry regression
To: Pidgin Devel Mailing List <devel at pidgin.im>


Second attempt to get this through


---------- Forwarded message ----------
From: Jorge Villaseñor <salinasv at gmail.com>
Date: Tue, Jun 16, 2015 at 12:02 AM
Subject: Gtkconv webview entry regression
To: Pidgin Devel Mailing List <devel at pidgin.im>


As some of you have noticed, on pidgin 3.0 the gtkconv->entry sometimes
have a 0-1 pixel height.

Finally, after poking too may ways to figure this out, I found a way to set
the size of the gtkconv entry at startup based on the prefs, autosize up to
half the conversation window and back.

The approach is to take the font-size form the DOM * min_lines from the
prefs + some padding for initial setup and then respect the DOM size
(+padding) to increment the size of the widget.

There is only one pice of it that I was not able to solve, but this is FAR
better than what we have right now. When we delete a line more than
min_lines, the DOM does not return to the needed size immediately, it
requires more events to incrementally get to the actual needed size. I
expect some of you with more knowledge of GtkWebkit and HTML magic can
figure out something to force this DOM height calculation.

Please review this code and give some inputs about what can be done better.
It needs a little of clean up, maybe move some lines to gtkwebview.[ch] and
delete my debug prints (I left them there to help whoever wants to tweak
the patch).

If nobody answer, I will just commit this by the end of the week. If you
want to review but don't have time this week, please let me know.

-- 
Masca

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pidgin.im/pipermail/devel/attachments/20150617/96496f79/attachment-0001.html>
-------------- next part --------------
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -4998,7 +4998,76 @@ resize_webview_cb(PidginConversation *gt
 	gtk_widget_set_size_request(gtkconv->lower_hbox, -1,
 		diff + lower_hbox_allocation.height);
 #endif
-	gtk_widget_set_size_request(gtkconv->lower_hbox, -1, -1);
+
+	WebKitWebView *webview;
+	WebKitDOMCSSStyleDeclaration *style;
+	WebKitDOMDocument *document;
+	WebKitDOMElement *dom_element;
+	WebKitDOMDOMWindow *dom_window;
+	gchar *value;
+	gint min_lines;
+	gint max_height;
+	gint min_height;
+	gint font_size;
+	gint total_height;
+	gint height;
+	gint toolbar_size;
+	GtkAllocation webview_allocation;
+	GtkAllocation entry_allocation;
+
+	webview = PIDGIN_WEBVIEW(gtkconv->entry);
+
+	/* Get text height from the DOM */
+	document = webkit_web_view_get_dom_document(webview);
+	dom_window = webkit_dom_document_get_default_view(document);
+
+	dom_element = webkit_dom_document_get_document_element(document);
+	style = webkit_dom_dom_window_get_computed_style(dom_window, dom_element, 0);
+	value = webkit_dom_css_style_declaration_get_property_value(style, "height");
+
+	purple_debug_error("Masca", "Height %s\n", value);
+	height = g_ascii_strtoll(value, NULL, 0);
+
+	/* Find the height of the conversation window to calculate the maximum possible entry
+	 * size (1/2 of the window)
+	 */
+	gtk_widget_get_allocation(gtkconv->webview, &webview_allocation);
+	gtk_widget_get_allocation(gtkconv->entry, &entry_allocation);
+	total_height = webview_allocation.height + entry_allocation.height;
+	max_height = total_height / 2;
+
+	/* Get size of the characters to calculate initial minimum space for the entry */
+	value = webkit_dom_css_style_declaration_get_property_value(style, "font-size");
+	purple_debug_error("Masca", "font size: %s\n", value);
+	font_size = g_ascii_strtoll(value, NULL, 0);
+
+#define WEBVIEW_DOM_FONT_PADDING 3
+#define WEBVIEW_DOM_TEXT_PADDING 16
+
+	/* Allow to have a minimum of "min_lines" height as defined in the preference */
+	min_lines = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/minimum_entry_lines");
+
+	min_height = (font_size + WEBVIEW_DOM_FONT_PADDING) * min_lines + WEBVIEW_DOM_TEXT_PADDING;
+
+
+	/* Take into account the size of the formatting toolbar */
+	if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/show_formatting_toolbar")) {
+		toolbar_size = gtk_widget_get_allocated_height(pidgin_webview_get_toolbar(webview));
+	} else {
+		toolbar_size = 0;
+	}
+
+	purple_debug_error("Masca", "DOM size: %d; toolbar: %d\n", height, toolbar_size);
+
+	/* Calculate conv entry height */
+	height = CLAMP(height, MIN(min_height, max_height), max_height);
+	/* Add the size used by the toolbar so we always take it into consideration. */
+	height += toolbar_size;
+	purple_debug_error("Masca", "min h: %d; max h:%d\n", min_height, max_height);
+
+	/* Actually set the size of the gtkconv entry widget. */
+	gtk_widget_set_size_request(gtkconv->lower_hbox, -1, height);
+	purple_debug_info("pidgin", "resizing to %d, %d lines\n", height, min_lines);
 
 	return FALSE;
 }
@@ -5718,6 +5787,10 @@ setup_common_pane(PidginConversation *gt
 	g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "size-allocate",
 				 G_CALLBACK(resize_webview_cb), gtkconv);
 #endif
+	g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "changed",
+				 G_CALLBACK(resize_webview_cb), gtkconv);
+	g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "size-allocate",
+				 G_CALLBACK(resize_webview_cb), gtkconv);
 
 	default_formatize(gtkconv);
 	g_signal_connect_after(G_OBJECT(gtkconv->entry), "format-cleared",
@@ -8135,7 +8208,7 @@ show_formatting_toolbar_pref_cb(const ch
 		else
 			pidgin_webview_hide_toolbar(PIDGIN_WEBVIEW(gtkconv->entry));
 
-		g_idle_add((GSourceFunc)resize_webview_cb, gtkconv);
+		resize_webview_cb(gtkconv);
 	}
 }
 


More information about the Devel mailing list