[Qt][WK2] History is not accessible in QML.
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / qt / qquickwebview_p.h
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #ifndef qquickwebview_p_h
22 #define qquickwebview_p_h
23
24 #include "qwebkitglobal.h"
25 #include <QtQuick/qquickitem.h>
26
27 class QWebNavigationRequest;
28 class QDeclarativeComponent;
29 class QQuickWebPage;
30 class QQuickWebViewAttached;
31 class QQuickWebViewPrivate;
32 class QQuickWebViewExperimental;
33 class QWebDownloadItem;
34 class QWebNavigationHistory;
35 class QWebPreferences;
36 class QWebPermissionRequest;
37
38 namespace WTR {
39 class PlatformWebView;
40 }
41
42 typedef const struct OpaqueWKContext* WKContextRef;
43 typedef const struct OpaqueWKPageGroup* WKPageGroupRef;
44 typedef const struct OpaqueWKPage* WKPageRef;
45
46 QT_BEGIN_NAMESPACE
47 class QPainter;
48 class QUrl;
49 QT_END_NAMESPACE
50
51 class QWEBKIT_EXPORT QQuickWebView : public QQuickItem {
52     Q_OBJECT
53     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
54     Q_PROPERTY(QUrl url READ url NOTIFY urlChanged)
55     Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged)
56     Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY navigationStateChanged FINAL)
57     Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY navigationStateChanged FINAL)
58     Q_PROPERTY(bool loading READ loading NOTIFY navigationStateChanged FINAL)
59     Q_PROPERTY(bool canReload READ canReload NOTIFY navigationStateChanged FINAL)
60     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
61     Q_PROPERTY(QQuickWebPage* page READ page CONSTANT FINAL)
62     Q_ENUMS(NavigationRequestAction)
63     Q_ENUMS(ErrorType)
64
65 public:
66     enum NavigationRequestAction {
67         AcceptRequest,
68         IgnoreRequest,
69         DownloadRequest
70     };
71
72     enum ErrorType {
73         EngineError,
74         NetworkError,
75         HttpError,
76         DownloadError
77     };
78     QQuickWebView(QQuickItem* parent = 0);
79     virtual ~QQuickWebView();
80
81     QUrl url() const;
82     QString title() const;
83     int loadProgress() const;
84
85     bool canGoBack() const;
86     bool canGoForward() const;
87     bool loading() const;
88     bool canReload() const;
89
90     QWebPreferences* preferences() const;
91     QQuickWebPage* page();
92
93     QQuickWebViewExperimental* experimental() const;
94     static QQuickWebViewAttached* qmlAttachedProperties(QObject*);
95
96     static void platformInitialize(); // Only needed by WTR.
97
98 public Q_SLOTS:
99     void load(const QUrl&);
100     void postMessage(const QString&);
101     void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());
102
103     void goBack();
104     void goForward();
105     void stop();
106     void reload();
107
108 Q_SIGNALS:
109     void titleChanged(const QString& title);
110     void statusBarMessageChanged(const QString& message);
111     void loadStarted();
112     void loadSucceeded();
113     void loadFailed(QQuickWebView::ErrorType errorType, int errorCode, const QUrl& url);
114     void loadProgressChanged(int progress);
115     void urlChanged(const QUrl& url);
116     void messageReceived(const QVariantMap& message);
117     void linkHovered(const QUrl& url, const QString& title);
118     void navigationStateChanged();
119     void navigationRequested(QWebNavigationRequest* request);
120
121 protected:
122     virtual void geometryChanged(const QRectF&, const QRectF&);
123     virtual void focusInEvent(QFocusEvent*);
124     virtual void focusOutEvent(QFocusEvent*);
125     virtual void touchEvent(QTouchEvent* event);
126
127 private:
128     Q_DECLARE_PRIVATE(QQuickWebView)
129
130     QQuickWebView(WKContextRef, WKPageGroupRef, QQuickItem* parent = 0);
131     WKPageRef pageRef() const;
132
133     Q_PRIVATE_SLOT(d_func(), void _q_suspend());
134     Q_PRIVATE_SLOT(d_func(), void _q_resume());
135     Q_PRIVATE_SLOT(d_func(), void _q_viewportTrajectoryVectorChanged(const QPointF&));
136     Q_PRIVATE_SLOT(d_func(), void _q_onOpenPanelFilesSelected());
137     Q_PRIVATE_SLOT(d_func(), void _q_onOpenPanelFinished(int result));
138     Q_PRIVATE_SLOT(d_func(), void _q_onVisibleChanged());
139     // Hides QObject::d_ptr allowing us to use the convenience macros.
140     QScopedPointer<QQuickWebViewPrivate> d_ptr;
141     QQuickWebViewExperimental* m_experimental;
142
143     friend class QtWebPageLoadClient;
144     friend class QtWebPagePolicyClient;
145     friend class QtWebPageProxy;
146     friend class QtWebPageUIClient;
147     friend class WTR::PlatformWebView;
148     friend class QQuickWebViewExperimental;
149 };
150
151 QML_DECLARE_TYPE(QQuickWebView)
152
153 class QWEBKIT_EXPORT QQuickWebViewAttached : public QObject {
154     Q_OBJECT
155     Q_PROPERTY(QQuickWebView* view READ view NOTIFY viewChanged FINAL)
156
157 public:
158     QQuickWebViewAttached(QObject* object);
159     QQuickWebView* view() const { return m_view; }
160     void setView(QQuickWebView*);
161
162 Q_SIGNALS:
163     void viewChanged();
164
165 private:
166     QQuickWebView* m_view;
167 };
168
169 QML_DECLARE_TYPEINFO(QQuickWebView, QML_HAS_ATTACHED_PROPERTIES)
170
171 class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
172     Q_OBJECT
173     Q_PROPERTY(QWebNavigationHistory* navigationHistory READ navigationHistory CONSTANT FINAL)
174     Q_PROPERTY(QDeclarativeComponent* alertDialog READ alertDialog WRITE setAlertDialog NOTIFY alertDialogChanged)
175     Q_PROPERTY(QDeclarativeComponent* confirmDialog READ confirmDialog WRITE setConfirmDialog NOTIFY confirmDialogChanged)
176     Q_PROPERTY(QDeclarativeComponent* promptDialog READ promptDialog WRITE setPromptDialog NOTIFY promptDialogChanged)
177     Q_PROPERTY(QDeclarativeComponent* itemSelector READ itemSelector WRITE setItemSelector NOTIFY itemSelectorChanged)
178     Q_PROPERTY(bool useTraditionalDesktopBehaviour READ useTraditionalDesktopBehaviour WRITE setUseTraditionalDesktopBehaviour)
179
180 public:
181     QQuickWebViewExperimental(QQuickWebView* webView);
182     virtual ~QQuickWebViewExperimental();
183
184     QDeclarativeComponent* alertDialog() const;
185     void setAlertDialog(QDeclarativeComponent*);
186     QDeclarativeComponent* confirmDialog() const;
187     void setConfirmDialog(QDeclarativeComponent*);
188     QDeclarativeComponent* promptDialog() const;
189     void setPromptDialog(QDeclarativeComponent*);
190     QDeclarativeComponent* itemSelector() const;
191     void setItemSelector(QDeclarativeComponent*);
192
193     bool useTraditionalDesktopBehaviour() const;
194     QWebNavigationHistory* navigationHistory() const;
195
196 public Q_SLOTS:
197     void setUseTraditionalDesktopBehaviour(bool enable);
198     void goBackTo(int index);
199     void goForwardTo(int index);
200
201 Q_SIGNALS:
202     void alertDialogChanged();
203     void confirmDialogChanged();
204     void promptDialogChanged();
205     void itemSelectorChanged();
206     void downloadRequested(QWebDownloadItem* downloadItem);
207     void permissionRequested(QWebPermissionRequest* permission);
208
209 private:
210     QQuickWebView* q_ptr;
211     QQuickWebViewPrivate* d_ptr;
212
213     friend class QtWebPageProxy;
214     friend class QtWebPageUIClient;
215
216     Q_DECLARE_PRIVATE(QQuickWebView)
217     Q_DECLARE_PUBLIC(QQuickWebView)
218 };
219
220 #endif // qquickwebview_p_h