Clean up and simplify some logic

This commit is contained in:
Jay Kamat 2018-06-13 15:37:32 -07:00
parent 5d38d28fee
commit e5b6552568
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 18 additions and 24 deletions

View File

@ -40,11 +40,12 @@ class ChildEventFilter(QObject):
_widget: The widget expected to send out childEvents.
"""
def __init__(self, eventfilter, widget, parent=None):
def __init__(self, eventfilter, widget, win_id, parent=None):
super().__init__(parent)
self._filter = eventfilter
assert widget is not None
self._widget = widget
self._win_id = win_id
def eventFilter(self, obj, event):
"""Act on ChildAdded events."""
@ -57,28 +58,21 @@ class ChildEventFilter(QObject):
if qtutils.version_check('5.11', compiled=False, exact=True):
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-68076
try:
# pylint: disable=protected-access
win_id = self._widget._win_id
# pylint: enable=protected-access
passthrough_modes = [usertypes.KeyMode.command,
usertypes.KeyMode.prompt,
usertypes.KeyMode.yesno]
if modeman.instance(win_id).mode not in passthrough_modes:
tabbed_browser = objreg.get('tabbed-browser',
scope='window',
window=win_id)
current_index = tabbed_browser.widget.currentIndex()
try:
widget_index = tabbed_browser.widget.indexOf(
self._widget.parent())
except RuntimeError:
widget_index = -1
if current_index == widget_index:
QTimer.singleShot(0, self._widget.setFocus)
except:
# Something failed, let's just setFocus
QTimer.singleShot(0, self._widget.setFocus)
pass_modes = [usertypes.KeyMode.command,
usertypes.KeyMode.prompt,
usertypes.KeyMode.yesno]
if modeman.instance(self._win_id).mode not in pass_modes:
tabbed_browser = objreg.get('tabbed-browser',
scope='window',
window=self._win_id)
current_index = tabbed_browser.widget.currentIndex()
try:
widget_index = tabbed_browser.widget.indexOf(
self._widget.parent())
except RuntimeError:
widget_index = -1
if current_index == widget_index:
QTimer.singleShot(0, self._widget.setFocus)
elif event.type() == QEvent.ChildRemoved:
child = event.child()

View File

@ -769,7 +769,7 @@ class WebEngineTab(browsertab.AbstractTab):
fp.installEventFilter(self._mouse_event_filter)
self._child_event_filter = mouse.ChildEventFilter(
eventfilter=self._mouse_event_filter, widget=self._widget,
parent=self)
win_id=self.win_id, parent=self)
self._widget.installEventFilter(self._child_event_filter)
@pyqtSlot()