1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Add support for HTML FullScreen

Esc is used to leave fullscreen
This commit is contained in:
David Rosca 2015-10-05 17:39:52 +02:00
parent 637f38684d
commit 949faa5856
11 changed files with 72 additions and 2 deletions

View File

@ -114,6 +114,7 @@ BrowserWindow::BrowserWindow(Qz::BrowserWindowType type, const QUrl &startUrl)
, m_startTab(0) , m_startTab(0)
, m_sideBarManager(new SideBarManager(this)) , m_sideBarManager(new SideBarManager(this))
, m_statusBarMessage(new StatusBarMessage(this)) , m_statusBarMessage(new StatusBarMessage(this))
, m_isHtmlFullScreen(false)
, m_hideNavigationTimer(0) , m_hideNavigationTimer(0)
{ {
setObjectName("mainwindow"); setObjectName("mainwindow");
@ -799,6 +800,12 @@ void BrowserWindow::toggleOfflineMode()
qzSettings->workOffline = enable; qzSettings->workOffline = enable;
} }
void BrowserWindow::enterHtmlFullScreen()
{
showFullScreen();
m_isHtmlFullScreen = true;
}
void BrowserWindow::showWebInspector() void BrowserWindow::showWebInspector()
{ {
if (weView() && weView()->webTab()) { if (weView() && weView()->webTab()) {
@ -1023,6 +1030,9 @@ bool BrowserWindow::fullScreenNavigationVisible() const
void BrowserWindow::showNavigationWithFullScreen() void BrowserWindow::showNavigationWithFullScreen()
{ {
if (m_isHtmlFullScreen)
return;
if (m_hideNavigationTimer->isActive()) { if (m_hideNavigationTimer->isActive()) {
m_hideNavigationTimer->stop(); m_hideNavigationTimer->stop();
} }
@ -1080,6 +1090,7 @@ bool BrowserWindow::event(QEvent* event)
m_navigationContainer->show(); m_navigationContainer->show();
m_navigationToolbar->setSuperMenuVisible(!m_menuBarVisible); m_navigationToolbar->setSuperMenuVisible(!m_menuBarVisible);
m_navigationToolbar->buttonExitFullscreen()->setVisible(false); m_navigationToolbar->buttonExitFullscreen()->setVisible(false);
m_isHtmlFullScreen = false;
} }
if (m_hideNavigationTimer) { if (m_hideNavigationTimer) {

View File

@ -132,6 +132,7 @@ public slots:
void toggleFullScreen(); void toggleFullScreen();
void toggleOfflineMode(); void toggleOfflineMode();
void enterHtmlFullScreen();
void loadActionUrl(QObject* obj = 0); void loadActionUrl(QObject* obj = 0);
void loadActionUrlInNewTab(QObject* obj = 0); void loadActionUrlInNewTab(QObject* obj = 0);
@ -210,6 +211,7 @@ private:
// Remember visibility of menubar and statusbar after entering Fullscreen // Remember visibility of menubar and statusbar after entering Fullscreen
bool m_menuBarVisible; bool m_menuBarVisible;
bool m_statusBarVisible; bool m_statusBarVisible;
bool m_isHtmlFullScreen;
Qt::WindowStates m_windowStates; Qt::WindowStates m_windowStates;
QTimer* m_hideNavigationTimer; QTimer* m_hideNavigationTimer;

View File

@ -877,6 +877,7 @@ void MainApplication::loadSettings()
webSettings->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, settings.value("SpatialNavigation", false).toBool()); webSettings->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, settings.value("SpatialNavigation", false).toBool());
webSettings->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, settings.value("AnimateScrolling", true).toBool()); webSettings->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, settings.value("AnimateScrolling", true).toBool());
webSettings->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, false); webSettings->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, false);
webSettings->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
webSettings->setDefaultTextEncoding(settings.value("DefaultEncoding", webSettings->defaultTextEncoding()).toString()); webSettings->setDefaultTextEncoding(settings.value("DefaultEncoding", webSettings->defaultTextEncoding()).toString());

View File

