Add contents_size_changed to tab API

This commit is contained in:
Florian Bruhin 2016-07-27 15:34:28 +02:00
parent c764733472
commit c5a91004f5
4 changed files with 15 additions and 32 deletions

View File

@ -21,7 +21,7 @@
import itertools
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QPoint
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QPoint, QSizeF
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget, QLayout
@ -482,6 +482,7 @@ class AbstractTab(QWidget):
new_tab_requested = pyqtSignal(QUrl)
url_changed = pyqtSignal(QUrl)
shutting_down = pyqtSignal()
contents_size_changed = pyqtSignal(QSizeF)
def __init__(self, win_id, parent=None):
self.win_id = win_id

View File

@ -64,8 +64,6 @@ class HintContext:
Attributes:
frames: The QWebFrames to use.
destroyed_frames: id()'s of QWebFrames which have been destroyed.
(Workaround for https://github.com/The-Compiler/qutebrowser/issues/152)
all_elems: A list of all (elem, label) namedtuples ever created.
elems: A mapping from key strings to (elem, label) namedtuples.
May contain less elements than `all_elems` due to filtering.
@ -95,7 +93,6 @@ class HintContext:
self.to_follow = None
self.rapid = False
self.frames = []
self.destroyed_frames = []
self.args = []
self.mainframe = None
self.tab = None
@ -179,22 +176,6 @@ class HintManager(QObject):
elem.label.removeFromDocument()
except webelem.IsNullError:
pass
for f in self._context.frames:
log.hints.debug("Disconnecting frame {}".format(f))
if id(f) in self._context.destroyed_frames:
# WORKAROUND for
# https://github.com/The-Compiler/qutebrowser/issues/152
log.hints.debug("Frame has been destroyed, ignoring.")
continue
try:
f.contentsSizeChanged.disconnect(self.on_contents_size_changed)
except TypeError:
# It seems we can get this here:
# TypeError: disconnect() failed between
# 'contentsSizeChanged' and 'on_contents_size_changed'
# See # https://github.com/The-Compiler/qutebrowser/issues/263
pass
log.hints.debug("Disconnected.")
text = self._get_text()
message_bridge = objreg.get('message-bridge', scope='window',
window=self._win_id)
@ -656,12 +637,6 @@ class HintManager(QObject):
log.hints.vdebug("No match on '{}'!".format(text))
return None
def _connect_frame_signals(self):
"""Connect the contentsSizeChanged signals to all frames."""
for f in self._context.frames:
log.hints.debug("Connecting frame {}".format(f))
f.contentsSizeChanged.connect(self.on_contents_size_changed)
def _check_args(self, target, *args):
"""Check the arguments passed to start() and raise if they're wrong.
@ -847,11 +822,6 @@ class HintManager(QObject):
except qtutils.QtValueError:
raise cmdexc.CommandError("No URL set for this page yet!")
self._context.frames = webelem.get_child_frames(mainframe)
for frame in self._context.frames:
# WORKAROUND for
# https://github.com/The-Compiler/qutebrowser/issues/152
frame.destroyed.connect(functools.partial(
self._context.destroyed_frames.append, id(frame)))
self._context.args = args
self._context.mainframe = mainframe
self._context.group = group

View File

@ -425,3 +425,7 @@ class WebEngineTab(browsertab.AbstractTab):
view.iconChanged.connect(self.icon_changed)
except AttributeError:
log.stub('iconChanged, on Qt < 5.7')
try:
page.contentsSizeChanged.connect(self.contents_size_changed)
except AttributeError:
log.stub('contentsSizeChanged, on Qt < 5.7')

View File

@ -25,7 +25,7 @@ import xml.etree.ElementTree
from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QUrl, QPoint, QTimer
from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.QtWebKitWidgets import QWebPage, QWebFrame
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtPrintSupport import QPrinter
@ -572,6 +572,14 @@ class WebKitTab(browsertab.AbstractTab):
"""Emit iconChanged with a QIcon like QWebEngineView does."""
self.icon_changed.emit(self._widget.icon())
@pyqtSlot(QWebFrame)
def _on_frame_created(self, frame):
"""Connect the contentsSizeChanged signal of each frame."""
# FIXME:qtwebengine those could theoretically regress:
# https://github.com/The-Compiler/qutebrowser/issues/152
# https://github.com/The-Compiler/qutebrowser/issues/263
frame.contentsSizeChanged.connect(self.contents_size_changed)
def _connect_signals(self):
view = self._widget
page = view.page()