parent
dd927ded6b
commit
8504d41db3
@ -24,7 +24,7 @@ import functools
|
|||||||
import html as html_utils
|
import html as html_utils
|
||||||
|
|
||||||
import sip
|
import sip
|
||||||
from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QPoint, QUrl, QTimer
|
from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QPoint, QPointF, QUrl, QTimer
|
||||||
from PyQt5.QtGui import QKeyEvent
|
from PyQt5.QtGui import QKeyEvent
|
||||||
from PyQt5.QtNetwork import QAuthenticator
|
from PyQt5.QtNetwork import QAuthenticator
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
@ -308,41 +308,31 @@ class WebEngineScroller(browsertab.AbstractScroller):
|
|||||||
for _ in range(min(count, 5000)):
|
for _ in range(min(count, 5000)):
|
||||||
self._tab.key_press(key, modifier)
|
self._tab.key_press(key, modifier)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot(QPointF)
|
||||||
def _update_pos(self):
|
def _update_pos(self, pos):
|
||||||
"""Update the scroll position attributes when it changed."""
|
"""Update the scroll position attributes when it changed."""
|
||||||
def update_pos_cb(jsret):
|
self._pos_px = pos.toPoint()
|
||||||
"""Callback after getting scroll position via JS."""
|
contents_size = self._widget.page().contentsSize()
|
||||||
if jsret is None:
|
|
||||||
# This can happen when the callback would get called after
|
|
||||||
# shutting down a tab
|
|
||||||
return
|
|
||||||
log.webview.vdebug(jsret)
|
|
||||||
assert isinstance(jsret, dict), jsret
|
|
||||||
self._pos_px = QPoint(jsret['px']['x'], jsret['px']['y'])
|
|
||||||
|
|
||||||
dx = jsret['scroll']['width'] - jsret['inner']['width']
|
scrollable_x = contents_size.width() - self._widget.width()
|
||||||
if dx == 0:
|
if scrollable_x == 0:
|
||||||
perc_x = 0
|
perc_x = 0
|
||||||
else:
|
else:
|
||||||
perc_x = min(100, round(100 / dx * jsret['px']['x']))
|
perc_x = min(100, round(100 / scrollable_x * pos.x()))
|
||||||
|
|
||||||
dy = jsret['scroll']['height'] - jsret['inner']['height']
|
scrollable_y = contents_size.height() - self._widget.height()
|
||||||
if dy == 0:
|
if scrollable_y == 0:
|
||||||
perc_y = 0
|
perc_y = 0
|
||||||
else:
|
else:
|
||||||
perc_y = min(100, round(100 / dy * jsret['px']['y']))
|
perc_y = min(100, round(100 / scrollable_y * pos.y()))
|
||||||
|
|
||||||
self._at_bottom = math.ceil(jsret['px']['y']) >= dy
|
self._at_bottom = math.ceil(pos.y()) >= scrollable_y
|
||||||
|
|
||||||
if (self._pos_perc != (perc_x, perc_y) or
|
if (self._pos_perc != (perc_x, perc_y) or
|
||||||
'no-scroll-filtering' in self._args.debug_flags):
|
'no-scroll-filtering' in self._args.debug_flags):
|
||||||
self._pos_perc = perc_x, perc_y
|
self._pos_perc = perc_x, perc_y
|
||||||
self.perc_changed.emit(*self._pos_perc)
|
self.perc_changed.emit(*self._pos_perc)
|
||||||
|
|
||||||
js_code = javascript.assemble('scroll', 'pos')
|
|
||||||
self._tab.run_js_async(js_code, update_pos_cb)
|
|
||||||
|
|
||||||
def pos_px(self):
|
def pos_px(self):
|
||||||
return self._pos_px
|
return self._pos_px
|
||||||
|
|
||||||
|
@ -71,32 +71,5 @@ window._qutebrowser.scroll = (function() {
|
|||||||
window.scrollBy(dx, dy);
|
window.scrollBy(dx, dy);
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.pos = function() {
|
|
||||||
var pos = {
|
|
||||||
"px": {"x": window.scrollX, "y": window.scrollY},
|
|
||||||
"scroll": {
|
|
||||||
"width": Math.max(
|
|
||||||
document.body.scrollWidth,
|
|
||||||
document.body.offsetWidth,
|
|
||||||
document.documentElement.scrollWidth,
|
|
||||||
document.documentElement.offsetWidth
|
|
||||||
),
|
|
||||||
"height": Math.max(
|
|
||||||
document.body.scrollHeight,
|
|
||||||
document.body.offsetHeight,
|
|
||||||
document.documentElement.scrollHeight,
|
|
||||||
document.documentElement.offsetHeight
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"inner": {
|
|
||||||
"width": window.innerWidth,
|
|
||||||
"height": window.innerHeight,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// console.log(JSON.stringify(pos));
|
|
||||||
return pos;
|
|
||||||
};
|
|
||||||
|
|
||||||
return funcs;
|
return funcs;
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user