Make sure external schemes are clickable via hints

This issue was probably introduced in 545539f28d
- with JavaScript, we can't "click" on an external link.

There might be a better solution using
QWebEngineSettings::setUnknownUrlSchemePolicy(QWebEngineSettings::AllowAllUnknownUrlSchemes)
temporarily when using hints with PyQt 5.11.

Fixes #2833
This commit is contained in:
Florian Bruhin 2018-06-07 14:27:53 +02:00
parent 59e5a2a6f1
commit 89f4333df1
4 changed files with 31 additions and 2 deletions

View File

@ -307,6 +307,10 @@ class AbstractWebElement(collections.abc.MutableMapping):
href_tags = ['a', 'area', 'link'] href_tags = ['a', 'area', 'link']
return self.tag_name() in href_tags and 'href' in self return self.tag_name() in href_tags and 'href' in self
def _requires_user_interaction(self):
"""Return True if clicking this element needs user interaction."""
raise NotImplementedError
def _mouse_pos(self): def _mouse_pos(self):
"""Get the position to click/hover.""" """Get the position to click/hover."""
# Click the center of the largest square fitting into the top/left # Click the center of the largest square fitting into the top/left
@ -405,7 +409,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
return return
if click_target == usertypes.ClickTarget.normal: if click_target == usertypes.ClickTarget.normal:
if self.is_link(): if self.is_link() and not self._requires_user_interaction():
log.webelem.debug("Clicking via JS click()") log.webelem.debug("Clicking via JS click()")
self._click_js(click_target) self._click_js(click_target)
elif self.is_editable(strict=True): elif self.is_editable(strict=True):

View File

@ -27,7 +27,7 @@ from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineSettings from PyQt5.QtWebEngineWidgets import QWebEngineSettings
from qutebrowser.utils import log, javascript from qutebrowser.utils import log, javascript, urlutils
from qutebrowser.browser import webelem from qutebrowser.browser import webelem
@ -198,6 +198,13 @@ class WebEngineElement(webelem.AbstractWebElement):
if self.is_text_input() and self.is_editable(): if self.is_text_input() and self.is_editable():
self._js_call('move_cursor_to_end') self._js_call('move_cursor_to_end')
def _requires_user_interaction(self):
baseurl = self._tab.url()
url = self.resolve_url(baseurl)
if url is None:
return True
return url.scheme() not in urlutils.WEBENGINE_SCHEMES
def _click_editable(self, click_target): def _click_editable(self, click_target):
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-58515 # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-58515
ev = QMouseEvent(QMouseEvent.MouseButtonPress, QPoint(0, 0), ev = QMouseEvent(QMouseEvent.MouseButtonPress, QPoint(0, 0),

View File

@ -305,6 +305,9 @@ class WebKitElement(webelem.AbstractWebElement):
if self.is_text_input() and self.is_editable(): if self.is_text_input() and self.is_editable():
self._tab.caret.move_to_end_of_document() self._tab.caret.move_to_end_of_document()
def _requires_user_interaction(self):
return False
def _click_editable(self, click_target): def _click_editable(self, click_target):
ok = self._elem.evaluateJavaScript('this.focus(); true;') ok = self._elem.evaluateJavaScript('this.focus(); true;')
if ok: if ok:

View File

@ -39,6 +39,21 @@ from qutebrowser.browser.network import pac
# https://github.com/qutebrowser/qutebrowser/issues/108 # https://github.com/qutebrowser/qutebrowser/issues/108
# URL schemes supported by QtWebEngine
WEBENGINE_SCHEMES = [
'about',
'data',
'file',
'filesystem',
'ftp',
'http',
'https',
'javascript',
'ws',
'wss',
]
class InvalidUrlError(ValueError): class InvalidUrlError(ValueError):
"""Error raised if a function got an invalid URL. """Error raised if a function got an invalid URL.