From 16d5917d43ba0b2837f6e2f63f35d2802ad0ea53 Mon Sep 17 00:00:00 2001
From: nowrep
Date: Sun, 12 May 2013 22:55:53 +0200
Subject: [PATCH] [Code] Make it possible to move TabbedWebView to other
window.
---
src/lib/popupwindow/popupwebpage.cpp | 7 ++++-
src/lib/popupwindow/popupwebpage.h | 4 +--
src/lib/webview/tabbedwebview.cpp | 43 +++++++++++++++++++---------
src/lib/webview/tabbedwebview.h | 8 +++---
src/lib/webview/webpage.cpp | 21 +++++++++-----
src/lib/webview/webpage.h | 3 +-
src/lib/webview/webtab.cpp | 10 ++++++-
src/lib/webview/webtab.h | 2 ++
tests/popupwindows.html | 4 +--
9 files changed, 69 insertions(+), 33 deletions(-)
diff --git a/src/lib/popupwindow/popupwebpage.cpp b/src/lib/popupwindow/popupwebpage.cpp
index d3054d812..16a79efdb 100644
--- a/src/lib/popupwindow/popupwebpage.cpp
+++ b/src/lib/popupwindow/popupwebpage.cpp
@@ -32,7 +32,7 @@
// Got an idea how to determine it from kWebKitPart.
PopupWebPage::PopupWebPage(QWebPage::WebWindowType type, QupZilla* mainClass)
- : WebPage(mainClass)
+ : WebPage()
, p_QupZilla(mainClass)
, m_type(type)
, m_createNewWindow(false)
@@ -54,6 +54,11 @@ PopupWebPage::PopupWebPage(QWebPage::WebWindowType type, QupZilla* mainClass)
QTimer::singleShot(0, this, SLOT(checkBehaviour()));
}
+QupZilla* PopupWebPage::mainWindow() const
+{
+ return p_QupZilla;
+}
+
void PopupWebPage::slotGeometryChangeRequested(const QRect &rect)
{
if (rect.isValid()) {
diff --git a/src/lib/popupwindow/popupwebpage.h b/src/lib/popupwindow/popupwebpage.h
index 8b8c6cbd3..acc969e1d 100644
--- a/src/lib/popupwindow/popupwebpage.h
+++ b/src/lib/popupwindow/popupwebpage.h
@@ -29,9 +29,7 @@ class QT_QUPZILLA_EXPORT PopupWebPage : public WebPage
public:
explicit PopupWebPage(WebWindowType type, QupZilla* mainClass);
-signals:
-
-public slots:
+ QupZilla* mainWindow() const;
private slots:
void slotGeometryChangeRequested(const QRect &rect);
diff --git a/src/lib/webview/tabbedwebview.cpp b/src/lib/webview/tabbedwebview.cpp
index 91645b91a..580b2568e 100644
--- a/src/lib/webview/tabbedwebview.cpp
+++ b/src/lib/webview/tabbedwebview.cpp
@@ -40,7 +40,6 @@
TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab)
: WebView(webTab)
, p_QupZilla(mainClass)
- , m_tabWidget(p_QupZilla->tabWidget())
, m_webTab(webTab)
, m_menu(new Menu(this))
, m_mouseTrack(false)
@@ -54,7 +53,6 @@ TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab)
connect(this, SIGNAL(iconChanged()), this, SLOT(showIcon()));
connect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
-
connect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
// Tracking mouse also on tabs created in fullscreen
@@ -83,7 +81,7 @@ WebTab* TabbedWebView::webTab() const
TabWidget* TabbedWebView::tabWidget() const
{
- return m_tabWidget;
+ return p_QupZilla->tabWidget();
}
QString TabbedWebView::getIp() const
@@ -93,7 +91,7 @@ QString TabbedWebView::getIp() const
bool TabbedWebView::isCurrent()
{
- WebTab* webTab = qobject_cast(m_tabWidget->widget(m_tabWidget->currentIndex()));
+ WebTab* webTab = qobject_cast(tabWidget()->widget(tabWidget()->currentIndex()));
if (!webTab) {
return false;
}
@@ -131,10 +129,10 @@ void TabbedWebView::userLoadAction(const QUrl &url)
void TabbedWebView::slotLoadStarted()
{
- m_tabWidget->startTabAnimation(tabIndex());
+ tabWidget()->startTabAnimation(tabIndex());
if (title().isNull()) {
- m_tabWidget->setTabText(tabIndex(), tr("Loading..."));
+ tabWidget()->setTabText(tabIndex(), tr("Loading..."));
}
m_currentIp.clear();
@@ -142,7 +140,7 @@ void TabbedWebView::slotLoadStarted()
void TabbedWebView::slotLoadFinished()
{
- m_tabWidget->stopTabAnimation(tabIndex());
+ tabWidget()->stopTabAnimation(tabIndex());
showIcon();
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
@@ -173,7 +171,7 @@ void TabbedWebView::titleChanged()
p_QupZilla->setWindowTitle(tr("%1 - QupZilla").arg(t));
}
- m_tabWidget->setTabText(tabIndex(), t);
+ tabWidget()->setTabText(tabIndex(), t);
}
void TabbedWebView::showIcon()
@@ -187,7 +185,7 @@ void TabbedWebView::showIcon()
icon_ = qIconProvider->emptyWebIcon();
}
- m_tabWidget->setTabIcon(tabIndex(), icon_);
+ tabWidget()->setTabIcon(tabIndex(), icon_);
}
void TabbedWebView::linkHovered(const QString &link, const QString &title, const QString &content)
@@ -207,7 +205,26 @@ void TabbedWebView::linkHovered(const QString &link, const QString &title, const
int TabbedWebView::tabIndex() const
{
- return m_tabWidget->indexOf(m_webTab);
+ return tabWidget()->indexOf(m_webTab);
+}
+
+QupZilla* TabbedWebView::mainWindow() const
+{
+ return p_QupZilla;
+}
+
+void TabbedWebView::moveToWindow(QupZilla* window)
+{
+ disconnect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
+ disconnect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
+
+ p_QupZilla = window;
+
+ connect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
+ connect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
+
+ // Tracking mouse also on tabs created in fullscreen
+ trackMouse(p_QupZilla->isFullScreen());
}
QWidget* TabbedWebView::overlayForJsAlert()
@@ -259,17 +276,17 @@ void TabbedWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag pos
req.setRawHeader("Referer", url().toEncoded());
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
- m_tabWidget->addView(req, position);
+ tabWidget()->addView(req, position);
}
void TabbedWebView::openNewTab()
{
- m_tabWidget->addView(QUrl());
+ tabWidget()->addView(QUrl());
}
void TabbedWebView::setAsCurrentTab()
{
- m_tabWidget->setCurrentWidget(m_webTab);
+ tabWidget()->setCurrentWidget(m_webTab);
}
void TabbedWebView::mouseMoveEvent(QMouseEvent* event)
diff --git a/src/lib/webview/tabbedwebview.h b/src/lib/webview/tabbedwebview.h
index 32e505696..b0d1f6d4e 100644
--- a/src/lib/webview/tabbedwebview.h
+++ b/src/lib/webview/tabbedwebview.h
@@ -45,6 +45,9 @@ public:
QString getIp() const;
int tabIndex() const;
+ QupZilla* mainWindow() const;
+ void moveToWindow(QupZilla* window);
+
QWidget* overlayForJsAlert();
void disconnectObjects();
@@ -85,13 +88,10 @@ private:
bool isCurrent();
QupZilla* p_QupZilla;
- TabWidget* m_tabWidget;
-
- QString m_currentIp;
-
WebTab* m_webTab;
Menu* m_menu;
+ QString m_currentIp;
bool m_mouseTrack;
};
diff --git a/src/lib/webview/webpage.cpp b/src/lib/webview/webpage.cpp
index 80bb9764d..cd07d2634 100644
--- a/src/lib/webview/webpage.cpp
+++ b/src/lib/webview/webpage.cpp
@@ -65,9 +65,8 @@ QUrl WebPage::s_lastUnsupportedUrl;
QTime WebPage::s_lastUnsupportedUrlTime;
QList WebPage::s_livingPages;
-WebPage::WebPage(QupZilla* mainClass)
- : QWebPage()
- , p_QupZilla(mainClass)
+WebPage::WebPage(QObject* parent)
+ : QWebPage(parent)
, m_view(0)
, m_speedDial(mApp->plugins()->speedDial())
, m_fileWatcher(0)
@@ -548,7 +547,15 @@ void WebPage::populateNetworkRequest(QNetworkRequest &request)
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
{
- return new PopupWebPage(type, p_QupZilla);
+ if (m_view) {
+ return new PopupWebPage(type, m_view->mainWindow());
+ }
+
+ if (PopupWebPage* popupPage = qobject_cast(this)) {
+ return new PopupWebPage(type, popupPage->mainWindow());
+ }
+
+ return 0;
}
QObject* WebPage::createPlugin(const QString &classid, const QUrl &url,
@@ -558,8 +565,8 @@ QObject* WebPage::createPlugin(const QString &classid, const QUrl &url,
Q_UNUSED(paramNames)
Q_UNUSED(paramValues)
- if (classid == QLatin1String("RecoveryWidget") && mApp->restoreManager()) {
- return new RecoveryWidget(qobject_cast(view()), p_QupZilla);
+ if (classid == QLatin1String("RecoveryWidget") && mApp->restoreManager() && m_view) {
+ return new RecoveryWidget(m_view, m_view->mainWindow());
}
else {
mainFrame()->load(QUrl("qupzilla:start"));
@@ -787,7 +794,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
WebView* view = qobject_cast(popupPage->view());
if (view) {
// Closing blocked popup
- p_QupZilla->adBlockIcon()->popupBlocked(rule, exOption->url);
+ popupPage->mainWindow()->adBlockIcon()->popupBlocked(rule, exOption->url);
view->closeView();
}
}
diff --git a/src/lib/webview/webpage.h b/src/lib/webview/webpage.h
index edd48474b..ddae698fe 100644
--- a/src/lib/webview/webpage.h
+++ b/src/lib/webview/webpage.h
@@ -48,7 +48,7 @@ public:
}
};
- WebPage(QupZilla* mainClass);
+ WebPage(QObject* parent = 0);
~WebPage();
QUrl url() const;
@@ -129,7 +129,6 @@ private:
static QTime s_lastUnsupportedUrlTime;
static QList s_livingPages;
- QupZilla* p_QupZilla;
NetworkManagerProxy* m_networkProxy;
TabbedWebView* m_view;
SpeedDial* m_speedDial;
diff --git a/src/lib/webview/webtab.cpp b/src/lib/webview/webtab.cpp
index 267c2ca22..ed0b42179 100644
--- a/src/lib/webview/webtab.cpp
+++ b/src/lib/webview/webtab.cpp
@@ -107,7 +107,7 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar)
m_view = new TabbedWebView(p_QupZilla, this);
m_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
- WebPage* page = new WebPage(p_QupZilla);
+ WebPage* page = new WebPage;
m_view->setWebPage(page);
m_layout->addWidget(m_view);
@@ -176,6 +176,14 @@ QWebHistory* WebTab::history() const
return m_view->history();
}
+void WebTab::moveToWindow(QupZilla* window)
+{
+ p_QupZilla = window;
+
+ m_view->moveToWindow(p_QupZilla);
+ //m_view->page()->moveToWindow(p_QupZilla);
+}
+
void WebTab::setHistoryData(const QByteArray &data)
{
QDataStream historyStream(data);
diff --git a/src/lib/webview/webtab.h b/src/lib/webview/webtab.h
index c9f555825..2ae182bf2 100644
--- a/src/lib/webview/webtab.h
+++ b/src/lib/webview/webtab.h
@@ -64,6 +64,8 @@ public:
QIcon icon() const;
QWebHistory* history() const;
+ void moveToWindow(QupZilla* window);
+
void setHistoryData(const QByteArray &data);
QByteArray historyData() const;
diff --git a/tests/popupwindows.html b/tests/popupwindows.html
index 70a19ae9d..01384921a 100644
--- a/tests/popupwindows.html
+++ b/tests/popupwindows.html
@@ -32,8 +32,8 @@
- with width, height, left and top
-Popup 6
-- with menubar
+Popup 6
+- with menubar (popupwindows.html)
Popup 7