diff --git a/qutebrowser/browser/tab.py b/qutebrowser/browser/tab.py index bfaef2194..8efe93352 100644 --- a/qutebrowser/browser/tab.py +++ b/qutebrowser/browser/tab.py @@ -25,6 +25,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QPoint from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QWidget, QLayout +from qutebrowser.keyinput import modeman from qutebrowser.config import config from qutebrowser.utils import utils, objreg, usertypes, message @@ -35,6 +36,25 @@ tab_id_gen = itertools.count(0) Backend = usertypes.enum('Backend', ['QtWebKit', 'QtWebEngine']) +def create(win_id, parent=None): + """Get a QtWebKit/QtWebEngine tab object. + + Args: + win_id: The window ID where the tab will be shown. + parent: The Qt parent to set. + """ + # Importing modules here so we don't depend on QtWebEngine without the + # argument and to avoid circular imports. + mode_manager = modeman.instance(win_id) + if objreg.get('args').backend == 'webengine': + from qutebrowser.browser.webengine import webenginetab + tab_class = webenginetab.WebEngineViewTab + else: + from qutebrowser.browser.webkit import webkittab + tab_class = webkittab.WebViewTab + return tab_class(win_id=win_id, mode_manager=mode_manager, parent=parent) + + class WebTabError(Exception): """Base class for various errors.""" diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 47751a47e..1a0313caf 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -381,20 +381,12 @@ class TabbedBrowser(tabwidget.TabWidget): window=window.win_id) return tabbed_browser.tabopen(url, background, explicit) - if objreg.get('args').backend == 'webengine': - # Importing this here so we don't depend on QtWebEngine without the - # argument. - from qutebrowser.browser.webengine import webenginetab - tab_class = webenginetab.WebEngineViewTab - else: - tab_class = webkittab.WebViewTab - - tab = tab_class(self._win_id, modeman.instance(self._win_id), - parent=self) - + tab = tabmod.create(win_id=self._win_id, parent=self) self._connect_tab_signals(tab) + idx = self._get_new_tab_idx(explicit) self.insertTab(idx, tab, "") + if url is not None: tab.openurl(url) if background is None: