Skip to content
Browse files

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

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.
  • Loading branch information
The-Compiler committed Aug 11, 2016
1 parent 3bffb71 commit 421b14681f21aa85b2b70b6ba1d7176e0f0404dd
Showing with 44 additions and 41 deletions.
  1. +43 −8 qutebrowser/browser/
  2. +0 −18 qutebrowser/browser/webkit/
  3. +1 −15 qutebrowser/browser/webkit/
@@ -23,14 +23,14 @@

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',

def __init__(self):
def __init__(self, parent=None):
self.keep_icon = False
self.viewing_source = False
self.inspector = None
@@ -89,6 +87,21 @@ def combined_target(self):
return self.open_target

def _on_start_hinting(self, hint_target):
"""Emitted before a hinting-click takes place.
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

def _on_stop_hinting(self):
log.webview.debug("Finishing hinting.")
self.hint_target = None

class AbstractPrinting:

@@ -475,7 +488,8 @@ def __init__(self, win_id, parent=None):
# self.zoom = AbstractZoom(win_id=win_id)
# = AbstractSearch(parent=self)
# self.printing = AbstractPrinting() = TabData() = TabData(parent=self)
self._layout = miscwidgets.WrapperLayout(self)
self._widget = None
self._progress = 0
@@ -484,6 +498,17 @@ def __init__(self, win_id, parent=None):
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)
# pylint: disable=protected-access
# 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 @@ def _set_load_status(self, val):
self._load_status = val

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))
QApplication.postEvent(self._widget, evt)

def _on_link_clicked(self, url):
log.webview.debug("link clicked: url {}, hint target {}, "
@@ -421,24 +421,6 @@ def on_restore_frame_state_requested(self, frame):
if 'scroll-pos' in data and frame.scrollPosition() == QPoint(0, 0):

def on_start_hinting(self, hint_target):
"""Emitted before a hinting-click takes place.
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

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 @@

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 @@ def __init__(self, win_id, tab_id, tab, parent=None):
self._tab_id = tab_id

page = self._init_page(
hintmanager = hints.HintManager(win_id, self._tab_id, self)
objreg.register('hintmanager', hintmanager, scope='tab', window=win_id,
mode_manager = objreg.get('mode-manager', scope='window',
@@ -241,13 +234,6 @@ def add_js_bridge(self):
bridge = objreg.get('js-bridge')
frame.addToJavaScriptWindowObject('qute', bridge)

def on_mouse_event(self, evt):
"""Post a new mouse event from a hintmanager."""
log.modes.debug("Hint triggered, focusing {!r}".format(self))
QApplication.postEvent(self, evt)

def on_load_finished(self):
"""Handle a finished page load.

0 comments on commit 421b146

Please sign in to comment.