Commit 769b3a61 authored by Szabolcs David's avatar Szabolcs David
Browse files

Promote fullscreen API to 5.5 public


Introduce a new FullScreenRequest object as the parameter of the
fullScreenRequested signal and expose the isFullScreen property
as read-only. This makes the API harder to misuse.

Change-Id: Ibb072ec93843e6df265bd930e8721d244bc2f4bc
Reviewed-by: default avatarAndras Becsi <andras.becsi@theqtcompany.com>
Showing with 132 additions and 28 deletions
......@@ -52,12 +52,26 @@ ApplicationWindow {
id: browserWindow
property QtObject applicationRoot
property Item currentWebView: tabs.currentIndex < tabs.count ? tabs.getTab(tabs.currentIndex).item : null
property int previousVisibility: Window.Windowed
property bool isFullScreen: visibility == Window.FullScreen
onIsFullScreenChanged: {
// This is for the case where the system forces us to leave fullscreen.
if (currentWebView && !isFullScreen) {
currentWebView.state = ""
if (currentWebView.isFullScreen)
currentWebView.fullScreenCancelled()
}
}
width: 1300
height: 900
visible: true
title: currentWebView && currentWebView.title
// Make sure the Qt.WindowFullscreenButtonHint is set on OS X.
Component.onCompleted: flags = flags | Qt.WindowFullscreenButtonHint
// Create a styleItem to determine the platform.
// When using style "mac", ToolButtons are not supposed to accept focus.
StyleItem { id: styleItem }
......@@ -123,6 +137,13 @@ ApplicationWindow {
tabs.removeTab(tabs.currentIndex)
}
}
Action {
shortcut: "Escape"
onTriggered: {
if (browserWindow.isFullScreen)
browserWindow.visibility = browserWindow.previousVisibility
}
}
Action {
shortcut: "Ctrl+0"
onTriggered: currentWebView.zoomFactor = 1.0;
......@@ -289,6 +310,21 @@ ApplicationWindow {
}
}
states: [
State {
name: "FullScreen"
PropertyChanges {
target: tabs
frameVisible: false
tabsVisible: false
}
PropertyChanges {
target: navigationBar
visible: false
}
}
]
onCertificateError: {
error.defer()
sslDialog.enqueue(error)
......@@ -308,6 +344,18 @@ ApplicationWindow {
request.openIn(window.currentWebView)
}
}
onFullScreenRequested: {
if (request.toggleOn) {
webEngineView.state = "FullScreen"
browserWindow.previousVisibility = browserWindow.visibility
browserWindow.showFullScreen()
} else {
webEngineView.state = ""
browserWindow.visibility = browserWindow.previousVisibility
}
request.accept()
}
}
}
}
......
......@@ -427,12 +427,14 @@ void QQuickWebEngineViewPrivate::close()
void QQuickWebEngineViewPrivate::requestFullScreen(bool fullScreen)
{
Q_EMIT e->fullScreenRequested(fullScreen);
Q_Q(QQuickWebEngineView);
QQuickWebEngineFullScreenRequest request(this, fullScreen);
Q_EMIT q->fullScreenRequested(request);
}
bool QQuickWebEngineViewPrivate::isFullScreen() const
{
return e->isFullScreen();
return m_isFullScreen;
}
void QQuickWebEngineViewPrivate::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID)
......@@ -821,15 +823,11 @@ qreal QQuickWebEngineView::zoomFactor() const
return d->adapter->currentZoomFactor();
}
void QQuickWebEngineViewExperimental::setIsFullScreen(bool fullscreen)
{
d_ptr->m_isFullScreen = fullscreen;
emit isFullScreenChanged();
}
bool QQuickWebEngineViewExperimental::isFullScreen() const
bool QQuickWebEngineView::isFullScreen() const
{
return d_ptr->m_isFullScreen;
Q_D(const QQuickWebEngineView);
return d->m_isFullScreen;
}
void QQuickWebEngineViewExperimental::setExtraContextMenuEntriesComponent(QQmlComponent *contextMenuExtras)
......@@ -947,6 +945,15 @@ void QQuickWebEngineView::goBackOrForward(int offset)
d->adapter->navigateToIndex(index);
}
void QQuickWebEngineView::fullScreenCancelled()
{
Q_D(QQuickWebEngineView);
if (d->m_isFullScreen) {
d->m_isFullScreen = false;
Q_EMIT isFullScreenChanged();
}
}
void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
QQuickItem::geometryChanged(newGeometry, oldGeometry);
......@@ -1010,6 +1017,26 @@ void QQuickWebEngineView::componentComplete()
d->ensureContentsAdapter();
}
QQuickWebEngineFullScreenRequest::QQuickWebEngineFullScreenRequest()
: viewPrivate(0)
, m_toggleOn(false)
{
}
QQuickWebEngineFullScreenRequest::QQuickWebEngineFullScreenRequest(QQuickWebEngineViewPrivate *viewPrivate, bool toggleOn)
: viewPrivate(viewPrivate)
, m_toggleOn(toggleOn)
{
}
void QQuickWebEngineFullScreenRequest::accept()
{
if (viewPrivate && viewPrivate->m_isFullScreen != m_toggleOn) {
viewPrivate->m_isFullScreen = m_toggleOn;
Q_EMIT viewPrivate->q_ptr->isFullScreenChanged();
}
}
QQuickWebEngineViewExperimental::QQuickWebEngineViewExperimental(QQuickWebEngineViewPrivate *viewPrivate)
: q_ptr(0)
, d_ptr(viewPrivate)
......
......@@ -58,6 +58,20 @@ class QQuickWebEngineViewPrivate;
class QQuickWebEngineTestSupport;
#endif
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineFullScreenRequest {
Q_GADGET
Q_PROPERTY(bool toggleOn READ toggleOn)
public:
QQuickWebEngineFullScreenRequest();
QQuickWebEngineFullScreenRequest(QQuickWebEngineViewPrivate *viewPrivate, bool toggleOn);
Q_INVOKABLE void accept();
bool toggleOn() { return m_toggleOn; }
private:
QQuickWebEngineViewPrivate *viewPrivate;
bool m_toggleOn;
};
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_OBJECT
......@@ -68,6 +82,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY urlChanged)
Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY urlChanged)
Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged REVISION 1)
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged REVISION 1)
Q_PROPERTY(QQuickWebEngineProfile *profile READ profile WRITE setProfile FINAL REVISION 1)
Q_PROPERTY(QQuickWebEngineSettings *settings READ settings REVISION 1)
......@@ -99,6 +114,7 @@ public:
QString title() const;
bool canGoBack() const;
bool canGoForward() const;
bool isFullScreen() const;
qreal zoomFactor() const;
void setZoomFactor(qreal arg);
......@@ -185,6 +201,7 @@ public Q_SLOTS:
void reload();
void stop();
Q_REVISION(1) void findText(const QString &subString, FindFlags options = 0, const QJSValue &callback = QJSValue());
Q_REVISION(1) void fullScreenCancelled();
Q_SIGNALS:
void titleChanged();
......@@ -196,6 +213,8 @@ Q_SIGNALS:
void navigationRequested(QQuickWebEngineNavigationRequest *request);
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID);
Q_REVISION(1) void certificateError(QQuickWebEngineCertificateError *error);
Q_REVISION(1) void fullScreenRequested(const QQuickWebEngineFullScreenRequest &request);
Q_REVISION(1) void isFullScreenChanged();
Q_REVISION(1) void newViewRequested(QQuickWebEngineNewViewRequest *request);
Q_REVISION(1) void zoomFactorChanged(qreal arg);
Q_REVISION(1) void webChannelChanged();
......@@ -220,5 +239,6 @@ private:
QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickWebEngineView)
Q_DECLARE_METATYPE(QQuickWebEngineFullScreenRequest)
#endif // QQUICKWEBENGINEVIEW_P_H
......@@ -83,7 +83,6 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewExperimental : public QObjec
Q_OBJECT
Q_PROPERTY(QQuickWebEngineViewport *viewport READ viewport)
Q_PROPERTY(QQmlComponent *extraContextMenuEntriesComponent READ extraContextMenuEntriesComponent WRITE setExtraContextMenuEntriesComponent NOTIFY extraContextMenuEntriesComponentChanged)
Q_PROPERTY(bool isFullScreen READ isFullScreen WRITE setIsFullScreen NOTIFY isFullScreenChanged)
Q_ENUMS(Feature)
public:
......@@ -94,8 +93,6 @@ public:
Geolocation
};
void setIsFullScreen(bool fullscreen);
bool isFullScreen() const;
QQuickWebEngineViewport *viewport() const;
void setExtraContextMenuEntriesComponent(QQmlComponent *);
QQmlComponent *extraContextMenuEntriesComponent() const;
......@@ -104,8 +101,6 @@ public Q_SLOTS:
void grantFeaturePermission(const QUrl &securityOrigin, Feature, bool granted);
Q_SIGNALS:
void fullScreenRequested(bool fullScreen);
void isFullScreenChanged();
void extraContextMenuEntriesComponentChanged();
void featurePermissionRequested(const QUrl &securityOrigin, Feature feature);
void loadVisuallyCommitted();
......
......@@ -81,6 +81,8 @@ public:
QObject::tr("Cannot create a separate instance of NavigationHistory"));
qmlRegisterUncreatableType<QQuickWebEngineHistoryListModel>(uri, 1, 1, "NavigationHistoryListModel",
QObject::tr("Cannot create a separate instance of NavigationHistory"));
qmlRegisterUncreatableType<QQuickWebEngineFullScreenRequest>(uri, 1, 1, "FullScreenRequest",
QObject::tr("Cannot create a separate instance of FullScreenRequest"));
}
};
......
......@@ -73,6 +73,7 @@ static QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *>()
<< &QQuickWebEngineNewViewRequest::staticMetaObject
<< &QQuickWebEngineProfile::staticMetaObject
<< &QQuickWebEngineScript::staticMetaObject
<< &QQuickWebEngineFullScreenRequest::staticMetaObject
;
static QList<const char *> knownEnumNames = QList<const char *>();
......@@ -127,6 +128,7 @@ static QStringList expectedAPI = QStringList()
<< "QQuickWebEngineView.icon --> QUrl"
<< "QQuickWebEngineView.canGoBack --> bool"
<< "QQuickWebEngineView.canGoForward --> bool"
<< "QQuickWebEngineView.isFullScreen --> bool"
<< "QQuickWebEngineView.loading --> bool"
<< "QQuickWebEngineView.loadProgress --> int"
<< "QQuickWebEngineView.titleChanged() --> void"
......@@ -138,6 +140,9 @@ static QStringList expectedAPI = QStringList()
<< "QQuickWebEngineView.iconChanged() --> void"
<< "QQuickWebEngineView.linkHovered(QUrl) --> void"
<< "QQuickWebEngineView.navigationRequested(QQuickWebEngineNavigationRequest*) --> void"
<< "QQuickWebEngineView.fullScreenRequested(QQuickWebEngineFullScreenRequest) --> void"
<< "QQuickWebEngineView.isFullScreenChanged() --> void"
<< "QQuickWebEngineView.fullScreenCancelled() --> void"
<< "QQuickWebEngineView.runJavaScript(QString,QJSValue) --> void"
<< "QQuickWebEngineView.runJavaScript(QString) --> void"
<< "QQuickWebEngineView.loadHtml(QString,QUrl) --> void"
......@@ -233,6 +238,8 @@ static QStringList expectedAPI = QStringList()
<< "QQuickWebEngineScript.setWorldId(ScriptWorldId) --> void"
<< "QQuickWebEngineScript.setRunOnSubframes(bool) --> void"
<< "QQuickWebEngineScript.toString() --> QString"
<< "QQuickWebEngineFullScreenRequest.toggleOn --> bool"
<< "QQuickWebEngineFullScreenRequest.accept() --> void"
;
static bool isCheckedEnum(const QByteArray &typeName)
......
......@@ -54,12 +54,16 @@ ApplicationWindow {
id: browserWindow
property QtObject applicationRoot
property Item currentWebView: tabs.currentIndex < tabs.count ? tabs.getTab(tabs.currentIndex).item.webView : null
property int previousVisibility: Window.Windowed
property bool isFullScreen: visibility == Window.FullScreen
onIsFullScreenChanged: {
// This is for the case where the system forces us to leave fullscreen.
if (currentWebView)
currentWebView.state = isFullScreen ? "FullScreen" : ""
if (currentWebView && !isFullScreen) {
currentWebView.state = ""
if (currentWebView.isFullScreen)
currentWebView.fullScreenCancelled()
}
}
height: 600
......@@ -89,7 +93,7 @@ ApplicationWindow {
offTheRecord: true
}
// Make sure the Qt.WindowFullscreenButtonHint is set on Mac.
// Make sure the Qt.WindowFullscreenButtonHint is set on OS X.
Component.onCompleted: flags = flags | Qt.WindowFullscreenButtonHint
// Create a styleItem to determine the platform.
......@@ -141,7 +145,7 @@ ApplicationWindow {
shortcut: "Escape"
onTriggered: {
if (browserWindow.isFullScreen)
browserWindow.showNormal()
browserWindow.visibility = browserWindow.previousVisibility
}
}
Action {
......@@ -380,18 +384,19 @@ ApplicationWindow {
}
}
experimental {
isFullScreen: webEngineView.state == "FullScreen" && browserWindow.isFullScreen
onFullScreenRequested: {
if (fullScreen) {
webEngineView.state = "FullScreen"
browserWindow.showFullScreen();
} else {
webEngineView.state = ""
browserWindow.showNormal();
}
onFullScreenRequested: {
if (request.toggleOn) {
webEngineView.state = "FullScreen"
browserWindow.previousVisibility = browserWindow.visibility
browserWindow.showFullScreen()
} else {
webEngineView.state = ""
browserWindow.visibility = browserWindow.previousVisibility
}
request.accept()
}
experimental {
onFeaturePermissionRequested: {
permBar.securityOrigin = securityOrigin;
permBar.requestedFeature = feature;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment