2016-06-13 15:32:19 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""Wrapper over a QWebEngineView."""
|
|
|
|
|
|
|
|
from PyQt5.QtCore import pyqtSlot
|
2016-06-14 09:43:22 +02:00
|
|
|
|
|
|
|
try:
|
2016-06-14 13:39:51 +02:00
|
|
|
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
|
2016-06-14 09:43:22 +02:00
|
|
|
except ImportError:
|
|
|
|
QWebEngineView = None
|
2016-06-14 13:39:51 +02:00
|
|
|
QWebEnginePage = None
|
2016-06-13 15:32:19 +02:00
|
|
|
|
2016-06-14 11:03:34 +02:00
|
|
|
from qutebrowser.browser import tab
|
|
|
|
from qutebrowser.utils import usertypes, qtutils
|
2016-06-13 15:32:19 +02:00
|
|
|
|
|
|
|
|
2016-07-04 11:23:46 +02:00
|
|
|
class WebEngineSearch(tab.AbstractSearch):
|
|
|
|
|
|
|
|
## TODO
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-06-14 18:08:46 +02:00
|
|
|
class WebEngineCaret(tab.AbstractCaret):
|
|
|
|
|
|
|
|
## TODO
|
|
|
|
|
2016-07-04 07:52:49 +02:00
|
|
|
def has_selection(self):
|
2016-07-04 11:33:15 +02:00
|
|
|
return self._widget.hasSelection()
|
2016-07-04 07:52:49 +02:00
|
|
|
|
|
|
|
def selection(self, html=False):
|
|
|
|
if html:
|
|
|
|
raise NotImplementedError
|
2016-07-04 11:33:15 +02:00
|
|
|
return self._widget.selectedText()
|
2016-06-14 18:08:46 +02:00
|
|
|
|
|
|
|
|
2016-06-14 17:32:36 +02:00
|
|
|
class WebEngineScroller(tab.AbstractScroller):
|
|
|
|
|
|
|
|
## TODO
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-06-14 11:03:34 +02:00
|
|
|
class WebEngineHistory(tab.AbstractHistory):
|
|
|
|
|
2016-06-14 13:53:35 +02:00
|
|
|
def current_idx(self):
|
2016-07-04 12:50:15 +02:00
|
|
|
return self._history.currentItemIndex()
|
2016-06-14 13:53:35 +02:00
|
|
|
|
2016-06-14 11:03:34 +02:00
|
|
|
def back(self):
|
2016-07-04 12:50:15 +02:00
|
|
|
self._history.back()
|
2016-06-14 11:03:34 +02:00
|
|
|
|
|
|
|
def forward(self):
|
2016-07-04 12:50:15 +02:00
|
|
|
self._history.forward()
|
2016-06-14 11:03:34 +02:00
|
|
|
|
|
|
|
def can_go_back(self):
|
2016-07-04 12:50:15 +02:00
|
|
|
return self._history.canGoBack()
|
2016-06-14 11:03:34 +02:00
|
|
|
|
|
|
|
def can_go_forward(self):
|
2016-07-04 12:50:15 +02:00
|
|
|
return self._history.canGoForward()
|
2016-06-14 11:03:34 +02:00
|
|
|
|
|
|
|
def serialize(self):
|
2016-07-04 12:50:15 +02:00
|
|
|
return qtutils.serialize(self._history)
|
2016-06-14 11:03:34 +02:00
|
|
|
|
|
|
|
def deserialize(self, data):
|
2016-07-04 12:50:15 +02:00
|
|
|
return qtutils.deserialize(data, self._history)
|
2016-06-14 11:03:34 +02:00
|
|
|
|
|
|
|
def load_items(self, items):
|
|
|
|
# TODO
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2016-06-15 13:02:24 +02:00
|
|
|
class WebEngineZoom(tab.AbstractZoom):
|
|
|
|
|
|
|
|
def _set_factor_internal(self, factor):
|
2016-07-04 11:33:15 +02:00
|
|
|
self._widget.setZoomFactor(factor)
|
2016-06-15 13:02:24 +02:00
|
|
|
|
|
|
|
def factor(self):
|
2016-07-04 11:33:15 +02:00
|
|
|
return self._widget.zoomFactor()
|
2016-06-15 13:02:24 +02:00
|
|
|
|
|
|
|
|
2016-06-14 11:03:34 +02:00
|
|
|
class WebEngineViewTab(tab.AbstractTab):
|
2016-06-13 15:32:19 +02:00
|
|
|
|
|
|
|
def __init__(self, win_id, parent=None):
|
2016-06-14 15:20:40 +02:00
|
|
|
super().__init__(win_id)
|
2016-06-13 15:32:19 +02:00
|
|
|
widget = QWebEngineView()
|
2016-06-14 11:03:34 +02:00
|
|
|
self.history = WebEngineHistory(self)
|
2016-06-14 18:08:46 +02:00
|
|
|
self.scroll = WebEngineScroller()
|
2016-07-04 07:52:49 +02:00
|
|
|
self.caret = WebEngineCaret(win_id=win_id, parent=self)
|
2016-06-15 13:02:24 +02:00
|
|
|
self.zoom = WebEngineZoom(win_id=win_id, parent=self)
|
2016-07-04 11:23:46 +02:00
|
|
|
self.search = WebEngineSearch(parent=self)
|
2016-06-13 15:32:19 +02:00
|
|
|
self._set_widget(widget)
|
|
|
|
self._connect_signals()
|
|
|
|
|
|
|
|
def openurl(self, url):
|
|
|
|
self._widget.load(url)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cur_url(self):
|
|
|
|
return self._widget.url()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def progress(self):
|
|
|
|
return 0 # FIXME:refactor
|
|
|
|
|
|
|
|
@property
|
|
|
|
def load_status(self):
|
|
|
|
return usertypes.LoadStatus.success
|
|
|
|
|
2016-06-14 18:35:28 +02:00
|
|
|
def dump_async(self, callback, *, plain=False):
|
2016-06-14 13:26:30 +02:00
|
|
|
if plain:
|
|
|
|
self._widget.page().toPlainText(callback)
|
|
|
|
else:
|
|
|
|
self._widget.page().toHtml(callback)
|
|
|
|
|
2016-06-14 18:47:26 +02:00
|
|
|
def run_js_async(self, code, callback=None):
|
|
|
|
if callback is None:
|
|
|
|
self._widget.page().runJavaScript(code)
|
|
|
|
else:
|
|
|
|
self._widget.page().runJavaScript(code, callback)
|
|
|
|
|
2016-06-14 13:31:02 +02:00
|
|
|
def shutdown(self):
|
|
|
|
# TODO
|
|
|
|
pass
|
|
|
|
|
2016-06-14 13:39:51 +02:00
|
|
|
def reload(self, *, force=False):
|
|
|
|
if force:
|
|
|
|
action = QWebEnginePage.ReloadAndBypassCache
|
|
|
|
else:
|
|
|
|
action = QWebEnginePage.Reload
|
|
|
|
self._widget.triggerPageAction(action)
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self._widget.stop()
|
|
|
|
|
2016-06-14 13:53:35 +02:00
|
|
|
def title(self):
|
|
|
|
return self._widget.title()
|
|
|
|
|
2016-06-14 15:22:22 +02:00
|
|
|
def icon(self):
|
|
|
|
return self._widget.icon()
|
|
|
|
|
2016-07-04 13:07:18 +02:00
|
|
|
def set_open_target(self, target):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2016-06-13 15:32:19 +02:00
|
|
|
def _connect_signals(self):
|
|
|
|
view = self._widget
|
|
|
|
page = view.page()
|
|
|
|
page.windowCloseRequested.connect(self.window_close_requested)
|
|
|
|
page.linkHovered.connect(self.link_hovered)
|
|
|
|
page.loadProgress.connect(self.load_progress)
|
|
|
|
page.loadStarted.connect(self.load_started)
|
|
|
|
view.titleChanged.connect(self.title_changed)
|
|
|
|
page.loadFinished.connect(self.load_finished)
|
|
|
|
# FIXME:refactor
|
|
|
|
# view.iconChanged.connect(self.icon_changed)
|
2016-06-14 17:32:36 +02:00
|
|
|
# view.scroll.pos_changed.connect(self.scroll.perc_changed)
|
2016-06-13 15:32:19 +02:00
|
|
|
# view.url_text_changed.connect(self.url_text_changed)
|
|
|
|
# view.load_status_changed.connect(self.load_status_changed)
|