2012-01-21 20:27:45 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2017-08-23 11:32:26 +02:00
|
|
|
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
|
2012-01-21 20:27:45 +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/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "tabbedwebview.h"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "webpage.h"
|
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "tabbar.h"
|
|
|
|
#include "webtab.h"
|
|
|
|
#include "statusbarmessage.h"
|
|
|
|
#include "progressbar.h"
|
|
|
|
#include "navigationbar.h"
|
|
|
|
#include "iconprovider.h"
|
|
|
|
#include "searchenginesmanager.h"
|
2012-01-24 23:28:18 +01:00
|
|
|
#include "enhancedmenu.h"
|
2012-02-04 18:45:59 +01:00
|
|
|
#include "adblockicon.h"
|
2014-02-12 13:48:34 +01:00
|
|
|
#include "locationbar.h"
|
2015-09-29 23:15:46 +02:00
|
|
|
#include "webhittestresult.h"
|
2016-04-05 09:19:57 +02:00
|
|
|
#include "webinspector.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QHostInfo>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QContextMenuEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-04-04 17:03:44 +02:00
|
|
|
TabbedWebView::TabbedWebView(WebTab* webTab)
|
2012-01-21 20:27:45 +01:00
|
|
|
: WebView(webTab)
|
2014-04-04 17:03:44 +02:00
|
|
|
, m_window(0)
|
2012-01-21 20:27:45 +01:00
|
|
|
, m_webTab(webTab)
|
2012-01-24 23:28:18 +01:00
|
|
|
, m_menu(new Menu(this))
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
2014-02-10 21:34:46 +01:00
|
|
|
m_menu->setCloseOnMiddleClick(true);
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
|
2014-04-01 18:47:19 +02:00
|
|
|
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
|
2012-01-21 20:27:45 +01:00
|
|
|
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
|
|
|
|
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::setWebPage(WebPage* page)
|
|
|
|
{
|
2012-04-03 20:23:15 +02:00
|
|
|
page->setParent(this);
|
|
|
|
setPage(page);
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2015-05-22 23:30:51 +02:00
|
|
|
connect(page, &WebPage::linkHovered, this, &TabbedWebView::linkHovered);
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
2014-04-04 17:03:44 +02:00
|
|
|
BrowserWindow* TabbedWebView::browserWindow() const
|
|
|
|
{
|
|
|
|
return m_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::setBrowserWindow(BrowserWindow* window)
|
|
|
|
{
|
|
|
|
m_window = window;
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void TabbedWebView::inspectElement()
|
|
|
|
{
|
2015-10-15 17:19:16 +02:00
|
|
|
if (m_webTab->haveInspector())
|
|
|
|
triggerPageAction(QWebEnginePage::InspectElement);
|
|
|
|
else
|
|
|
|
m_webTab->showWebInspector(true);
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
WebTab* TabbedWebView::webTab() const
|
|
|
|
{
|
|
|
|
return m_webTab;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TabbedWebView::getIp() const
|
|
|
|
{
|
|
|
|
return m_currentIp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::urlChanged(const QUrl &url)
|
|
|
|
{
|
2015-09-08 11:24:16 +02:00
|
|
|
Q_UNUSED(url)
|
|
|
|
|
2014-04-04 17:03:44 +02:00
|
|
|
if (m_webTab->isCurrentTab() && m_window) {
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window->navigationBar()->refreshHistory();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:47:19 +02:00
|
|
|
void TabbedWebView::slotLoadProgress(int prog)
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
2013-02-10 14:09:11 +01:00
|
|
|
Q_UNUSED(prog)
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2014-04-04 17:03:44 +02:00
|
|
|
if (m_webTab->isCurrentTab() && m_window) {
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window->updateLoadingActions();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
void TabbedWebView::userLoadAction(const LoadRequest &req)
|
2012-07-13 11:04:14 +02:00
|
|
|
{
|
2015-10-06 09:46:23 +02:00
|
|
|
load(req);
|
2012-07-13 11:04:14 +02:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
void TabbedWebView::slotLoadStarted()
|
|
|
|
{
|
|
|
|
m_currentIp.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::slotLoadFinished()
|
|
|
|
{
|
|
|
|
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
|
|
|
|
|
2014-04-04 17:03:44 +02:00
|
|
|
if (m_webTab->isCurrentTab() && m_window) {
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window->updateLoadingActions();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::setIp(const QHostInfo &info)
|
|
|
|
{
|
|
|
|
if (info.addresses().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
m_currentIp = QString("%1 (%2)").arg(info.hostName(), info.addresses().at(0).toString());
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2014-03-18 20:00:34 +01:00
|
|
|
if (m_webTab->isCurrentTab()) {
|
2012-01-21 20:27:45 +01:00
|
|
|
emit ipChanged(m_currentIp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-22 23:30:51 +02:00
|
|
|
void TabbedWebView::linkHovered(const QString &link)
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
2014-04-04 17:03:44 +02:00
|
|
|
if (m_webTab->isCurrentTab() && m_window) {
|
2012-09-02 11:42:41 +02:00
|
|
|
if (link.isEmpty()) {
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window->statusBarMessage()->clearMessage();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window->statusBarMessage()->showMessage(link);
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabbedWebView::tabIndex() const
|
|
|
|
{
|
2014-04-01 18:47:19 +02:00
|
|
|
return m_webTab->tabIndex();
|
2013-05-12 22:55:53 +02:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:32:55 +02:00
|
|
|
QWidget* TabbedWebView::overlayWidget()
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
|
|
|
return m_webTab;
|
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
void TabbedWebView::closeView()
|
|
|
|
{
|
|
|
|
emit wantsCloseTab(tabIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position)
|
|
|
|
{
|
2014-04-04 17:03:44 +02:00
|
|
|
if (m_window) {
|
2014-04-11 22:23:42 +02:00
|
|
|
int index = m_window->tabWidget()->addView(QUrl(), position);
|
2014-04-04 17:03:44 +02:00
|
|
|
m_window->weView(index)->webTab()->locationBar()->showUrl(req.url());
|
|
|
|
m_window->weView(index)->load(req);
|
|
|
|
}
|
2014-03-19 21:27:43 +01:00
|
|
|
}
|
|
|
|
|
2015-10-05 17:39:52 +02:00
|
|
|
bool TabbedWebView::isFullScreen()
|
|
|
|
{
|
|
|
|
return m_window && m_window->isFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::requestFullScreen(bool enable)
|
|
|
|
{
|
|
|
|
if (!m_window)
|
|
|
|
return;
|
|
|
|
|
2017-08-23 11:32:26 +02:00
|
|
|
m_window->toggleHtmlFullScreen(enable);
|
2015-10-05 17:39:52 +02:00
|
|
|
}
|
|
|
|
|
2013-02-10 10:38:12 +01:00
|
|
|
void TabbedWebView::setAsCurrentTab()
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
2014-04-11 22:23:42 +02:00
|
|
|
if (m_window) {
|
|
|
|
m_window->tabWidget()->setCurrentWidget(m_webTab);
|
|
|
|
}
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void TabbedWebView::_contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
|
|
|
m_menu->clear();
|
|
|
|
|
2016-12-26 17:23:52 +01:00
|
|
|
WebHitTestResult hitTest = page()->hitTestContent(event->pos());
|
2015-09-29 23:15:46 +02:00
|
|
|
createContextMenu(m_menu, hitTest);
|
|
|
|
|
|
|
|
if (!hitTest.isContentEditable() && !hitTest.isContentSelected() && m_window) {
|
|
|
|
m_menu->addAction(m_window->adBlockIcon()->menuAction());
|
|
|
|
}
|
|
|
|
|
2016-04-05 09:19:57 +02:00
|
|
|
if (WebInspector::isEnabled()) {
|
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(tr("Inspect Element"), this, SLOT(inspectElement()));
|
|
|
|
}
|
2015-09-29 23:15:46 +02:00
|
|
|
|
|
|
|
if (!m_menu->isEmpty()) {
|
|
|
|
// Prevent choosing first option with double rightclick
|
|
|
|
const QPoint pos = event->globalPos();
|
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
|
|
|
|
|
|
|
m_menu->popup(p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView::_contextMenuEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
void TabbedWebView::_mouseMoveEvent(QMouseEvent *event)
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
2014-04-04 17:03:44 +02:00
|
|
|
if (m_window && m_window->isFullScreen()) {
|
2014-02-19 22:07:21 +01:00
|
|
|
if (m_window->fullScreenNavigationVisible()) {
|
|
|
|
m_window->hideNavigationWithFullScreen();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
else if (event->y() < 5) {
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window->showNavigationWithFullScreen();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-05 13:16:34 +01:00
|
|
|
|
2015-09-29 17:21:49 +02:00
|
|
|
WebView::_mouseMoveEvent(event);
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|