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 <QtWebViewQuick/private/qquickviewcontroller_p.h> |
20 | #include <QtWebView/private/qwebviewinterface_p.h> |
21 | #include <QtWebView/private/qwebview_p.h> |
22 | #include <QtQml/qqmlregistration.h> |
23 | Q_MOC_INCLUDE(<QtWebViewQuick/private/qquickwebviewloadrequest_p.h>) |
24 | Q_MOC_INCLUDE(<QtWebViewQuick/private/qquickwebviewsettings_p.h>) |
25 | Q_MOC_INCLUDE(<QtWebView/private/qwebviewloadrequest_p.h>) |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QQuickWebViewLoadRequest; |
30 | class QWebViewLoadRequestPrivate; |
31 | class QQuickWebViewSettings; |
32 | |
33 | class Q_WEBVIEWQUICK_EXPORT QQuickWebView : public QQuickViewController, public QWebViewInterface |
34 | { |
35 | Q_OBJECT |
36 | Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY |
37 | httpUserAgentChanged FINAL REVISION(1, 14)) |
38 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged FINAL) |
39 | Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged FINAL REVISION(1, 1)) |
40 | Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged FINAL) |
41 | Q_PROPERTY(QString title READ title NOTIFY titleChanged FINAL) |
42 | Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingChanged FINAL) |
43 | Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingChanged FINAL) |
44 | Q_PROPERTY(QQuickWebViewSettings *settings READ settings CONSTANT FINAL REVISION(6, 5)) |
45 | Q_ENUMS(LoadStatus) |
46 | QML_NAMED_ELEMENT(WebView) |
47 | QML_ADDED_IN_VERSION(1, 0) |
48 | QML_EXTRA_VERSION(2, 0) |
49 | |
50 | public: |
51 | enum LoadStatus { // Changes here needs to be done in QWebView as well |
52 | LoadStartedStatus, |
53 | LoadStoppedStatus, |
54 | LoadSucceededStatus, |
55 | LoadFailedStatus |
56 | }; |
57 | QQuickWebView(QQuickItem *parent = nullptr); |
58 | ~QQuickWebView(); |
59 | |
60 | QString httpUserAgent() const override; |
61 | void setHttpUserAgent(const QString &userAgent) override; |
62 | QUrl url() const override; |
63 | void setUrl(const QUrl &url) override; |
64 | int loadProgress() const override; |
65 | QString title() const override; |
66 | bool canGoBack() const override; |
67 | bool isLoading() const override; |
68 | bool canGoForward() const override; |
69 | QWebView &webView() const { return *m_webView; }; |
70 | |
71 | QQuickWebViewSettings *settings() const; |
72 | |
73 | public Q_SLOTS: |
74 | void goBack() override; |
75 | void goForward() override; |
76 | void reload() override; |
77 | void stop() override; |
78 | Q_REVISION(1, 1) void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) override; |
79 | Q_REVISION(1, 1) |
80 | void runJavaScript(const QString &script, const QJSValue &callback = QJSValue()); |
81 | Q_REVISION(6, 3) void setCookie(const QString &domain, const QString &name, const QString &value) override; |
82 | Q_REVISION(6, 3) void deleteCookie(const QString &domain, const QString &name) override; |
83 | Q_REVISION(6, 3) void deleteAllCookies() override; |
84 | |
85 | Q_SIGNALS: |
86 | void titleChanged(); |
87 | void urlChanged(); |
88 | Q_REVISION(1, 1) void loadingChanged(QQuickWebViewLoadRequest *loadRequest); |
89 | void loadProgressChanged(); |
90 | Q_REVISION(1, 14) void httpUserAgentChanged(); |
91 | Q_REVISION(6, 3) void cookieAdded(const QString &domain, const QString &name); |
92 | Q_REVISION(6, 3) void cookieRemoved(const QString &domain, const QString &name); |
93 | |
94 | protected: |
95 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
96 | void runJavaScriptPrivate(const QString &script, int callbackId) override; |
97 | |
98 | private Q_SLOTS: |
99 | void onRunJavaScriptResult(int id, const QVariant &variant); |
100 | void onFocusRequest(bool focus); |
101 | void onLoadingChanged(const QWebViewLoadRequestPrivate &loadRequest); |
102 | |
103 | private: |
104 | friend class QWebEngineWebViewPrivate; |
105 | static QJSValue takeCallback(int id); |
106 | |
107 | QWebView *m_webView; |
108 | QQuickWebViewSettings *m_settings; |
109 | }; |
110 | |
111 | QT_END_NAMESPACE |
112 | |
113 | #endif // QQUICKWEBVIEW_H |
114 | |