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