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