@ -59,6 +59,19 @@ void PopupWebView::closeView()
parentWidget()->close(); parentWidget()->close();
} }
bool PopupWebView::isFullScreen()
{
return parentWidget()->isFullScreen();
}
void PopupWebView::requestFullScreen(bool enable)
{
if (enable)
parentWidget()->showFullScreen();
else
parentWidget()->showNormal();
}
void PopupWebView::inspectElement() void PopupWebView::inspectElement()
{ {
WebInspector *inspector = new WebInspector; WebInspector *inspector = new WebInspector;

View File

@ -33,10 +33,11 @@ public:
QWidget* overlayWidget() Q_DECL_OVERRIDE; QWidget* overlayWidget() Q_DECL_OVERRIDE;
void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE; void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE;
signals: void closeView() Q_DECL_OVERRIDE;
bool isFullScreen() Q_DECL_OVERRIDE;
void requestFullScreen(bool enable) Q_DECL_OVERRIDE;
public slots: public slots:
void closeView();
void inspectElement(); void inspectElement();
private: private:

View File

@ -81,6 +81,7 @@ WebPage::WebPage(QObject* parent)
connect(this, &QWebEnginePage::urlChanged, this, &WebPage::urlChanged); connect(this, &QWebEnginePage::urlChanged, this, &WebPage::urlChanged);
connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::featurePermissionRequested); connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::featurePermissionRequested);
connect(this, &QWebEnginePage::windowCloseRequested, this, &WebPage::windowCloseRequested); connect(this, &QWebEnginePage::windowCloseRequested, this, &WebPage::windowCloseRequested);
connect(this, &QWebEnginePage::fullScreenRequested, this, &WebPage::fullScreenRequested);
connect(this, &QWebEnginePage::authenticationRequired, this, [this](const QUrl &url, QAuthenticator *auth) { connect(this, &QWebEnginePage::authenticationRequired, this, [this](const QUrl &url, QAuthenticator *auth) {
mApp->networkManager()->authentication(url, auth, view()); mApp->networkManager()->authentication(url, auth, view());
@ -316,11 +317,21 @@ void WebPage::windowCloseRequested()
view()->closeView(); view()->closeView();
} }
void WebPage::fullScreenRequested(bool fullScreen)
{
view()->requestFullScreen(fullScreen);
}
void WebPage::featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature) void WebPage::featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature)
{ {
mApp->html5PermissionsManager()->requestPermissions(this, origin, feature); mApp->html5PermissionsManager()->requestPermissions(this, origin, feature);
} }
bool WebPage::isFullScreen()
{
return view()->isFullScreen();
}
bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{ {
m_lastRequestUrl = url; m_lastRequestUrl = url;

View File

@ -87,9 +87,11 @@ private slots:
void urlChanged(const QUrl &url); void urlChanged(const QUrl &url);
void watchedFileChanged(const QString &file); void watchedFileChanged(const QString &file);
void windowCloseRequested(); void windowCloseRequested();
void fullScreenRequested(bool fullScreen);
void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature); void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature);
private: private:
bool isFullScreen() Q_DECL_OVERRIDE;
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE; bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE;
bool certificateError(const QWebEngineCertificateError &error) Q_DECL_OVERRIDE; bool certificateError(const QWebEngineCertificateError &error) Q_DECL_OVERRIDE;
QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE; QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE;

View File

@ -1077,6 +1077,13 @@ void WebView::_keyPressEvent(QKeyEvent *event)
} }
break; break;
case Qt::Key_Escape:
if (isFullScreen()) {
triggerPageAction(QWebEnginePage::ExitFullScreen);
event->accept();
}
break;
default: default:
break; break;
} }

View File

@ -107,6 +107,9 @@ public slots:
virtual void closeView() = 0; virtual void closeView() = 0;
virtual void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) = 0; virtual void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) = 0;
virtual bool isFullScreen() = 0;
virtual void requestFullScreen(bool enable) = 0;
protected slots: protected slots:
void slotLoadStarted(); void slotLoadStarted();
void slotLoadProgress(int progress); void slotLoadProgress(int progress);

View File

@ -174,6 +174,22 @@ void TabbedWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags
} }
} }
bool TabbedWebView::isFullScreen()
{
return m_window && m_window->isFullScreen();
}
void TabbedWebView::requestFullScreen(bool enable)
{
if (!m_window)
return;
if (enable)
m_window->enterHtmlFullScreen();
else
m_window->showNormal();
}
void TabbedWebView::setAsCurrentTab() void TabbedWebView::setAsCurrentTab()
{ {
if (m_window) { if (m_window) {

View File

@ -51,6 +51,9 @@ public:
void closeView() Q_DECL_OVERRIDE; void closeView() Q_DECL_OVERRIDE;
void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE; void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE;
bool isFullScreen() Q_DECL_OVERRIDE;
void requestFullScreen(bool enable) Q_DECL_OVERRIDE;
signals: signals:
void wantsCloseTab(int); void wantsCloseTab(int);
void ipChanged(QString); void ipChanged(QString);