1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42:10 +02:00

WebTab: Fix detaching completer and site icon

Fixes crash when detaching tab and closing the originating window.
This commit is contained in:
David Rosca 2018-01-31 10:30:28 +01:00
parent 67973d704d
commit 2b994920ad
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
7 changed files with 54 additions and 34 deletions

View File

@ -30,12 +30,12 @@ void WebTabTest::cleanupTestCase()
void WebTabTest::parentChildTabsTest()
{
WebTab tab1(mApp->getWindow());
WebTab tab2(mApp->getWindow());
WebTab tab3(mApp->getWindow());
WebTab tab4(mApp->getWindow());
WebTab tab5(mApp->getWindow());
WebTab tab6(mApp->getWindow());
WebTab tab1;
WebTab tab2;
WebTab tab3;
WebTab tab4;
WebTab tab5;
WebTab tab6;
tab1.addChildTab(&tab2);
QCOMPARE(tab1.childTabs(), QVector<WebTab*>{&tab2});

View File

@ -42,9 +42,9 @@
#include <QContextMenuEvent>
#include <QStyleOptionFrameV3>
LocationBar::LocationBar(BrowserWindow* window)
: LineEdit(window)
, m_window(window)
LocationBar::LocationBar(QWidget *parent)
: LineEdit(parent)
, m_window(nullptr)
, m_webView(0)
, m_holdingAlt(false)
, m_oldTextLength(0)
@ -60,7 +60,7 @@ LocationBar::LocationBar(BrowserWindow* window)
m_bookmarkIcon = new BookmarksIcon(this);
m_goIcon = new GoIcon(this);
m_siteIcon = new SiteIcon(m_window, this);
m_siteIcon = new SiteIcon(this);
m_autofillIcon = new AutoFillIcon(this);
DownIcon* down = new DownIcon(this);
@ -71,7 +71,6 @@ LocationBar::LocationBar(BrowserWindow* window)
addWidget(down, LineEdit::RightSide);
m_completer = new LocationCompleter(this);
m_completer->setMainWindow(m_window);
m_completer->setLocationBar(this);
connect(m_completer, SIGNAL(showCompletion(QString,bool)), this, SLOT(showCompletion(QString,bool)));
connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString)));
@ -112,6 +111,18 @@ LocationBar::LocationBar(BrowserWindow* window)
QTimer::singleShot(0, this, SLOT(updatePlaceHolderText()));
}
BrowserWindow *LocationBar::browserWindow() const
{
return m_window;
}
void LocationBar::setBrowserWindow(BrowserWindow *window)
{
m_window = window;
m_completer->setMainWindow(m_window);
m_siteIcon->setBrowserWindow(m_window);
}
TabbedWebView* LocationBar::webView() const
{
return m_webView;
@ -475,7 +486,7 @@ void LocationBar::focusInEvent(QFocusEvent* event)
clearTextFormat();
LineEdit::focusInEvent(event);
if (Settings().value("Browser-View-Settings/instantBookmarksToolbar").toBool()) {
if (m_window && Settings().value("Browser-View-Settings/instantBookmarksToolbar").toBool()) {
m_window->bookmarksToolbar()->show();
}
}
@ -498,7 +509,7 @@ void LocationBar::focusOutEvent(QFocusEvent* event)
refreshTextFormat();
if (Settings().value("Browser-View-Settings/instantBookmarksToolbar").toBool()) {
if (m_window && Settings().value("Browser-View-Settings/instantBookmarksToolbar").toBool()) {
m_window->bookmarksToolbar()->hide();
}
}
@ -577,7 +588,9 @@ void LocationBar::keyPressEvent(QKeyEvent* event)
case Qt::AltModifier:
m_completer->closePopup();
m_window->tabWidget()->addView(loadAction(text()).loadRequest);
if (m_window) {
m_window->tabWidget()->addView(loadAction(text()).loadRequest);
}
m_holdingAlt = false;
break;

View File

@ -40,7 +40,7 @@ class FALKON_EXPORT LocationBar : public LineEdit
Q_OBJECT
public:
explicit LocationBar(BrowserWindow* window);
explicit LocationBar(QWidget *parent = nullptr);
struct LoadAction {
enum Type {
@ -55,6 +55,10 @@ public:
LoadRequest loadRequest;
};
// BrowserWindow can be null!
BrowserWindow *browserWindow() const;
void setBrowserWindow(BrowserWindow *window);
TabbedWebView* webView() const;
void setWebView(TabbedWebView* view);

View File

@ -28,9 +28,9 @@
#include <QApplication>
#include <QContextMenuEvent>
SiteIcon::SiteIcon(BrowserWindow* window, LocationBar* parent)
SiteIcon::SiteIcon(LocationBar *parent)
: ToolButton(parent)
, m_window(window)
, m_window(nullptr)
, m_locationBar(parent)
, m_view(0)
{
@ -46,6 +46,11 @@ SiteIcon::SiteIcon(BrowserWindow* window, LocationBar* parent)
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateIcon()));
}
void SiteIcon::setBrowserWindow(BrowserWindow *window)
{
m_window = window;
}
void SiteIcon::setWebView(WebView* view)
{
m_view = view;

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
*
* 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
@ -32,8 +32,9 @@ class FALKON_EXPORT SiteIcon : public ToolButton
Q_OBJECT
public:
explicit SiteIcon(BrowserWindow* window, LocationBar* parent);
explicit SiteIcon(LocationBar *parent);
void setBrowserWindow(BrowserWindow *window);
void setWebView(WebView* view);
void setIcon(const QIcon &icon);

View File

@ -114,20 +114,16 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
return stream;
}
WebTab::WebTab(BrowserWindow* window)
: QWidget()
, m_window(window)
, m_tabBar(0)
, m_isPinned(false)
WebTab::WebTab(QWidget *parent)
: QWidget(parent)
{
setObjectName(QSL("webtab"));
m_webView = new TabbedWebView(this);
m_webView->setBrowserWindow(m_window);
m_webView->setPage(new WebPage);
m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
m_locationBar = new LocationBar(m_window);
m_locationBar = new LocationBar(this);
m_locationBar->setWebView(m_webView);
m_tabIcon = new TabIcon(this);
@ -298,15 +294,15 @@ void WebTab::detach()
// Remove the tab from tabbar
m_window->tabWidget()->removeTab(tabIndex());
setParent(0);
setParent(nullptr);
// Remove the locationbar from window
m_locationBar->setParent(this);
// Detach TabbedWebView
m_webView->setBrowserWindow(0);
m_webView->setBrowserWindow(nullptr);
// WebTab is now standalone widget
m_window = 0;
m_tabBar = 0;
m_window = nullptr;
m_tabBar = nullptr;
}
void WebTab::attach(BrowserWindow* window)
@ -315,6 +311,7 @@ void WebTab::attach(BrowserWindow* window)
m_tabBar = m_window->tabWidget()->tabBar();
m_webView->setBrowserWindow(m_window);
m_locationBar->setBrowserWindow(m_window);
m_tabBar->setTabText(tabIndex(), title());
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), m_tabIcon);
m_tabIcon->updateIcon();

View File

@ -58,7 +58,7 @@ public:
friend FALKON_EXPORT QDataStream &operator>>(QDataStream &stream, SavedTab &tab);
};
explicit WebTab(BrowserWindow* window);
explicit WebTab(QWidget *parent = nullptr);
TabbedWebView* webView() const;
LocationBar* locationBar() const;
@ -130,7 +130,6 @@ private:
void titleWasChanged(const QString &title);
void resizeEvent(QResizeEvent *event) override;
BrowserWindow* m_window;
QVBoxLayout* m_layout;
QSplitter* m_splitter;
@ -138,14 +137,15 @@ private:
WebInspector* m_inspector;
LocationBar* m_locationBar;
TabIcon* m_tabIcon;
TabBar* m_tabBar;
QWidget *m_notificationWidget;
BrowserWindow* m_window = nullptr;
TabBar* m_tabBar = nullptr;
WebTab *m_parentTab = nullptr;
QVector<WebTab*> m_childTabs;
SavedTab m_savedTab;
bool m_isPinned;
bool m_isPinned = false;
};
#endif // WEBTAB_H