2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-05 00:57:47 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "webview.h"
|
|
|
|
#include "webpage.h"
|
|
|
|
#include "mainapplication.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2013-01-17 15:24:30 +01:00
|
|
|
#include "pluginproxy.h"
|
2012-01-21 20:20:48 +01:00
|
|
|
#include "downloadmanager.h"
|
|
|
|
#include "siteinfo.h"
|
2011-10-21 23:26:34 +02:00
|
|
|
#include "searchenginesmanager.h"
|
2012-01-22 11:49:58 +01:00
|
|
|
#include "browsinglibrary.h"
|
2014-02-08 23:01:01 +01:00
|
|
|
#include "bookmarkstools.h"
|
2012-01-24 15:16:33 +01:00
|
|
|
#include "settings.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2012-01-24 23:28:18 +01:00
|
|
|
#include "enhancedmenu.h"
|
2015-01-21 12:38:12 +01:00
|
|
|
#include "locationbar.h"
|
2015-08-30 14:44:00 +02:00
|
|
|
#include "webinspector.h"
|
2015-08-30 15:36:34 +02:00
|
|
|
#include "scripts.h"
|
2015-09-29 22:00:09 +02:00
|
|
|
#include "webhittestresult.h"
|
2015-10-02 17:05:42 +02:00
|
|
|
#include "iconloader.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-05-24 21:26:17 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QDir>
|
2012-03-30 13:43:47 +02:00
|
|
|
#include <QTimer>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QDesktopServices>
|
2015-01-27 11:01:52 +01:00
|
|
|
#include <QWebEngineHistory>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QClipboard>
|
2015-10-01 19:25:17 +02:00
|
|
|
#include <QHostInfo>
|
2015-10-23 11:50:56 +02:00
|
|
|
#include <QMimeData>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-04-05 13:20:21 +02:00
|
|
|
bool WebView::s_forceContextMenuOnMouseRelease = false;
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
WebView::WebView(QWidget* parent)
|
2015-01-27 11:01:52 +01:00
|
|
|
: QWebEngineView(parent)
|
2015-02-08 11:13:12 +01:00
|
|
|
, m_siteIconLoader(0)
|
2015-09-08 11:24:16 +02:00
|
|
|
, m_progress(100)
|
2012-04-03 19:28:12 +02:00
|
|
|
, m_page(0)
|
2015-08-30 14:44:00 +02:00
|
|
|
, m_firstLoad(false)
|
2015-09-29 17:21:49 +02:00
|
|
|
, m_rwhvqt(0)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2015-10-01 19:25:17 +02:00
|
|
|
connect(this, &QWebEngineView::loadStarted, this, &WebView::slotLoadStarted);
|
|
|
|
connect(this, &QWebEngineView::loadProgress, this, &WebView::slotLoadProgress);
|
|
|
|
connect(this, &QWebEngineView::loadFinished, this, &WebView::slotLoadFinished);
|
2015-10-09 21:32:43 +02:00
|
|
|
connect(this, &QWebEngineView::urlChanged, this, &WebView::slotUrlChanged);
|
2015-10-01 19:25:17 +02:00
|
|
|
connect(this, &QWebEngineView::iconUrlChanged, this, &WebView::slotIconUrlChanged);
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2015-09-25 20:44:05 +02:00
|
|
|
m_currentZoomLevel = zoomLevels().indexOf(100);
|
2011-11-05 21:27:01 +01:00
|
|
|
|
2015-10-23 11:50:56 +02:00
|
|
|
setAcceptDrops(true);
|
2012-03-26 17:47:05 +02:00
|
|
|
installEventFilter(this);
|
2013-05-04 15:15:43 +02:00
|
|
|
|
2015-08-30 14:44:00 +02:00
|
|
|
WebInspector::registerView(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-24 21:21:07 +01:00
|
|
|
WebView::~WebView()
|
|
|
|
{
|
2015-08-30 14:44:00 +02:00
|
|
|
WebInspector::unregisterView(this);
|
2014-03-24 21:21:07 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QIcon WebView::icon() const
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2015-10-02 17:05:42 +02:00
|
|
|
if (!m_siteIcon.isNull()) {
|
|
|
|
return m_siteIcon;
|
2012-08-23 16:17:56 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 14:23:10 +01:00
|
|
|
if (url().scheme() == QLatin1String("ftp")) {
|
2014-03-07 18:03:42 +01:00
|
|
|
return IconProvider::standardIcon(QStyle::SP_ComputerIcon);
|
2013-01-29 14:23:10 +01:00
|
|
|
}
|
|
|
|
|
2015-10-02 17:05:42 +02:00
|
|
|
if (url().scheme() == QLatin1String("file")) {
|
|
|
|
return IconProvider::standardIcon(QStyle::SP_DriveHDIcon);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-07 18:03:42 +01:00
|
|
|
return IconProvider::iconForUrl(url());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QString WebView::title() const
|
2011-12-04 16:54:57 +01:00
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QString title = QWebEngineView::title();
|
2011-12-04 16:54:57 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (title.isEmpty()) {
|
|
|
|
title = url().toString(QUrl::RemoveFragment);
|
2011-12-04 16:54:57 +01:00
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (title.isEmpty() || title == QLatin1String("about:blank")) {
|
2014-04-01 18:47:19 +02:00
|
|
|
return tr("Empty Page");
|
2011-12-04 16:54:57 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
return title;
|
2011-12-04 16:54:57 +01:00
|
|
|
}
|
|
|
|
|
2014-04-01 18:47:19 +02:00
|
|
|
bool WebView::isTitleEmpty() const
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
return QWebEngineView::title().isEmpty();
|
2014-04-01 18:47:19 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 19:28:12 +02:00
|
|
|
WebPage* WebView::page() const
|
|
|
|
{
|
|
|
|
return m_page;
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:00:27 +02:00
|
|
|
void WebView::setPage(WebPage *page)
|
2012-01-24 19:58:20 +01:00
|
|
|
{
|
2012-07-06 14:47:34 +02:00
|
|
|
if (m_page == page) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineView::setPage(page);
|
2012-04-03 19:28:12 +02:00
|
|
|
m_page = qobject_cast<WebPage*>(page);
|
2012-01-24 19:58:20 +01:00
|
|
|
|
2012-04-03 20:23:15 +02:00
|
|
|
connect(m_page, SIGNAL(privacyChanged(bool)), this, SIGNAL(privacyChanged(bool)));
|
2012-04-01 10:48:50 +02:00
|
|
|
|
2014-03-29 15:49:49 +01:00
|
|
|
// Set default zoom level
|
|
|
|
zoomReset();
|
|
|
|
|
2014-10-17 18:37:18 +02:00
|
|
|
// Actions needs to be initialized for every QWebPage change
|
|
|
|
initializeActions();
|
|
|
|
|
2012-04-03 19:28:12 +02:00
|
|
|
mApp->plugins()->emitWebPageCreated(m_page);
|
2012-01-24 19:58:20 +01:00
|
|
|
}
|
|
|
|
|
2015-08-30 14:44:00 +02:00
|
|
|
void WebView::load(const QUrl &url)
|
|
|
|
{
|
|
|
|
QWebEngineView::load(url);
|
|
|
|
|
|
|
|
if (!m_firstLoad) {
|
|
|
|
m_firstLoad = true;
|
|
|
|
WebInspector::pushView(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
void WebView::load(const LoadRequest &request)
|
2012-03-10 13:57:50 +01:00
|
|
|
{
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl reqUrl = request.url();
|
2012-03-10 13:57:50 +01:00
|
|
|
|
2015-10-01 19:25:17 +02:00
|
|
|
if (reqUrl.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2014-04-12 22:24:42 +02:00
|
|
|
if (reqUrl.scheme() == QL1S("javascript")) {
|
|
|
|
const QString scriptSource = reqUrl.toString().mid(11);
|
|
|
|
// Is the javascript source percent encoded or not?
|
|
|
|
// Looking for % character in source should work in most cases
|
|
|
|
if (scriptSource.contains(QL1C('%')))
|
2015-01-27 11:01:52 +01:00
|
|
|
page()->runJavaScript(QUrl::fromPercentEncoding(scriptSource.toUtf8()));
|
2014-04-12 22:24:42 +02:00
|
|
|
else
|
2015-01-27 11:01:52 +01:00
|
|
|
page()->runJavaScript(scriptSource);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-10-01 19:25:17 +02:00
|
|
|
if (isUrlValid(reqUrl)) {
|
2014-06-06 23:29:49 +02:00
|
|
|
loadRequest(request);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure to correctly load hosts like localhost (eg. without the dot)
|
|
|
|
if (!reqUrl.isEmpty() &&
|
|
|
|
reqUrl.scheme().isEmpty() &&
|
|
|
|
!reqUrl.path().contains(QL1C(' ')) &&
|
|
|
|
!reqUrl.path().contains(QL1C('.'))
|
|
|
|
) {
|
2015-10-01 19:25:17 +02:00
|
|
|
// FIXME: This is blocking...
|
|
|
|
QHostInfo info = QHostInfo::fromName(reqUrl.path());
|
|
|
|
if (info.error() != QHostInfo::HostNotFound) {
|
|
|
|
LoadRequest req = request;
|
|
|
|
req.setUrl(QUrl(QSL("http://") + reqUrl.path()));
|
|
|
|
loadRequest(req);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-15 16:37:32 +02:00
|
|
|
|
2015-01-21 12:21:54 +01:00
|
|
|
const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(request.urlString());
|
2014-06-06 23:29:49 +02:00
|
|
|
loadRequest(searchRequest);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
bool WebView::isLoading() const
|
2011-04-04 17:03:41 +02:00
|
|
|
{
|
2015-09-08 11:24:16 +02:00
|
|
|
return m_progress < 100;
|
2011-04-04 17:03:41 +02:00
|
|
|
}
|
|
|
|
|
2012-06-27 18:29:00 +02:00
|
|
|
int WebView::loadingProgress() const
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
return m_progress;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-06-27 18:29:00 +02:00
|
|
|
void WebView::fakeLoadingProgress(int progress)
|
|
|
|
{
|
|
|
|
emit loadStarted();
|
|
|
|
emit loadProgress(progress);
|
|
|
|
}
|
|
|
|
|
2014-03-29 15:49:49 +01:00
|
|
|
int WebView::zoomLevel() const
|
|
|
|
{
|
|
|
|
return m_currentZoomLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::setZoomLevel(int level)
|
|
|
|
{
|
|
|
|
m_currentZoomLevel = level;
|
|
|
|
applyZoom();
|
|
|
|
}
|
|
|
|
|
2015-08-29 19:15:33 +02:00
|
|
|
void WebView::restoreHistory(const QByteArray &data)
|
|
|
|
{
|
|
|
|
QDataStream stream(data);
|
|
|
|
stream >> *history();
|
|
|
|
|
|
|
|
// Workaround clearing QWebChannel after restoring history
|
|
|
|
m_page->setupWebChannel();
|
|
|
|
}
|
|
|
|
|
2015-10-02 15:23:59 +02:00
|
|
|
QWidget *WebView::inputWidget() const
|
|
|
|
{
|
2015-10-14 12:11:57 +02:00
|
|
|
return m_rwhvqt;
|
2015-10-02 15:23:59 +02:00
|
|
|
}
|
|
|
|
|
2014-03-29 15:49:49 +01:00
|
|
|
// static
|
2012-01-21 20:20:48 +01:00
|
|
|
bool WebView::isUrlValid(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-12-05 19:52:13 +01:00
|
|
|
// Valid url must have scheme and actually contains something (therefore scheme:// is invalid)
|
2013-12-22 00:44:49 +01:00
|
|
|
return url.isValid() && !url.scheme().isEmpty() && (!url.host().isEmpty() || !url.path().isEmpty() || url.hasQuery());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-29 15:49:49 +01:00
|
|
|
// static
|
|
|
|
QList<int> WebView::zoomLevels()
|
|
|
|
{
|
|
|
|
return QList<int>() << 30 << 40 << 50 << 67 << 80 << 90 << 100
|
|
|
|
<< 110 << 120 << 133 << 150 << 170 << 200
|
|
|
|
<< 220 << 233 << 250 << 270 << 285 << 300;
|
|
|
|
}
|
|
|
|
|
2014-04-05 13:20:21 +02:00
|
|
|
// static
|
|
|
|
bool WebView::forceContextMenuOnMouseRelease()
|
|
|
|
{
|
|
|
|
return s_forceContextMenuOnMouseRelease;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void WebView::setForceContextMenuOnMouseRelease(bool force)
|
|
|
|
{
|
|
|
|
s_forceContextMenuOnMouseRelease = force;
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::addNotification(QWidget* notif)
|
2011-03-03 14:25:02 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
emit showNotification(notif);
|
2011-03-03 14:25:02 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::applyZoom()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2015-09-25 20:44:05 +02:00
|
|
|
setZoomFactor(qreal(zoomLevels().at(m_currentZoomLevel)) / 100.0);
|
2014-03-29 15:49:49 +01:00
|
|
|
|
|
|
|
emit zoomLevelChanged(m_currentZoomLevel);
|
2012-01-21 20:20:48 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::zoomIn()
|
|
|
|
{
|
2015-09-25 20:44:05 +02:00
|
|
|
if (m_currentZoomLevel < zoomLevels().count() - 1) {
|
2014-03-29 15:49:49 +01:00
|
|
|
m_currentZoomLevel++;
|
|
|
|
applyZoom();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::zoomOut()
|
|
|
|
{
|
2014-03-29 15:49:49 +01:00
|
|
|
if (m_currentZoomLevel > 0) {
|
|
|
|
m_currentZoomLevel--;
|
|
|
|
applyZoom();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::zoomReset()
|
|
|
|
{
|
2014-03-29 15:49:49 +01:00
|
|
|
if (m_currentZoomLevel != qzSettings->defaultZoomLevel) {
|
|
|
|
m_currentZoomLevel = qzSettings->defaultZoomLevel;
|
|
|
|
applyZoom();
|
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
void WebView::editUndo()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
triggerPageAction(QWebEnginePage::Undo);
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::editRedo()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
triggerPageAction(QWebEnginePage::Redo);
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::editCut()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
triggerPageAction(QWebEnginePage::Cut);
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::editCopy()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
triggerPageAction(QWebEnginePage::Copy);
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::editPaste()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
triggerPageAction(QWebEnginePage::Paste);
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::editSelectAll()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
triggerPageAction(QWebEnginePage::SelectAll);
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::editDelete()
|
|
|
|
{
|
|
|
|
QKeyEvent ev(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier);
|
|
|
|
QApplication::sendEvent(this, &ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::reloadBypassCache()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
triggerPageAction(QWebEnginePage::ReloadAndBypassCache);
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::back()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = page()->history();
|
2012-01-09 12:39:34 +01:00
|
|
|
|
2012-04-04 13:21:53 +02:00
|
|
|
if (history->canGoBack()) {
|
|
|
|
history->back();
|
2011-10-21 23:26:34 +02:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
emit urlChanged(url());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::forward()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = page()->history();
|
2012-01-21 20:20:48 +01:00
|
|
|
|
2012-04-04 13:21:53 +02:00
|
|
|
if (history->canGoForward()) {
|
|
|
|
history->forward();
|
2012-01-21 20:20:48 +01:00
|
|
|
|
|
|
|
emit urlChanged(url());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::slotLoadStarted()
|
2011-07-21 17:16:53 +02:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
m_progress = 0;
|
2011-07-21 17:16:53 +02:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::slotLoadProgress(int progress)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
m_progress = progress;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2015-10-01 19:25:17 +02:00
|
|
|
void WebView::slotLoadFinished(bool ok)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
m_progress = 100;
|
|
|
|
|
2015-10-01 19:25:17 +02:00
|
|
|
if (ok)
|
|
|
|
mApp->history()->addHistoryEntry(this);
|
2012-01-21 20:20:48 +01:00
|
|
|
}
|
|
|
|
|
2015-10-09 21:32:43 +02:00
|
|
|
void WebView::slotUrlChanged(const QUrl &url)
|
|
|
|
{
|
|
|
|
Q_UNUSED(url)
|
|
|
|
|
|
|
|
// Don't save blank page / speed dial in tab history
|
|
|
|
if (!history()->canGoForward() && history()->backItems(1).size() == 1) {
|
|
|
|
const QString s = LocationBar::convertUrlToText(history()->backItem().url());
|
|
|
|
if (s.isEmpty())
|
|
|
|
history()->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-08 11:13:12 +01:00
|
|
|
void WebView::slotIconUrlChanged(const QUrl &url)
|
2012-01-21 20:20:48 +01:00
|
|
|
{
|
2015-10-05 22:08:31 +02:00
|
|
|
m_siteIcon = QIcon();
|
2015-02-08 11:13:12 +01:00
|
|
|
delete m_siteIconLoader;
|
|
|
|
m_siteIconLoader = new IconLoader(url, this);
|
|
|
|
|
|
|
|
connect(m_siteIconLoader, &IconLoader::iconLoaded, [this, url](const QIcon &icon) {
|
|
|
|
m_siteIcon = icon;
|
|
|
|
emit iconChanged();
|
2014-03-07 18:03:42 +01:00
|
|
|
IconProvider::instance()->saveIcon(this);
|
2015-02-08 11:13:12 +01:00
|
|
|
});
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::openUrlInNewWindow()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2014-03-10 00:47:07 +01:00
|
|
|
mApp->createWindow(Qz::BW_NewWindow, action->data().toUrl());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::sendLinkByMail()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl mailUrl = QUrl::fromEncoded("mailto:%20?body=" + QUrl::toPercentEncoding(action->data().toUrl().toEncoded()));
|
2012-03-31 22:16:20 +02:00
|
|
|
QDesktopServices::openUrl(mailUrl);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-31 22:16:20 +02:00
|
|
|
void WebView::sendPageByMail()
|
|
|
|
{
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl mailUrl = QUrl::fromEncoded("mailto:%20?body=" + QUrl::toPercentEncoding(url().toEncoded()) + "&subject=" + QUrl::toPercentEncoding(title()));
|
2012-03-31 22:16:20 +02:00
|
|
|
QDesktopServices::openUrl(mailUrl);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void WebView::copyLinkToClipboard()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2013-02-23 17:21:33 +01:00
|
|
|
QApplication::clipboard()->setText(action->data().toUrl().toEncoded());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 19:35:02 +02:00
|
|
|
void WebView::downloadLinkToDisk()
|
2013-11-09 13:32:03 +01:00
|
|
|
{
|
2015-10-04 19:35:02 +02:00
|
|
|
triggerPageAction(QWebEnginePage::DownloadLinkToDisk);
|
|
|
|
}
|
2014-10-13 16:59:37 +02:00
|
|
|
|
2015-10-04 19:35:02 +02:00
|
|
|
void WebView::downloadImageToDisk()
|
|
|
|
{
|
|
|
|
triggerPageAction(QWebEnginePage::DownloadImageToDisk);
|
2013-11-09 13:32:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-04 19:35:02 +02:00
|
|
|
void WebView::downloadMediaToDisk()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2015-10-04 19:35:02 +02:00
|
|
|
triggerPageAction(QWebEnginePage::DownloadMediaToDisk);
|
|
|
|
}
|
2012-03-23 13:58:31 +01:00
|
|
|
|
2015-10-04 19:35:02 +02:00
|
|
|
void WebView::openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlags position)
|
|
|
|
{
|
2015-10-06 09:46:23 +02:00
|
|
|
loadInNewTab(url, position);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::openActionUrl()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2012-01-21 20:20:48 +01:00
|
|
|
load(action->data().toUrl());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-24 21:26:17 +02:00
|
|
|
void WebView::showSource()
|
2011-07-19 22:04:08 +02:00
|
|
|
{
|
2015-05-24 21:26:17 +02:00
|
|
|
// view-source: doesn't work on itself and custom schemes
|
2015-08-28 17:43:44 +02:00
|
|
|
if (url().scheme() == QL1S("view-source") || url().scheme() == QL1S("qupzilla") || url().scheme() == QL1S("qrc")) {
|
2015-05-24 21:26:17 +02:00
|
|
|
page()->toHtml([](const QString &html) {
|
|
|
|
std::cout << html.toLocal8Bit().constData() << std::endl;
|
|
|
|
});
|
|
|
|
return;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2015-05-24 21:26:17 +02:00
|
|
|
QUrl u;
|
|
|
|
u.setScheme(QSL("view-source"));
|
|
|
|
u.setPath(url().toString());
|
|
|
|
openUrlInNewTab(u, Qz::NT_SelectedTab);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showSiteInfo()
|
|
|
|
{
|
2015-09-25 22:31:04 +02:00
|
|
|
SiteInfo* s = new SiteInfo(this);
|
2012-01-21 20:20:48 +01:00
|
|
|
s->show();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void WebView::searchSelectedText()
|
|
|
|
{
|
2012-02-24 21:03:44 +01:00
|
|
|
SearchEngine engine = mApp->searchEnginesManager()->activeEngine();
|
|
|
|
if (QAction* act = qobject_cast<QAction*>(sender())) {
|
|
|
|
if (act->data().isValid()) {
|
2012-12-20 14:45:35 +01:00
|
|
|
engine = act->data().value<SearchEngine>();
|
2012-02-24 21:03:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 09:46:23 +02:00
|
|
|
const LoadRequest req = mApp->searchEnginesManager()->searchResult(engine, selectedText());
|
2014-03-19 21:27:43 +01:00
|
|
|
loadInNewTab(req, Qz::NT_SelectedTab);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2012-06-01 20:25:37 +02:00
|
|
|
void WebView::searchSelectedTextInBackgroundTab()
|
|
|
|
{
|
|
|
|
SearchEngine engine = mApp->searchEnginesManager()->activeEngine();
|
|
|
|
if (QAction* act = qobject_cast<QAction*>(sender())) {
|
|
|
|
if (act->data().isValid()) {
|
2012-12-20 14:45:35 +01:00
|
|
|
engine = act->data().value<SearchEngine>();
|
2012-06-01 20:25:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 09:46:23 +02:00
|
|
|
const LoadRequest req = mApp->searchEnginesManager()->searchResult(engine, selectedText());
|
2014-03-19 21:27:43 +01:00
|
|
|
loadInNewTab(req, Qz::NT_NotSelectedTab);
|
2012-06-01 20:25:37 +02:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void WebView::bookmarkLink()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
if (action->data().isNull()) {
|
2014-02-08 23:01:01 +01:00
|
|
|
BookmarksTools::addBookmarkDialog(this, url(), title());
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-01-26 11:21:53 +01:00
|
|
|
const QVariantList bData = action->data().value<QVariantList>();
|
|
|
|
const QString bookmarkTitle = bData.at(1).toString().isEmpty() ? title() : bData.at(1).toString();
|
|
|
|
|
2014-02-08 23:01:01 +01:00
|
|
|
BookmarksTools::addBookmarkDialog(this, bData.at(0).toUrl(), bookmarkTitle);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
void WebView::openUrlInSelectedTab()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2014-02-12 13:48:34 +01:00
|
|
|
openUrlInNewTab(action->data().toUrl(), Qz::NT_CleanSelectedTab);
|
2012-01-22 15:15:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::openUrlInBackgroundTab()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2014-02-12 13:48:34 +01:00
|
|
|
openUrlInNewTab(action->data().toUrl(), Qz::NT_CleanNotSelectedTab);
|
2012-01-22 15:15:43 +01:00
|
|
|
}
|
2012-01-24 15:16:33 +01:00
|
|
|
}
|
2012-01-22 15:15:43 +01:00
|
|
|
|
2012-07-03 11:28:14 +02:00
|
|
|
void WebView::userDefinedOpenUrlInNewTab(const QUrl &url, bool invert)
|
2012-06-26 23:39:23 +02:00
|
|
|
{
|
2014-02-12 13:48:34 +01:00
|
|
|
Qz::NewTabPositionFlags position = qzSettings->newTabPosition;
|
2012-07-03 11:28:14 +02:00
|
|
|
if (invert) {
|
2014-02-12 13:48:34 +01:00
|
|
|
if (position & Qz::NT_SelectedTab) {
|
|
|
|
position &= ~Qz::NT_SelectedTab;
|
|
|
|
position |= Qz::NT_NotSelectedTab;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
position &= ~Qz::NT_NotSelectedTab;
|
|
|
|
position |= Qz::NT_SelectedTab;
|
|
|
|
}
|
2012-07-03 11:28:14 +02:00
|
|
|
}
|
|
|
|
|
2013-01-26 12:04:30 +01:00
|
|
|
QUrl actionUrl;
|
|
|
|
|
|
|
|
if (!url.isEmpty()) {
|
|
|
|
actionUrl = url;
|
2012-06-26 23:39:23 +02:00
|
|
|
}
|
2013-01-26 12:04:30 +01:00
|
|
|
else if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
actionUrl = action->data().toUrl();
|
2012-06-26 23:39:23 +02:00
|
|
|
}
|
2013-01-26 12:04:30 +01:00
|
|
|
|
|
|
|
openUrlInNewTab(actionUrl, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::userDefinedOpenUrlInBgTab(const QUrl &url)
|
|
|
|
{
|
|
|
|
QUrl actionUrl;
|
|
|
|
|
|
|
|
if (!url.isEmpty()) {
|
|
|
|
actionUrl = url;
|
|
|
|
}
|
|
|
|
else if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
actionUrl = action->data().toUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
userDefinedOpenUrlInNewTab(actionUrl, true);
|
2012-06-26 23:39:23 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 11:50:56 +02:00
|
|
|
void WebView::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasUrls()) {
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebEngineView::dragEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::dropEvent(QDropEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasUrls()) {
|
|
|
|
const QList<QUrl> &urls = event->mimeData()->urls();
|
|
|
|
load(urls.at(0));
|
|
|
|
for (int i = 1; i < urls.size(); ++i) {
|
|
|
|
openUrlInNewTab(urls.at(i), Qz::NT_CleanSelectedTab);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebEngineView::dropEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void WebView::createContextMenu(QMenu *menu, const WebHitTestResult &hitTest)
|
2012-01-22 11:49:58 +01:00
|
|
|
{
|
2013-04-28 17:48:51 +02:00
|
|
|
// cppcheck-suppress variableScope
|
2013-02-05 20:43:53 +01:00
|
|
|
int spellCheckActionCount = 0;
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
if (!hitTest.linkUrl().isEmpty() && hitTest.linkUrl().scheme() != QL1S("javascript")) {
|
2012-01-22 11:49:58 +01:00
|
|
|
createLinkContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hitTest.imageUrl().isEmpty()) {
|
|
|
|
createImageContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
2015-09-30 15:26:52 +02:00
|
|
|
if (!hitTest.mediaUrl().isEmpty()) {
|
2012-01-22 11:49:58 +01:00
|
|
|
createMediaContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
2012-02-20 18:28:09 +01:00
|
|
|
if (hitTest.isContentEditable()) {
|
2013-04-28 17:48:51 +02:00
|
|
|
// This only checks if the menu is empty (only spellchecker actions added)
|
2013-02-05 20:43:53 +01:00
|
|
|
if (menu->actions().count() == spellCheckActionCount) {
|
2015-09-29 23:15:46 +02:00
|
|
|
menu->addAction(pageAction(QWebEnginePage::Undo));
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Redo));
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Cut));
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Copy));
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Paste));
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
if (hitTest.tagName() == QL1S("input")) {
|
2015-09-30 14:57:08 +02:00
|
|
|
QAction *act = menu->addAction(QString());
|
|
|
|
act->setVisible(false);
|
|
|
|
checkForForm(act, hitTest.pos());
|
2012-03-08 17:17:41 +01:00
|
|
|
}
|
2012-03-08 13:05:57 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
if (!selectedText().isEmpty()) {
|
|
|
|
createSelectedTextContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
2012-01-23 17:30:34 +01:00
|
|
|
if (menu->isEmpty()) {
|
2015-09-29 23:15:46 +02:00
|
|
|
createPageContextMenu(menu);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2012-02-19 17:50:02 +01:00
|
|
|
menu->addSeparator();
|
|
|
|
mApp->plugins()->populateWebViewMenu(menu, this, hitTest);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void WebView::createPageContextMenu(QMenu* menu)
|
2012-01-22 11:49:58 +01:00
|
|
|
{
|
|
|
|
QAction* action = menu->addAction(tr("&Back"), this, SLOT(back()));
|
2014-03-07 18:03:42 +01:00
|
|
|
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
2012-04-04 13:21:53 +02:00
|
|
|
action->setEnabled(history()->canGoBack());
|
2012-01-22 11:49:58 +01:00
|
|
|
|
|
|
|
action = menu->addAction(tr("&Forward"), this, SLOT(forward()));
|
2014-03-07 18:03:42 +01:00
|
|
|
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowForward));
|
2012-04-04 13:21:53 +02:00
|
|
|
action->setEnabled(history()->canGoForward());
|
2012-01-22 11:49:58 +01:00
|
|
|
|
2014-06-05 20:15:58 +02:00
|
|
|
// Special menu for Speed Dial page
|
|
|
|
if (url().toString() == QL1S("qupzilla:speeddial")) {
|
2014-01-04 22:37:18 +01:00
|
|
|
menu->addSeparator();
|
2014-06-05 20:15:58 +02:00
|
|
|
menu->addAction(QIcon::fromTheme("list-add"), tr("&Add New Page"), this, SLOT(addSpeedDial()));
|
|
|
|
menu->addAction(IconProvider::settingsIcon(), tr("&Configure Speed Dial"), this, SLOT(configureSpeedDial()));
|
2014-05-30 15:12:36 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon::fromTheme(QSL("view-refresh")), tr("Reload All Dials"), this, SLOT(reloadAllSpeedDials()));
|
2014-06-05 20:15:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-01-04 22:37:18 +01:00
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
menu->addAction(pageAction(QWebEnginePage::Reload));
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Stop));
|
2014-06-05 20:15:58 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon::fromTheme("bookmark-new"), tr("Book&mark page"), this, SLOT(bookmarkLink()));
|
|
|
|
menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy page link"), this, SLOT(copyLinkToClipboard()))->setData(url());
|
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send page link..."), this, SLOT(sendPageByMail()));
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &all"), this, SLOT(editSelectAll()));
|
|
|
|
menu->addSeparator();
|
2014-01-04 22:37:18 +01:00
|
|
|
|
2014-06-05 20:15:58 +02:00
|
|
|
if (url().scheme() == QLatin1String("http") || url().scheme() == QLatin1String("https")) {
|
|
|
|
const QUrl w3url = QUrl::fromEncoded("http://validator.w3.org/check?uri=" + QUrl::toPercentEncoding(url().toEncoded()));
|
|
|
|
menu->addAction(QIcon(":icons/sites/w3.png"), tr("Validate page"), this, SLOT(openUrlInSelectedTab()))->setData(w3url);
|
2013-12-24 14:55:43 +01:00
|
|
|
|
2014-06-05 20:15:58 +02:00
|
|
|
QByteArray langCode = mApp->currentLanguage().left(2).toUtf8();
|
|
|
|
const QUrl gturl = QUrl::fromEncoded("http://translate.google.com/translate?sl=auto&tl=" + langCode + "&u=" + QUrl::toPercentEncoding(url().toEncoded()));
|
|
|
|
menu->addAction(QIcon(":icons/sites/translate.png"), tr("Translate page"), this, SLOT(openUrlInSelectedTab()))->setData(gturl);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2014-06-05 20:15:58 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon::fromTheme("text-html"), tr("Show so&urce code"), this, SLOT(showSource()));
|
2015-10-14 12:50:30 +02:00
|
|
|
|
|
|
|
if (SiteInfo::canShowSiteInfo(url()))
|
|
|
|
menu->addAction(QIcon::fromTheme("dialog-information"), tr("Show info ab&out site"), this, SLOT(showSiteInfo()));
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void WebView::createLinkContextMenu(QMenu* menu, const WebHitTestResult &hitTest)
|
2012-01-22 11:49:58 +01:00
|
|
|
{
|
|
|
|
menu->addSeparator();
|
2014-03-24 16:08:33 +01:00
|
|
|
Action* act = new Action(IconProvider::newTabIcon(), tr("Open link in new &tab"));
|
2013-01-26 12:04:30 +01:00
|
|
|
act->setData(hitTest.linkUrl());
|
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(userDefinedOpenUrlInNewTab()));
|
2014-02-09 01:14:00 +01:00
|
|
|
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(userDefinedOpenUrlInBgTab()));
|
2013-01-26 12:04:30 +01:00
|
|
|
menu->addAction(act);
|
2014-03-24 16:08:33 +01:00
|
|
|
menu->addAction(IconProvider::newWindowIcon(), tr("Open link in new &window"), this, SLOT(openUrlInNewWindow()))->setData(hitTest.linkUrl());
|
|
|
|
menu->addAction(IconProvider::privateBrowsingIcon(), tr("Open link in &private window"), mApp, SLOT(startPrivateBrowsing()))->setData(hitTest.linkUrl());
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addSeparator();
|
2014-01-26 11:21:53 +01:00
|
|
|
|
|
|
|
QVariantList bData;
|
|
|
|
bData << hitTest.linkUrl() << hitTest.linkTitle();
|
2014-03-24 16:08:33 +01:00
|
|
|
menu->addAction(QIcon::fromTheme("bookmark-new"), tr("B&ookmark link"), this, SLOT(bookmarkLink()))->setData(bData);
|
2014-01-26 11:21:53 +01:00
|
|
|
|
2015-10-04 19:35:02 +02:00
|
|
|
menu->addAction(QIcon::fromTheme("document-save"), tr("&Save link as..."), this, SLOT(downloadLinkToDisk()));
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send link..."), this, SLOT(sendLinkByMail()))->setData(hitTest.linkUrl());
|
|
|
|
menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy link address"), this, SLOT(copyLinkToClipboard()))->setData(hitTest.linkUrl());
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
if (!selectedText().isEmpty()) {
|
2015-01-27 11:01:52 +01:00
|
|
|
pageAction(QWebEnginePage::Copy)->setIcon(QIcon::fromTheme("edit-copy"));
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Copy));
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void WebView::createImageContextMenu(QMenu* menu, const WebHitTestResult &hitTest)
|
2012-01-22 11:49:58 +01:00
|
|
|
{
|
|
|
|
menu->addSeparator();
|
2012-01-24 23:28:18 +01:00
|
|
|
Action* act = new Action(tr("Show i&mage"));
|
|
|
|
act->setData(hitTest.imageUrl());
|
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(openActionUrl()));
|
2014-02-09 01:14:00 +01:00
|
|
|
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(userDefinedOpenUrlInNewTab()));
|
2012-01-24 23:28:18 +01:00
|
|
|
menu->addAction(act);
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addAction(QIcon::fromTheme("edit-copy"), tr("Copy image ad&dress"), this, SLOT(copyLinkToClipboard()))->setData(hitTest.imageUrl());
|
|
|
|
menu->addSeparator();
|
2015-10-04 19:35:02 +02:00
|
|
|
menu->addAction(QIcon::fromTheme("document-save"), tr("&Save image as..."), this, SLOT(downloadImageToDisk()));
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send image..."), this, SLOT(sendLinkByMail()))->setData(hitTest.imageUrl());
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
if (!selectedText().isEmpty()) {
|
2015-01-27 11:01:52 +01:00
|
|
|
pageAction(QWebEnginePage::Copy)->setIcon(QIcon::fromTheme("edit-copy"));
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Copy));
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void WebView::createSelectedTextContextMenu(QMenu* menu, const WebHitTestResult &hitTest)
|
2012-01-22 11:49:58 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(hitTest)
|
|
|
|
|
|
|
|
QString selectedText = page()->selectedText();
|
|
|
|
|
|
|
|
menu->addSeparator();
|
2015-01-27 11:01:52 +01:00
|
|
|
if (!menu->actions().contains(pageAction(QWebEnginePage::Copy))) {
|
|
|
|
menu->addAction(pageAction(QWebEnginePage::Copy));
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send text..."), this, SLOT(sendLinkByMail()))->setData(selectedText);
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2013-12-26 21:26:30 +01:00
|
|
|
QString langCode = mApp->currentLanguage().left(2).toUtf8();
|
2014-05-09 18:25:17 +02:00
|
|
|
QUrl googleTranslateUrl = QUrl(QString("https://translate.google.com/#auto/%1/%2").arg(langCode, selectedText));
|
2012-06-28 17:16:45 +02:00
|
|
|
Action* gtwact = new Action(QIcon(":icons/sites/translate.png"), tr("Google Translate"));
|
2012-02-25 12:34:16 +01:00
|
|
|
gtwact->setData(googleTranslateUrl);
|
|
|
|
connect(gtwact, SIGNAL(triggered()), this, SLOT(openUrlInSelectedTab()));
|
2014-02-09 01:14:00 +01:00
|
|
|
connect(gtwact, SIGNAL(ctrlTriggered()), this, SLOT(openUrlInBackgroundTab()));
|
2012-02-24 20:56:19 +01:00
|
|
|
menu->addAction(gtwact);
|
2013-12-26 21:26:30 +01:00
|
|
|
|
2012-02-24 20:56:19 +01:00
|
|
|
Action* dictact = new Action(QIcon::fromTheme("accessories-dictionary"), tr("Dictionary"));
|
2012-09-02 11:42:41 +02:00
|
|
|
dictact->setData(QUrl("http://" + (!langCode.isEmpty() ? langCode + "." : langCode) + "wiktionary.org/wiki/Special:Search?search=" + selectedText));
|
2012-02-25 12:34:16 +01:00
|
|
|
connect(dictact, SIGNAL(triggered()), this, SLOT(openUrlInSelectedTab()));
|
2014-02-09 01:14:00 +01:00
|
|
|
connect(dictact, SIGNAL(ctrlTriggered()), this, SLOT(openUrlInBackgroundTab()));
|
2012-02-24 20:56:19 +01:00
|
|
|
menu->addAction(dictact);
|
2012-01-22 11:49:58 +01:00
|
|
|
|
2012-04-14 10:54:03 +02:00
|
|
|
// #379: Remove newlines
|
2012-09-04 12:42:45 +02:00
|
|
|
QString selectedString = selectedText.trimmed().remove(QLatin1Char('\n'));
|
|
|
|
if (!selectedString.contains(QLatin1Char('.'))) {
|
2012-01-22 11:49:58 +01:00
|
|
|
// Try to add .com
|
2012-09-04 12:42:45 +02:00
|
|
|
selectedString.append(QLatin1String(".com"));
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
QUrl guessedUrl = QUrl::fromUserInput(selectedString);
|
|
|
|
|
|
|
|
if (isUrlValid(guessedUrl)) {
|
2012-02-24 20:55:35 +01:00
|
|
|
Action* act = new Action(QIcon::fromTheme("document-open-remote"), tr("Go to &web address"));
|
2012-02-01 15:37:45 +01:00
|
|
|
act->setData(guessedUrl);
|
2012-06-01 20:25:37 +02:00
|
|
|
|
2012-02-01 15:37:45 +01:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(openActionUrl()));
|
2014-02-09 01:14:00 +01:00
|
|
|
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(userDefinedOpenUrlInNewTab()));
|
2012-02-01 15:37:45 +01:00
|
|
|
menu->addAction(act);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2012-02-24 20:55:35 +01:00
|
|
|
menu->addSeparator();
|
2012-01-22 11:49:58 +01:00
|
|
|
selectedText.truncate(20);
|
2013-12-28 15:26:56 +01:00
|
|
|
// KDE is displaying newlines in menu actions ... weird -,-
|
|
|
|
selectedText.replace(QLatin1Char('\n'), QLatin1Char(' ')).replace(QLatin1Char('\t'), QLatin1Char(' '));
|
2012-01-22 11:49:58 +01:00
|
|
|
|
|
|
|
SearchEngine engine = mApp->searchEnginesManager()->activeEngine();
|
2012-06-01 20:25:37 +02:00
|
|
|
Action* act = new Action(engine.icon, tr("Search \"%1 ..\" with %2").arg(selectedText, engine.name));
|
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(searchSelectedText()));
|
2014-02-09 01:14:00 +01:00
|
|
|
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(searchSelectedTextInBackgroundTab()));
|
2012-06-01 20:25:37 +02:00
|
|
|
menu->addAction(act);
|
|
|
|
|
|
|
|
// Search with ...
|
|
|
|
Menu* swMenu = new Menu(tr("Search with..."), menu);
|
2014-02-10 21:34:46 +01:00
|
|
|
swMenu->setCloseOnMiddleClick(true);
|
2012-02-24 21:13:06 +01:00
|
|
|
SearchEnginesManager* searchManager = mApp->searchEnginesManager();
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const SearchEngine &en, searchManager->allEngines()) {
|
2012-06-01 20:25:37 +02:00
|
|
|
Action* act = new Action(en.icon, en.name);
|
2013-02-05 22:33:54 +01:00
|
|
|
act->setData(QVariant::fromValue(en));
|
2012-06-01 20:25:37 +02:00
|
|
|
|
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(searchSelectedText()));
|
2014-02-09 01:14:00 +01:00
|
|
|
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(searchSelectedTextInBackgroundTab()));
|
2012-06-01 20:25:37 +02:00
|
|
|
swMenu->addAction(act);
|
2012-02-24 20:54:05 +01:00
|
|
|
}
|
2012-06-01 20:25:37 +02:00
|
|
|
|
2012-02-24 20:54:05 +01:00
|
|
|
menu->addMenu(swMenu);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 15:26:52 +02:00
|
|
|
void WebView::createMediaContextMenu(QMenu *menu, const WebHitTestResult &hitTest)
|
|
|
|
{
|
|
|
|
m_clickedPos = hitTest.pos();
|
|
|
|
bool paused = hitTest.mediaPaused();
|
|
|
|
bool muted = hitTest.mediaMuted();
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(paused ? tr("&Play") : tr("&Pause"), this, SLOT(toggleMediaPause()))->setIcon(QIcon::fromTheme(paused ? "media-playback-start" : "media-playback-pause"));
|
|
|
|
menu->addAction(muted ? tr("Un&mute") : tr("&Mute"), this, SLOT(toggleMediaMute()))->setIcon(QIcon::fromTheme(muted ? "audio-volume-muted" : "audio-volume-high"));
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy Media Address"), this, SLOT(copyLinkToClipboard()))->setData(hitTest.mediaUrl());
|
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("&Send Media Address"), this, SLOT(sendLinkByMail()))->setData(hitTest.mediaUrl());
|
2015-10-04 19:35:02 +02:00
|
|
|
menu->addAction(QIcon::fromTheme("document-save"), tr("Save Media To &Disk"), this, SLOT(downloadMediaToDisk()));
|
2015-09-30 15:26:52 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:57:08 +02:00
|
|
|
void WebView::checkForForm(QAction *action, const QPoint &pos)
|
2015-09-29 23:15:46 +02:00
|
|
|
{
|
2015-09-30 15:05:28 +02:00
|
|
|
m_clickedPos = pos;
|
2015-09-30 14:57:08 +02:00
|
|
|
QPointer<QAction> act = action;
|
2015-09-29 23:15:46 +02:00
|
|
|
|
2015-09-30 14:57:08 +02:00
|
|
|
page()->runJavaScript(Scripts::getFormData(pos), [this, act](const QVariant &res) {
|
2015-09-30 15:05:28 +02:00
|
|
|
const QVariantMap &map = res.toMap();
|
|
|
|
if (!act || map.isEmpty())
|
2015-09-30 14:57:08 +02:00
|
|
|
return;
|
2015-09-29 23:15:46 +02:00
|
|
|
|
2015-09-30 15:05:28 +02:00
|
|
|
const QUrl url = map.value(QSL("action")).toUrl();
|
|
|
|
const QString method = map.value(QSL("method")).toString();
|
2015-09-29 23:15:46 +02:00
|
|
|
|
2015-09-30 14:57:08 +02:00
|
|
|
if (!url.isEmpty() && (method == QL1S("get") || method == QL1S("post"))) {
|
|
|
|
act->setVisible(true);
|
|
|
|
act->setIcon(QIcon(QSL(":icons/menu/search-icon.png")));
|
|
|
|
act->setText(tr("Create Search Engine"));
|
|
|
|
connect(act, &QAction::triggered, this, &WebView::createSearchEngine);
|
|
|
|
}
|
|
|
|
});
|
2015-09-29 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::createSearchEngine()
|
|
|
|
{
|
2015-09-30 15:05:28 +02:00
|
|
|
page()->runJavaScript(Scripts::getFormData(m_clickedPos), [this](const QVariant &res) {
|
|
|
|
mApp->searchEnginesManager()->addEngineFromForm(res.toMap(), this);
|
|
|
|
});
|
2015-09-29 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2014-01-04 22:37:18 +01:00
|
|
|
void WebView::addSpeedDial()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
page()->runJavaScript("addSpeedDial()");
|
2014-01-04 22:37:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::configureSpeedDial()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
page()->runJavaScript("configureSpeedDial()");
|
2014-01-04 22:37:18 +01:00
|
|
|
}
|
|
|
|
|
2014-05-30 15:12:36 +02:00
|
|
|
void WebView::reloadAllSpeedDials()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
page()->runJavaScript("reloadAll()");
|
2014-05-30 15:12:36 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 15:26:52 +02:00
|
|
|
void WebView::toggleMediaPause()
|
|
|
|
{
|
|
|
|
page()->runJavaScript(Scripts::toggleMediaPause(m_clickedPos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::toggleMediaMute()
|
|
|
|
{
|
|
|
|
page()->runJavaScript(Scripts::toggleMediaMute(m_clickedPos));
|
|
|
|
}
|
|
|
|
|
2014-10-17 18:37:18 +02:00
|
|
|
void WebView::initializeActions()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* undoAction = pageAction(QWebEnginePage::Undo);
|
2014-10-17 18:37:18 +02:00
|
|
|
undoAction->setText(tr("&Undo"));
|
|
|
|
undoAction->setShortcut(QKeySequence("Ctrl+Z"));
|
2014-10-18 16:33:21 +02:00
|
|
|
undoAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2014-10-17 18:37:18 +02:00
|
|
|
undoAction->setIcon(QIcon::fromTheme(QSL("edit-undo")));
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* redoAction = pageAction(QWebEnginePage::Redo);
|
2014-10-17 18:37:18 +02:00
|
|
|
redoAction->setText(tr("&Redo"));
|
|
|
|
redoAction->setShortcut(QKeySequence("Ctrl+Shift+Z"));
|
2014-10-18 16:33:21 +02:00
|
|
|
redoAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2014-10-17 18:37:18 +02:00
|
|
|
redoAction->setIcon(QIcon::fromTheme(QSL("edit-redo")));
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* cutAction = pageAction(QWebEnginePage::Cut);
|
2014-10-17 18:37:18 +02:00
|
|
|
cutAction->setText(tr("&Cut"));
|
|
|
|
cutAction->setShortcut(QKeySequence("Ctrl+X"));
|
2014-10-18 16:33:21 +02:00
|
|
|
cutAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2014-10-17 18:37:18 +02:00
|
|
|
cutAction->setIcon(QIcon::fromTheme(QSL("edit-cut")));
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* copyAction = pageAction(QWebEnginePage::Copy);
|
2014-10-17 18:37:18 +02:00
|
|
|
copyAction->setText(tr("&Copy"));
|
|
|
|
copyAction->setShortcut(QKeySequence("Ctrl+C"));
|
2014-10-18 16:33:21 +02:00
|
|
|
copyAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2014-10-17 18:37:18 +02:00
|
|
|
copyAction->setIcon(QIcon::fromTheme(QSL("edit-copy")));
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* pasteAction = pageAction(QWebEnginePage::Paste);
|
2014-10-17 18:37:18 +02:00
|
|
|
pasteAction->setText(tr("&Paste"));
|
|
|
|
pasteAction->setShortcut(QKeySequence("Ctrl+V"));
|
2014-10-18 16:33:21 +02:00
|
|
|
pasteAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2014-10-17 18:37:18 +02:00
|
|
|
pasteAction->setIcon(QIcon::fromTheme(QSL("edit-paste")));
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* selectAllAction = pageAction(QWebEnginePage::SelectAll);
|
2014-10-17 18:37:18 +02:00
|
|
|
selectAllAction->setText(tr("Select All"));
|
|
|
|
selectAllAction->setShortcut(QKeySequence("Ctrl+A"));
|
2014-10-18 16:33:21 +02:00
|
|
|
selectAllAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2014-10-17 18:37:18 +02:00
|
|
|
selectAllAction->setIcon(QIcon::fromTheme(QSL("edit-select-all")));
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* reloadAction = pageAction(QWebEnginePage::Reload);
|
2014-10-17 18:37:18 +02:00
|
|
|
reloadAction->setText(tr("&Reload"));
|
|
|
|
reloadAction->setIcon(QIcon::fromTheme(QSL("view-refresh")));
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QAction* stopAction = pageAction(QWebEnginePage::Stop);
|
2014-10-17 18:37:18 +02:00
|
|
|
stopAction->setText(tr("S&top"));
|
|
|
|
stopAction->setIcon(QIcon::fromTheme(QSL("process-stop")));
|
|
|
|
|
|
|
|
// Make action shortcuts available for webview
|
|
|
|
addAction(undoAction);
|
|
|
|
addAction(redoAction);
|
|
|
|
addAction(cutAction);
|
|
|
|
addAction(copyAction);
|
|
|
|
addAction(pasteAction);
|
|
|
|
addAction(selectAllAction);
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void WebView::_wheelEvent(QWheelEvent *event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-03-07 12:19:08 +01:00
|
|
|
if (mApp->plugins()->processWheelEvent(Qz::ON_WebView, this, event)) {
|
2015-09-29 17:21:49 +02:00
|
|
|
event->accept();
|
2012-03-07 12:19:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
2012-07-13 18:00:03 +02:00
|
|
|
event->delta() > 0 ? zoomIn() : zoomOut();
|
2011-03-02 16:57:41 +01:00
|
|
|
event->accept();
|
|
|
|
}
|
2012-01-02 13:56:52 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void WebView::_mousePressEvent(QMouseEvent *event)
|
2011-12-24 12:21:23 +01:00
|
|
|
{
|
2015-10-01 18:16:48 +02:00
|
|
|
m_clickedUrl = QUrl();
|
|
|
|
m_clickedPos = QPoint();
|
|
|
|
|
2012-02-22 18:33:44 +01:00
|
|
|
if (mApp->plugins()->processMousePress(Qz::ON_WebView, this, event)) {
|
2015-09-29 17:21:49 +02:00
|
|
|
event->accept();
|
2012-02-22 18:33:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::XButton1:
|
|
|
|
back();
|
2012-01-14 09:54:51 +01:00
|
|
|
event->accept();
|
2011-12-24 12:21:23 +01:00
|
|
|
break;
|
2012-01-21 20:20:48 +01:00
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
case Qt::XButton2:
|
|
|
|
forward();
|
2012-01-14 09:54:51 +01:00
|
|
|
event->accept();
|
2011-12-24 12:21:23 +01:00
|
|
|
break;
|
2012-01-21 20:20:48 +01:00
|
|
|
|
2015-09-29 22:00:09 +02:00
|
|
|
case Qt::MiddleButton:
|
|
|
|
m_clickedUrl = page()->hitTestContent(event->pos()).linkUrl();
|
|
|
|
if (!m_clickedUrl.isEmpty())
|
|
|
|
event->accept();
|
2012-01-28 16:04:02 +01:00
|
|
|
break;
|
2012-01-22 15:15:43 +01:00
|
|
|
|
2015-10-02 15:50:29 +02:00
|
|
|
case Qt::LeftButton:
|
2015-10-01 17:47:50 +02:00
|
|
|
m_clickedUrl = page()->hitTestContent(event->pos()).linkUrl();
|
2015-09-29 17:21:49 +02:00
|
|
|
break;
|
2012-01-24 19:12:31 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-22 15:15:43 +01:00
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void WebView::_mouseReleaseEvent(QMouseEvent *event)
|
2012-01-24 19:12:31 +01:00
|
|
|
{
|
2012-02-22 18:33:44 +01:00
|
|
|
if (mApp->plugins()->processMouseRelease(Qz::ON_WebView, this, event)) {
|
2015-09-29 17:21:49 +02:00
|
|
|
event->accept();
|
2012-02-22 18:33:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-24 19:12:31 +01:00
|
|
|
switch (event->button()) {
|
2015-10-02 15:50:29 +02:00
|
|
|
case Qt::MiddleButton:
|
|
|
|
if (!m_clickedUrl.isEmpty()) {
|
|
|
|
const QUrl link = page()->hitTestContent(event->pos()).linkUrl();
|
|
|
|
if (m_clickedUrl == link && isUrlValid(link)) {
|
2015-10-01 17:47:50 +02:00
|
|
|
userDefinedOpenUrlInNewTab(link, event->modifiers() & Qt::ShiftModifier);
|
|
|
|
event->accept();
|
|
|
|
}
|
2015-10-02 15:50:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::LeftButton:
|
|
|
|
if (!m_clickedUrl.isEmpty()) {
|
|
|
|
const QUrl link = page()->hitTestContent(event->pos()).linkUrl();
|
|
|
|
if (m_clickedUrl == link && isUrlValid(link)) {
|
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
userDefinedOpenUrlInNewTab(link, event->modifiers() & Qt::ShiftModifier);
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else if (event->modifiers() & Qt::ShiftModifier) {
|
|
|
|
mApp->createWindow(Qz::BW_NewWindow, link);
|
|
|
|
event->accept();
|
|
|
|
}
|
2015-10-01 17:47:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-04-05 13:20:21 +02:00
|
|
|
case Qt::RightButton:
|
|
|
|
if (s_forceContextMenuOnMouseRelease) {
|
|
|
|
QContextMenuEvent ev(QContextMenuEvent::Mouse, event->pos(), event->globalPos(), event->modifiers());
|
2015-10-02 11:14:10 +02:00
|
|
|
_contextMenuEvent(&ev);
|
2015-09-29 17:21:49 +02:00
|
|
|
event->accept();
|
2014-04-05 13:20:21 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void WebView::_mouseMoveEvent(QMouseEvent *event)
|
2012-02-22 18:33:44 +01:00
|
|
|
{
|
|
|
|
if (mApp->plugins()->processMouseMove(Qz::ON_WebView, this, event)) {
|
2015-09-29 17:21:49 +02:00
|
|
|
event->accept();
|
2012-02-22 18:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void WebView::_keyPressEvent(QKeyEvent *event)
|
2011-12-24 12:21:23 +01:00
|
|
|
{
|
2012-02-22 18:33:44 +01:00
|
|
|
if (mApp->plugins()->processKeyPress(Qz::ON_WebView, this, event)) {
|
2015-09-29 17:21:49 +02:00
|
|
|
event->accept();
|
2012-02-22 18:33:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-04 19:03:40 +02:00
|
|
|
switch (event->key()) {
|
2014-12-13 19:29:45 +01:00
|
|
|
case Qt::Key_ZoomIn:
|
|
|
|
zoomIn();
|
|
|
|
event->accept();
|
2015-09-29 17:21:49 +02:00
|
|
|
break;
|
2014-12-13 19:29:45 +01:00
|
|
|
|
|
|
|
case Qt::Key_ZoomOut:
|
|
|
|
zoomOut();
|
|
|
|
event->accept();
|
2015-09-29 17:21:49 +02:00
|
|
|
break;
|
2014-12-13 19:29:45 +01:00
|
|
|
|
|
|
|
case Qt::Key_Plus:
|
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
zoomIn();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_Minus:
|
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
zoomOut();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_0:
|
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
zoomReset();
|
|
|
|
event->accept();
|
2013-05-19 10:22:40 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-10-05 17:39:52 +02:00
|
|
|
case Qt::Key_Escape:
|
|
|
|
if (isFullScreen()) {
|
|
|
|
triggerPageAction(QWebEnginePage::ExitFullScreen);
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void WebView::_keyReleaseEvent(QKeyEvent *event)
|
2012-02-22 18:33:44 +01:00
|
|
|
{
|
|
|
|
if (mApp->plugins()->processKeyRelease(Qz::ON_WebView, this, event)) {
|
2015-09-29 17:21:49 +02:00
|
|
|
event->accept();
|
2012-02-22 18:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void WebView::_contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void WebView::resizeEvent(QResizeEvent *event)
|
2011-12-24 12:21:23 +01:00
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineView::resizeEvent(event);
|
2015-08-30 15:52:15 +02:00
|
|
|
emit viewportResized(size());
|
2011-12-24 12:21:23 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void WebView::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
2015-10-02 11:14:10 +02:00
|
|
|
// Context menu is created in mouseReleaseEvent
|
|
|
|
if (s_forceContextMenuOnMouseRelease)
|
|
|
|
return;
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
const QPoint pos = event->pos();
|
|
|
|
const QContextMenuEvent::Reason reason = event->reason();
|
|
|
|
|
|
|
|
QTimer::singleShot(0, this, [this, pos, reason]() {
|
|
|
|
QContextMenuEvent ev(reason, pos);
|
|
|
|
_contextMenuEvent(&ev);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-06 23:29:49 +02:00
|
|
|
void WebView::loadRequest(const LoadRequest &req)
|
|
|
|
{
|
|
|
|
if (req.operation() == LoadRequest::GetOperation)
|
2015-08-30 15:36:34 +02:00
|
|
|
load(req.url());
|
2014-06-06 23:29:49 +02:00
|
|
|
else
|
2015-08-30 15:36:34 +02:00
|
|
|
m_page->runJavaScript(Scripts::sendPostData(req.url(), req.data()));
|
2014-06-06 23:29:49 +02:00
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
bool WebView::eventFilter(QObject *obj, QEvent *event)
|
2011-11-05 21:27:01 +01:00
|
|
|
{
|
2015-09-29 17:21:49 +02:00
|
|
|
// Hack to find widget that receives input events
|
|
|
|
if (obj == this && event->type() == QEvent::ChildAdded) {
|
2015-10-14 12:11:57 +02:00
|
|
|
QWidget *child = qobject_cast<QWidget*>(static_cast<QChildEvent*>(event)->child());
|
|
|
|
if (child && child->inherits("QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget")) {
|
2015-09-29 17:21:49 +02:00
|
|
|
m_rwhvqt = child;
|
|
|
|
m_rwhvqt->installEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward events to WebView
|
|
|
|
if (obj == m_rwhvqt) {
|
2015-11-06 00:06:03 +01:00
|
|
|
bool ret = false;
|
|
|
|
bool wasAccepted = event->isAccepted();
|
|
|
|
|
|
|
|
#define HANDLE_EVENT(x) \
|
|
|
|
event->setAccepted(false); \
|
|
|
|
(x); \
|
|
|
|
ret = event->isAccepted(); \
|
|
|
|
event->setAccepted(wasAccepted); \
|
|
|
|
return ret
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::KeyPress:
|
2015-11-06 00:06:03 +01:00
|
|
|
HANDLE_EVENT(_keyPressEvent(static_cast<QKeyEvent*>(event)));
|
2015-09-29 17:21:49 +02:00
|
|
|
|
|
|
|
case QEvent::KeyRelease:
|
2015-11-06 00:06:03 +01:00
|
|
|
HANDLE_EVENT(_keyReleaseEvent(static_cast<QKeyEvent*>(event)));
|
2015-09-29 17:21:49 +02:00
|
|
|
|
|
|
|
case QEvent::MouseButtonPress:
|
2015-11-06 00:06:03 +01:00
|
|
|
HANDLE_EVENT(_mousePressEvent(static_cast<QMouseEvent*>(event)));
|
2015-09-29 17:21:49 +02:00
|
|
|
|
|
|
|
case QEvent::MouseButtonRelease:
|
2015-11-06 00:06:03 +01:00
|
|
|
HANDLE_EVENT(_mouseReleaseEvent(static_cast<QMouseEvent*>(event)));
|
2015-09-29 17:21:49 +02:00
|
|
|
|
|
|
|
case QEvent::MouseMove:
|
2015-11-06 00:06:03 +01:00
|
|
|
HANDLE_EVENT(_mouseMoveEvent(static_cast<QMouseEvent*>(event)));
|
2015-09-29 17:21:49 +02:00
|
|
|
|
|
|
|
case QEvent::Wheel:
|
2015-11-06 00:06:03 +01:00
|
|
|
HANDLE_EVENT(_wheelEvent(static_cast<QWheelEvent*>(event)));
|
2015-09-29 17:21:49 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-11-06 00:06:03 +01:00
|
|
|
|
|
|
|
#undef HANDLE_EVENT
|
2015-09-29 17:21:49 +02:00
|
|
|
}
|
|
|
|
|
2015-10-04 19:03:40 +02:00
|
|
|
// Block already handled events
|
|
|
|
if (obj == this) {
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
case QEvent::Wheel:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
return QWebEngineView::eventFilter(obj, event);
|
2011-11-05 21:27:01 +01:00
|
|
|
}
|