/pidgin/main: d8d6e87ce594: Add autoscrolling for the debug window.
Elliott Sales de Andrade
qulogic at pidgin.im
Tue Aug 14 04:03:25 EDT 2012
Changeset: d8d6e87ce594aafecd2e6f549a627d0e3edee3b0
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2012-08-11 20:55 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/d8d6e87ce594
Description:
Add autoscrolling for the debug window.
diffstat:
pidgin/gtkdebug.c | 1 +
pidgin/gtkwebview.c | 39 +++++++++++++++++++++++++++++++++++++++
pidgin/gtkwebview.h | 19 +++++++++++++++++++
3 files changed, 59 insertions(+), 0 deletions(-)
diffs (117 lines):
diff --git a/pidgin/gtkdebug.c b/pidgin/gtkdebug.c
--- a/pidgin/gtkdebug.c
+++ b/pidgin/gtkdebug.c
@@ -812,6 +812,7 @@ debug_window_new(void)
frame = pidgin_create_webview(FALSE, &win->text, NULL, NULL);
gtk_webview_set_format_functions(GTK_WEBVIEW(win->text),
GTK_WEBVIEW_ALL ^ GTK_WEBVIEW_SMILEY ^ GTK_WEBVIEW_IMAGE);
+ gtk_webview_set_autoscroll(GTK_WEBVIEW(win->text), TRUE);
gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
gtk_widget_show(frame);
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -78,6 +78,7 @@ typedef struct _GtkWebViewPriv {
/* Scroll adjustments */
GtkAdjustment *vadj;
+ gboolean autoscroll;
guint scroll_src;
GTimer *scroll_time;
@@ -150,6 +151,7 @@ process_load_queue(GtkWebView *webview)
WebKitDOMHTMLElement *body;
WebKitDOMNode *start, *end;
WebKitDOMRange *range;
+ gboolean require_scroll = FALSE;
if (priv->is_loading) {
priv->loader = 0;
@@ -169,6 +171,12 @@ process_load_queue(GtkWebView *webview)
body = webkit_dom_document_get_body(doc);
start = webkit_dom_node_get_last_child(WEBKIT_DOM_NODE(body));
+ if (priv->autoscroll) {
+ require_scroll = (gtk_adjustment_get_value(priv->vadj)
+ >= (gtk_adjustment_get_upper(priv->vadj) -
+ gtk_adjustment_get_page_size(priv->vadj)));
+ }
+
webkit_dom_html_element_insert_adjacent_html(body, "beforeend",
str, NULL);
@@ -187,6 +195,15 @@ process_load_queue(GtkWebView *webview)
NULL);
}
+ if (require_scroll) {
+ if (start)
+ webkit_dom_element_scroll_into_view(WEBKIT_DOM_ELEMENT(start),
+ TRUE);
+ else
+ webkit_dom_element_scroll_into_view(WEBKIT_DOM_ELEMENT(body),
+ TRUE);
+ }
+
g_signal_emit(webview, signals[HTML_APPENDED], 0, range);
break;
@@ -855,6 +872,28 @@ gtk_webview_scroll_to_end(GtkWebView *we
}
void
+gtk_webview_set_autoscroll(GtkWebView *webview, gboolean scroll)
+{
+ GtkWebViewPriv *priv;
+
+ g_return_if_fail(webview != NULL);
+
+ priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->autoscroll = scroll;
+}
+
+gboolean
+gtk_webview_get_autoscroll(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv;
+
+ g_return_val_if_fail(webview != NULL, FALSE);
+
+ priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ return priv->autoscroll;
+}
+
+void
gtk_webview_page_up(GtkWebView *webview)
{
GtkWebViewPriv *priv;
diff --git a/pidgin/gtkwebview.h b/pidgin/gtkwebview.h
--- a/pidgin/gtkwebview.h
+++ b/pidgin/gtkwebview.h
@@ -163,6 +163,25 @@ void gtk_webview_set_vadjustment(GtkWebV
void gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth);
/**
+ * Set whether the GtkWebView stays at its end when HTML content is appended. If
+ * not already at the end before appending, then scrolling will not occur.
+ *
+ * @param webview The GtkWebView object
+ * @param scroll Whether to automatically scroll
+ */
+void gtk_webview_set_autoscroll(GtkWebView *webview, gboolean scroll);
+
+/**
+ * Set whether the GtkWebView stays at its end when HTML content is appended. If
+ * not already at the end before appending, then scrolling will not occur.
+ *
+ * @param webview The GtkWebView object
+ *
+ * @return Whether to automatically scroll
+ */
+gboolean gtk_webview_get_autoscroll(GtkWebView *webview);
+
+/**
* Scrolls a GtkWebView up by one page.
*
* @param webview The GtkWebView.
More information about the Commits
mailing list