1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Fix initial focus when opening new browser window

Web page is now correctly focused when opening browser window
or opening/restoring sessions.

This is still not absolutely reliable solution as it uses delay
to change focus to webview, because QWebEngineView doesn't accept
focus until after it is initialized.
This commit is contained in:
David Rosca 2017-12-03 11:41:16 +01:00
parent b03c5f3cb0
commit ee5a11ae72
2 changed files with 16 additions and 10 deletions

View File

@ -230,16 +230,7 @@ void BrowserWindow::postLaunch()
raise();
activateWindow();
QTimer::singleShot(0, this, [this]() {
// Scroll to current tab
tabWidget()->tabBar()->ensureVisible();
// Update focus
if (!m_startPage && LocationBar::convertUrlToText(weView()->page()->requestedUrl()).isEmpty())
locationBar()->setFocus();
else
weView()->setFocus();
});
updateStartupFocus();
}
void BrowserWindow::setupUi()
@ -383,6 +374,19 @@ void BrowserWindow::setupMenu()
connect(inspectorAction, SIGNAL(activated()), this, SLOT(toggleWebInspector()));
}
void BrowserWindow::updateStartupFocus()
{
QTimer::singleShot(500, this, [this]() {
// Scroll to current tab
tabWidget()->tabBar()->ensureVisible();
// Update focus
if (!m_startPage && LocationBar::convertUrlToText(weView()->page()->requestedUrl()).isEmpty())
locationBar()->setFocus();
else
weView()->setFocus();
});
}
QAction* BrowserWindow::createEncodingAction(const QString &codecName,
const QString &activeCodecName, QMenu* menu)
{
@ -884,6 +888,7 @@ void BrowserWindow::restoreWindowState(const RestoreManager::WindowData &d)
{
restoreState(d.windowState);
m_tabWidget->restoreState(d.tabsState, d.currentTab);
updateStartupFocus();
}
void BrowserWindow::createToolbarsMenu(QMenu* menu)

View File

@ -170,6 +170,7 @@ private:
void setupUi();
void setupMenu();
void updateStartupFocus();
QAction *createEncodingAction(const QString &codecName, const QString &activeCodecName,
QMenu *menu);