Permalink
Browse files

QtWebEngine: Implement pixel scroll position in JS

  • Loading branch information...
The-Compiler committed Jul 15, 2016
1 parent 7adc8ab commit 695864281bd480bbfdb9afb752a4cb47663e6f12
Showing with 15 additions and 12 deletions.
  1. +9 −8 qutebrowser/browser/webengine/webenginetab.py
  2. +6 −4 qutebrowser/javascript/scroll.js
@@ -185,6 +185,7 @@ class WebEngineScroller(browsertab.AbstractScroller):
def __init__(self, tab, parent=None):
super().__init__(tab, parent)
self._pos_perc = (None, None)
+ self._pos_px = QPoint()
def _init_widget(self, widget):
super()._init_widget(widget)
@@ -203,20 +204,20 @@ def _key_press(self, key, count=1):
@pyqtSlot()
def _on_scroll_pos_changed(self):
- def update_scroll_pos_perc(jsret):
- assert len(jsret) == 2, jsret
- self._pos_perc = jsret
- self.perc_changed.emit(*jsret)
+ def update_scroll_pos(jsret):
+ assert isinstance(jsret, dict)
+ self._pos_perc = (jsret['perc']['x'], jsret['perc']['y'])
+ self._pos_px = QPoint(jsret['px']['x'], jsret['px']['y'])
+ self.perc_changed.emit(*self._pos_perc)
js_code = """
{scroll_js}
- scroll_pos_perc();
+ scroll_pos();
""".format(scroll_js=utils.read_file('javascript/scroll.js'))
- self._tab.run_js_async(js_code, update_scroll_pos_perc)
+ self._tab.run_js_async(js_code, update_scroll_pos)
def pos_px(self):
- log.stub()
- return QPoint(0, 0)
+ return self._pos_px
def pos_perc(self):
return self._pos_perc
@@ -39,7 +39,7 @@ function scroll_delta_page(x, y) {
window.scrollBy(dx, dy);
}
-function scroll_pos_perc() {
+function scroll_pos() {
var elem = document.documentElement;
var dx = (elem.scrollWidth - elem.clientWidth);
var dy = (elem.scrollHeight - elem.clientHeight);
@@ -58,8 +58,10 @@ function scroll_pos_perc() {
perc_y = 100 / dy * window.scrollY;
}
- // console.log(perc_x);
- // console.log(perc_y);
+ var pos_perc = {'x': perc_x, 'y': perc_y};
+ var pos_px = {'x': window.scrollX, 'y': window.scrollY};
+ var pos = {'perc': pos_perc, 'px': pos_px};
- return [perc_x, perc_y];
+ // console.log(JSON.stringify(pos));
+ return pos;
}

0 comments on commit 6958642

Please sign in to comment.