static VbResult normal_scroll(Client *c, const NormalCmdInfo *info)
{
- int x = 0, y = 0, page_height = 0, count = info->count ? info->count : 1;
char *js;
- GtkAllocation alloc;
- /* The overall page height is only required for the <C-*> commands. */
- if (VB_IS_CTRL(info->key)) {
- gtk_widget_get_allocation(GTK_WIDGET(c->webview), &alloc);
- page_height = (int)alloc.height;
- }
-
- switch (info->key) {
- case 'j':
- y = count * c->config.scrollstep;
- break;
- case 'h':
- x = -count * c->config.scrollstep;
- break;
- case 'k':
- y = -count * c->config.scrollstep;
- break;
- case 'l':
- x = count * c->config.scrollstep;
- break;
- case CTRL('D'):
- y = count * page_height / 2;
- break;
- case CTRL('U'):
- y = -count * page_height / 2;
- break;
- case CTRL('F'):
- y = count * page_height;
- break;
- case CTRL('B'):
- y = -count * page_height;
- break;
- case 'G':
- if (info->count) {
- js = g_strdup_printf(
- "window.scroll(window.scrollX, %d * ((document.documentElement.scrollHeight - window.innerHeight) / 100));",
- info->count);
- ext_proxy_eval_script(c, js, NULL);
- g_free(js);
- return RESULT_COMPLETE;
- }
-
- /* Without count scroll to the end of the page. */
- ext_proxy_eval_script(c, "window.scroll(window.scrollX, document.body.scrollHeight);", NULL);
- return RESULT_COMPLETE;
- case '0':
- ext_proxy_eval_script(c, "window.scroll(0, window.scrollY);", NULL);
- return RESULT_COMPLETE;
- case '$':
- ext_proxy_eval_script(c, "window.scroll(document.body.scrollWidth, window.scrollY);", NULL);
- return RESULT_COMPLETE;
- default:
- if (info->key2 == 'g') {
- if (info->count) {
- js = g_strdup_printf(
- "window.scroll(window.scrollX, %d * (1 + (document.height - window.innerHeight) / 100));",
- info->count);
- ext_proxy_eval_script(c, js, NULL);
- g_free(js);
- return RESULT_COMPLETE;
- }
- /* Without count gg scrolls to the top of the page. */
- ext_proxy_eval_script(c, "window.scroll(window.scrollX, 0);", NULL);
- return RESULT_COMPLETE;
- }
- return RESULT_ERROR;
- }
- js = g_strdup_printf("window.scrollBy(%d,%d);", x, y);
+ js = g_strdup_printf("vbscroll('%c',%d,%d);", info->key, c->config.scrollstep, info->count);
ext_proxy_eval_script(c, js, NULL);
g_free(js);
webkit_user_content_manager_remove_all_scripts(ucm);
}
- /* Inject the global hints script. */
- script = webkit_user_script_new(JS_HINTS,
+ /* Inject the global scripts. */
+ script = webkit_user_script_new(JS_HINTS " " JS_SCROLL,
WEBKIT_USER_CONTENT_INJECT_TOP_FRAME,
WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END, NULL, NULL);
webkit_user_content_manager_add_script(ucm, script);