mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
WebTab: Fix detaching completer and site icon
Fixes crash when detaching tab and closing the originating window.
This commit is contained in:
parent
67973d704d
commit
2b994920ad
|
@ -30,12 +30,12 @@ void WebTabTest::cleanupTestCase()
|
||||||
|
|
||||||
void WebTabTest::parentChildTabsTest()
|
void WebTabTest::parentChildTabsTest()
|
||||||
{
|
{
|
||||||
WebTab tab1(mApp->getWindow());
|
WebTab tab1;
|
||||||
WebTab tab2(mApp->getWindow());
|
WebTab tab2;
|
||||||
WebTab tab3(mApp->getWindow());
|
WebTab tab3;
|
||||||
WebTab tab4(mApp->getWindow());
|
WebTab tab4;
|
||||||
WebTab tab5(mApp->getWindow());
|
WebTab tab5;
|
||||||
WebTab tab6(mApp->getWindow());
|
WebTab tab6;
|
||||||
|
|
||||||
tab1.addChildTab(&tab2);
|
tab1.addChildTab(&tab2);
|
||||||
QCOMPARE(tab1.childTabs(), QVector<WebTab*>{&tab2});
|
QCOMPARE(tab1.childTabs(), QVector<WebTab*>{&tab2});
|
||||||
|
|
|
@ -42,9 +42,9 @@
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
#include <QStyleOptionFrameV3>
|
#include <QStyleOptionFrameV3>
|
||||||
|
|
||||||
LocationBar::LocationBar(BrowserWindow* window)
|
LocationBar::LocationBar(QWidget *parent)
|
||||||
: LineEdit(window)
|
: LineEdit(parent)
|
||||||
, m_window(window)
|
, m_window(nullptr)
|
||||||
, m_webView(0)
|
, m_webView(0)
|
||||||
, m_holdingAlt(false)
|
, m_holdingAlt(false)
|
||||||
, m_oldTextLength(0)
|
, m_oldTextLength(0)
|
||||||
|
@ -60,7 +60,7 @@ LocationBar::LocationBar(BrowserWindow* window)
|
||||||
|
|
||||||
m_bookmarkIcon = new BookmarksIcon(this);
|
m_bookmarkIcon = new BookmarksIcon(this);
|
||||||
m_goIcon = new GoIcon(this);
|
m_goIcon = new GoIcon(this);
|
||||||
m_siteIcon = new SiteIcon(m_window, this);
|
m_siteIcon = new SiteIcon(this);
|
||||||
m_autofillIcon = new AutoFillIcon(this);
|
m_autofillIcon = new AutoFillIcon(this);
|
||||||
DownIcon* down = new DownIcon(this);
|
DownIcon* down = new DownIcon(this);
|
||||||
|
|
||||||
|
@ -71,7 +71,6 @@ LocationBar::LocationBar(BrowserWindow* window)
|
||||||
addWidget(down, LineEdit::RightSide);
|
addWidget(down, LineEdit::RightSide);
|
||||||
|
|
||||||
m_completer = new LocationCompleter(this);
|
m_completer = new LocationCompleter(this);
|
||||||
m_completer->setMainWindow(m_window);
|
|
||||||
m_completer->setLocationBar(this);
|
m_completer->setLocationBar(this);
|
||||||
connect(m_completer, SIGNAL(showCompletion(QString,bool)), this, SLOT(showCompletion(QString,bool)));
|
connect(m_completer, SIGNAL(showCompletion(QString,bool)), this, SLOT(showCompletion(QString,bool)));
|
||||||
connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString)));
|
connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString)));
|
||||||
|
@ -112,6 +111,18 @@ LocationBar::LocationBar(BrowserWindow* window)
|
||||||
QTimer::singleShot(0, this, SLOT(updatePlaceHolderText()));
|
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
|
TabbedWebView* LocationBar::webView() const
|
||||||
{
|
{
|
||||||
return m_webView;
|
return m_webView;
|
||||||
|
@ -475,7 +486,7 @@ void LocationBar::focusInEvent(QFocusEvent* event)
|
||||||
clearTextFormat();
|
clearTextFormat();
|
||||||
LineEdit::focusInEvent(event);
|
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();
|
m_window->bookmarksToolbar()->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -498,7 +509,7 @@ void LocationBar::focusOutEvent(QFocusEvent* event)
|
||||||
|
|
||||||
refreshTextFormat();
|
refreshTextFormat();
|
||||||
|
|
||||||
if (Settings().value("Browser-View-Settings/instantBookmarksToolbar").toBool()) {
|
if (m_window && Settings().value("Browser-View-Settings/instantBookmarksToolbar").toBool()) {
|
||||||
m_window->bookmarksToolbar()->hide();
|
m_window->bookmarksToolbar()->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -577,7 +588,9 @@ void LocationBar::keyPressEvent(QKeyEvent* event)
|
||||||
|
|
||||||
case Qt::AltModifier:
|
case Qt::AltModifier:
|
||||||
m_completer->closePopup();
|
m_completer->closePopup();
|
||||||
m_window->tabWidget()->addView(loadAction(text()).loadRequest);
|
if (m_window) {
|
||||||
|
m_window->tabWidget()->addView(loadAction(text()).loadRequest);
|
||||||
|
}
|
||||||
m_holdingAlt = false;
|
m_holdingAlt = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class FALKON_EXPORT LocationBar : public LineEdit
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LocationBar(BrowserWindow* window);
|
explicit LocationBar(QWidget *parent = nullptr);
|
||||||
|
|
||||||
struct LoadAction {
|
struct LoadAction {
|
||||||
enum Type {
|
enum Type {
|
||||||
|
@ -55,6 +55,10 @@ public:
|
||||||
LoadRequest loadRequest;
|
LoadRequest loadRequest;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// BrowserWindow can be null!
|
||||||
|
BrowserWindow *browserWindow() const;
|
||||||
|
void setBrowserWindow(BrowserWindow *window);
|
||||||
|
|
||||||
TabbedWebView* webView() const;
|
TabbedWebView* webView() const;
|
||||||
void setWebView(TabbedWebView* view);
|
void setWebView(TabbedWebView* view);
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
|
|
||||||
SiteIcon::SiteIcon(BrowserWindow* window, LocationBar* parent)
|
SiteIcon::SiteIcon(LocationBar *parent)
|
||||||
: ToolButton(parent)
|
: ToolButton(parent)
|
||||||
, m_window(window)
|
, m_window(nullptr)
|
||||||
, m_locationBar(parent)
|
, m_locationBar(parent)
|
||||||
, m_view(0)
|
, m_view(0)
|
||||||
{
|
{
|
||||||
|
@ -46,6 +46,11 @@ SiteIcon::SiteIcon(BrowserWindow* window, LocationBar* parent)
|
||||||
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateIcon()));
|
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateIcon()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SiteIcon::setBrowserWindow(BrowserWindow *window)
|
||||||
|
{
|
||||||
|
m_window = window;
|
||||||
|
}
|
||||||
|
|
||||||
void SiteIcon::setWebView(WebView* view)
|
void SiteIcon::setWebView(WebView* view)
|
||||||
{
|
{
|
||||||
m_view = view;
|
m_view = view;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* 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
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SiteIcon(BrowserWindow* window, LocationBar* parent);
|
explicit SiteIcon(LocationBar *parent);
|
||||||
|
|
||||||
|
void setBrowserWindow(BrowserWindow *window);
|
||||||
void setWebView(WebView* view);
|
void setWebView(WebView* view);
|
||||||
void setIcon(const QIcon &icon);
|
void setIcon(const QIcon &icon);
|
||||||
|
|
||||||
|
|
|
@ -114,20 +114,16 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebTab::WebTab(BrowserWindow* window)
|
WebTab::WebTab(QWidget *parent)
|
||||||
: QWidget()
|
: QWidget(parent)
|
||||||
, m_window(window)
|
|
||||||
, m_tabBar(0)
|
|
||||||
, m_isPinned(false)
|
|
||||||
{
|
{
|
||||||
setObjectName(QSL("webtab"));
|
setObjectName(QSL("webtab"));
|
||||||
|
|
||||||
m_webView = new TabbedWebView(this);
|
m_webView = new TabbedWebView(this);
|
||||||
m_webView->setBrowserWindow(m_window);
|
|
||||||
m_webView->setPage(new WebPage);
|
m_webView->setPage(new WebPage);
|
||||||
m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||||
|
|
||||||
m_locationBar = new LocationBar(m_window);
|
m_locationBar = new LocationBar(this);
|
||||||
m_locationBar->setWebView(m_webView);
|
m_locationBar->setWebView(m_webView);
|
||||||
|
|
||||||
m_tabIcon = new TabIcon(this);
|
m_tabIcon = new TabIcon(this);
|
||||||
|
@ -298,15 +294,15 @@ void WebTab::detach()
|
||||||
|
|
||||||
// Remove the tab from tabbar
|
// Remove the tab from tabbar
|
||||||
m_window->tabWidget()->removeTab(tabIndex());
|
m_window->tabWidget()->removeTab(tabIndex());
|
||||||
setParent(0);
|
setParent(nullptr);
|
||||||
// Remove the locationbar from window
|
// Remove the locationbar from window
|
||||||
m_locationBar->setParent(this);
|
m_locationBar->setParent(this);
|
||||||
// Detach TabbedWebView
|
// Detach TabbedWebView
|
||||||
m_webView->setBrowserWindow(0);
|
m_webView->setBrowserWindow(nullptr);
|
||||||
|
|
||||||
// WebTab is now standalone widget
|
// WebTab is now standalone widget
|
||||||
m_window = 0;
|
m_window = nullptr;
|
||||||
m_tabBar = 0;
|
m_tabBar = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebTab::attach(BrowserWindow* window)
|
void WebTab::attach(BrowserWindow* window)
|
||||||
|
@ -315,6 +311,7 @@ void WebTab::attach(BrowserWindow* window)
|
||||||
m_tabBar = m_window->tabWidget()->tabBar();
|
m_tabBar = m_window->tabWidget()->tabBar();
|
||||||
|
|
||||||
m_webView->setBrowserWindow(m_window);
|
m_webView->setBrowserWindow(m_window);
|
||||||
|
m_locationBar->setBrowserWindow(m_window);
|
||||||
m_tabBar->setTabText(tabIndex(), title());
|
m_tabBar->setTabText(tabIndex(), title());
|
||||||
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), m_tabIcon);
|
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), m_tabIcon);
|
||||||
m_tabIcon->updateIcon();
|
m_tabIcon->updateIcon();
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
friend FALKON_EXPORT QDataStream &operator>>(QDataStream &stream, SavedTab &tab);
|
friend FALKON_EXPORT QDataStream &operator>>(QDataStream &stream, SavedTab &tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit WebTab(BrowserWindow* window);
|
explicit WebTab(QWidget *parent = nullptr);
|
||||||
|
|
||||||
TabbedWebView* webView() const;
|
TabbedWebView* webView() const;
|
||||||
LocationBar* locationBar() const;
|
LocationBar* locationBar() const;
|
||||||
|
@ -130,7 +130,6 @@ private:
|
||||||
void titleWasChanged(const QString &title);
|
void titleWasChanged(const QString &title);
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
BrowserWindow* m_window;
|
|
||||||
QVBoxLayout* m_layout;
|
QVBoxLayout* m_layout;
|
||||||
QSplitter* m_splitter;
|
QSplitter* m_splitter;
|
||||||
|
|
||||||
|
@ -138,14 +137,15 @@ private:
|
||||||
WebInspector* m_inspector;
|
WebInspector* m_inspector;
|
||||||
LocationBar* m_locationBar;
|
LocationBar* m_locationBar;
|
||||||
TabIcon* m_tabIcon;
|
TabIcon* m_tabIcon;
|
||||||
TabBar* m_tabBar;
|
|
||||||
QWidget *m_notificationWidget;
|
QWidget *m_notificationWidget;
|
||||||
|
BrowserWindow* m_window = nullptr;
|
||||||
|
TabBar* m_tabBar = nullptr;
|
||||||
|
|
||||||
WebTab *m_parentTab = nullptr;
|
WebTab *m_parentTab = nullptr;
|
||||||
QVector<WebTab*> m_childTabs;
|
QVector<WebTab*> m_childTabs;
|
||||||
|
|
||||||
SavedTab m_savedTab;
|
SavedTab m_savedTab;
|
||||||
bool m_isPinned;
|
bool m_isPinned = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBTAB_H
|
#endif // WEBTAB_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user