parent
e5176e18bd
commit
ba2f4fb1b9
@ -486,10 +486,6 @@ class AbstractTab(QWidget):
|
|||||||
|
|
||||||
We use this to unify QWebView and QWebEngineView.
|
We use this to unify QWebView and QWebEngineView.
|
||||||
|
|
||||||
Class attributes:
|
|
||||||
WIDGET_CLASS: The class of the main widget recieving events.
|
|
||||||
Needs to be overridden by subclasses.
|
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
history: The AbstractHistory for the current tab.
|
history: The AbstractHistory for the current tab.
|
||||||
registry: The ObjectRegistry associated with this tab.
|
registry: The ObjectRegistry associated with this tab.
|
||||||
@ -523,8 +519,6 @@ class AbstractTab(QWidget):
|
|||||||
contents_size_changed = pyqtSignal(QSizeF)
|
contents_size_changed = pyqtSignal(QSizeF)
|
||||||
add_history_item = pyqtSignal(QUrl, QUrl, str) # url, requested url, title
|
add_history_item = pyqtSignal(QUrl, QUrl, str) # url, requested url, title
|
||||||
|
|
||||||
WIDGET_CLASS = None
|
|
||||||
|
|
||||||
def __init__(self, win_id, mode_manager, parent=None):
|
def __init__(self, win_id, mode_manager, parent=None):
|
||||||
self.win_id = win_id
|
self.win_id = win_id
|
||||||
self.tab_id = next(tab_id_gen)
|
self.tab_id = next(tab_id_gen)
|
||||||
@ -553,7 +547,7 @@ class AbstractTab(QWidget):
|
|||||||
self._mode_manager = mode_manager
|
self._mode_manager = mode_manager
|
||||||
self._load_status = usertypes.LoadStatus.none
|
self._load_status = usertypes.LoadStatus.none
|
||||||
self._mouse_event_filter = mouse.MouseEventFilter(
|
self._mouse_event_filter = mouse.MouseEventFilter(
|
||||||
self, widget_class=self.WIDGET_CLASS, parent=self)
|
self, parent=self)
|
||||||
self.backend = None
|
self.backend = None
|
||||||
|
|
||||||
# FIXME:qtwebengine Should this be public api via self.hints?
|
# FIXME:qtwebengine Should this be public api via self.hints?
|
||||||
@ -588,7 +582,7 @@ class AbstractTab(QWidget):
|
|||||||
self._load_status = val
|
self._load_status = val
|
||||||
self.load_status_changed.emit(val.name)
|
self.load_status_changed.emit(val.name)
|
||||||
|
|
||||||
def _event_target(self):
|
def event_target(self):
|
||||||
"""Return the widget events should be sent to."""
|
"""Return the widget events should be sent to."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -603,7 +597,7 @@ class AbstractTab(QWidget):
|
|||||||
if getattr(evt, 'posted', False):
|
if getattr(evt, 'posted', False):
|
||||||
raise AssertionError("Can't re-use an event which was already "
|
raise AssertionError("Can't re-use an event which was already "
|
||||||
"posted!")
|
"posted!")
|
||||||
recipient = self._event_target()
|
recipient = self.event_target()
|
||||||
evt.posted = True
|
evt.posted = True
|
||||||
QApplication.postEvent(recipient, evt)
|
QApplication.postEvent(recipient, evt)
|
||||||
|
|
||||||
|
@ -64,8 +64,6 @@ class MouseEventFilter(QObject):
|
|||||||
"""Handle mouse events on a tab.
|
"""Handle mouse events on a tab.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_widget_class: The class of the main widget getting the events.
|
|
||||||
All other events are ignored.
|
|
||||||
_tab: The browsertab object this filter is installed on.
|
_tab: The browsertab object this filter is installed on.
|
||||||
_handlers: A dict of handler functions for the handled events.
|
_handlers: A dict of handler functions for the handled events.
|
||||||
_ignore_wheel_event: Whether to ignore the next wheelEvent.
|
_ignore_wheel_event: Whether to ignore the next wheelEvent.
|
||||||
@ -73,9 +71,8 @@ class MouseEventFilter(QObject):
|
|||||||
done when the mouse is released.
|
done when the mouse is released.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, tab, *, widget_class, parent=None):
|
def __init__(self, tab, *, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._widget_class = widget_class
|
|
||||||
self._tab = tab
|
self._tab = tab
|
||||||
self._handlers = {
|
self._handlers = {
|
||||||
QEvent.MouseButtonPress: self._handle_mouse_press,
|
QEvent.MouseButtonPress: self._handle_mouse_press,
|
||||||
@ -207,9 +204,7 @@ class MouseEventFilter(QObject):
|
|||||||
evtype = event.type()
|
evtype = event.type()
|
||||||
if evtype not in self._handlers:
|
if evtype not in self._handlers:
|
||||||
return False
|
return False
|
||||||
if not isinstance(obj, self._widget_class):
|
if obj is not self._tab.event_target():
|
||||||
log.mouse.debug("Ignoring {} to {} which is not an instance of "
|
log.mouse.debug("Ignoring {} to {}".format(event.__class__.__name__, obj))
|
||||||
"{}".format(event.__class__.__name__, obj,
|
|
||||||
self._widget_class))
|
|
||||||
return False
|
return False
|
||||||
return self._handlers[evtype](event)
|
return self._handlers[evtype](event)
|
||||||
|
@ -452,8 +452,6 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||||||
|
|
||||||
"""A QtWebEngine tab in the browser."""
|
"""A QtWebEngine tab in the browser."""
|
||||||
|
|
||||||
WIDGET_CLASS = QOpenGLWidget
|
|
||||||
|
|
||||||
def __init__(self, win_id, mode_manager, parent=None):
|
def __init__(self, win_id, mode_manager, parent=None):
|
||||||
super().__init__(win_id=win_id, mode_manager=mode_manager,
|
super().__init__(win_id=win_id, mode_manager=mode_manager,
|
||||||
parent=parent)
|
parent=parent)
|
||||||
@ -654,5 +652,5 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
log.stub('contentsSizeChanged, on Qt < 5.7')
|
log.stub('contentsSizeChanged, on Qt < 5.7')
|
||||||
|
|
||||||
def _event_target(self):
|
def event_target(self):
|
||||||
return self._widget.focusProxy()
|
return self._widget.focusProxy()
|
||||||
|
@ -590,8 +590,6 @@ class WebKitTab(browsertab.AbstractTab):
|
|||||||
|
|
||||||
"""A QtWebKit tab in the browser."""
|
"""A QtWebKit tab in the browser."""
|
||||||
|
|
||||||
WIDGET_CLASS = webview.WebView
|
|
||||||
|
|
||||||
def __init__(self, win_id, mode_manager, parent=None):
|
def __init__(self, win_id, mode_manager, parent=None):
|
||||||
super().__init__(win_id=win_id, mode_manager=mode_manager,
|
super().__init__(win_id=win_id, mode_manager=mode_manager,
|
||||||
parent=parent)
|
parent=parent)
|
||||||
@ -717,5 +715,5 @@ class WebKitTab(browsertab.AbstractTab):
|
|||||||
frame.contentsSizeChanged.connect(self._on_contents_size_changed)
|
frame.contentsSizeChanged.connect(self._on_contents_size_changed)
|
||||||
frame.initialLayoutCompleted.connect(self._on_history_trigger)
|
frame.initialLayoutCompleted.connect(self._on_history_trigger)
|
||||||
|
|
||||||
def _event_target(self):
|
def event_target(self):
|
||||||
return self._widget
|
return self._widget
|
||||||
|
Loading…
Reference in New Issue
Block a user