2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 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"
|
2012-01-21 20:20:48 +01:00
|
|
|
#include "webhistorywrapper.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
2012-01-21 20:20:48 +01:00
|
|
|
#include "globalfunctions.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2012-01-21 20:20:48 +01:00
|
|
|
#include "historymodel.h"
|
|
|
|
#include "autofillmodel.h"
|
|
|
|
#include "downloadmanager.h"
|
|
|
|
#include "sourceviewer.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"
|
|
|
|
#include "bookmarksmanager.h"
|
2012-01-24 15:16:33 +01:00
|
|
|
#include "settings.h"
|
2012-01-24 19:58:20 +01:00
|
|
|
#include "webviewsettings.h"
|
2012-01-24 23:28:18 +01:00
|
|
|
#include "enhancedmenu.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
WebView::WebView(QWidget* parent)
|
|
|
|
: QWebView(parent)
|
2011-10-30 17:20:22 +01:00
|
|
|
, m_currentZoom(100)
|
|
|
|
, m_isLoading(false)
|
2012-01-21 20:20:48 +01:00
|
|
|
, m_progress(0)
|
2012-01-22 11:49:58 +01:00
|
|
|
, m_clickedFrame(0)
|
|
|
|
, m_actionsHaveImages(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
|
|
|
|
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
|
|
|
|
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
connect(this, SIGNAL(iconChanged()), this, SLOT(slotIconChanged()));
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2011-10-29 18:37:28 +02:00
|
|
|
// Zoom levels same as in firefox
|
2011-03-02 16:57:41 +01:00
|
|
|
m_zoomLevels << 30 << 50 << 67 << 80 << 90 << 100 << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300;
|
2011-11-05 21:27:01 +01:00
|
|
|
|
|
|
|
qApp->installEventFilter(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QIcon WebView::icon() const
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
if (url().scheme() == "qupzilla") {
|
|
|
|
return QIcon(":icons/qupzilla.png");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (!QWebView::icon().isNull()) {
|
|
|
|
return QWebView::icon();
|
2011-07-11 20:30:49 +02:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (!m_siteIcon.isNull() && m_siteIconUrl.host() == url().host()) {
|
|
|
|
return m_siteIcon;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
return _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
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
QString title = QWebView::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-01-21 20:20:48 +01:00
|
|
|
if (title.isEmpty() || title == "about:blank") {
|
|
|
|
return tr("No Named 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
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QUrl WebView::url() const
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
QUrl returnUrl = QWebView::url();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (returnUrl.isEmpty()) {
|
|
|
|
returnUrl = m_aboutToLoadUrl;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-12-20 18:58:42 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
return returnUrl;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-27 23:01:17 +01:00
|
|
|
void WebView::setPage(QWebPage* page)
|
2012-01-24 19:58:20 +01:00
|
|
|
{
|
|
|
|
QWebView::setPage(page);
|
|
|
|
|
|
|
|
setZoom(WebViewSettings::defaultZoom);
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::load(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
if (url.scheme() == "javascript") {
|
|
|
|
page()->mainFrame()->evaluateJavaScript(url.toString());
|
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
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (isUrlValid(url)) {
|
|
|
|
QWebView::load(url);
|
|
|
|
emit urlChanged(url);
|
|
|
|
m_aboutToLoadUrl = url;
|
2011-10-15 16:37:32 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-15 16:37:32 +02:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QUrl searchUrl = mApp->searchEnginesManager()->searchUrl(url.toString());
|
|
|
|
QWebView::load(searchUrl);
|
|
|
|
emit urlChanged(searchUrl);
|
|
|
|
m_aboutToLoadUrl = searchUrl;
|
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
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
return m_isLoading;
|
2011-04-04 17:03:41 +02:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
int WebView::loadProgress() 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-01-21 20:20:48 +01:00
|
|
|
bool WebView::isUrlValid(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
if (url.scheme() == "data" || url.scheme() == "qrc" || url.scheme() == "mailto") {
|
|
|
|
return true;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (url.scheme() == "qupzilla" || url.scheme() == "file") {
|
|
|
|
return !url.path().isEmpty();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (url.isValid() && !url.host().isEmpty() && !url.scheme().isEmpty()) {
|
|
|
|
return true;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
|
|
|
|
return false;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QUrl WebView::guessUrlFromString(const QString &string)
|
|
|
|
{
|
|
|
|
QString trimmedString = string.trimmed();
|
|
|
|
|
|
|
|
// Check the most common case of a valid url with scheme and host first
|
|
|
|
QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return url;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
// Absolute files that exists
|
2011-11-06 17:01:23 +01:00
|
|
|
if (QDir::isAbsolutePath(trimmedString) && QFile::exists(trimmedString)) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return QUrl::fromLocalFile(trimmedString);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
// If the string is missing the scheme or the scheme is not valid prepend a scheme
|
|
|
|
QString scheme = url.scheme();
|
|
|
|
if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) {
|
|
|
|
// Do not do anything for strings such as "foo", only "foo.com"
|
|
|
|
int dotIndex = trimmedString.indexOf(QLatin1Char('.'));
|
|
|
|
if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) {
|
|
|
|
const QString hostscheme = trimmedString.left(dotIndex).toLower();
|
|
|
|
QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http";
|
|
|
|
trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString;
|
|
|
|
}
|
|
|
|
url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isValid()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return url;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
return QUrl();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
setZoomFactor(qreal(m_currentZoom) / 100.0);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::zoomIn()
|
|
|
|
{
|
|
|
|
int i = m_zoomLevels.indexOf(m_currentZoom);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (i < m_zoomLevels.count() - 1) {
|
|
|
|
m_currentZoom = m_zoomLevels[i + 1];
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
applyZoom();
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::zoomOut()
|
|
|
|
{
|
|
|
|
int i = m_zoomLevels.indexOf(m_currentZoom);
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
m_currentZoom = m_zoomLevels[i - 1];
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
applyZoom();
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::zoomReset()
|
|
|
|
{
|
|
|
|
m_currentZoom = 100;
|
|
|
|
applyZoom();
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::reload()
|
|
|
|
{
|
|
|
|
if (QWebView::url().isEmpty() && !m_aboutToLoadUrl.isEmpty()) {
|
|
|
|
load(m_aboutToLoadUrl);
|
|
|
|
return;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QWebView::reload();
|
|
|
|
}
|
2012-01-09 12:39:34 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::back()
|
|
|
|
{
|
|
|
|
QWebHistory* history = page()->history();
|
2012-01-09 12:39:34 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (WebHistoryWrapper::canGoBack(history)) {
|
|
|
|
WebHistoryWrapper::goBack(history);
|
2011-10-21 23:26:34 +02:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
emit urlChanged(url());
|
|
|
|
emit iconChanged();
|
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()
|
|
|
|
{
|
|
|
|
QWebHistory* history = page()->history();
|
|
|
|
|
|
|
|
if (WebHistoryWrapper::canGoForward(history)) {
|
|
|
|
WebHistoryWrapper::goForward(history);
|
|
|
|
|
|
|
|
emit urlChanged(url());
|
|
|
|
emit iconChanged();
|
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::selectAll()
|
|
|
|
{
|
|
|
|
triggerPageAction(QWebPage::SelectAll);
|
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_isLoading = true;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::slotLoadFinished()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
m_isLoading = false;
|
|
|
|
m_progress = 100;
|
|
|
|
|
|
|
|
if (m_lastUrl != url()) {
|
|
|
|
mApp->history()->addHistoryEntry(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
|
|
|
|
mApp->autoFill()->completePage(qobject_cast<WebPage*>(page()));
|
|
|
|
|
|
|
|
m_lastUrl = url();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::slotIconChanged()
|
|
|
|
{
|
|
|
|
m_siteIcon = icon();
|
|
|
|
m_siteIconUrl = url();
|
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())) {
|
2012-01-21 23:19:38 +01:00
|
|
|
mApp->makeNewWindow(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())) {
|
2011-11-06 17:01:23 +01:00
|
|
|
QDesktopServices::openUrl(QUrl("mailto:?body=" + action->data().toString()));
|
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())) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QApplication::clipboard()->setText(action->data().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::downloadLinkToDisk()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-03-24 22:31:38 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
DownloadManager* dManager = mApp->downManager();
|
|
|
|
QNetworkRequest request(action->data().toUrl());
|
2012-01-21 20:20:48 +01:00
|
|
|
dManager->download(request, qobject_cast<WebPage*>(page()), false);
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::copyImageToClipboard()
|
|
|
|
{
|
|
|
|
triggerPageAction(QWebPage::CopyImageToClipboard);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::showSource(QWebFrame* frame, const QString &selectedHtml)
|
2011-07-19 22:04:08 +02:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
if (!frame) {
|
|
|
|
frame = page()->mainFrame();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
SourceViewer* source = new SourceViewer(frame, selectedHtml);
|
|
|
|
qz_centerWidgetToParent(source, this);
|
|
|
|
source->show();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showSiteInfo()
|
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
SiteInfo* s = new SiteInfo(this, this);
|
|
|
|
s->show();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void WebView::searchSelectedText()
|
|
|
|
{
|
|
|
|
QUrl urlToLoad = mApp->searchEnginesManager()->searchUrl(selectedText());
|
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
openUrlInNewTab(urlToLoad, Qz::NT_SelectedTab);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::bookmarkLink()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
if (action->data().isNull()) {
|
|
|
|
mApp->browsingLibrary()->bookmarksManager()->addBookmark(this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mApp->browsingLibrary()->bookmarksManager()->insertBookmark(action->data().toUrl(), title(), icon());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showSourceOfSelection()
|
|
|
|
{
|
|
|
|
#if (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0))
|
|
|
|
showSource(page()->mainFrame(), selectedHtml());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
void WebView::openUrlInSelectedTab()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
openUrlInNewTab(action->data().toUrl(), Qz::NT_SelectedTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::openUrlInBackgroundTab()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2012-01-26 17:21:11 +01:00
|
|
|
openUrlInNewTab(action->data().toUrl(), Qz::NT_NotSelectedTab);
|
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-01-22 11:49:58 +01:00
|
|
|
void WebView::loadClickedFrame()
|
|
|
|
{
|
|
|
|
QUrl frameUrl = m_clickedFrame->url();
|
|
|
|
if (frameUrl.isEmpty()) {
|
|
|
|
frameUrl = m_clickedFrame->requestedUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
load(frameUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::loadClickedFrameInNewTab()
|
|
|
|
{
|
|
|
|
QUrl frameUrl = m_clickedFrame->url();
|
|
|
|
if (frameUrl.isEmpty()) {
|
|
|
|
frameUrl = m_clickedFrame->requestedUrl();
|
|
|
|
}
|
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
openUrlInNewTab(frameUrl, Qz::NT_SelectedTab);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::reloadClickedFrame()
|
|
|
|
{
|
|
|
|
QUrl frameUrl = m_clickedFrame->url();
|
|
|
|
if (frameUrl.isEmpty()) {
|
|
|
|
frameUrl = m_clickedFrame->requestedUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_clickedFrame->load(frameUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::printClickedFrame()
|
|
|
|
{
|
|
|
|
printPage(m_clickedFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::clickedFrameZoomIn()
|
|
|
|
{
|
|
|
|
qreal zFactor = m_clickedFrame->zoomFactor() + 0.1;
|
|
|
|
if (zFactor > 2.5) {
|
|
|
|
zFactor = 2.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_clickedFrame->setZoomFactor(zFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::clickedFrameZoomOut()
|
|
|
|
{
|
|
|
|
qreal zFactor = m_clickedFrame->zoomFactor() - 0.1;
|
|
|
|
if (zFactor < 0.5) {
|
|
|
|
zFactor = 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_clickedFrame->setZoomFactor(zFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::clickedFrameZoomReset()
|
|
|
|
{
|
|
|
|
m_clickedFrame->setZoomFactor(zoomFactor());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showClickedFrameSource()
|
|
|
|
{
|
|
|
|
showSource(m_clickedFrame);
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::printPage(QWebFrame* frame)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
QPrintPreviewDialog* dialog = new QPrintPreviewDialog(this);
|
|
|
|
dialog->resize(800, 750);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
if (!frame) {
|
|
|
|
connect(dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-21 20:20:48 +01:00
|
|
|
else {
|
|
|
|
connect(dialog, SIGNAL(paintRequested(QPrinter*)), frame, SLOT(print(QPrinter*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog->exec();
|
|
|
|
dialog->deleteLater();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::copyText()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
if (!selectedText().isEmpty()) {
|
|
|
|
QApplication::clipboard()->setText(selectedText());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QUrl WebView::lastUrl()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
return m_lastUrl;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 00:20:29 +01:00
|
|
|
bool WebView::isMediaElement(const QWebElement &element)
|
|
|
|
{
|
|
|
|
return (element.tagName().toLower() == "video" || element.tagName().toLower() == "audio");
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void WebView::createContextMenu(QMenu* menu, const QWebHitTestResult &hitTest, const QPoint &pos)
|
|
|
|
{
|
|
|
|
if (!m_actionsHaveImages) {
|
|
|
|
m_actionsHaveImages = true;
|
|
|
|
|
|
|
|
pageAction(QWebPage::Cut)->setIcon(QIcon::fromTheme("edit-cut"));
|
|
|
|
pageAction(QWebPage::Copy)->setIcon(QIcon::fromTheme("edit-copy"));
|
|
|
|
pageAction(QWebPage::Paste)->setIcon(QIcon::fromTheme("edit-paste"));
|
|
|
|
pageAction(QWebPage::SelectAll)->setIcon(QIcon::fromTheme("edit-select-all"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hitTest.linkUrl().isEmpty() && hitTest.linkUrl().scheme() != "javascript") {
|
|
|
|
createLinkContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hitTest.imageUrl().isEmpty()) {
|
|
|
|
createImageContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMediaElement(hitTest.element())) {
|
|
|
|
createMediaContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebElement element = hitTest.element();
|
|
|
|
if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea")) {
|
|
|
|
if (menu->isEmpty()) {
|
|
|
|
QMenu* pageMenu = page()->createStandardContextMenu();
|
|
|
|
|
|
|
|
int i = 0;
|
2012-01-24 19:12:31 +01:00
|
|
|
foreach(QAction * act, pageMenu->actions()) {
|
2012-01-22 11:49:58 +01:00
|
|
|
if (act->isSeparator()) {
|
|
|
|
menu->addSeparator();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hiding double Direction menu (bug in QtWebKit 2.2)
|
|
|
|
if (i == 0 && act->menu()) {
|
|
|
|
act->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
menu->addAction(act);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu->actions().last() == pageAction(QWebPage::InspectElement)) {
|
|
|
|
// We have own Inspect Element action
|
|
|
|
menu->actions().last()->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pageMenu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!selectedText().isEmpty()) {
|
|
|
|
createSelectedTextContextMenu(menu, hitTest);
|
|
|
|
}
|
|
|
|
|
2012-01-23 17:30:34 +01:00
|
|
|
if (menu->isEmpty()) {
|
2012-01-22 11:49:58 +01:00
|
|
|
createPageContextMenu(menu, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0))
|
2012-01-26 20:19:56 +01:00
|
|
|
// still bugged? in 4.8 RC (it shows selection of webkit's internal source, not html from page)
|
|
|
|
// it may or may not be bug, but this implementation is useless for us
|
|
|
|
//
|
|
|
|
// if (!selectedHtml().isEmpty())
|
|
|
|
// menu->addAction(tr("Show source of selection"), this, SLOT(showSourceOfSelection()));
|
2012-01-22 11:49:58 +01:00
|
|
|
#endif
|
|
|
|
|
2012-01-26 20:19:56 +01:00
|
|
|
// mApp->plugins()->populateWebViewMenu(m_menu, this, hitTest);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::createPageContextMenu(QMenu* menu, const QPoint &pos)
|
|
|
|
{
|
|
|
|
QWebFrame* frameAtPos = page()->frameAt(pos);
|
|
|
|
|
|
|
|
QAction* action = menu->addAction(tr("&Back"), this, SLOT(back()));
|
|
|
|
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
|
|
|
action->setEnabled(history()->canGoBack());
|
|
|
|
|
|
|
|
action = menu->addAction(tr("&Forward"), this, SLOT(forward()));
|
|
|
|
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowForward));
|
|
|
|
action->setEnabled(history()->canGoForward());
|
|
|
|
|
|
|
|
menu->addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), this, SLOT(reload()));
|
|
|
|
action = menu->addAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("S&top"), this, SLOT(stop()));
|
|
|
|
action->setEnabled(isLoading());
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
if (frameAtPos && page()->mainFrame() != frameAtPos) {
|
|
|
|
m_clickedFrame = frameAtPos;
|
|
|
|
QMenu* frameMenu = new QMenu(tr("This frame"));
|
|
|
|
frameMenu->addAction(tr("Show &only this frame"), this, SLOT(loadClickedFrame()));
|
|
|
|
frameMenu->addAction(QIcon(":/icons/menu/popup.png"), tr("Show this frame in new &tab"), this, SLOT(loadClickedFrameInNewTab()));
|
|
|
|
frameMenu->addSeparator();
|
|
|
|
frameMenu->addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), this, SLOT(reloadClickedFrame()));
|
|
|
|
frameMenu->addAction(QIcon::fromTheme("document-print"), tr("Print frame"), this, SLOT(printClickedFrame()));
|
|
|
|
frameMenu->addSeparator();
|
|
|
|
frameMenu->addAction(QIcon::fromTheme("zoom-in"), tr("Zoom &in"), this, SLOT(clickedFrameZoomIn()));
|
|
|
|
frameMenu->addAction(QIcon::fromTheme("zoom-out"), tr("&Zoom out"), this, SLOT(clickedFrameZoomOut()));
|
|
|
|
frameMenu->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), this, SLOT(clickedFrameZoomReset()));
|
|
|
|
frameMenu->addSeparator();
|
|
|
|
frameMenu->addAction(QIcon::fromTheme("text-html"), tr("Show so&urce of frame"), this, SLOT(showClickedFrameSource()));
|
|
|
|
|
|
|
|
menu->addMenu(frameMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(IconProvider::fromTheme("user-bookmarks"), tr("Book&mark page"), this, SLOT(bookmarkLink()));
|
|
|
|
menu->addAction(QIcon::fromTheme("document-save"), tr("&Save page as..."), this, SLOT(downloadLinkToDisk()))->setData(url());
|
|
|
|
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(sendLinkByMail()))->setData(url());
|
|
|
|
menu->addAction(QIcon::fromTheme("document-print"), tr("&Print page"), this, SLOT(printPage()));
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &all"), this, SLOT(selectAll()));
|
|
|
|
menu->addSeparator();
|
|
|
|
if (url().scheme() == "http" || url().scheme() == "https") {
|
2012-01-26 20:19:56 +01:00
|
|
|
// bool result = validateConfirm(tr("Do you want to upload this page to an online source code validator?"));
|
|
|
|
// if (result)
|
2012-01-22 15:15:43 +01:00
|
|
|
menu->addAction(tr("Validate page"), this, SLOT(openUrlInSelectedTab()))->setData("http://validator.w3.org/check?uri=" + url().toString());
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
menu->addAction(QIcon::fromTheme("text-html"), tr("Show so&urce code"), this, SLOT(showSource()));
|
|
|
|
menu->addAction(QIcon::fromTheme("dialog-information"), tr("Show info ab&out site"), this, SLOT(showSiteInfo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::createLinkContextMenu(QMenu* menu, const QWebHitTestResult &hitTest)
|
|
|
|
{
|
|
|
|
// Workaround for QtWebKit <= 2.0 when selecting link text on right click
|
|
|
|
if (page()->selectedText() == hitTest.linkText()) {
|
|
|
|
findText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
menu->addSeparator();
|
2012-01-22 15:15:43 +01:00
|
|
|
menu->addAction(QIcon(":/icons/menu/popup.png"), tr("Open link in new &tab"), this, SLOT(openUrlInBackgroundTab()))->setData(hitTest.linkUrl());
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addAction(QIcon::fromTheme("window-new"), tr("Open link in new &window"), this, SLOT(openUrlInNewWindow()))->setData(hitTest.linkUrl());
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(IconProvider::fromTheme("user-bookmarks"), tr("B&ookmark link"), this, SLOT(bookmarkLink()))->setData(hitTest.linkUrl());
|
|
|
|
menu->addAction(QIcon::fromTheme("document-save"), tr("&Save link as..."), this, SLOT(downloadLinkToDisk()))->setData(hitTest.linkUrl());
|
|
|
|
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()) {
|
|
|
|
pageAction(QWebPage::Copy)->setIcon(QIcon::fromTheme("edit-copy"));
|
|
|
|
menu->addAction(pageAction(QWebPage::Copy));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::createImageContextMenu(QMenu* menu, const QWebHitTestResult &hitTest)
|
|
|
|
{
|
|
|
|
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()));
|
|
|
|
connect(act, SIGNAL(middleClicked()), this, SLOT(openUrlInBackgroundTab()));
|
|
|
|
menu->addAction(act);
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addAction(tr("Copy im&age"), this, SLOT(copyImageToClipboard()))->setData(hitTest.imageUrl());
|
|
|
|
menu->addAction(QIcon::fromTheme("edit-copy"), tr("Copy image ad&dress"), this, SLOT(copyLinkToClipboard()))->setData(hitTest.imageUrl());
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon::fromTheme("document-save"), tr("&Save image as..."), this, SLOT(downloadLinkToDisk()))->setData(hitTest.imageUrl());
|
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send image..."), this, SLOT(sendLinkByMail()))->setData(hitTest.imageUrl());
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
if (!selectedText().isEmpty()) {
|
|
|
|
pageAction(QWebPage::Copy)->setIcon(QIcon::fromTheme("edit-copy"));
|
|
|
|
menu->addAction(pageAction(QWebPage::Copy));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::createSelectedTextContextMenu(QMenu* menu, const QWebHitTestResult &hitTest)
|
|
|
|
{
|
|
|
|
Q_UNUSED(hitTest)
|
|
|
|
|
|
|
|
QString selectedText = page()->selectedText();
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
if (!menu->actions().contains(pageAction(QWebPage::Copy))) {
|
|
|
|
menu->addAction(pageAction(QWebPage::Copy));
|
|
|
|
}
|
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send text..."), this, SLOT(sendLinkByMail()))->setData(selectedText);
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
QString langCode = mApp->getActiveLanguage().left(2);
|
|
|
|
QUrl googleTranslateUrl = QUrl(QString("http://translate.google.com/#auto|%1|%2").arg(langCode, selectedText));
|
2012-01-22 15:15:43 +01:00
|
|
|
menu->addAction(QIcon(":icons/menu/translate.png"), tr("Google Translate"), this, SLOT(openUrlInSelectedTab()))->setData(googleTranslateUrl);
|
|
|
|
menu->addAction(QIcon::fromTheme("accessories-dictionary"), tr("Dictionary"), this, SLOT(openUrlInSelectedTab()))->setData("http://" + (langCode != "" ? langCode + "." : langCode) + "wiktionary.org/wiki/Special:Search?search=" + selectedText);
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
QString selectedString = selectedText.trimmed();
|
|
|
|
if (!selectedString.contains(".")) {
|
|
|
|
// Try to add .com
|
|
|
|
selectedString.append(".com");
|
|
|
|
}
|
|
|
|
QUrl guessedUrl = QUrl::fromUserInput(selectedString);
|
|
|
|
|
|
|
|
if (isUrlValid(guessedUrl)) {
|
2012-01-22 15:15:43 +01:00
|
|
|
menu->addAction(QIcon(":/icons/menu/popup.png"), tr("Go to &web address"), this, SLOT(openUrlInSelectedTab()))->setData(guessedUrl);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
selectedText.truncate(20);
|
|
|
|
|
|
|
|
SearchEngine engine = mApp->searchEnginesManager()->activeEngine();
|
|
|
|
menu->addAction(engine.icon, tr("Search \"%1 ..\" with %2").arg(selectedText, engine.name), this, SLOT(searchSelectedText()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::createMediaContextMenu(QMenu* menu, const QWebHitTestResult &hitTest)
|
2012-01-22 00:20:29 +01:00
|
|
|
{
|
|
|
|
m_mediaElement = hitTest.element();
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
if (m_mediaElement.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-22 00:20:29 +01:00
|
|
|
bool paused = m_mediaElement.evaluateJavaScript("this.paused").toBool();
|
|
|
|
bool muted = m_mediaElement.evaluateJavaScript("this.muted").toBool();
|
|
|
|
QUrl videoUrl = m_mediaElement.evaluateJavaScript("this.currentSrc").toUrl();
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addSeparator();
|
2012-01-22 01:24:35 +01:00
|
|
|
menu->addAction(paused ? tr("&Play") : tr("&Pause"), this, SLOT(pauseMedia()))->setIcon(QIcon::fromTheme(paused ? "media-playback-start" : "media-playback-pause"));
|
2012-01-22 01:43:09 +01:00
|
|
|
menu->addAction(muted ? tr("Un&mute") : tr("&Mute"), this, SLOT(muteMedia()))->setIcon(QIcon::fromTheme(muted ? "audio-volume-muted" : "audio-volume-high"));
|
2012-01-22 00:20:29 +01:00
|
|
|
menu->addSeparator();
|
2012-01-22 01:24:35 +01:00
|
|
|
menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy Media Address"), this, SLOT(copyLinkToClipboard()))->setData(videoUrl);
|
|
|
|
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("&Send Media Address"), this, SLOT(sendLinkByMail()))->setData(videoUrl);
|
2012-01-22 11:49:58 +01:00
|
|
|
menu->addAction(QIcon::fromTheme("document-save"), tr("Save Media To &Disk"), this, SLOT(downloadLinkToDisk()))->setData(videoUrl);
|
2012-01-22 00:20:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::pauseMedia()
|
|
|
|
{
|
|
|
|
bool paused = m_mediaElement.evaluateJavaScript("this.paused").toBool();
|
|
|
|
|
|
|
|
if (paused) {
|
|
|
|
m_mediaElement.evaluateJavaScript("this.play()");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_mediaElement.evaluateJavaScript("this.pause()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::muteMedia()
|
|
|
|
{
|
|
|
|
bool muted = m_mediaElement.evaluateJavaScript("this.muted").toBool();
|
|
|
|
|
|
|
|
if (muted) {
|
|
|
|
m_mediaElement.evaluateJavaScript("this.muted = false");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_mediaElement.evaluateJavaScript("this.muted = true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebView::wheelEvent(QWheelEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
int numDegrees = event->delta() / 8;
|
|
|
|
int numSteps = numDegrees / 15;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (numSteps == 1) {
|
2011-03-02 16:57:41 +01:00
|
|
|
zoomIn();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 16:57:41 +01:00
|
|
|
zoomOut();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QWebView::wheelEvent(event);
|
2012-01-02 13:56:52 +01:00
|
|
|
}
|
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
void WebView::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
case Qt::MiddleButton: {
|
2012-01-24 19:12:31 +01:00
|
|
|
QWebFrame* frame = page()->frameAt(event->pos());
|
2012-01-26 21:21:26 +01:00
|
|
|
#ifdef Q_WS_WIN
|
2012-01-24 19:12:31 +01:00
|
|
|
if (frame && frame->hitTestContent(event->pos()).linkUrl().isEmpty()) {
|
2012-01-22 15:15:43 +01:00
|
|
|
// Creating auto scroll on Windows
|
2012-01-24 19:12:31 +01:00
|
|
|
m_clickedUrl = QUrl();
|
2012-01-22 15:15:43 +01:00
|
|
|
QWebView::mouseDoubleClickEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-26 20:19:56 +01:00
|
|
|
if (frame) {
|
|
|
|
m_clickedUrl = frame->hitTestContent(event->pos()).linkUrl();
|
|
|
|
}
|
2012-01-22 15:15:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case Qt::LeftButton: {
|
|
|
|
QWebFrame* frame = page()->frameAt(event->pos());
|
2012-01-24 19:12:31 +01:00
|
|
|
if (frame) {
|
2012-01-26 20:19:56 +01:00
|
|
|
QUrl link = frame->hitTestContent(event->pos()).linkUrl();
|
|
|
|
if (event->modifiers() == Qt::ControlModifier && isUrlValid(link)) {
|
|
|
|
openUrlInNewTab(link, Qz::NT_NotSelectedTab);
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
2012-01-24 19:12:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebView::mousePressEvent(event);
|
|
|
|
}
|
2012-01-22 15:15:43 +01:00
|
|
|
|
2012-01-24 19:12:31 +01:00
|
|
|
void WebView::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::MiddleButton: {
|
|
|
|
QWebFrame* frame = page()->frameAt(event->pos());
|
|
|
|
if (frame) {
|
2012-01-22 15:15:43 +01:00
|
|
|
QUrl link = frame->hitTestContent(event->pos()).linkUrl();
|
2012-01-24 19:12:31 +01:00
|
|
|
if (m_clickedUrl == link && isUrlValid(link)) {
|
2012-01-26 17:21:11 +01:00
|
|
|
openUrlInNewTab(link, Qz::NT_NotSelectedTab);
|
2012-01-22 15:15:43 +01:00
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-01-22 15:15:43 +01:00
|
|
|
|
2012-01-24 19:12:31 +01:00
|
|
|
QWebView::mouseReleaseEvent(event);
|
2011-12-24 12:21:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->key()) {
|
|
|
|
case Qt::Key_C:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
|
|
|
copyText();
|
2012-01-14 09:54:51 +01:00
|
|
|
event->accept();
|
2011-12-24 12:21:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_A:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
|
|
|
selectAll();
|
2012-01-14 09:54:51 +01:00
|
|
|
event->accept();
|
2011-12-24 12:21:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebView::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QWebView::resizeEvent(event);
|
2012-01-21 20:20:48 +01:00
|
|
|
emit viewportResized(page()->viewportSize());
|
2011-12-24 12:21:23 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void WebView::setZoom(int zoom)
|
2011-12-24 12:21:23 +01:00
|
|
|
{
|
2012-01-21 20:20:48 +01:00
|
|
|
m_currentZoom = zoom;
|
|
|
|
applyZoom();
|
2011-12-24 12:21:23 +01:00
|
|
|
}
|
|
|
|
|
2011-11-05 21:27:01 +01:00
|
|
|
///
|
2011-12-17 14:30:54 +01:00
|
|
|
// This function was taken and modified from QTestBrowser to fix bug #33 with flightradar24.com
|
2011-11-05 21:27:01 +01:00
|
|
|
// You can find original source and copyright here:
|
|
|
|
// http://gitorious.org/+qtwebkit-developers/webkit/qtwebkit/blobs/qtwebkit-2.2/Tools/QtTestBrowser/launcherwindow.cpp
|
|
|
|
///
|
|
|
|
bool WebView::eventFilter(QObject* obj, QEvent* event)
|
|
|
|
{
|
2011-12-24 12:21:23 +01:00
|
|
|
if (obj != this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-05 21:27:01 +01:00
|
|
|
if (event->type() == QEvent::MouseButtonPress ||
|
2011-11-06 17:01:23 +01:00
|
|
|
event->type() == QEvent::MouseButtonRelease ||
|
|
|
|
event->type() == QEvent::MouseButtonDblClick ||
|
|
|
|
event->type() == QEvent::MouseMove) {
|
2011-11-05 21:27:01 +01:00
|
|
|
|
|
|
|
QMouseEvent* ev = static_cast<QMouseEvent*>(event);
|
2012-01-23 17:30:34 +01:00
|
|
|
if (ev->type() == QEvent::MouseMove && !(ev->buttons() & Qt::LeftButton)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev->type() == QEvent::MouseButtonPress && ev->buttons() & Qt::RightButton) {
|
2011-11-05 21:27:01 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-05 21:27:01 +01:00
|
|
|
|
|
|
|
QTouchEvent::TouchPoint touchPoint;
|
|
|
|
touchPoint.setState(Qt::TouchPointMoved);
|
|
|
|
if ((ev->type() == QEvent::MouseButtonPress
|
2012-01-27 23:01:17 +01:00
|
|
|
|| ev->type() == QEvent::MouseButtonDblClick)) {
|
2011-11-05 21:27:01 +01:00
|
|
|
touchPoint.setState(Qt::TouchPointPressed);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (ev->type() == QEvent::MouseButtonRelease) {
|
2011-11-05 21:27:01 +01:00
|
|
|
touchPoint.setState(Qt::TouchPointReleased);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-05 21:27:01 +01:00
|
|
|
|
|
|
|
touchPoint.setId(0);
|
|
|
|
touchPoint.setScreenPos(ev->globalPos());
|
|
|
|
touchPoint.setPos(ev->pos());
|
|
|
|
touchPoint.setPressure(1);
|
|
|
|
|
|
|
|
// If the point already exists, update it. Otherwise create it.
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_touchPoints.size() > 0 && !m_touchPoints[0].id()) {
|
2011-11-05 21:27:01 +01:00
|
|
|
m_touchPoints[0] = touchPoint;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (m_touchPoints.size() > 1 && !m_touchPoints[1].id()) {
|
2011-11-05 21:27:01 +01:00
|
|
|
m_touchPoints[1] = touchPoint;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-11-05 21:27:01 +01:00
|
|
|
m_touchPoints.append(touchPoint);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-05 21:27:01 +01:00
|
|
|
|
|
|
|
if (!m_touchPoints.isEmpty()) {
|
|
|
|
QEvent::Type type = QEvent::TouchUpdate;
|
|
|
|
if (m_touchPoints.size() == 1) {
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_touchPoints[0].state() == Qt::TouchPointReleased) {
|
2011-11-05 21:27:01 +01:00
|
|
|
type = QEvent::TouchEnd;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (m_touchPoints[0].state() == Qt::TouchPointPressed) {
|
2011-11-05 21:27:01 +01:00
|
|
|
type = QEvent::TouchBegin;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-05 21:27:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QTouchEvent touchEv(type);
|
|
|
|
touchEv.setTouchPoints(m_touchPoints);
|
|
|
|
QCoreApplication::sendEvent(page(), &touchEv);
|
|
|
|
|
|
|
|
// After sending the event, remove all touchpoints that were released
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_touchPoints[0].state() == Qt::TouchPointReleased) {
|
2011-11-05 21:27:01 +01:00
|
|
|
m_touchPoints.removeAt(0);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (m_touchPoints.size() > 1 && m_touchPoints[1].state() == Qt::TouchPointReleased) {
|
2011-11-05 21:27:01 +01:00
|
|
|
m_touchPoints.removeAt(1);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-05 21:27:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-06 12:05:16 +01:00
|
|
|
|
|
|
|
return QWebView::eventFilter(obj, event);
|
2011-11-05 21:27:01 +01:00
|
|
|
}
|
|
|
|
|