• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <QtGui/qwidget.h>
30 
31 QT_BEGIN_NAMESPACE
32 class QNetworkProxy;
33 class QUndoStack;
34 class QMenu;
35 class QNetworkRequest;
36 class QNetworkReply;
37 class QNetworkAccessManager;
38 QT_END_NAMESPACE
39 
40 class QWebElement;
41 class QWebFrame;
42 class QWebNetworkRequest;
43 class QWebHistory;
44 
45 class QWebPagePrivate;
46 class QWebFrameData;
47 class QWebNetworkInterface;
48 class QWebPluginFactory;
49 class QWebHitTestResult;
50 class QWebHistoryItem;
51 
52 namespace WebCore {
53     class ChromeClientQt;
54     class EditorClientQt;
55     class FrameLoaderClientQt;
56     class InspectorClientQt;
57     class ResourceHandle;
58     class HitTestResult;
59     class QNetworkReplyHandler;
60 
61     struct FrameLoadRequest;
62 }
63 
64 class QWEBKIT_EXPORT QWebPage : public QObject {
65     Q_OBJECT
66 
67     Q_PROPERTY(bool modified READ isModified)
68     Q_PROPERTY(QString selectedText READ selectedText)
69     Q_PROPERTY(QSize viewportSize READ viewportSize WRITE setViewportSize)
70     Q_PROPERTY(QSize preferredContentsSize READ preferredContentsSize WRITE setPreferredContentsSize)
71     Q_PROPERTY(bool forwardUnsupportedContent READ forwardUnsupportedContent WRITE setForwardUnsupportedContent)
72     Q_PROPERTY(LinkDelegationPolicy linkDelegationPolicy READ linkDelegationPolicy WRITE setLinkDelegationPolicy)
73     Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
74     Q_PROPERTY(bool contentEditable READ isContentEditable WRITE setContentEditable)
75     Q_ENUMS(LinkDelegationPolicy NavigationType WebAction)
76 public:
77     enum NavigationType {
78         NavigationTypeLinkClicked,
79         NavigationTypeFormSubmitted,
80         NavigationTypeBackOrForward,
81         NavigationTypeReload,
82         NavigationTypeFormResubmitted,
83         NavigationTypeOther
84     };
85 
86     enum WebAction {
87         NoWebAction = - 1,
88 
89         OpenLink,
90 
91         OpenLinkInNewWindow,
92         OpenFrameInNewWindow,
93 
94         DownloadLinkToDisk,
95         CopyLinkToClipboard,
96 
97         OpenImageInNewWindow,
98         DownloadImageToDisk,
99         CopyImageToClipboard,
100 
101         Back,
102         Forward,
103         Stop,
104         Reload,
105 
106         Cut,
107         Copy,
108         Paste,
109 
110         Undo,
111         Redo,
112         MoveToNextChar,
113         MoveToPreviousChar,
114         MoveToNextWord,
115         MoveToPreviousWord,
116         MoveToNextLine,
117         MoveToPreviousLine,
118         MoveToStartOfLine,
119         MoveToEndOfLine,
120         MoveToStartOfBlock,
121         MoveToEndOfBlock,
122         MoveToStartOfDocument,
123         MoveToEndOfDocument,
124         SelectNextChar,
125         SelectPreviousChar,
126         SelectNextWord,
127         SelectPreviousWord,
128         SelectNextLine,
129         SelectPreviousLine,
130         SelectStartOfLine,
131         SelectEndOfLine,
132         SelectStartOfBlock,
133         SelectEndOfBlock,
134         SelectStartOfDocument,
135         SelectEndOfDocument,
136         DeleteStartOfWord,
137         DeleteEndOfWord,
138 
139         SetTextDirectionDefault,
140         SetTextDirectionLeftToRight,
141         SetTextDirectionRightToLeft,
142 
143         ToggleBold,
144         ToggleItalic,
145         ToggleUnderline,
146 
147         InspectElement,
148 
149         InsertParagraphSeparator,
150         InsertLineSeparator,
151 
152         SelectAll,
153         ReloadAndBypassCache,
154 
155         PasteAndMatchStyle,
156         RemoveFormat,
157 
158         ToggleStrikethrough,
159         ToggleSubscript,
160         ToggleSuperscript,
161         InsertUnorderedList,
162         InsertOrderedList,
163         Indent,
164         Outdent,
165 
166         AlignCenter,
167         AlignJustified,
168         AlignLeft,
169         AlignRight,
170 
171         WebActionCount
172     };
173 
174     enum FindFlag {
175         FindBackward = 1,
176         FindCaseSensitively = 2,
177         FindWrapsAroundDocument = 4,
178         HighlightAllOccurrences = 8
179     };
180     Q_DECLARE_FLAGS(FindFlags, FindFlag)
181 
182     enum LinkDelegationPolicy {
183         DontDelegateLinks,
184         DelegateExternalLinks,
185         DelegateAllLinks
186     };
187 
188     enum WebWindowType {
189         WebBrowserWindow,
190         WebModalDialog
191     };
192 
193     explicit QWebPage(QObject *parent = 0);
194     ~QWebPage();
195 
196     QWebFrame *mainFrame() const;
197     QWebFrame *currentFrame() const;
198     QWebFrame* frameAt(const QPoint& pos) const;
199 
200     QWebHistory *history() const;
201     QWebSettings *settings() const;
202 
203     void setView(QWidget *view);
204     QWidget *view() const;
205 
206     bool isModified() const;
207 #ifndef QT_NO_UNDOSTACK
208     QUndoStack *undoStack() const;
209 #endif
210 
211     void setNetworkAccessManager(QNetworkAccessManager *manager);
212     QNetworkAccessManager *networkAccessManager() const;
213 
214     void setPluginFactory(QWebPluginFactory *factory);
215     QWebPluginFactory *pluginFactory() const;
216 
217     quint64 totalBytes() const;
218     quint64 bytesReceived() const;
219 
220     QString selectedText() const;
221 
222     QAction *action(WebAction action) const;
223     virtual void triggerAction(WebAction action, bool checked = false);
224 
225     QSize viewportSize() const;
226     void setViewportSize(const QSize &size) const;
227 
228     QSize preferredContentsSize() const;
229     void setPreferredContentsSize(const QSize &size) const;
230 
231     virtual bool event(QEvent*);
232     bool focusNextPrevChild(bool next);
233 
234     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
235 
236     bool findText(const QString &subString, FindFlags options = 0);
237 
238     void setForwardUnsupportedContent(bool forward);
239     bool forwardUnsupportedContent() const;
240 
241     void setLinkDelegationPolicy(LinkDelegationPolicy policy);
242     LinkDelegationPolicy linkDelegationPolicy() const;
243 
244     void setPalette(const QPalette &palette);
245     QPalette palette() const;
246 
247     void setContentEditable(bool editable);
248     bool isContentEditable() const;
249 
250 #ifndef QT_NO_CONTEXTMENU
251     bool swallowContextMenuEvent(QContextMenuEvent *event);
252 #endif
253     void updatePositionDependentActions(const QPoint &pos);
254 
255     QMenu *createStandardContextMenu();
256 
257     enum Extension {
258         ChooseMultipleFilesExtension,
259         ErrorPageExtension
260     };
261     class ExtensionOption
262     {};
263     class ExtensionReturn
264     {};
265 
266     class ChooseMultipleFilesExtensionOption : public ExtensionOption {
267     public:
268         QWebFrame *parentFrame;
269         QStringList suggestedFileNames;
270     };
271 
272     class ChooseMultipleFilesExtensionReturn : public ExtensionReturn {
273     public:
274         QStringList fileNames;
275     };
276 
277     enum ErrorDomain { QtNetwork, Http, WebKit };
278     class ErrorPageExtensionOption : public ExtensionOption {
279     public:
280         QUrl url;
281         QWebFrame* frame;
282         ErrorDomain domain;
283         int error;
284         QString errorString;
285     };
286 
287     class ErrorPageExtensionReturn : public ExtensionReturn {
288     public:
ErrorPageExtensionReturn()289         ErrorPageExtensionReturn() : contentType(QLatin1String("text/html")), encoding(QLatin1String("utf-8")) {};
290         QString contentType;
291         QString encoding;
292         QUrl baseUrl;
293         QByteArray content;
294     };
295 
296 
297     virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
298     virtual bool supportsExtension(Extension extension) const;
299 
handle()300     inline QWebPagePrivate* handle() const { return d; }
301 
302 public Q_SLOTS:
303     bool shouldInterruptJavaScript();
304 
305 Q_SIGNALS:
306     void loadStarted();
307     void loadProgress(int progress);
308     void loadFinished(bool ok);
309 
310     void linkHovered(const QString &link, const QString &title, const QString &textContent);
311     void statusBarMessage(const QString& text);
312     void selectionChanged();
313     void frameCreated(QWebFrame *frame);
314     void geometryChangeRequested(const QRect& geom);
315     void repaintRequested(const QRect& dirtyRect);
316     void scrollRequested(int dx, int dy, const QRect& scrollViewRect);
317     void windowCloseRequested();
318     void printRequested(QWebFrame *frame);
319     void linkClicked(const QUrl &url);
320 
321     void toolBarVisibilityChangeRequested(bool visible);
322     void statusBarVisibilityChangeRequested(bool visible);
323     void menuBarVisibilityChangeRequested(bool visible);
324 
325     void unsupportedContent(QNetworkReply *reply);
326     void downloadRequested(const QNetworkRequest &request);
327 
328     void microFocusChanged();
329     void contentsChanged();
330     void databaseQuotaExceeded(QWebFrame* frame, QString databaseName);
331 
332     void saveFrameStateRequested(QWebFrame* frame, QWebHistoryItem* item);
333     void restoreFrameStateRequested(QWebFrame* frame);
334 
335 protected:
336     virtual QWebPage *createWindow(WebWindowType type);
337     virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
338 
339     virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
340     virtual QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile);
341     virtual void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg);
342     virtual bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg);
343     virtual bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result);
344     virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID);
345 
346     virtual QString userAgentForUrl(const QUrl& url) const;
347 
348 private:
349     Q_PRIVATE_SLOT(d, void _q_onLoadProgressChanged(int))
350     Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked))
351     Q_PRIVATE_SLOT(d, void _q_cleanupLeakMessages())
352 
353     QWebPagePrivate *d;
354 
355     friend class QWebFrame;
356     friend class QWebPagePrivate;
357     friend class QWebView;
358     friend class QGraphicsWebView;
359     friend class QWebInspector;
360     friend class WebCore::ChromeClientQt;
361     friend class WebCore::EditorClientQt;
362     friend class WebCore::FrameLoaderClientQt;
363     friend class WebCore::InspectorClientQt;
364     friend class WebCore::ResourceHandle;
365     friend class WebCore::QNetworkReplyHandler;
366 };
367 
368 Q_DECLARE_OPERATORS_FOR_FLAGS(QWebPage::FindFlags)
369 
370 #endif
371