From b30d37e3e0b1d488f348efeb6001512ec0700fba Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 14 Nov 2016 23:03:36 +0100 Subject: [PATCH] WebEngine: Fake keypresses with modifiers instead of override_target With QtWebEngine, handling a click (e.g. createWindow being called) happens some time after a click event has been handled. When setting override_target, that means we don't know when to set the override target back, and we can't simply only unset it in createWindow as elements not causing a new tab to be opened (like an input field) can be hinted too. Instead, we now only use override_target with QtWebKit, and simply generate fake key events with the right modifiers to do the right thing in createWindow for QtWebEngine. Fixes #2119. --- qutebrowser/browser/browsertab.py | 1 + qutebrowser/browser/webelem.py | 20 +++++++++++++------- qutebrowser/browser/webengine/webview.py | 12 +++--------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index cbf566847..efc6d6f4b 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -84,6 +84,7 @@ class TabData: inspector: The QWebInspector used for this webview. viewing_source: Set if we're currently showing a source view. override_target: Override for open_target for fake clicks (like hints). + Only used for QtWebKit. """ def __init__(self): diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index cd56a9127..97c5695c4 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -338,6 +338,8 @@ class AbstractWebElement(collections.abc.MutableMapping): """Simulate a click on the element.""" # FIXME:qtwebengine do we need this? # self._widget.setFocus() + + # For QtWebKit self._tab.data.override_target = click_target pos = self._mouse_pos() @@ -345,20 +347,24 @@ class AbstractWebElement(collections.abc.MutableMapping): log.webelem.debug("Sending fake click to {!r} at position {} with " "target {}".format(self, pos, click_target)) - if click_target in [usertypes.ClickTarget.tab, - usertypes.ClickTarget.tab_bg, - usertypes.ClickTarget.window]: - modifiers = Qt.ControlModifier + modifiers = { + usertypes.ClickTarget.normal: Qt.NoModifier, + usertypes.ClickTarget.window: Qt.AltModifier | Qt.ShiftModifier, + usertypes.ClickTarget.tab: Qt.ControlModifier, + usertypes.ClickTarget.tab_bg: Qt.ControlModifier, + } + if config.get('tabs', 'background-tabs'): + modifiers[usertypes.ClickTarget.tab] |= Qt.ShiftModifier else: - modifiers = Qt.NoModifier + modifiers[usertypes.ClickTarget.tab_bg] |= Qt.ShiftModifier events = [ QMouseEvent(QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton, Qt.NoModifier), QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, - Qt.LeftButton, modifiers), + Qt.LeftButton, modifiers[click_target]), QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, - Qt.NoButton, modifiers), + Qt.NoButton, modifiers[click_target]), ] for evt in events: diff --git a/qutebrowser/browser/webengine/webview.py b/qutebrowser/browser/webengine/webview.py index 882e2379f..ffc9555f3 100644 --- a/qutebrowser/browser/webengine/webview.py +++ b/qutebrowser/browser/webengine/webview.py @@ -74,18 +74,12 @@ class WebEngineView(QWebEngineView): """ debug_type = debug.qenum_key(QWebEnginePage, wintype) background_tabs = config.get('tabs', 'background-tabs') - override_target = self._tabdata.override_target log.webview.debug("createWindow with type {}, background_tabs " - "{}, override_target {}".format( - debug_type, background_tabs, override_target)) + "{}".format(debug_type, background_tabs)) - if override_target is not None: - target = override_target - self._tabdata.override_target = None - elif wintype == QWebEnginePage.WebBrowserWindow: - log.webview.debug("createWindow with WebBrowserWindow - when does " - "this happen?!") + if wintype == QWebEnginePage.WebBrowserWindow: + # Shift-Alt-Click target = usertypes.ClickTarget.window elif wintype == QWebEnginePage.WebDialog: log.webview.warning("{} requested, but we don't support "