Skip to content
Permalink
Browse files
QtWebEngine: Implement :scroll-perc via JS
  • Loading branch information
The-Compiler committed Jul 13, 2016
1 parent e0ab70c commit b78b89f04f75c3b113e62179a863dca3395112ec
@@ -349,8 +349,9 @@ class AbstractScroller(QObject):

perc_changed = pyqtSignal(int, int)

def __init__(self, parent=None):
def __init__(self, tab, parent=None):
super().__init__(parent)
self._tab = tab
self._widget = None

def pos_px(self):
@@ -493,7 +494,7 @@ def __init__(self, win_id, parent=None):
objreg.register('tab', self, registry=self.registry)

# self.history = AbstractHistory(self)
# self.scroll = AbstractScroller(parent=self)
# self.scroll = AbstractScroller(self, parent=self)
# self.caret = AbstractCaret(win_id=win_id, tab=self, mode_manager=...,
# parent=self)
# self.zoom = AbstractZoom(win_id=win_id)
@@ -32,7 +32,7 @@

from qutebrowser.browser import browsertab
from qutebrowser.browser.webengine import webview
from qutebrowser.utils import usertypes, qtutils, log
from qutebrowser.utils import usertypes, qtutils, log, utils


class WebEnginePrinting(browsertab.AbstractPrinting):
@@ -213,7 +213,13 @@ def pos_perc(self):
return (perc_x, perc_y)

def to_perc(self, x=None, y=None):
log.stub()
js_code = """
{scroll_js}
scroll_to_perc({x}, {y});
""".format(scroll_js=utils.read_file('javascript/scroll.js'),
x='undefined' if x is None else x,
y='undefined' if y is None else y)
self._tab.run_js_async(js_code)

def to_point(self, point):
log.stub()
@@ -303,7 +309,7 @@ def __init__(self, win_id, mode_manager, parent=None):
super().__init__(win_id)
widget = webview.WebEngineView()
self.history = WebEngineHistory(self)
self.scroll = WebEngineScroller()
self.scroll = WebEngineScroller(self, parent=self)
self.caret = WebEngineCaret(win_id=win_id, mode_manager=mode_manager,
tab=self, parent=self)
self.zoom = WebEngineZoom(win_id=win_id, parent=self)
@@ -499,7 +499,7 @@ def __init__(self, win_id, mode_manager, parent=None):
super().__init__(win_id)
widget = webview.WebView(win_id, self.tab_id, tab=self)
self.history = WebKitHistory(self)
self.scroll = WebKitScroller(parent=self)
self.scroll = WebKitScroller(self, parent=self)
self.caret = WebKitCaret(win_id=win_id, mode_manager=mode_manager,
tab=self, parent=self)
self.zoom = WebKitZoom(win_id=win_id, parent=self)
@@ -0,0 +1,34 @@
/**
* Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
*
* This file is part of qutebrowser.
*
* qutebrowser is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qutebrowser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
*/

function scroll_to_perc(x, y) {
var elem = document.documentElement;
var x_px = window.scrollX;
var y_px = window.scrollY;

if (x !== undefined) {
x_px = (elem.scrollWidth - elem.clientWidth) / 100 * x;
}

if (y !== undefined) {
y_px = (elem.scrollHeight - elem.clientHeight) / 100 * y;
}

window.scroll(x_px, y_px);
}

0 comments on commit b78b89f

Please sign in to comment.