1/*
2 Copyright (C) 2008,2009 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 QWEBFRAME_H
22#define QWEBFRAME_H
23
24#include <QtCore/qobject.h>
25#include <QtCore/qurl.h>
26#include <QtCore/qvariant.h>
27#include <QtGui/qicon.h>
28#include <QtNetwork/qnetworkaccessmanager.h>
29#include <QtWebKit/qwebkitglobal.h>
30
31QT_BEGIN_NAMESPACE
32class QRect;
33class QPoint;
34class QPainter;
35class QPixmap;
36class QMouseEvent;
37class QWheelEvent;
38class QNetworkRequest;
39class QRegion;
40class QPrinter;
41QT_END_NAMESPACE
42
43class QWebNetworkRequest;
44class QWebFrameAdapter;
45class QWebFramePrivate;
46class QWebPage;
47class QWebPageAdapter;
48class QWebHitTestResult;
49class QWebHistoryItem;
50class QWebSecurityOrigin;
51class QWebElement;
52class QWebElementCollection;
53class QWebScriptWorld;
54
55class DumpRenderTreeSupportQt;
56namespace WebCore {
57 class WidgetPrivate;
58 class FrameLoaderClientQt;
59 class ChromeClientQt;
60 class TextureMapperLayerClientQt;
61}
62class QWebFrameData;
63class QWebHitTestResultPrivate;
64class QWebFrame;
65
66class QWEBKITWIDGETS_EXPORT QWebHitTestResult {
67public:
68 QWebHitTestResult();
69 QWebHitTestResult(const QWebHitTestResult &other);
70 QWebHitTestResult &operator=(const QWebHitTestResult &other);
71 ~QWebHitTestResult();
72
73 bool isNull() const;
74
75 QPoint pos() const;
76 QRect boundingRect() const;
77 QWebElement enclosingBlockElement() const;
78 QString title() const;
79
80 QString linkText() const;
81 QUrl linkUrl() const;
82#if QT_DEPRECATED_SINCE(5,5)
83 QT_DEPRECATED QUrl linkTitle() const;
84#endif // QT_DEPRECATED_SINCE(5,5)
85 QString linkTitleString() const;
86 QWebFrame *linkTargetFrame() const;
87 QWebElement linkElement() const;
88
89 QString alternateText() const; // for img, area, input and applet
90
91 QUrl imageUrl() const;
92 QPixmap pixmap() const;
93 QUrl mediaUrl() const;
94
95 bool isContentEditable() const;
96 bool isContentSelected() const;
97
98 QWebElement element() const;
99
100 QWebFrame *frame() const;
101
102private:
103 QWebHitTestResult(QWebHitTestResultPrivate *priv);
104 QWebHitTestResultPrivate *d;
105
106 friend class QWebFrame;
107 friend class QWebPagePrivate;
108 friend class QWebPage;
109};
110
111class QWEBKITWIDGETS_EXPORT QWebFrame : public QObject {
112 Q_OBJECT
113 Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false)
114 Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
115 Q_PROPERTY(QString title READ title)
116 Q_PROPERTY(QUrl url READ url WRITE setUrl)
117 Q_PROPERTY(QUrl requestedUrl READ requestedUrl)
118 Q_PROPERTY(QUrl baseUrl READ baseUrl)
119 Q_PROPERTY(QIcon icon READ icon)
120 Q_PROPERTY(QSize contentsSize READ contentsSize)
121 Q_PROPERTY(QPoint scrollPosition READ scrollPosition WRITE setScrollPosition)
122 Q_PROPERTY(bool focus READ hasFocus)
123private:
124 QWebFrame(QWebPage *parentPage);
125 QWebFrame(QWebFrame* parent, QWebFrameData*);
126 ~QWebFrame();
127
128public:
129 enum ValueOwnership {
130 QtOwnership,
131 ScriptOwnership,
132 AutoOwnership
133 };
134
135 QWebPage *page() const;
136
137 void load(const QUrl &url);
138 void load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray &body = QByteArray());
139 void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
140 void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
141
142 void addToJavaScriptWindowObject(const QString &name, QObject *object, ValueOwnership ownership = QtOwnership);
143 QString toHtml() const;
144 QString toPlainText() const;
145
146 QString title() const;
147 void setUrl(const QUrl &url);
148 QUrl url() const;
149 QUrl requestedUrl() const;
150 QUrl baseUrl() const;
151 QIcon icon() const;
152 QMultiMap<QString, QString> metaData() const;
153
154 QString frameName() const;
155
156 QWebFrame *parentFrame() const;
157 QList<QWebFrame*> childFrames() const;
158
159 Qt::ScrollBarPolicy scrollBarPolicy(Qt::Orientation orientation) const;
160 void setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy);
161
162 void setScrollBarValue(Qt::Orientation orientation, int value);
163 int scrollBarValue(Qt::Orientation orientation) const;
164 int scrollBarMinimum(Qt::Orientation orientation) const;
165 int scrollBarMaximum(Qt::Orientation orientation) const;
166 QRect scrollBarGeometry(Qt::Orientation orientation) const;
167
168 void scroll(int, int);
169 QPoint scrollPosition() const;
170 void setScrollPosition(const QPoint &pos);
171
172 void scrollToAnchor(const QString& anchor);
173
174 enum RenderLayer {
175 ContentsLayer = 0x10,
176 ScrollBarLayer = 0x20,
177 PanIconLayer = 0x40,
178
179 AllLayers = 0xff
180 };
181 Q_DECLARE_FLAGS(RenderLayers, RenderLayer)
182
183 void render(QPainter*, const QRegion& clip = QRegion());
184 void render(QPainter*, RenderLayers layer, const QRegion& clip = QRegion());
185
186 void setTextSizeMultiplier(qreal factor);
187 qreal textSizeMultiplier() const;
188
189 qreal zoomFactor() const;
190 void setZoomFactor(qreal factor);
191
192 bool hasFocus() const;
193 void setFocus();
194
195 QPoint pos() const;
196 QRect geometry() const;
197 QSize contentsSize() const;
198
199 QWebElement documentElement() const;
200 QWebElement ownerElement() const;
201 QWebElementCollection findAllElements(const QString &selectorQuery) const;
202 QWebElement findFirstElement(const QString &selectorQuery) const;
203
204 QWebHitTestResult hitTestContent(const QPoint &pos) const;
205
206 bool event(QEvent *) Q_DECL_OVERRIDE;
207
208 QWebSecurityOrigin securityOrigin() const;
209 QWebFrameAdapter* handle() const;
210
211public Q_SLOTS:
212 QVariant evaluateJavaScript(const QString& scriptSource);
213#ifndef QT_NO_PRINTER
214 void print(QPrinter *printer) const;
215#endif
216
217Q_SIGNALS:
218 void javaScriptWindowObjectCleared();
219
220 void provisionalLoad();
221 void titleChanged(const QString &title);
222 void urlChanged(const QUrl &url);
223
224 void initialLayoutCompleted();
225
226 void iconChanged();
227
228 void contentsSizeChanged(const QSize &size);
229
230 void loadStarted();
231 void loadFinished(bool ok);
232
233 void pageChanged();
234
235private:
236 friend class QGraphicsWebView;
237 friend class QWebPage;
238 friend class QWebPagePrivate;
239 friend class QWebFramePrivate;
240 friend class DumpRenderTreeSupportQt;
241 friend class WebCore::WidgetPrivate;
242 friend class WebCore::FrameLoaderClientQt;
243 friend class WebCore::ChromeClientQt;
244 friend class WebCore::TextureMapperLayerClientQt;
245 QWebFramePrivate *d;
246 Q_PRIVATE_SLOT(d, void _q_orientationChanged())
247};
248
249Q_DECLARE_OPERATORS_FOR_FLAGS(QWebFrame::RenderLayers)
250
251#endif
252