Move HintManager out of WebView
This moves creating the HintManager to AbstractTab, and lets TabData (which is now a QObject) handle the start_hinting/end_hinting signal. For the mouse_event signal of HintManager, we now have a slot in AbstractTab too, though that might actually be moved to WebKitTab/WebEngineTab later when needed.
This commit is contained in:
parent
3bffb71b55
commit
421b14681f
@ -23,14 +23,14 @@ import itertools
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QPoint, QSizeF
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QWidget
|
||||
from PyQt5.QtWidgets import QWidget, QApplication
|
||||
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import (utils, objreg, usertypes, message, log, qtutils,
|
||||
debug, urlutils)
|
||||
from qutebrowser.misc import miscwidgets
|
||||
from qutebrowser.browser import mouse
|
||||
from qutebrowser.browser import mouse, hints
|
||||
|
||||
|
||||
tab_id_gen = itertools.count(0)
|
||||
@ -60,7 +60,7 @@ class WebTabError(Exception):
|
||||
"""Base class for various errors."""
|
||||
|
||||
|
||||
class TabData:
|
||||
class TabData(QObject):
|
||||
|
||||
"""A simple namespace with a fixed set of attributes.
|
||||
|
||||
@ -73,10 +73,8 @@ class TabData:
|
||||
hint_target: Override for open_target for hints.
|
||||
"""
|
||||
|
||||
__slots__ = ['keep_icon', 'viewing_source', 'inspector', 'open_target',
|
||||
'hint_target']
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.keep_icon = False
|
||||
self.viewing_source = False
|
||||
self.inspector = None
|
||||
@ -89,6 +87,21 @@ class TabData:
|
||||
else:
|
||||
return self.open_target
|
||||
|
||||
@pyqtSlot(usertypes.ClickTarget)
|
||||
def _on_start_hinting(self, hint_target):
|
||||
"""Emitted before a hinting-click takes place.
|
||||
|
||||
Args:
|
||||
hint_target: A ClickTarget member to set self.hint_target to.
|
||||
"""
|
||||
log.webview.debug("Setting force target to {}".format(hint_target))
|
||||
self.hint_target = hint_target
|
||||
|
||||
@pyqtSlot()
|
||||
def _on_stop_hinting(self):
|
||||
log.webview.debug("Finishing hinting.")
|
||||
self.hint_target = None
|
||||
|
||||
|
||||
class AbstractPrinting:
|
||||
|
||||
@ -475,7 +488,8 @@ class AbstractTab(QWidget):
|
||||
# self.zoom = AbstractZoom(win_id=win_id)
|
||||
# self.search = AbstractSearch(parent=self)
|
||||
# self.printing = AbstractPrinting()
|
||||
self.data = TabData()
|
||||
|
||||
self.data = TabData(parent=self)
|
||||
self._layout = miscwidgets.WrapperLayout(self)
|
||||
self._widget = None
|
||||
self._progress = 0
|
||||
@ -484,6 +498,17 @@ class AbstractTab(QWidget):
|
||||
self._mouse_event_filter = mouse.MouseEventFilter(self, parent=self)
|
||||
self.backend = None
|
||||
|
||||
# FIXME:qtwebengine Should this be public api via self.hints?
|
||||
# Also, should we get it out of objreg?
|
||||
hintmanager = hints.HintManager(win_id, self.tab_id, parent=self)
|
||||
hintmanager.mouse_event.connect(self._on_hint_mouse_event)
|
||||
# pylint: disable=protected-access
|
||||
hintmanager.start_hinting.connect(self.data._on_start_hinting)
|
||||
hintmanager.stop_hinting.connect(self.data._on_stop_hinting)
|
||||
# pylint: enable=protected-access
|
||||
objreg.register('hintmanager', hintmanager, scope='tab',
|
||||
window=self.win_id, tab=self.tab_id)
|
||||
|
||||
def _set_widget(self, widget):
|
||||
# pylint: disable=protected-access
|
||||
self._widget = widget
|
||||
@ -507,6 +532,16 @@ class AbstractTab(QWidget):
|
||||
self._load_status = val
|
||||
self.load_status_changed.emit(val.name)
|
||||
|
||||
@pyqtSlot('QMouseEvent')
|
||||
def _on_hint_mouse_event(self, evt):
|
||||
"""Post a new mouse event from a hintmanager."""
|
||||
# FIXME:qtwebengine Will this implementation work for QtWebEngine?
|
||||
# We probably need to send the event to the
|
||||
# focusProxy()?
|
||||
log.modes.debug("Hint triggered, focusing {!r}".format(self))
|
||||
self._widget.setFocus()
|
||||
QApplication.postEvent(self._widget, evt)
|
||||
|
||||
@pyqtSlot(QUrl)
|
||||
def _on_link_clicked(self, url):
|
||||
log.webview.debug("link clicked: url {}, hint target {}, "
|
||||
|
@ -421,24 +421,6 @@ class BrowserPage(QWebPage):
|
||||
if 'scroll-pos' in data and frame.scrollPosition() == QPoint(0, 0):
|
||||
frame.setScrollPosition(data['scroll-pos'])
|
||||
|
||||
@pyqtSlot(usertypes.ClickTarget)
|
||||
def on_start_hinting(self, hint_target):
|
||||
"""Emitted before a hinting-click takes place.
|
||||
|
||||
Args:
|
||||
hint_target: A ClickTarget member to set self._hint_target to.
|
||||
"""
|
||||
# FIXME move this away
|
||||
log.webview.debug("Setting force target to {}".format(hint_target))
|
||||
self._tabdata.hint_target = hint_target
|
||||
|
||||
@pyqtSlot()
|
||||
def on_stop_hinting(self):
|
||||
"""Emitted when hinting is finished."""
|
||||
# FIXME move this away
|
||||
log.webview.debug("Finishing hinting.")
|
||||
self._tabdata.hint_target = None
|
||||
|
||||
def userAgentForUrl(self, url):
|
||||
"""Override QWebPage::userAgentForUrl to customize the user agent."""
|
||||
ua = config.get('network', 'user-agent')
|
||||
|
@ -23,14 +23,13 @@ import sys
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl, QPoint
|
||||
from PyQt5.QtGui import QPalette
|
||||
from PyQt5.QtWidgets import QApplication, QStyleFactory
|
||||
from PyQt5.QtWidgets import QStyleFactory
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage, QWebFrame
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.utils import log, usertypes, utils, qtutils, objreg
|
||||
from qutebrowser.browser import hints
|
||||
from qutebrowser.browser.webkit import webpage, webkitelem
|
||||
|
||||
|
||||
@ -75,12 +74,6 @@ class WebView(QWebView):
|
||||
self._tab_id = tab_id
|
||||
|
||||
page = self._init_page(tab.data)
|
||||
hintmanager = hints.HintManager(win_id, self._tab_id, self)
|
||||
hintmanager.mouse_event.connect(self.on_mouse_event)
|
||||
hintmanager.start_hinting.connect(page.on_start_hinting)
|
||||
hintmanager.stop_hinting.connect(page.on_stop_hinting)
|
||||
objreg.register('hintmanager', hintmanager, scope='tab', window=win_id,
|
||||
tab=tab_id)
|
||||
mode_manager = objreg.get('mode-manager', scope='window',
|
||||
window=win_id)
|
||||
mode_manager.entered.connect(self.on_mode_entered)
|
||||
@ -241,13 +234,6 @@ class WebView(QWebView):
|
||||
bridge = objreg.get('js-bridge')
|
||||
frame.addToJavaScriptWindowObject('qute', bridge)
|
||||
|
||||
@pyqtSlot('QMouseEvent')
|
||||
def on_mouse_event(self, evt):
|
||||
"""Post a new mouse event from a hintmanager."""
|
||||
log.modes.debug("Hint triggered, focusing {!r}".format(self))
|
||||
self.setFocus()
|
||||
QApplication.postEvent(self, evt)
|
||||
|
||||
@pyqtSlot()
|
||||
def on_load_finished(self):
|
||||
"""Handle a finished page load.
|
||||
|
Loading…
Reference in New Issue
Block a user