| 1 | // Copyright (C) 2015 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKWEBVIEW_H |
| 5 | #define QQUICKWEBVIEW_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtWebViewQuick/private/qtwebviewquickglobal_p.h> |
| 19 | #include <QtWebView/private/qwebview_p.h> |
| 20 | #include <QtQml/qqmlregistration.h> |
| 21 | |
| 22 | #include <QtQuick/private/qquickwindowcontainer_p.h> |
| 23 | |
| 24 | Q_MOC_INCLUDE(<QtWebViewQuick/private/qquickwebviewloadrequest_p.h>) |
| 25 | Q_MOC_INCLUDE(<QtWebViewQuick/private/qquickwebviewsettings_p.h>) |
| 26 | Q_MOC_INCLUDE(<QtWebView/private/qwebviewloadrequest_p.h>) |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QQuickWebViewLoadRequest; |
| 31 | class QWebViewLoadRequestPrivate; |
| 32 | class QQuickWebViewSettings; |
| 33 | |
| 34 | class Q_WEBVIEWQUICK_EXPORT QQuickWebView : public QQuickWindowContainer |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY |
| 38 | httpUserAgentChanged FINAL REVISION(1, 14)) |
| 39 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged FINAL) |
| 40 | Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged FINAL REVISION(1, 1)) |
| 41 | Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged FINAL) |
| 42 | Q_PROPERTY(QString title READ title NOTIFY titleChanged FINAL) |
| 43 | Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingChanged FINAL) |
| 44 | Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingChanged FINAL) |
| 45 | Q_PROPERTY(QQuickWebViewSettings *settings READ settings CONSTANT FINAL REVISION(6, 5)) |
| 46 | Q_ENUMS(LoadStatus) |
| 47 | QML_NAMED_ELEMENT(WebView) |
| 48 | QML_ADDED_IN_VERSION(1, 0) |
| 49 | QML_EXTRA_VERSION(2, 0) |
| 50 | |
| 51 | public: |
| 52 | enum LoadStatus { // Changes here needs to be done in QWebView as well |
| 53 | LoadStartedStatus, |
| 54 | LoadStoppedStatus, |
| 55 | LoadSucceededStatus, |
| 56 | LoadFailedStatus |
| 57 | }; |
| 58 | QQuickWebView(QQuickItem *parent = nullptr); |
| 59 | ~QQuickWebView(); |
| 60 | |
| 61 | QString httpUserAgent() const ; |
| 62 | void setHttpUserAgent(const QString &userAgent); |
| 63 | QUrl url() const; |
| 64 | QWebView &webView() const { return *m_webView; }; |
| 65 | void setUrl(const QUrl &url); |
| 66 | int loadProgress() const; |
| 67 | QString title() const; |
| 68 | bool canGoBack() const; |
| 69 | bool isLoading() const; |
| 70 | bool canGoForward() const; |
| 71 | QWindow *nativeWindow(); |
| 72 | QQuickWebViewSettings *settings() const; |
| 73 | |
| 74 | public Q_SLOTS: |
| 75 | void goBack(); |
| 76 | void goForward(); |
| 77 | void reload(); |
| 78 | void stop(); |
| 79 | Q_REVISION(1, 1) void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()); |
| 80 | Q_REVISION(1, 1) |
| 81 | void runJavaScript(const QString &script, const QJSValue &callback = QJSValue()); |
| 82 | Q_REVISION(6, 3) void setCookie(const QString &domain, const QString &name, const QString &value); |
| 83 | Q_REVISION(6, 3) void deleteCookie(const QString &domain, const QString &name); |
| 84 | Q_REVISION(6, 3) void deleteAllCookies(); |
| 85 | |
| 86 | Q_SIGNALS: |
| 87 | void titleChanged(); |
| 88 | void urlChanged(); |
| 89 | Q_REVISION(1, 1) void loadingChanged(QQuickWebViewLoadRequest *loadRequest); |
| 90 | void loadProgressChanged(); |
| 91 | Q_REVISION(1, 14) void httpUserAgentChanged(); |
| 92 | Q_REVISION(6, 3) void cookieAdded(const QString &domain, const QString &name); |
| 93 | Q_REVISION(6, 3) void cookieRemoved(const QString &domain, const QString &name); |
| 94 | |
| 95 | protected: |
| 96 | #if defined(Q_OS_WASM) |
| 97 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 98 | #endif // Q_OS_WASM |
| 99 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
| 100 | void runJavaScriptPrivate(const QString &script, int callbackId); |
| 101 | |
| 102 | private Q_SLOTS: |
| 103 | void onRunJavaScriptResult(int id, const QVariant &variant); |
| 104 | void onLoadingChanged(const QWebViewLoadRequestPrivate &loadRequest); |
| 105 | void onNativeWindowChanged(QWindow *window); |
| 106 | |
| 107 | private: |
| 108 | friend class QWebEngineWebViewPrivate; |
| 109 | static QJSValue takeCallback(int id); |
| 110 | |
| 111 | QWebView *m_webView; |
| 112 | QQuickWebViewSettings *m_settings; |
| 113 | }; |
| 114 | |
| 115 | QT_END_NAMESPACE |
| 116 | |
| 117 | #endif // QQUICKWEBVIEW_H |
| 118 | |