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