1/*
2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2007 Staikos Computing Services Inc.
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 library 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 library; 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#ifndef QWEBPAGE_H
22#define QWEBPAGE_H
23
24#include <QtWebKit/qwebkitglobal.h>
25#include <QtWebKit/qwebfullscreenrequest.h>
26#include <QtWebKit/qwebsettings.h>
27
28#include <QtCore/qobject.h>
29#include <QtCore/qurl.h>
30#include <QtWidgets/qwidget.h>
31
32QT_BEGIN_NAMESPACE
33class QNetworkProxy;
34class QUndoStack;
35class QMenu;
36class QNetworkRequest;
37class QNetworkReply;
38class QNetworkAccessManager;
39class QScreen;
40QT_END_NAMESPACE
41
42class QWebElement;
43class QWebFrame;
44class QWebNetworkRequest;
45class QWebHistory;
46
47class QWebFrameData;
48class QWebFullScreenRequest;
49class QWebHistoryItem;
50class QWebHitTestResult;
51class QWebNetworkInterface;
52class QWebPageAdapter;
53class QWebPagePrivate;
54class QWebPluginFactory;
55class QWebSecurityOrigin;
56class QtViewportAttributesPrivate;
57
58namespace WebCore {
59 class ChromeClientQt;
60 class EditorClientQt;
61 class FrameLoaderClientQt;
62 class InspectorClientQt;
63 class InspectorServerRequestHandlerQt;
64 class InspectorFrontendClientQt;
65 class ResourceHandle;
66 class QNetworkReplyHandler;
67
68 struct FrameLoadRequest;
69}
70
71class QWEBKITWIDGETS_EXPORT QWebPage : public QObject {
72 Q_OBJECT
73
74 Q_PROPERTY(bool modified READ isModified)
75 Q_PROPERTY(QString selectedText READ selectedText)
76 Q_PROPERTY(QString selectedHtml READ selectedHtml)
77 Q_PROPERTY(bool hasSelection READ hasSelection)
78 Q_PROPERTY(QSize viewportSize READ viewportSize WRITE setViewportSize)
79 Q_PROPERTY(QSize preferredContentsSize READ preferredContentsSize WRITE setPreferredContentsSize)
80 Q_PROPERTY(bool forwardUnsupportedContent READ forwardUnsupportedContent WRITE setForwardUnsupportedContent)
81 Q_PROPERTY(LinkDelegationPolicy linkDelegationPolicy READ linkDelegationPolicy WRITE setLinkDelegationPolicy)
82 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
83 Q_PROPERTY(bool contentEditable READ isContentEditable WRITE setContentEditable)
84 Q_PROPERTY(VisibilityState visibilityState READ visibilityState WRITE setVisibilityState)
85 Q_PROPERTY(bool recentlyAudible READ recentlyAudible NOTIFY recentlyAudibleChanged)
86 Q_ENUMS(LinkDelegationPolicy MessageLevel MessageSource NavigationType VisibilityState WebAction)
87public:
88 enum NavigationType {
89 NavigationTypeLinkClicked,
90 NavigationTypeFormSubmitted,
91 NavigationTypeBackOrForward,
92 NavigationTypeReload,
93 NavigationTypeFormResubmitted,
94 NavigationTypeOther
95 };
96
97 enum WebAction {
98 NoWebAction = - 1,
99
100 OpenLink,
101
102 OpenLinkInNewWindow,
103 OpenFrameInNewWindow,
104
105 DownloadLinkToDisk,
106 CopyLinkToClipboard,
107
108 OpenImageInNewWindow,
109 DownloadImageToDisk,
110 CopyImageToClipboard,
111
112 Back,
113 Forward,
114 Stop,
115 Reload,
116
117 Cut,
118 Copy,
119 Paste,
120
121 Undo,
122 Redo,
123 MoveToNextChar,
124 MoveToPreviousChar,
125 MoveToNextWord,
126 MoveToPreviousWord,
127 MoveToNextLine,
128 MoveToPreviousLine,
129 MoveToStartOfLine,
130 MoveToEndOfLine,
131 MoveToStartOfBlock,
132 MoveToEndOfBlock,
133 MoveToStartOfDocument,
134 MoveToEndOfDocument,
135 SelectNextChar,
136 SelectPreviousChar,
137 SelectNextWord,
138 SelectPreviousWord,
139 SelectNextLine,
140 SelectPreviousLine,
141 SelectStartOfLine,
142 SelectEndOfLine,
143 SelectStartOfBlock,
144 SelectEndOfBlock,
145 SelectStartOfDocument,
146 SelectEndOfDocument,
147 DeleteStartOfWord,
148 DeleteEndOfWord,
149
150 SetTextDirectionDefault,
151 SetTextDirectionLeftToRight,
152 SetTextDirectionRightToLeft,
153
154 ToggleBold,
155 ToggleItalic,
156 ToggleUnderline,
157
158 InspectElement,
159
160 InsertParagraphSeparator,
161 InsertLineSeparator,
162
163 SelectAll,
164 ReloadAndBypassCache,
165
166 PasteAndMatchStyle,
167 RemoveFormat,
168
169 ToggleStrikethrough,
170 ToggleSubscript,
171 ToggleSuperscript,
172 InsertUnorderedList,
173 InsertOrderedList,
174 Indent,
175 Outdent,
176
177 AlignCenter,
178 AlignJustified,
179 AlignLeft,
180 AlignRight,
181
182 StopScheduledPageRefresh,
183
184 CopyImageUrlToClipboard,
185
186 OpenLinkInThisWindow,
187
188 DownloadMediaToDisk,
189 CopyMediaUrlToClipboard,
190 ToggleMediaControls,
191 ToggleMediaLoop,
192 ToggleMediaPlayPause,
193 ToggleMediaMute,
194 ToggleVideoFullscreen,
195
196 RequestClose,
197
198 Unselect,
199
200 WebActionCount
201 };
202
203 enum FindFlag {
204 FindBackward = 1,
205 FindCaseSensitively = 2,
206 FindWrapsAroundDocument = 4,
207 HighlightAllOccurrences = 8,
208 FindAtWordBeginningsOnly = 16,
209 TreatMedialCapitalAsWordBeginning = 32,
210 FindBeginsInSelection = 64
211 };
212 Q_DECLARE_FLAGS(FindFlags, FindFlag)
213
214 enum LinkDelegationPolicy {
215 DontDelegateLinks,
216 DelegateExternalLinks,
217 DelegateAllLinks
218 };
219
220 enum WebWindowType {
221 WebBrowserWindow,
222 WebModalDialog
223 };
224
225 enum PermissionPolicy {
226 PermissionUnknown,
227 PermissionGrantedByUser,
228 PermissionDeniedByUser
229 };
230
231 enum Feature {
232 Notifications,
233 Geolocation
234 };
235
236 enum VisibilityState {
237 VisibilityStateVisible,
238 VisibilityStateHidden,
239 VisibilityStatePrerender,
240 VisibilityStateUnloaded
241 };
242
243 enum MessageSource {
244 XmlMessageSource,
245 JSMessageSource,
246 NetworkMessageSource,
247 ConsoleAPIMessageSource,
248 StorageMessageSource,
249 AppCacheMessageSource,
250 RenderingMessageSource,
251 CSSMessageSource,
252 SecurityMessageSource,
253 ContentBlockerMessageSource,
254 OtherMessageSource,
255 };
256
257 enum MessageLevel {
258 LogMessageLevel = 1,
259 WarningMessageLevel = 2,
260 ErrorMessageLevel = 3,
261 DebugMessageLevel = 4,
262 InfoMessageLevel = 5,
263 };
264
265 class QWEBKITWIDGETS_EXPORT ViewportAttributes {
266 public:
267 ViewportAttributes();
268 ViewportAttributes(const QWebPage::ViewportAttributes& other);
269
270 ~ViewportAttributes();
271
272 QWebPage::ViewportAttributes& operator=(const QWebPage::ViewportAttributes& other);
273
274 inline qreal initialScaleFactor() const { return m_initialScaleFactor; }
275 inline qreal minimumScaleFactor() const { return m_minimumScaleFactor; }
276 inline qreal maximumScaleFactor() const { return m_maximumScaleFactor; }
277 inline qreal devicePixelRatio() const { return m_devicePixelRatio; }
278 inline bool isUserScalable() const { return m_isUserScalable; }
279 inline bool isValid() const { return m_isValid; }
280 inline QSizeF size() const { return m_size; }
281
282 private:
283 QSharedDataPointer<QtViewportAttributesPrivate> d;
284 qreal m_initialScaleFactor;
285 qreal m_minimumScaleFactor;
286 qreal m_maximumScaleFactor;
287 qreal m_devicePixelRatio;
288 bool m_isUserScalable;
289 bool m_isValid;
290 QSizeF m_size;
291
292 friend class WebCore::ChromeClientQt;
293 friend class QWebPage;
294 };
295
296
297 explicit QWebPage(QObject *parent = Q_NULLPTR);
298 ~QWebPage();
299
300 QWebFrame *mainFrame() const;
301 QWebFrame *currentFrame() const;
302 QWebFrame* frameAt(const QPoint& pos) const;
303
304 QWebHistory *history() const;
305 QWebSettings *settings() const;
306
307 void setView(QWidget *view);
308 QWidget *view() const;
309
310 bool isModified() const;
311#ifndef QT_NO_UNDOSTACK
312 QUndoStack *undoStack() const;
313#endif
314
315 void setNetworkAccessManager(QNetworkAccessManager *manager);
316 QNetworkAccessManager *networkAccessManager() const;
317
318 void setPluginFactory(QWebPluginFactory *factory);
319 QWebPluginFactory *pluginFactory() const;
320
321 quint64 totalBytes() const;
322 quint64 bytesReceived() const;
323
324 VisibilityState visibilityState() const;
325 void setVisibilityState(VisibilityState);
326
327 bool recentlyAudible() const;
328
329 bool hasSelection() const;
330 QString selectedText() const;
331 QString selectedHtml() const;
332
333#ifndef QT_NO_ACTION
334 QAction *action(WebAction action) const;
335 QAction *customAction(int action) const;
336#endif
337 virtual void triggerAction(WebAction action, bool checked = false);
338
339 void setDevicePixelRatio(qreal ratio);
340 qreal devicePixelRatio() const;
341 void resetDevicePixelRatio();
342
343 QSize viewportSize() const;
344 void setViewportSize(const QSize &size) const;
345 ViewportAttributes viewportAttributesForSize(const QSize& availableSize) const;
346
347 QSize preferredContentsSize() const;
348 void setPreferredContentsSize(const QSize &size) const;
349 void setActualVisibleContentRect(const QRect& rect) const;
350
351 bool event(QEvent*) Q_DECL_OVERRIDE;
352 bool focusNextPrevChild(bool next);
353
354 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
355
356 bool findText(const QString &subString, FindFlags options = FindFlags());
357
358 void setForwardUnsupportedContent(bool forward);
359 bool forwardUnsupportedContent() const;
360
361 void setLinkDelegationPolicy(LinkDelegationPolicy policy);
362 LinkDelegationPolicy linkDelegationPolicy() const;
363
364 void setPalette(const QPalette &palette);
365 QPalette palette() const;
366
367 void setContentEditable(bool editable);
368 bool isContentEditable() const;
369
370#ifndef QT_NO_CONTEXTMENU
371 bool swallowContextMenuEvent(QContextMenuEvent *event);
372#endif
373 void updatePositionDependentActions(const QPoint &pos);
374
375 QMenu *createStandardContextMenu();
376
377 void setFeaturePermission(QWebFrame* frame, Feature feature, PermissionPolicy policy);
378
379 QStringList supportedContentTypes() const;
380 bool supportsContentType(const QString& mimeType) const;
381
382 enum Extension {
383 ChooseMultipleFilesExtension,
384 ErrorPageExtension
385 };
386 class ExtensionOption
387 {};
388 class ExtensionReturn
389 {};
390
391 class ChooseMultipleFilesExtensionOption : public ExtensionOption {
392 public:
393 QWebFrame *parentFrame;
394 QStringList suggestedFileNames;
395 };
396
397 class ChooseMultipleFilesExtensionReturn : public ExtensionReturn {
398 public:
399 QStringList fileNames;
400 };
401
402 enum ErrorDomain { QtNetwork, Http, WebKit };
403 class ErrorPageExtensionOption : public ExtensionOption {
404 public:
405 QUrl url;
406 QWebFrame* frame;
407 ErrorDomain domain;
408 int error;
409 QString errorString;
410 };
411
412 class ErrorPageExtensionReturn : public ExtensionReturn {
413 public:
414 ErrorPageExtensionReturn() : contentType(QLatin1String("text/html")), encoding(QLatin1String("utf-8")) {};
415 QString contentType;
416 QString encoding;
417 QUrl baseUrl;
418 QByteArray content;
419 };
420
421
422 virtual bool extension(Extension extension, const ExtensionOption *option = Q_NULLPTR, ExtensionReturn *output = Q_NULLPTR);
423 virtual bool supportsExtension(Extension extension) const;
424
425 QWebPageAdapter* handle() const;
426
427 virtual bool shouldInterruptJavaScript();
428
429Q_SIGNALS:
430 void loadStarted();
431 void loadProgress(int progress);
432 void loadFinished(bool ok);
433
434 void linkHovered(const QString &link, const QString &title, const QString &textContent);
435 void statusBarMessage(const QString& text);
436 void selectionChanged();
437 void frameCreated(QWebFrame *frame);
438 void geometryChangeRequested(const QRect& geom);
439 void repaintRequested(const QRect& dirtyRect);
440 void scrollRequested(int dx, int dy, const QRect& scrollViewRect);
441 void windowCloseRequested();
442 void printRequested(QWebFrame *frame);
443 void linkClicked(const QUrl &url);
444
445 void toolBarVisibilityChangeRequested(bool visible);
446 void statusBarVisibilityChangeRequested(bool visible);
447 void menuBarVisibilityChangeRequested(bool visible);
448
449 void unsupportedContent(QNetworkReply *reply);
450 void downloadRequested(const QNetworkRequest &request);
451
452 void focusedElementChanged(const QWebElement &element);
453 void microFocusChanged();
454 void contentsChanged();
455 void databaseQuotaExceeded(QWebFrame* frame, QString databaseName);
456 void applicationCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 defaultOriginQuota, quint64 totalSpaceNeeded);
457
458 void saveFrameStateRequested(QWebFrame* frame, QWebHistoryItem* item);
459 void restoreFrameStateRequested(QWebFrame* frame);
460
461 void viewportChangeRequested();
462
463 void featurePermissionRequested(QWebFrame* frame, QWebPage::Feature feature);
464 void featurePermissionRequestCanceled(QWebFrame* frame, QWebPage::Feature feature);
465 void fullScreenRequested(QWebFullScreenRequest fullScreenRequest);
466
467 void consoleMessageReceived(MessageSource source, MessageLevel level, const QString& message, int lineNumber, const QString& sourceID);
468
469 void recentlyAudibleChanged(bool recentlyAudible);
470
471protected:
472 virtual QWebPage *createWindow(WebWindowType type);
473 virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
474
475 virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
476 virtual QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile);
477 virtual void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg);
478 virtual bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg);
479 virtual bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result);
480 virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID);
481
482 virtual QString userAgentForUrl(const QUrl& url) const;
483
484private:
485 Q_PRIVATE_SLOT(d, void _q_onLoadProgressChanged(int))
486#ifndef QT_NO_ACTION
487 Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked))
488 Q_PRIVATE_SLOT(d, void _q_customActionTriggered(bool checked))
489#endif
490 Q_PRIVATE_SLOT(d, void _q_cleanupLeakMessages())
491 Q_PRIVATE_SLOT(d, void _q_updateScreen(QScreen*))
492
493 QWebPagePrivate *d;
494
495 friend class QWebFrame;
496 friend class QWebFullScreenRequest;
497 friend class QWebPagePrivate;
498 friend class QWebView;
499 friend class QWebViewPrivate;
500 friend class QGraphicsWebView;
501 friend class QGraphicsWebViewPrivate;
502 friend class QWebInspector;
503 friend class WebCore::ChromeClientQt;
504 friend class WebCore::EditorClientQt;
505 friend class WebCore::FrameLoaderClientQt;
506 friend class WebCore::InspectorClientQt;
507 friend class WebCore::InspectorServerRequestHandlerQt;
508 friend class WebCore::InspectorFrontendClientQt;
509 friend class WebCore::ResourceHandle;
510 friend class WebCore::QNetworkReplyHandler;
511 friend class DumpRenderTreeSupportQt;
512};
513
514Q_DECLARE_OPERATORS_FOR_FLAGS(QWebPage::FindFlags)
515
516#endif
517