Move some scroll logic from JS to Python
This commit is contained in:
parent
71a89bd418
commit
b45f940e72
@ -230,9 +230,16 @@ class WebEngineScroller(browsertab.AbstractScroller):
|
||||
# shutting down a tab
|
||||
return
|
||||
assert isinstance(jsret, dict), jsret
|
||||
self._pos_perc = (jsret['perc']['x'], jsret['perc']['y'])
|
||||
self._pos_px = QPoint(jsret['px']['x'], jsret['px']['y'])
|
||||
self._at_bottom = jsret['at_bottom']
|
||||
|
||||
dx = jsret['scroll']['width'] - jsret['inner']['width']
|
||||
perc_x = 0 if dx == 0 else 100 / dx * jsret['px']['x']
|
||||
dy = jsret['scroll']['height'] - jsret['inner']['height']
|
||||
perc_y = 0 if dy == 0 else 100 / dy * jsret['px']['y']
|
||||
|
||||
self._at_bottom = dy == jsret['scroll']['height']
|
||||
self._pos_perc = perc_x, perc_y
|
||||
|
||||
self.perc_changed.emit(*self._pos_perc)
|
||||
|
||||
js_code = javascript.assemble('scroll', 'pos')
|
||||
|
@ -61,26 +61,17 @@ window._qutebrowser.scroll = (function() {
|
||||
|
||||
funcs.pos = function() {
|
||||
var elem = document.documentElement;
|
||||
var dx = elem.scrollWidth - window.innerWidth;
|
||||
var dy = elem.scrollHeight - window.innerHeight;
|
||||
var perc_x, perc_y;
|
||||
|
||||
if (dx === 0) {
|
||||
perc_x = 0;
|
||||
} else {
|
||||
perc_x = 100 / dx * window.scrollX;
|
||||
}
|
||||
|
||||
if (dy === 0) {
|
||||
perc_y = 0;
|
||||
} else {
|
||||
perc_y = 100 / dy * window.scrollY;
|
||||
}
|
||||
|
||||
var pos = {
|
||||
"perc": {"x": perc_x, "y": perc_y},
|
||||
"px": {"x": window.scrollX, "y": window.scrollY},
|
||||
"at_bottom": dy === window.scrollY,
|
||||
"scroll": {
|
||||
"width": elem.scrollWidth,
|
||||
"height": elem.scrollHeight,
|
||||
},
|
||||
"inner": {
|
||||
"width": window.innerWidth,
|
||||
"height": window.innerHeight,
|
||||
},
|
||||
};
|
||||
|
||||
// console.log(JSON.stringify(pos));
|
||||
|
Loading…
Reference in New Issue
Block a user