2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-12-15 18:34:48 +01:00
|
|
|
* Copyright (C) 2010-2011 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 "qupzilla.h"
|
|
|
|
#include "webpage.h"
|
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "historymodel.h"
|
|
|
|
#include "locationbar.h"
|
|
|
|
#include "downloadmanager.h"
|
|
|
|
#include "networkmanager.h"
|
|
|
|
#include "autofillmodel.h"
|
|
|
|
#include "networkmanagerproxy.h"
|
2011-03-19 13:15:01 +01:00
|
|
|
#include "networkmanager.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "tabbar.h"
|
|
|
|
#include "pluginproxy.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "webtab.h"
|
2011-05-09 17:58:19 +02:00
|
|
|
#include "statusbarmessage.h"
|
2011-07-11 20:30:49 +02:00
|
|
|
#include "progressbar.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "navigationbar.h"
|
2011-10-21 23:26:34 +02:00
|
|
|
#include "searchenginesmanager.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-05-22 10:47:03 +02:00
|
|
|
WebView::WebView(QupZilla* mainClass, WebTab* webTab)
|
2011-07-19 15:18:49 +02:00
|
|
|
: QWebView(webTab)
|
2011-10-29 18:37:28 +02:00
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_aboutToLoadUrl(QUrl())
|
|
|
|
, m_lastUrl(QUrl())
|
2011-10-30 17:20:22 +01:00
|
|
|
, m_progress(0)
|
|
|
|
, m_currentZoom(100)
|
2011-10-29 18:37:28 +02:00
|
|
|
, m_page(new WebPage(this, p_QupZilla))
|
|
|
|
, m_webTab(webTab)
|
|
|
|
, m_locationBar(0)
|
2011-12-06 19:18:06 +01:00
|
|
|
, m_menu(new QMenu(this))
|
2011-10-29 18:37:28 +02:00
|
|
|
, m_mouseTrack(false)
|
|
|
|
, m_navigationVisible(false)
|
|
|
|
, m_mouseWheelEnabled(true)
|
2011-10-30 17:20:22 +01:00
|
|
|
, m_wantsClose(false)
|
|
|
|
, m_isLoading(false)
|
|
|
|
, m_hasRss(false)
|
|
|
|
, m_rssChecked(false)
|
2011-10-29 18:37:28 +02:00
|
|
|
// , m_loadingTimer(0)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-12-04 19:15:44 +01:00
|
|
|
m_networkProxy = new NetworkManagerProxy(this);
|
2011-03-04 13:59:07 +01:00
|
|
|
m_networkProxy->setPrimaryNetworkAccessManager(mApp->networkManager());
|
2011-12-04 19:15:44 +01:00
|
|
|
m_networkProxy->setPage(m_page);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_networkProxy->setView(this);
|
|
|
|
m_page->setNetworkAccessManager(m_networkProxy);
|
|
|
|
m_page->setView(this);
|
|
|
|
setPage(m_page);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
|
|
|
|
connect(this, SIGNAL(loadProgress(int)), this, SLOT(setProgress(int)));
|
|
|
|
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
|
|
|
|
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
|
2011-03-18 15:01:01 +01:00
|
|
|
connect(this, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged()));
|
2011-03-31 16:01:59 +02:00
|
|
|
connect(this, SIGNAL(iconChanged()), this, SLOT(slotIconChanged()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
connect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
|
|
|
|
|
|
|
|
connect(page(), SIGNAL(linkHovered(QString, QString, QString)), this, SLOT(linkHovered(QString, QString, QString)));
|
|
|
|
connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(closeTab()));
|
|
|
|
connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequested(const QNetworkRequest &)));
|
|
|
|
|
2011-03-04 13:59:07 +01:00
|
|
|
connect(mApp->networkManager(), SIGNAL(finishLoading(bool)), this, SLOT(loadFinished(bool)));
|
|
|
|
connect(mApp->networkManager(), SIGNAL(wantsFocus(QUrl)), this, SLOT(getFocus(QUrl)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-04-22 07:45:15 +02:00
|
|
|
connect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
|
|
|
|
|
2011-10-29 18:37:28 +02:00
|
|
|
// Tracking mouse also on tabs created in fullscreen
|
2011-10-24 17:46:45 +02:00
|
|
|
trackMouse(p_QupZilla->isFullScreen());
|
|
|
|
|
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-10-29 18:37:28 +02:00
|
|
|
// Set default zoom
|
|
|
|
m_currentZoom = mApp->defaultZoom();
|
|
|
|
applyZoom();
|
2011-11-05 21:27:01 +01:00
|
|
|
|
|
|
|
qApp->installEventFilter(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-31 16:01:59 +02:00
|
|
|
void WebView::slotIconChanged()
|
|
|
|
{
|
2011-04-04 16:00:27 +02:00
|
|
|
m_siteIcon = icon();
|
2011-04-26 10:03:17 +02:00
|
|
|
|
2011-12-03 15:51:08 +01:00
|
|
|
if (url().scheme() == "file" || title().contains(tr("Failed loading page"))) {
|
2011-04-26 10:03:17 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-26 10:03:17 +02:00
|
|
|
|
|
|
|
mApp->iconProvider()->saveIcon(this);
|
2011-03-31 16:01:59 +02:00
|
|
|
}
|
|
|
|
|
2011-11-27 15:43:54 +01:00
|
|
|
void WebView::copyText()
|
|
|
|
{
|
|
|
|
if (!selectedText().isEmpty()) {
|
|
|
|
QApplication::clipboard()->setText(selectedText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-22 21:36:15 +01:00
|
|
|
WebPage* WebView::webPage() const
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
return m_page;
|
|
|
|
}
|
|
|
|
|
2011-10-29 23:01:17 +02:00
|
|
|
void WebView::back()
|
|
|
|
{
|
|
|
|
if (page()) {
|
|
|
|
emit ipChanged(m_currentIp);
|
|
|
|
p_QupZilla->navigationBar()->goBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::forward()
|
|
|
|
{
|
|
|
|
if (page()) {
|
|
|
|
emit ipChanged(m_currentIp);
|
|
|
|
p_QupZilla->navigationBar()->goForward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::slotReload()
|
|
|
|
{
|
|
|
|
if (page()) {
|
|
|
|
emit ipChanged(m_currentIp);
|
|
|
|
page()->triggerAction(QWebPage::Reload);
|
|
|
|
}
|
|
|
|
}
|
2011-05-22 10:47:03 +02:00
|
|
|
|
|
|
|
WebTab* WebView::webTab() const
|
|
|
|
{
|
|
|
|
return m_webTab;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
bool WebView::isCurrent()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!tabWidget()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-03 15:54:12 +01:00
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(tabWidget()->widget(tabWidget()->currentIndex()));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!webTab) {
|
2011-03-03 15:54:12 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-03 15:54:12 +01:00
|
|
|
return (webTab->view() == this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::urlChanged(const QUrl &url)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (isCurrent()) {
|
2011-09-11 19:15:06 +02:00
|
|
|
p_QupZilla->navigationBar()->refreshHistory();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-15 18:08:52 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_lastUrl != url) {
|
2011-03-29 20:30:05 +02:00
|
|
|
emit changed();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-15 18:08:52 +02:00
|
|
|
|
|
|
|
emit showUrl(url);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::linkClicked(const QUrl &url)
|
|
|
|
{
|
2011-07-31 13:33:44 +02:00
|
|
|
load(url);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::setProgress(int prog)
|
|
|
|
{
|
|
|
|
m_progress = prog;
|
2011-10-30 17:20:22 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (prog > 60) {
|
2011-10-30 17:20:22 +01:00
|
|
|
checkRss();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
|
|
|
if (isCurrent()) {
|
|
|
|
p_QupZilla->ipLabel()->hide();
|
|
|
|
p_QupZilla->progressBar()->setVisible(true);
|
|
|
|
p_QupZilla->progressBar()->setValue(m_progress);
|
2011-09-11 19:15:06 +02:00
|
|
|
p_QupZilla->navigationBar()->showStopButton();
|
2011-07-11 20:30:49 +02:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::loadStarted()
|
|
|
|
{
|
|
|
|
m_progress = 0;
|
|
|
|
m_isLoading = true;
|
2011-10-30 17:20:22 +01:00
|
|
|
m_rssChecked = false;
|
|
|
|
emit rssChanged(false);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
animationLoading(tabIndex(), true);
|
2011-10-30 17:20:22 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title().isNull()) {
|
|
|
|
tabWidget()->setTabText(tabIndex(), tr("Loading..."));
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
m_currentIp.clear();
|
|
|
|
|
|
|
|
// if (m_loadingTimer)
|
|
|
|
// delete m_loadingTimer;
|
|
|
|
// m_loadingTimer = new QTimer();
|
|
|
|
// connect(m_loadingTimer, SIGNAL(timeout()), this, SLOT(stopAnimation()));
|
|
|
|
// m_loadingTimer->start(1000*20); //20 seconds timeout to automatically "stop" loading animation
|
|
|
|
}
|
|
|
|
|
2011-12-04 16:54:57 +01:00
|
|
|
void WebView::loadFinished(bool state)
|
|
|
|
{
|
|
|
|
Q_UNUSED(state);
|
|
|
|
|
|
|
|
if (mApp->isClosing() || p_QupZilla->isClosing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animationLoading(tabIndex(), false)->movie()) {
|
|
|
|
animationLoading(tabIndex(), false)->movie()->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_isLoading = false;
|
|
|
|
|
|
|
|
if (m_lastUrl != url()) {
|
|
|
|
mApp->history()->addHistoryEntry(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit showUrl(url());
|
|
|
|
|
|
|
|
iconChanged();
|
|
|
|
m_lastUrl = url();
|
|
|
|
|
|
|
|
//Icon is sometimes not available at the moment of finished loading
|
|
|
|
if (icon().isNull()) {
|
|
|
|
QTimer::singleShot(1000, this, SLOT(iconChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
titleChanged();
|
|
|
|
mApp->autoFill()->completePage(this);
|
|
|
|
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
|
|
|
|
|
|
|
|
if (isCurrent()) {
|
|
|
|
p_QupZilla->progressBar()->setVisible(false);
|
|
|
|
p_QupZilla->navigationBar()->showReloadButton();
|
|
|
|
p_QupZilla->ipLabel()->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit urlChanged(url());
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
QLabel* WebView::animationLoading(int index, bool addMovie)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (-1 == index) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return 0;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
QLabel* loadingAnimation = qobject_cast<QLabel*>(tabWidget()->getTabBar()->tabButton(index, QTabBar::LeftSide));
|
2011-03-02 16:57:41 +01:00
|
|
|
if (!loadingAnimation) {
|
2011-03-26 13:34:08 +01:00
|
|
|
loadingAnimation = new QLabel();
|
2011-12-07 21:32:47 +01:00
|
|
|
// loadingAnimation->setStyleSheet("margin: 0px; padding: 0px; width: 16px; height: 16px;");
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
if (addMovie && !loadingAnimation->movie()) {
|
2011-03-17 17:03:04 +01:00
|
|
|
QMovie* movie = new QMovie(":icons/other/progress.gif", QByteArray(), loadingAnimation);
|
2011-03-02 16:57:41 +01:00
|
|
|
movie->setSpeed(70);
|
|
|
|
loadingAnimation->setMovie(movie);
|
|
|
|
movie->start();
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
else if (loadingAnimation->movie()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
loadingAnimation->movie()->stop();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
tabWidget()->getTabBar()->setTabButton(index, QTabBar::LeftSide, 0);
|
|
|
|
tabWidget()->getTabBar()->setTabButton(index, QTabBar::LeftSide, loadingAnimation);
|
|
|
|
return loadingAnimation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::stopAnimation()
|
|
|
|
{
|
|
|
|
//m_loadingTimer->stop();
|
|
|
|
QMovie* mov = animationLoading(tabIndex(), false)->movie();
|
|
|
|
if (mov) {
|
|
|
|
mov->stop();
|
|
|
|
}
|
2011-12-20 18:58:42 +01:00
|
|
|
|
|
|
|
iconChanged();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-04-24 09:08:53 +02:00
|
|
|
void WebView::setIp(const QHostInfo &info)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (info.addresses().isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
m_currentIp = info.hostName() + " (" + info.addresses().at(0).toString() + ")";
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (isCurrent()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
emit ipChanged(m_currentIp);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 15:01:01 +01:00
|
|
|
void WebView::titleChanged()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-03-18 15:01:01 +01:00
|
|
|
QString title_ = title();
|
|
|
|
QString title2 = title_;
|
2011-11-06 17:01:23 +01:00
|
|
|
tabWidget()->setTabToolTip(tabIndex(), title2);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-15 16:37:32 +02:00
|
|
|
title2 += " - QupZilla";
|
2011-11-06 17:01:23 +01:00
|
|
|
if (isCurrent()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla->setWindowTitle(title2);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-15 16:37:32 +02:00
|
|
|
tabWidget()->setTabText(tabIndex(), title_);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::iconChanged()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (mApp->isClosing() || p_QupZilla->isClosing()) {
|
2011-09-11 19:15:06 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2011-10-24 17:46:45 +02:00
|
|
|
// if (isCurrent())
|
2011-11-06 17:01:23 +01:00
|
|
|
emit siteIconChanged();
|
2011-10-15 16:37:32 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_isLoading) {
|
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
|
|
|
|
2011-04-04 16:00:27 +02:00
|
|
|
QIcon icon_ = siteIcon();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!icon_.isNull()) {
|
|
|
|
animationLoading(tabIndex(), false)->setPixmap(icon_.pixmap(16, 16));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
animationLoading(tabIndex(), false)->setPixmap(IconProvider::fromTheme("text-plain").pixmap(16, 16));
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-04-04 17:03:41 +02:00
|
|
|
QIcon WebView::siteIcon()
|
|
|
|
{
|
2011-12-07 21:32:47 +01:00
|
|
|
if (url().scheme() == "qupzilla") {
|
|
|
|
return QIcon(":icons/qupzilla.png");
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!icon().isNull()) {
|
2011-04-04 17:03:41 +02:00
|
|
|
return icon();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (!m_siteIcon.isNull()) {
|
2011-04-05 18:45:17 +02:00
|
|
|
return m_siteIcon;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-07 21:32:47 +01:00
|
|
|
|
2011-04-25 20:56:45 +02:00
|
|
|
return _iconForUrl(url());
|
2011-04-04 17:03:41 +02:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void WebView::linkHovered(const QString &link, const QString &title, const QString &content)
|
|
|
|
{
|
2011-12-04 16:54:57 +01:00
|
|
|
Q_UNUSED(title)
|
|
|
|
Q_UNUSED(content)
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
if (isCurrent()) {
|
2011-11-06 17:01:23 +01:00
|
|
|
if (link != "") {
|
2011-05-09 17:58:19 +02:00
|
|
|
p_QupZilla->statusBarMessage()->showMessage(link);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-05-09 17:58:19 +02:00
|
|
|
p_QupZilla->statusBarMessage()->clearMessage();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
m_hoveredLink = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabWidget* WebView::tabWidget() const
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
QObject* widget = this->parent();
|
2011-03-02 16:57:41 +01:00
|
|
|
while (widget) {
|
2011-11-06 17:01:23 +01:00
|
|
|
if (TabWidget* tw = qobject_cast<TabWidget*>(widget)) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return tw;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
widget = widget->parent();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebView::tabIndex() const
|
|
|
|
{
|
|
|
|
TabWidget* tabWid = tabWidget();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!tabWid) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return -1;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
int i = 0;
|
2011-11-06 17:01:23 +01:00
|
|
|
while (qobject_cast<WebTab*>(tabWid->widget(i))->view() != this) {
|
2011-03-02 16:57:41 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-03-03 14:25:02 +01:00
|
|
|
void WebView::checkRss()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_rssChecked) {
|
2011-10-30 17:20:22 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-30 17:20:22 +01:00
|
|
|
|
|
|
|
m_rssChecked = true;
|
2011-03-03 14:25:02 +01:00
|
|
|
QWebFrame* frame = page()->mainFrame();
|
2011-10-30 17:20:22 +01:00
|
|
|
QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]");
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2011-10-30 17:20:22 +01:00
|
|
|
m_hasRss = links.count() != 0;
|
|
|
|
emit rssChanged(m_hasRss);
|
2011-03-03 14:25:02 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebView::contextMenuEvent(QContextMenuEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->clear();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!r.linkUrl().isEmpty() && r.linkUrl().scheme() != "javascript") {
|
|
|
|
if (page()->selectedText() == r.linkText()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
findText("");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addAction(QIcon(":/icons/menu/popup.png"), tr("Open link in new &tab"), this, SLOT(openUrlInNewTab()))->setData(r.linkUrl());
|
|
|
|
m_menu->addAction(tr("Open link in new &window"), this, SLOT(openUrlInNewWindow()))->setData(r.linkUrl());
|
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(IconProvider::fromTheme("user-bookmarks"), tr("B&ookmark link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl());
|
|
|
|
m_menu->addAction(QIcon::fromTheme("document-save"), tr("&Save link as..."), this, SLOT(downloadLinkToDisk()))->setData(r.linkUrl());
|
|
|
|
m_menu->addAction(tr("Send link..."), this, SLOT(sendLinkByMail()))->setData(r.linkUrl());
|
|
|
|
m_menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy link address"), this, SLOT(copyLinkToClipboard()))->setData(r.linkUrl());
|
|
|
|
m_menu->addSeparator();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!selectedText().isEmpty()) {
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addAction(pageAction(QWebPage::Copy));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!r.imageUrl().isEmpty()) {
|
2011-12-06 19:18:06 +01:00
|
|
|
if (!m_menu->isEmpty()) {
|
|
|
|
m_menu->addSeparator();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addAction(tr("Show i&mage"), this, SLOT(showImage()))->setData(r.imageUrl());
|
|
|
|
m_menu->addAction(tr("Copy im&age"), this, SLOT(copyImageToClipboard()))->setData(r.imageUrl());
|
|
|
|
m_menu->addAction(QIcon::fromTheme("edit-copy"), tr("Copy image ad&dress"), this, SLOT(copyLinkToClipboard()))->setData(r.imageUrl());
|
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(QIcon::fromTheme("document-save"), tr("&Save image as..."), this, SLOT(downloadImageToDisk()))->setData(r.imageUrl());
|
|
|
|
m_menu->addAction(tr("Send image..."), this, SLOT(sendLinkByMail()))->setData(r.linkUrl());
|
|
|
|
m_menu->addSeparator();
|
2011-03-02 16:57:41 +01:00
|
|
|
//menu->addAction(tr("Block image"), this, SLOT(blockImage()))->setData(r.imageUrl().toString());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!selectedText().isEmpty()) {
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addAction(pageAction(QWebPage::Copy));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QWebElement element = r.element();
|
2011-12-06 19:18:06 +01:00
|
|
|
if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea" ||
|
2011-12-08 21:52:03 +01:00
|
|
|
element.tagName().toLower() == "video" || element.tagName().toLower() == "audio")) {
|
2011-12-06 19:18:06 +01:00
|
|
|
if (m_menu->isEmpty()) {
|
|
|
|
page()->createStandardContextMenu()->popup(QCursor::pos());
|
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
if (m_menu->isEmpty()) {
|
|
|
|
QAction* action = m_menu->addAction(tr("&Back"), this, SLOT(back()));
|
2011-09-30 21:44:18 +02:00
|
|
|
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
2011-12-12 21:14:43 +01:00
|
|
|
action->setEnabled(history()->canGoBack());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
action = m_menu->addAction(tr("&Forward"), this, SLOT(forward()));
|
2011-09-30 21:44:18 +02:00
|
|
|
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowForward));
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
action->setEnabled(history()->canGoForward());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), this, SLOT(slotReload()));
|
|
|
|
action = m_menu->addAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("S&top"), this, SLOT(stop()));
|
2011-12-12 21:14:43 +01:00
|
|
|
action->setEnabled(isLoading());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(IconProvider::fromTheme("user-bookmarks"), tr("Book&mark page"), this, SLOT(bookmarkLink()));
|
|
|
|
m_menu->addAction(QIcon::fromTheme("document-save"), tr("&Save page as..."), this, SLOT(downloadLinkToDisk()))->setData(url());
|
|
|
|
m_menu->addAction(tr("Send page..."), this, SLOT(sendLinkByMail()))->setData(url());
|
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &all"), this, SLOT(selectAll()));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!selectedText().isEmpty()) {
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addAction(pageAction(QWebPage::Copy));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(QIcon::fromTheme("text-html"), tr("Show so&urce code"), this, SLOT(showSource()));
|
|
|
|
m_menu->addAction(QIcon::fromTheme("dialog-information"), tr("Show info ab&out site"), this, SLOT(showSiteInfo()))->setData(url());
|
|
|
|
m_menu->addAction(tr("Show Web &Inspector"), this, SLOT(showInspector()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
mApp->plugins()->populateWebViewMenu(m_menu, this, r);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-19 22:04:08 +02:00
|
|
|
if (!selectedText().isEmpty()) {
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addSeparator();
|
2011-03-02 16:57:41 +01:00
|
|
|
QString selectedText = page()->selectedText();
|
|
|
|
selectedText.truncate(20);
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
SearchEngine engine = mApp->searchEnginesManager()->activeEngine();
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->addAction(engine.icon, tr("Search \"%1 ..\" with %2").arg(selectedText, engine.name), this, SLOT(searchSelectedText()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:03 +01:00
|
|
|
#if (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0))
|
2011-12-13 21:15:07 +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
|
2011-12-13 19:18:05 +01:00
|
|
|
//
|
2011-07-19 22:04:08 +02:00
|
|
|
// if (!selectedHtml().isEmpty())
|
|
|
|
// menu->addAction(tr("Show source of selection"), this, SLOT(showSourceOfSelection()));
|
|
|
|
#endif
|
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
if (!m_menu->isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
//Prevent choosing first option with double rightclick
|
|
|
|
QPoint pos = QCursor::pos();
|
2011-11-06 17:01:23 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
2011-12-06 19:18:06 +01:00
|
|
|
m_menu->popup(p);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebView::contextMenuEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-07-21 17:16:53 +02:00
|
|
|
void WebView::stop()
|
|
|
|
{
|
|
|
|
if (page()) {
|
|
|
|
emit ipChanged(m_currentIp);
|
|
|
|
page()->triggerAction(QWebPage::Stop);
|
|
|
|
loadFinished(true);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_locationBar->text().isEmpty()) {
|
2011-12-13 19:18:05 +01:00
|
|
|
setFocus();
|
2011-12-11 11:07:26 +01:00
|
|
|
emit urlChanged(url());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-21 17:16:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebView::addNotification(QWidget* notif)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
emit showNotification(notif);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::openUrlInNewTab()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2011-12-23 17:32:55 +01:00
|
|
|
tabWidget()->addView(action->data().toUrl(), tr("New tab"), TabWidget::NewBackgroundTab);
|
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())) {
|
2011-03-04 13:59:07 +01:00
|
|
|
mApp->makeNewWindow(false, action->data().toString());
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
void WebView::searchSelectedText()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-10-21 23:26:34 +02:00
|
|
|
SearchEngine engine = mApp->searchEnginesManager()->activeEngine();
|
|
|
|
load(engine.url.replace("%s", selectedText()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::selectAll()
|
|
|
|
{
|
|
|
|
triggerPageAction(QWebPage::SelectAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::downloadImageToDisk()
|
|
|
|
{
|
2011-03-24 22:31:38 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
DownloadManager* dManager = mApp->downManager();
|
|
|
|
QNetworkRequest request(action->data().toUrl());
|
2011-11-08 15:20:53 +01:00
|
|
|
dManager->download(request, m_page, false);
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::copyImageToClipboard()
|
|
|
|
{
|
|
|
|
triggerPageAction(QWebPage::CopyImageToClipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showImage()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2011-03-02 16:57:41 +01:00
|
|
|
load(QUrl(action->data().toString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showSource()
|
|
|
|
{
|
|
|
|
p_QupZilla->showSource();
|
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:03 +01:00
|
|
|
#if (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0))
|
2011-07-19 22:04:08 +02:00
|
|
|
void WebView::showSourceOfSelection()
|
|
|
|
{
|
|
|
|
p_QupZilla->showSource(selectedHtml());
|
|
|
|
}
|
2011-08-19 15:57:51 +02:00
|
|
|
#endif
|
2011-07-19 22:04:08 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void WebView::downloadLinkToDisk()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QNetworkRequest request(action->data().toUrl());
|
2011-03-04 13:59:07 +01:00
|
|
|
DownloadManager* dManager = mApp->downManager();
|
2011-11-08 15:20:53 +01:00
|
|
|
dManager->download(request, m_page, false);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::downloadRequested(const QNetworkRequest &request)
|
|
|
|
{
|
2011-03-04 13:59:07 +01:00
|
|
|
DownloadManager* dManager = mApp->downManager();
|
2011-11-08 15:20:53 +01:00
|
|
|
dManager->download(request, m_page);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::bookmarkLink()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2011-11-06 17:01:23 +01:00
|
|
|
if (action->data().isNull()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla->bookmarkPage();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-07-30 17:57:14 +02:00
|
|
|
p_QupZilla->addBookmark(action->data().toUrl(), action->data().toString(), siteIcon());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showInspector()
|
|
|
|
{
|
2011-10-14 20:14:57 +02:00
|
|
|
p_QupZilla->showWebInspector();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::showSiteInfo()
|
|
|
|
{
|
|
|
|
p_QupZilla->showPageInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::applyZoom()
|
|
|
|
{
|
|
|
|
setZoomFactor(qreal(m_currentZoom) / 100.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::zoomIn()
|
|
|
|
{
|
|
|
|
int i = m_zoomLevels.indexOf(m_currentZoom);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (i < m_zoomLevels.count() - 1) {
|
2011-03-02 16:57:41 +01:00
|
|
|
m_currentZoom = m_zoomLevels[i + 1];
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
applyZoom();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::zoomOut()
|
|
|
|
{
|
|
|
|
int i = m_zoomLevels.indexOf(m_currentZoom);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (i > 0) {
|
2011-03-02 16:57:41 +01:00
|
|
|
m_currentZoom = m_zoomLevels[i - 1];
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
applyZoom();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::zoomReset()
|
|
|
|
{
|
|
|
|
m_currentZoom = 100;
|
|
|
|
applyZoom();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_mouseWheelEnabled) {
|
2011-05-22 10:47:03 +02:00
|
|
|
QWebView::wheelEvent(event);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::getFocus(const QUrl &urla)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (urla == url()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
tabWidget()->setCurrentWidget(this);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::closeTab()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_wantsClose) {
|
2011-03-02 16:57:41 +01:00
|
|
|
emit wantsCloseTab(tabIndex());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
else {
|
|
|
|
m_wantsClose = true;
|
2011-11-08 15:20:53 +01:00
|
|
|
QTimer::singleShot(100, this, SLOT(closeTab()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-24 09:08:53 +02:00
|
|
|
void WebView::load(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-09-18 15:35:44 +02:00
|
|
|
if (url.scheme() == "javascript") {
|
2011-03-02 16:57:41 +01:00
|
|
|
page()->mainFrame()->evaluateJavaScript(url.toString());
|
|
|
|
return;
|
|
|
|
}
|
2011-11-05 11:51:46 +01:00
|
|
|
|
2011-12-03 15:51:08 +01:00
|
|
|
if (url.scheme() == "data" || url.scheme() == "qrc") {
|
2011-11-05 11:51:46 +01:00
|
|
|
QWebView::load(url);
|
2011-12-11 11:07:26 +01:00
|
|
|
emit urlChanged(url);
|
2011-11-05 11:51:46 +01:00
|
|
|
m_aboutToLoadUrl = url;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
if (isUrlValid(url)) {
|
|
|
|
QWebView::load(url);
|
2011-12-11 11:07:26 +01:00
|
|
|
emit urlChanged(url);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_aboutToLoadUrl = url;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-03 15:51:08 +01:00
|
|
|
if (QFile::exists(url.toLocalFile())) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QWebView::load(url);
|
2011-12-11 11:07:26 +01:00
|
|
|
emit urlChanged(url);
|
2011-12-03 15:51:08 +01:00
|
|
|
}
|
2011-10-01 17:55:10 +02:00
|
|
|
else {
|
2011-10-21 23:26:34 +02:00
|
|
|
SearchEngine engine = mApp->searchEnginesManager()->activeEngine();
|
|
|
|
QString urlString = engine.url.replace("%s", url.toString());
|
2011-10-01 17:55:10 +02:00
|
|
|
QWebView::load(QUrl(urlString));
|
2011-12-11 11:07:26 +01:00
|
|
|
emit urlChanged(url);
|
2011-10-01 17:55:10 +02:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QUrl WebView::url() const
|
|
|
|
{
|
2011-11-08 15:20:53 +01:00
|
|
|
return QWebView::url();
|
2011-03-02 16:57:41 +01:00
|
|
|
QUrl ur = QWebView::url();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (ur.isEmpty() && !m_aboutToLoadUrl.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return m_aboutToLoadUrl;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return ur;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WebView::title() const
|
|
|
|
{
|
|
|
|
QString title = QWebView::title();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title.isEmpty()) {
|
2011-12-16 20:17:17 +01:00
|
|
|
title = url().toString(QUrl::RemoveFragment);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (title.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return tr("No Named Page");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-16 20:17:17 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::reload()
|
|
|
|
{
|
|
|
|
if (QWebView::url().isEmpty() && !m_aboutToLoadUrl.isEmpty()) {
|
2011-09-18 15:35:44 +02:00
|
|
|
// qDebug() << "loading about to load";
|
2011-03-02 16:57:41 +01:00
|
|
|
load(m_aboutToLoadUrl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QWebView::reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebView::isUrlValid(const QUrl &url)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.scheme() == "qupzilla") {
|
2011-09-18 15:35:44 +02:00
|
|
|
return true;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isValid() && !url.host().isEmpty() && !url.scheme().isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
void WebView::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::XButton1:
|
|
|
|
back();
|
|
|
|
break;
|
|
|
|
case Qt::XButton2:
|
|
|
|
forward();
|
|
|
|
break;
|
|
|
|
case Qt::MiddleButton:
|
|
|
|
if (isUrlValid(QUrl(m_hoveredLink))) {
|
|
|
|
tabWidget()->addView(QUrl::fromEncoded(m_hoveredLink.toUtf8()), tr("New tab"), TabWidget::NewBackgroundTab);
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
else {
|
|
|
|
QWebView::mouseDoubleClickEvent(event);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case Qt::LeftButton:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier && isUrlValid(QUrl(m_hoveredLink))) {
|
|
|
|
tabWidget()->addView(QUrl::fromEncoded(m_hoveredLink.toUtf8()), tr("New tab"), TabWidget::NewBackgroundTab);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
QWebView::mousePressEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->key()) {
|
|
|
|
case Qt::Key_C:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
|
|
|
copyText();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_A:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
|
|
|
selectAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebView::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QWebView::resizeEvent(event);
|
|
|
|
emit viewportResized(m_page->viewportSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
//Workaround for crash in mouseReleaseEvent when closing tab from javascript :/
|
|
|
|
if (!m_wantsClose) {
|
|
|
|
QWebView::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebView::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (m_mouseTrack) {
|
|
|
|
if (m_navigationVisible) {
|
|
|
|
m_navigationVisible = false;
|
|
|
|
p_QupZilla->showNavigationWithFullscreen();
|
|
|
|
}
|
|
|
|
else if (event->y() < 5) {
|
|
|
|
m_navigationVisible = true;
|
|
|
|
p_QupZilla->showNavigationWithFullscreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QWebView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
if (ev->type() == QEvent::MouseMove
|
2011-11-06 17:01:23 +01:00
|
|
|
&& !(ev->buttons() & Qt::LeftButton)) {
|
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
|
2011-11-06 17:01:23 +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
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
WebView::~WebView()
|
|
|
|
{
|
|
|
|
}
|