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