From edce4234d3d2b205eab1c5aaef6623849f1cbb32 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Tue, 27 Jun 2017 23:21:16 +0200 Subject: [PATCH] Fixed wrong scroll position calculation #428. We use the scrollHeight and the scrollTop of the document.documentElement. But there are pages where the scrollHeight is calculated as the same value like the height of the viewport. I can't identify what causes this issue, but using the document.body scrollHeight fixes this. --- src/webextension/ext-main.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/webextension/ext-main.c b/src/webextension/ext-main.c index 371c58b..ef67c79 100644 --- a/src/webextension/ext-main.c +++ b/src/webextension/ext-main.c @@ -239,34 +239,33 @@ static void on_document_scroll(WebKitDOMEventTarget *target, WebKitDOMEvent *eve } if (doc) { - WebKitDOMElement *b, *de; - glong max, scrollTop, scrollHeight, clientHeight; + WebKitDOMElement *body, *de; + glong max = 0, scrollTop, scrollHeight, clientHeight; guint percent = 0; de = webkit_dom_document_get_document_element(doc); if (!de) { return; } - /* Get the clientHeight. */ - clientHeight = webkit_dom_element_get_client_height(WEBKIT_DOM_ELEMENT(de)); - b = WEBKIT_DOM_ELEMENT(webkit_dom_document_get_body(doc)); - /* Get the scrollTop of the document or the body. */ - if (!(scrollTop = webkit_dom_element_get_scroll_top(de)) && b) { - scrollTop = webkit_dom_element_get_scroll_top(b); - } - /* Get the scrollHeight of the document or the body. */ - if (!(scrollHeight = webkit_dom_element_get_scroll_height(de)) && b) { - scrollHeight = webkit_dom_element_get_scroll_height(b); + body = WEBKIT_DOM_ELEMENT(webkit_dom_document_get_body(doc)); + if (!body) { + return; } - /* Get the maximum scrollable page size. This is the size of the whole - * document - height of the viewport. */ - max = scrollHeight - clientHeight ; - - if (scrollTop && max) { - percent = (guint)(0.5 + (scrollTop * 100 / max)); + scrollTop = webkit_dom_element_get_scroll_top(body); + if (scrollTop) { + clientHeight = webkit_dom_element_get_client_height(WEBKIT_DOM_ELEMENT(de)); + scrollHeight = webkit_dom_element_get_scroll_height(body); + + /* Get the maximum scrollable page size. This is the size of the whole + * document - height of the viewport. */ + max = scrollHeight - clientHeight ; + if (max) { + percent = (guint)(0.5 + (scrollTop * 100 / max)); + } } + dbus_emit_signal("VerticalScroll", g_variant_new("(ttq)", webkit_web_page_get_id(page), max, percent)); } -- 2.20.1