1/* 2 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (c) 2012 Hewlett-Packard Development Company, L.P. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this program; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 * 20 */ 21 22#ifndef qquickwebview_p_h 23#define qquickwebview_p_h 24 25#include "qquickurlschemedelegate_p.h" 26#include "qwebkitglobal.h" 27#include <QtQml/qqmllist.h> 28#include <QtQuick/qquickitem.h> 29#include <private/qquickflickable_p.h> 30 31QT_BEGIN_NAMESPACE 32class QQmlComponent; 33QT_END_NAMESPACE 34class QWebNavigationRequest; 35class QQuickWebPage; 36class QQuickWebViewAttached; 37class QWebLoadRequest; 38class QQuickWebViewPrivate; 39class QQuickWebViewExperimental; 40class QWebDownloadItem; 41class QWebNavigationHistory; 42class QWebPreferences; 43class QWebPermissionRequest; 44class QWebKitTest; 45class QQuickNetworkReply; 46 47namespace WTR { 48class PlatformWebView; 49} 50 51namespace TestWebKitAPI { 52class PlatformWebView; 53} 54 55namespace WebKit { 56struct QtRefCountedNetworkRequestData; 57class PageViewportControllerClientQt; 58class QtWebPagePolicyClient; 59class QtWebPageUIClient; 60} 61 62namespace WTF { 63template<class T> class PassRefPtr; 64} 65 66typedef const struct OpaqueWKContext* WKContextRef; 67typedef const struct OpaqueWKPageGroup* WKPageGroupRef; 68typedef const struct OpaqueWKPage* WKPageRef; 69 70QT_BEGIN_NAMESPACE 71class QPainter; 72class QUrl; 73class QQuickFlickable; 74class QJSValue; 75QT_END_NAMESPACE 76 77 78// Instantiating the WebView in C++ is only possible by creating 79// a QQmlComponent as the initialization depends on the 80// componentComplete method being called. 81class QWEBKIT_EXPORT QQuickWebView : public QQuickFlickable { 82 Q_OBJECT 83 Q_PROPERTY(QString title READ title NOTIFY titleChanged) 84 Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) 85 Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged FINAL) 86 Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY navigationHistoryChanged FINAL) 87 Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY navigationHistoryChanged FINAL) 88 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged FINAL) 89 Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged) 90 Q_ENUMS(NavigationRequestAction) 91 Q_ENUMS(LoadStatus) 92 Q_ENUMS(ErrorDomain) 93 Q_ENUMS(NavigationType) 94 95public: 96 enum NavigationRequestAction { 97 AcceptRequest, 98 // Make room in the valid range of the enum for extra actions exposed in Experimental. 99 IgnoreRequest = 0xFF 100 }; 101 enum LoadStatus { 102 LoadStartedStatus, 103 LoadStoppedStatus, 104 LoadSucceededStatus, 105 LoadFailedStatus 106 }; 107 enum ErrorDomain { 108 NoErrorDomain, 109 InternalErrorDomain, 110 NetworkErrorDomain, 111 HttpErrorDomain, 112 DownloadErrorDomain 113 }; 114 115 enum NavigationType { 116 LinkClickedNavigation, 117 FormSubmittedNavigation, 118 BackForwardNavigation, 119 ReloadNavigation, 120 FormResubmittedNavigation, 121 OtherNavigation 122 }; 123 124 QQuickWebView(QQuickItem* parent = 0); 125 virtual ~QQuickWebView(); 126 127 QUrl url() const; 128 void setUrl(const QUrl&); 129 QUrl icon() const; 130 QString title() const; 131 int loadProgress() const; 132 133 bool canGoBack() const; 134 bool canGoForward() const; 135 bool loading() const; 136 137 virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const; 138 139 QPointF mapToWebContent(const QPointF&) const; 140 QRectF mapRectToWebContent(const QRectF&) const; 141 QPointF mapFromWebContent(const QPointF&) const; 142 QRectF mapRectFromWebContent(const QRectF&) const; 143 144 QQuickWebPage* page(); 145 146 QQuickWebViewExperimental* experimental() const; 147 static QQuickWebViewAttached* qmlAttachedProperties(QObject*); 148 149 static void platformInitialize(); // Only needed by WTR. 150 151 // Private C++-only API. 152 qreal zoomFactor() const; 153 void setZoomFactor(qreal); 154 void runJavaScriptInMainFrame(const QString& script, QObject* receiver, const char* method); 155 // Used to automatically accept the HTTPS certificate in WTR. No other use intended. 156 bool allowAnyHTTPSCertificateForLocalHost() const; 157 void setAllowAnyHTTPSCertificateForLocalHost(bool allow); 158 159public Q_SLOTS: 160 void loadHtml(const QString& html, const QUrl& baseUrl = QUrl(), const QUrl& unreachableUrl = QUrl()); 161 162 void goBack(); 163 void goForward(); 164 void stop(); 165 void reload(); 166 167Q_SIGNALS: 168 void titleChanged(); 169 void navigationHistoryChanged(); 170 void loadingChanged(QWebLoadRequest* loadRequest); 171 void loadProgressChanged(); 172 void urlChanged(); 173 void iconChanged(); 174 void linkHovered(const QUrl& hoveredUrl, const QString& hoveredTitle); 175 void navigationRequested(QWebNavigationRequest* request); 176 177protected: 178 virtual bool childMouseEventFilter(QQuickItem*, QEvent*); 179 virtual void geometryChanged(const QRectF&, const QRectF&); 180 virtual void componentComplete(); 181 virtual void keyPressEvent(QKeyEvent*); 182 virtual void keyReleaseEvent(QKeyEvent*); 183 virtual void inputMethodEvent(QInputMethodEvent*); 184 virtual void focusInEvent(QFocusEvent*); 185 virtual void itemChange(ItemChange change, const ItemChangeData &value); 186 virtual void touchEvent(QTouchEvent*); 187 virtual void mousePressEvent(QMouseEvent*); 188 virtual void mouseMoveEvent(QMouseEvent*); 189 virtual void mouseReleaseEvent(QMouseEvent *); 190 virtual void mouseDoubleClickEvent(QMouseEvent*); 191 virtual void wheelEvent(QWheelEvent*); 192 virtual void hoverEnterEvent(QHoverEvent*); 193 virtual void hoverMoveEvent(QHoverEvent*); 194 virtual void hoverLeaveEvent(QHoverEvent*); 195 virtual void dragMoveEvent(QDragMoveEvent*); 196 virtual void dragEnterEvent(QDragEnterEvent*); 197 virtual void dragLeaveEvent(QDragLeaveEvent*); 198 virtual void dropEvent(QDropEvent*); 199 virtual bool event(QEvent*); 200 201private: 202 Q_DECLARE_PRIVATE(QQuickWebView) 203 204 void handleFlickableMousePress(const QPointF& position, qint64 eventTimestampMillis); 205 void handleFlickableMouseMove(const QPointF& position, qint64 eventTimestampMillis); 206 void handleFlickableMouseRelease(const QPointF& position, qint64 eventTimestampMillis); 207 208 QPointF contentPos() const; 209 void setContentPos(const QPointF&); 210 211 QQuickWebView(WKContextRef, WKPageGroupRef, QQuickItem* parent = 0); 212 WKPageRef pageRef() const; 213 214 void emitUrlChangeIfNeeded(); 215 216 Q_PRIVATE_SLOT(d_func(), void _q_onVisibleChanged()); 217 Q_PRIVATE_SLOT(d_func(), void _q_onUrlChanged()); 218 Q_PRIVATE_SLOT(d_func(), void _q_onReceivedResponseFromDownload(QWebDownloadItem*)); 219 Q_PRIVATE_SLOT(d_func(), void _q_onIconChangedForPageURL(const QString&)); 220 221 // Hides QObject::d_ptr allowing us to use the convenience macros. 222 QScopedPointer<QQuickWebViewPrivate> d_ptr; 223 224 friend class QWebKitTest; 225 friend class WebKit::PageViewportControllerClientQt; 226 friend class WebKit::QtWebPagePolicyClient; 227 friend class WebKit::QtWebPageUIClient; 228 friend class WTR::PlatformWebView; 229 friend class TestWebKitAPI::PlatformWebView; 230 friend class QQuickWebViewExperimental; 231}; 232 233QML_DECLARE_TYPE(QQuickWebView) 234 235class QWEBKIT_EXPORT QQuickWebViewAttached : public QObject { 236 Q_OBJECT 237 Q_PROPERTY(QQuickWebView* view READ view NOTIFY viewChanged FINAL) 238 239public: 240 QQuickWebViewAttached(QObject* object); 241 QQuickWebView* view() const { return m_view; } 242 void setView(QQuickWebView*); 243 244Q_SIGNALS: 245 void viewChanged(); 246 247private: 248 QQuickWebView* m_view; 249}; 250 251QML_DECLARE_TYPEINFO(QQuickWebView, QML_HAS_ATTACHED_PROPERTIES) 252 253class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject { 254 Q_OBJECT 255 Q_PROPERTY(QQuickWebPage* page READ page CONSTANT FINAL) 256 257 Q_PROPERTY(bool transparentBackground WRITE setTransparentBackground READ transparentBackground) 258 Q_PROPERTY(bool useDefaultContentItemSize WRITE setUseDefaultContentItemSize READ useDefaultContentItemSize) 259 260 Q_PROPERTY(int preferredMinimumContentsWidth WRITE setPreferredMinimumContentsWidth READ preferredMinimumContentsWidth NOTIFY preferredMinimumContentsWidthChanged) 261 Q_PROPERTY(int deviceWidth WRITE setDeviceWidth READ deviceWidth NOTIFY deviceWidthChanged) 262 Q_PROPERTY(int deviceHeight WRITE setDeviceHeight READ deviceHeight NOTIFY deviceHeightChanged) 263 264 Q_PROPERTY(QWebNavigationHistory* navigationHistory READ navigationHistory CONSTANT FINAL) 265 266 Q_PROPERTY(QQmlComponent* alertDialog READ alertDialog WRITE setAlertDialog NOTIFY alertDialogChanged) 267 Q_PROPERTY(QQmlComponent* confirmDialog READ confirmDialog WRITE setConfirmDialog NOTIFY confirmDialogChanged) 268 Q_PROPERTY(QQmlComponent* promptDialog READ promptDialog WRITE setPromptDialog NOTIFY promptDialogChanged) 269 Q_PROPERTY(QQmlComponent* authenticationDialog READ authenticationDialog WRITE setAuthenticationDialog NOTIFY authenticationDialogChanged) 270 Q_PROPERTY(QQmlComponent* proxyAuthenticationDialog READ proxyAuthenticationDialog WRITE setProxyAuthenticationDialog NOTIFY proxyAuthenticationDialogChanged) 271 Q_PROPERTY(QQmlComponent* certificateVerificationDialog READ certificateVerificationDialog WRITE setCertificateVerificationDialog NOTIFY certificateVerificationDialogChanged) 272 Q_PROPERTY(QQmlComponent* itemSelector READ itemSelector WRITE setItemSelector NOTIFY itemSelectorChanged) 273 Q_PROPERTY(QQmlComponent* filePicker READ filePicker WRITE setFilePicker NOTIFY filePickerChanged) 274 Q_PROPERTY(QQmlComponent* databaseQuotaDialog READ databaseQuotaDialog WRITE setDatabaseQuotaDialog NOTIFY databaseQuotaDialogChanged) 275 Q_PROPERTY(QQmlComponent* colorChooser READ colorChooser WRITE setColorChooser NOTIFY colorChooserChanged) 276 277 Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL) 278 Q_PROPERTY(QWebKitTest* test READ test CONSTANT FINAL) 279 Q_PROPERTY(QQmlListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates) 280 Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent NOTIFY userAgentChanged) 281 Q_PROPERTY(QList<QUrl> userScripts READ userScripts WRITE setUserScripts NOTIFY userScriptsChanged) 282 Q_PROPERTY(QUrl remoteInspectorUrl READ remoteInspectorUrl NOTIFY remoteInspectorUrlChanged FINAL) 283 Q_ENUMS(NavigationRequestActionExperimental) 284 Q_FLAGS(FindFlags) 285 286public: 287 enum NavigationRequestActionExperimental { 288 DownloadRequest = QQuickWebView::IgnoreRequest - 1 289 }; 290 291 enum FindFlag { 292 FindCaseSensitively = 1 << 0, 293 FindBackward = 1 << 1, 294 FindWrapsAroundDocument = 1 << 2, 295 FindHighlightAllOccurrences = 1 << 3 296 }; 297 Q_DECLARE_FLAGS(FindFlags, FindFlag) 298 299 virtual ~QQuickWebViewExperimental(); 300 301 QQmlComponent* alertDialog() const; 302 void setAlertDialog(QQmlComponent*); 303 QQmlComponent* confirmDialog() const; 304 void setConfirmDialog(QQmlComponent*); 305 QQmlComponent* promptDialog() const; 306 void setPromptDialog(QQmlComponent*); 307 QQmlComponent* authenticationDialog() const; 308 void setAuthenticationDialog(QQmlComponent*); 309 QQmlComponent* certificateVerificationDialog() const; 310 void setCertificateVerificationDialog(QQmlComponent*); 311 QQmlComponent* itemSelector() const; 312 void setItemSelector(QQmlComponent*); 313 QQmlComponent* proxyAuthenticationDialog() const; 314 void setProxyAuthenticationDialog(QQmlComponent*); 315 QQmlComponent* filePicker() const; 316 void setFilePicker(QQmlComponent*); 317 QQmlComponent* databaseQuotaDialog() const; 318 void setDatabaseQuotaDialog(QQmlComponent*); 319 QQmlComponent* colorChooser() const; 320 void setColorChooser(QQmlComponent*); 321 QString userAgent() const; 322 void setUserAgent(const QString& userAgent); 323 int deviceWidth() const; 324 void setDeviceWidth(int); 325 int deviceHeight() const; 326 void setDeviceHeight(int); 327 QList<QUrl> userScripts() const; 328 void setUserScripts(const QList<QUrl>& userScripts); 329 QUrl remoteInspectorUrl() const; 330 331 QWebKitTest* test(); 332 333 QWebPreferences* preferences() const; 334 QWebNavigationHistory* navigationHistory() const; 335 QQuickWebPage* page(); 336 337 static QQuickUrlSchemeDelegate* schemeDelegates_At(QQmlListProperty<QQuickUrlSchemeDelegate>*, int index); 338 static void schemeDelegates_Append(QQmlListProperty<QQuickUrlSchemeDelegate>*, QQuickUrlSchemeDelegate*); 339 static int schemeDelegates_Count(QQmlListProperty<QQuickUrlSchemeDelegate>*); 340 static void schemeDelegates_Clear(QQmlListProperty<QQuickUrlSchemeDelegate>*); 341 QQmlListProperty<QQuickUrlSchemeDelegate> schemeDelegates(); 342 void invokeApplicationSchemeHandler(WTF::PassRefPtr<WebKit::QtRefCountedNetworkRequestData>); 343 void sendApplicationSchemeReply(QQuickNetworkReply*); 344 345 bool transparentBackground() const; 346 void setTransparentBackground(bool); 347 348 bool useDefaultContentItemSize() const; 349 void setUseDefaultContentItemSize(bool enable); 350 351 int preferredMinimumContentsWidth() const; 352 void setPreferredMinimumContentsWidth(int); 353 354 // C++ only 355 bool renderToOffscreenBuffer() const; 356 void setRenderToOffscreenBuffer(bool enable); 357 static void setFlickableViewportEnabled(bool enable); 358 static bool flickableViewportEnabled(); 359 360public Q_SLOTS: 361 void goBackTo(int index); 362 void goForwardTo(int index); 363 void postMessage(const QString&); 364 void evaluateJavaScript(const QString& script, const QJSValue& value = QJSValue()); 365 void findText(const QString& string, FindFlags options = 0); 366 367Q_SIGNALS: 368 void loadVisuallyCommitted(); 369 void alertDialogChanged(); 370 void confirmDialogChanged(); 371 void promptDialogChanged(); 372 void authenticationDialogChanged(); 373 void certificateVerificationDialogChanged(); 374 void itemSelectorChanged(); 375 void filePickerChanged(); 376 void databaseQuotaDialogChanged(); 377 void colorChooserChanged(); 378 void downloadRequested(QWebDownloadItem* downloadItem); 379 void permissionRequested(QWebPermissionRequest* permission); 380 void messageReceived(const QVariantMap& message); 381 void proxyAuthenticationDialogChanged(); 382 void userAgentChanged(); 383 void deviceWidthChanged(); 384 void deviceHeightChanged(); 385 void enterFullScreenRequested(); 386 void exitFullScreenRequested(); 387 void userScriptsChanged(); 388 void preferredMinimumContentsWidthChanged(); 389 void remoteInspectorUrlChanged(); 390 void textFound(int matchCount); 391 392private: 393 QQuickWebViewExperimental(QQuickWebView* webView, QQuickWebViewPrivate* webViewPrivate); 394 QQuickWebView* q_ptr; 395 QQuickWebViewPrivate* d_ptr; 396 QObject* schemeParent; 397 QWebKitTest* m_test; 398 399 friend class WebKit::QtWebPageUIClient; 400 401 Q_DECLARE_PRIVATE(QQuickWebView) 402 Q_DECLARE_PUBLIC(QQuickWebView) 403}; 404 405Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWebViewExperimental::FindFlags) 406 407#endif // qquickwebview_p_h 408