[Qt][WK2] Move non-api classes to WebKit namespace at WebKit2/UiProcess/qt
[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 "qquickurlschemedelegate_p.h"
25 #include "qwebkitglobal.h"
26 #include <QtQml/qqmllist.h>
27 #include <QtQuick/qquickitem.h>
28 #include <private/qquickflickable_p.h>
29
30 class QWebNavigationRequest;
31 class QDeclarativeComponent;
32 class QQuickWebPage;
33 class QQuickWebViewAttached;
34 class QWebLoadRequest;
35 class QQuickWebViewPrivate;
36 class QQuickWebViewExperimental;
37 class QWebDownloadItem;
38 class QWebNavigationHistory;
39 class QWebPreferences;
40 class QWebPermissionRequest;
41 class QWebViewportInfo;
42 class QQuickNetworkReply;
43
44 namespace WTR {
45 class PlatformWebView;
46 }
47
48 namespace WebKit {
49 class QtRefCountedNetworkRequestData;
50 class QtViewportInteractionEngine;
51 class QtWebPageLoadClient;
52 class QtWebPagePolicyClient;
53 class QtWebPageUIClient;
54 }
55
56 namespace WTF {
57 template<class T> class PassRefPtr;
58 }
59
60 typedef const struct OpaqueWKContext* WKContextRef;
61 typedef const struct OpaqueWKPageGroup* WKPageGroupRef;
62 typedef const struct OpaqueWKPage* WKPageRef;
63
64 QT_BEGIN_NAMESPACE
65 class QPainter;
66 class QUrl;
67 class QQuickFlickable;
68 QT_END_NAMESPACE
69
70
71 // Instantiating the WebView in C++ is only possible by creating
72 // a QDeclarativeComponent as the initialization depends on the
73 // componentComplete method being called.
74 class QWEBKIT_EXPORT QQuickWebView : public QQuickFlickable {
75     Q_OBJECT
76     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
77     Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
78     Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged FINAL)
79     Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY navigationHistoryChanged FINAL)
80     Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY navigationHistoryChanged FINAL)
81     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged FINAL)
82     Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged)
83     Q_ENUMS(NavigationRequestAction)
84     Q_ENUMS(LoadStatus)
85     Q_ENUMS(ErrorDomain)
86     Q_ENUMS(NavigationType)
87
88 public:
89     enum NavigationRequestAction {
90         AcceptRequest,
91         // Make room in the valid range of the enum for extra actions exposed in Experimental.
92         IgnoreRequest = 0xFF
93     };
94     enum LoadStatus {
95         LoadStartedStatus,
96         LoadSucceededStatus,
97         LoadFailedStatus
98     };
99     enum ErrorDomain {
100         NoErrorDomain,
101         InternalErrorDomain,
102         NetworkErrorDomain,
103         HttpErrorDomain,
104         DownloadErrorDomain
105     };
106
107     enum NavigationType {
108         LinkClickedNavigation,
109         FormSubmittedNavigation,
110         BackForwardNavigation,
111         ReloadNavigation,
112         FormResubmittedNavigation,
113         OtherNavigation
114     };
115
116     QQuickWebView(QQuickItem* parent = 0);
117     virtual ~QQuickWebView();
118
119     QUrl url() const;
120     void setUrl(const QUrl&);
121     QUrl icon() const;
122     QString title() const;
123     int loadProgress() const;
124
125     bool canGoBack() const;
126     bool canGoForward() const;
127     bool loading() const;
128
129     virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
130
131     QPointF mapToWebContent(const QPointF&) const;
132     QRectF mapRectToWebContent(const QRectF&) const;
133     QPointF mapFromWebContent(const QPointF&) const;
134     QRectF mapRectFromWebContent(const QRectF&) const;
135
136     QQuickWebPage* page();
137
138     QQuickWebViewExperimental* experimental() const;
139     static QQuickWebViewAttached* qmlAttachedProperties(QObject*);
140
141     static void platformInitialize(); // Only needed by WTR.
142
143     // Internal API used by WebPage.
144     void updateContentsSize(const QSizeF&);
145     QPointF pageItemPos();
146
147 public Q_SLOTS:
148     void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());
149
150     void goBack();
151     void goForward();
152     void stop();
153     void reload();
154
155 Q_SIGNALS:
156     void titleChanged();
157     void navigationHistoryChanged();
158     void loadingChanged(QWebLoadRequest* loadRequest);
159     void loadProgressChanged();
160     void urlChanged();
161     void iconChanged();
162     void linkHovered(const QUrl& hoveredUrl, const QString& hoveredTitle);
163     void navigationRequested(QWebNavigationRequest* request);
164
165 protected:
166     virtual void geometryChanged(const QRectF&, const QRectF&);
167     virtual void componentComplete();
168     virtual void keyPressEvent(QKeyEvent*);
169     virtual void keyReleaseEvent(QKeyEvent*);
170     virtual void inputMethodEvent(QInputMethodEvent*);
171     virtual void focusInEvent(QFocusEvent*);
172     virtual void focusOutEvent(QFocusEvent*);
173     virtual void touchEvent(QTouchEvent*);
174     virtual void mousePressEvent(QMouseEvent*);
175     virtual void mouseMoveEvent(QMouseEvent*);
176     virtual void mouseReleaseEvent(QMouseEvent *);
177     virtual void mouseDoubleClickEvent(QMouseEvent*);
178     virtual void wheelEvent(QWheelEvent*);
179     virtual void hoverEnterEvent(QHoverEvent*);
180     virtual void hoverMoveEvent(QHoverEvent*);
181     virtual void hoverLeaveEvent(QHoverEvent*);
182     virtual void dragMoveEvent(QDragMoveEvent*);
183     virtual void dragEnterEvent(QDragEnterEvent*);
184     virtual void dragLeaveEvent(QDragLeaveEvent*);
185     virtual void dropEvent(QDropEvent*);
186     virtual bool event(QEvent*);
187
188 private:
189     Q_DECLARE_PRIVATE(QQuickWebView)
190
191     void handleFlickableMousePress(const QPointF& position, qint64 eventTimestampMillis);
192     void handleFlickableMouseMove(const QPointF& position, qint64 eventTimestampMillis);
193     void handleFlickableMouseRelease(const QPointF& position, qint64 eventTimestampMillis);
194
195     QPointF contentPos() const;
196     void setContentPos(const QPointF&);
197
198     QQuickWebView(WKContextRef, WKPageGroupRef, QQuickItem* parent = 0);
199     WKPageRef pageRef() const;
200
201     Q_PRIVATE_SLOT(d_func(), void _q_suspend());
202     Q_PRIVATE_SLOT(d_func(), void _q_resume());
203     Q_PRIVATE_SLOT(d_func(), void _q_contentViewportChanged(const QPointF&));
204
205     Q_PRIVATE_SLOT(d_func(), void _q_onVisibleChanged());
206     Q_PRIVATE_SLOT(d_func(), void _q_onUrlChanged());
207     Q_PRIVATE_SLOT(d_func(), void _q_onReceivedResponseFromDownload(QWebDownloadItem*));
208     Q_PRIVATE_SLOT(d_func(), void _q_onIconChangedForPageURL(const QUrl&, const QUrl&));
209     // Hides QObject::d_ptr allowing us to use the convenience macros.
210     QScopedPointer<QQuickWebViewPrivate> d_ptr;
211     QQuickWebViewExperimental* m_experimental;
212
213     friend class WebKit::QtViewportInteractionEngine;
214     friend class WebKit::QtWebPageLoadClient;
215     friend class WebKit::QtWebPagePolicyClient;
216     friend class WebKit::QtWebPageUIClient;
217     friend class WTR::PlatformWebView;
218     friend class QQuickWebViewExperimental;
219 };
220
221 QML_DECLARE_TYPE(QQuickWebView)
222
223 class QWEBKIT_EXPORT QQuickWebViewAttached : public QObject {
224     Q_OBJECT
225     Q_PROPERTY(QQuickWebView* view READ view NOTIFY viewChanged FINAL)
226
227 public:
228     QQuickWebViewAttached(QObject* object);
229     QQuickWebView* view() const { return m_view; }
230     void setView(QQuickWebView*);
231
232 Q_SIGNALS:
233     void viewChanged();
234
235 private:
236     QQuickWebView* m_view;
237 };
238
239 QML_DECLARE_TYPEINFO(QQuickWebView, QML_HAS_ATTACHED_PROPERTIES)
240
241 class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
242     Q_OBJECT
243     Q_PROPERTY(QQuickWebPage* page READ page CONSTANT FINAL)
244
245     Q_PROPERTY(bool transparentBackground WRITE setTransparentBackground READ transparentBackground)
246     Q_PROPERTY(bool useDefaultContentItemSize WRITE setUseDefaultContentItemSize READ useDefaultContentItemSize)
247
248     Q_PROPERTY(QWebNavigationHistory* navigationHistory READ navigationHistory CONSTANT FINAL)
249     Q_PROPERTY(QDeclarativeComponent* alertDialog READ alertDialog WRITE setAlertDialog NOTIFY alertDialogChanged)
250     Q_PROPERTY(QDeclarativeComponent* confirmDialog READ confirmDialog WRITE setConfirmDialog NOTIFY confirmDialogChanged)
251     Q_PROPERTY(QDeclarativeComponent* promptDialog READ promptDialog WRITE setPromptDialog NOTIFY promptDialogChanged)
252     Q_PROPERTY(QDeclarativeComponent* authenticationDialog READ authenticationDialog WRITE setAuthenticationDialog NOTIFY authenticationDialogChanged)
253     Q_PROPERTY(QDeclarativeComponent* proxyAuthenticationDialog READ proxyAuthenticationDialog WRITE setProxyAuthenticationDialog NOTIFY proxyAuthenticationDialogChanged)
254     Q_PROPERTY(QDeclarativeComponent* certificateVerificationDialog READ certificateVerificationDialog WRITE setCertificateVerificationDialog NOTIFY certificateVerificationDialogChanged)
255     Q_PROPERTY(QDeclarativeComponent* itemSelector READ itemSelector WRITE setItemSelector NOTIFY itemSelectorChanged)
256     Q_PROPERTY(QDeclarativeComponent* filePicker READ filePicker WRITE setFilePicker NOTIFY filePickerChanged)
257     Q_PROPERTY(QDeclarativeComponent* databaseQuotaDialog READ databaseQuotaDialog WRITE setDatabaseQuotaDialog NOTIFY databaseQuotaDialogChanged)
258     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
259     Q_PROPERTY(QWebViewportInfo* viewportInfo READ viewportInfo CONSTANT FINAL)
260     Q_PROPERTY(QDeclarativeListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates)
261     Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent NOTIFY userAgentChanged)
262     Q_ENUMS(NavigationRequestActionExperimental)
263
264 public:
265     enum NavigationRequestActionExperimental {
266         DownloadRequest = QQuickWebView::IgnoreRequest - 1
267     };
268
269     QQuickWebViewExperimental(QQuickWebView* webView);
270     virtual ~QQuickWebViewExperimental();
271
272     QDeclarativeComponent* alertDialog() const;
273     void setAlertDialog(QDeclarativeComponent*);
274     QDeclarativeComponent* confirmDialog() const;
275     void setConfirmDialog(QDeclarativeComponent*);
276     QDeclarativeComponent* promptDialog() const;
277     void setPromptDialog(QDeclarativeComponent*);
278     QDeclarativeComponent* authenticationDialog() const;
279     void setAuthenticationDialog(QDeclarativeComponent*);
280     QDeclarativeComponent* certificateVerificationDialog() const;
281     void setCertificateVerificationDialog(QDeclarativeComponent*);
282     QDeclarativeComponent* itemSelector() const;
283     void setItemSelector(QDeclarativeComponent*);
284     QDeclarativeComponent* proxyAuthenticationDialog() const;
285     void setProxyAuthenticationDialog(QDeclarativeComponent*);
286     QDeclarativeComponent* filePicker() const;
287     void setFilePicker(QDeclarativeComponent*);
288     QDeclarativeComponent* databaseQuotaDialog() const;
289     void setDatabaseQuotaDialog(QDeclarativeComponent*);
290     QString userAgent() const;
291     void setUserAgent(const QString& userAgent);
292
293     QWebViewportInfo* viewportInfo();
294
295     QWebPreferences* preferences() const;
296     QWebNavigationHistory* navigationHistory() const;
297     QQuickWebPage* page();
298
299     static QQuickUrlSchemeDelegate* schemeDelegates_At(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*, int index);
300     static void schemeDelegates_Append(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*, QQuickUrlSchemeDelegate*);
301     static int schemeDelegates_Count(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*);
302     static void schemeDelegates_Clear(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*);
303     QDeclarativeListProperty<QQuickUrlSchemeDelegate> schemeDelegates();
304     void invokeApplicationSchemeHandler(WTF::PassRefPtr<WebKit::QtRefCountedNetworkRequestData>);
305     void sendApplicationSchemeReply(QQuickNetworkReply*);
306
307     bool transparentBackground() const;
308     void setTransparentBackground(bool);
309
310     bool useDefaultContentItemSize() const;
311     void setUseDefaultContentItemSize(bool enable);
312
313     // C++ only
314     bool renderToOffscreenBuffer() const;
315     void setRenderToOffscreenBuffer(bool enable);
316     static void setFlickableViewportEnabled(bool enable);
317     static bool flickableViewportEnabled();
318
319 public Q_SLOTS:
320     void goBackTo(int index);
321     void goForwardTo(int index);
322     void postMessage(const QString&);
323
324 Q_SIGNALS:
325     void alertDialogChanged();
326     void confirmDialogChanged();
327     void promptDialogChanged();
328     void authenticationDialogChanged();
329     void certificateVerificationDialogChanged();
330     void itemSelectorChanged();
331     void filePickerChanged();
332     void databaseQuotaDialogChanged();
333     void downloadRequested(QWebDownloadItem* downloadItem);
334     void permissionRequested(QWebPermissionRequest* permission);
335     void messageReceived(const QVariantMap& message);
336     void proxyAuthenticationDialogChanged();
337     void userAgentChanged();
338
339 private:
340     QQuickWebView* q_ptr;
341     QQuickWebViewPrivate* d_ptr;
342     QObject* schemeParent;
343     QWebViewportInfo* m_viewportInfo;
344
345     friend class WebKit::QtWebPageUIClient;
346
347     Q_DECLARE_PRIVATE(QQuickWebView)
348     Q_DECLARE_PUBLIC(QQuickWebView)
349 };
350
351 #endif // qquickwebview_p_h