1/*
2 * Copyright (C) 2015 The Qt Company Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef QWebFrameAdapter_h
21#define QWebFrameAdapter_h
22
23#if ENABLE(ORIENTATION_EVENTS) && HAVE(QTSENSORS)
24#include "qorientationsensor.h"
25#endif // ENABLE(ORIENTATION_EVENTS).
26#include "qwebelement.h"
27
28#include <QList>
29#include <QNetworkAccessManager>
30#include <QPixmap>
31#include <QPointer>
32#include <QRect>
33#include <QSize>
34#include <QUrl>
35
36namespace WebCore {
37class Frame;
38class FrameLoaderClientQt;
39class HitTestResult;
40class GraphicsContext;
41class IntRect;
42class Scrollbar;
43class TextureMapperLayer;
44}
45
46QT_BEGIN_NAMESPACE
47class QPoint;
48QT_END_NAMESPACE
49
50#if ENABLE(QT_GESTURE_EVENTS)
51struct QGestureEventFacade;
52#endif
53class QWebFrame;
54class QWebFrameData;
55class QWebPageAdapter;
56class QWebSecurityOrigin;
57
58class QWEBKIT_EXPORT QWebHitTestResultPrivate {
59public:
60 QWebHitTestResultPrivate()
61 : isContentEditable(false)
62 , isContentSelected(false), isScrollBar(false)
63 , innerNode(0)
64 , innerNonSharedNode(0)
65 , webCoreFrame(0)
66 { }
67 QWebHitTestResultPrivate(const WebCore::HitTestResult &);
68 QWebHitTestResultPrivate(const QWebHitTestResultPrivate&);
69 QWebHitTestResultPrivate& operator=(const QWebHitTestResultPrivate&);
70 ~QWebHitTestResultPrivate();
71
72 QWebElement elementForInnerNode() const;
73
74 QPoint pos;
75 QRect boundingRect;
76 QWebElement enclosingBlock;
77 QString title;
78 QString linkText;
79 QUrl linkUrl;
80 QString linkTitle;
81 QPointer<QObject> linkTargetFrame;
82 QWebElement linkElement;
83 QString alternateText;
84 QUrl imageUrl;
85 QUrl mediaUrl;
86 QPixmap pixmap;
87 bool isContentEditable;
88 bool isContentSelected;
89 bool isScrollBar;
90 QPointer<QObject> frame;
91private:
92 WebCore::Node* innerNode;
93 WebCore::Node* innerNonSharedNode;
94 WebCore::Frame* webCoreFrame;
95 friend class QWebFrameAdapter;
96 friend class QWebPageAdapter;
97};
98
99class QWEBKIT_EXPORT QWebFrameAdapter {
100public:
101 enum ValueOwnership {
102 QtOwnership,
103 ScriptOwnership,
104 AutoOwnership
105 };
106
107 enum RenderLayers {
108 ContentsLayer = 0x10,
109 ScrollBarLayer = 0x20,
110 PanIconLayer = 0x40,
111
112 AllLayers = 0xff
113 };
114
115 static QUrl ensureAbsoluteUrl(const QUrl&);
116
117 QWebFrameAdapter();
118 virtual ~QWebFrameAdapter();
119
120 virtual QWebFrame* apiHandle() = 0;
121 virtual QObject* handle() = 0;
122 virtual void contentsSizeDidChange(const QSize&) = 0;
123 virtual int scrollBarPolicy(Qt::Orientation) const = 0;
124 virtual void emitUrlChanged() = 0;
125 virtual void didStartProvisionalLoad() = 0;
126 virtual void didClearWindowObject() = 0;
127 virtual bool handleProgressFinished(QPoint*) = 0;
128 virtual void emitInitialLayoutCompleted() = 0;
129 virtual void emitIconChanged() = 0;
130 virtual void emitLoadStarted(bool originatingLoad) = 0;
131 virtual void emitLoadFinished(bool originatingLoad, bool ok) = 0;
132 virtual QWebFrameAdapter* createChildFrame(QWebFrameData*) = 0;
133
134 void load(const QNetworkRequest&, QNetworkAccessManager::Operation = QNetworkAccessManager::GetOperation, const QByteArray& body = QByteArray());
135 bool hasView() const;
136#if ENABLE(QT_GESTURE_EVENTS)
137 void handleGestureEvent(QGestureEventFacade*);
138#endif
139 QWebFrameAdapter* createFrame(QWebFrameData*);
140
141 QVariant evaluateJavaScript(const QString& scriptSource);
142 void addToJavaScriptWindowObject(const QString& name, QObject*, ValueOwnership);
143
144 QString toHtml() const;
145 QString toPlainText() const;
146
147 void setContent(const QByteArray& data, const QString& mimeType, const QUrl& baseUrl);
148 void setHtml(const QString& html, const QUrl& baseUrl);
149
150 QMultiMap<QString, QString> metaData() const;
151
152 QWebHitTestResultPrivate* hitTestContent(const QPoint&) const;
153 QWebElement documentElement() const;
154 QWebElement ownerElement() const;
155 QString title() const;
156 void clearCoreFrame();
157 QUrl baseUrl() const;
158 QUrl coreFrameUrl() const;
159 QUrl lastRequestedUrl() const;
160 QWebSecurityOrigin securityOrigin() const;
161 QString uniqueName() const;
162
163 void renderRelativeCoords(QPainter*, int layers, const QRegion& clip);
164 void renderFrameExtras(WebCore::GraphicsContext&, int layers, const QRegion& clip);
165 void renderCompositedLayers(WebCore::GraphicsContext&, const WebCore::IntRect& clip);
166#if USE(TILED_BACKING_STORE)
167 void setTiledBackingStoreFrozen(bool);
168 bool tiledBackingStoreFrozen() const;
169 void setTiledBackingStoreContentsScale(float);
170 bool renderFromTiledBackingStore(QPainter*, const QRegion& clip);
171#endif
172
173 // Called from QWebFrame as a private slot:
174 void _q_orientationChanged();
175
176 QList<QObject*> childFrames() const;
177 bool hasFocus() const;
178 void setFocus();
179
180 void setScrollBarPolicy(Qt::Orientation, Qt::ScrollBarPolicy);
181 void scrollToAnchor(const QString&);
182 void scrollBy(int, int);
183 void setScrollBarValue(Qt::Orientation, int);
184 int scrollBarValue(Qt::Orientation) const;
185 int scrollBarMaximum(Qt::Orientation) const;
186 QRect scrollBarGeometry(Qt::Orientation) const;
187
188 QPoint scrollPosition() const;
189 QRect frameRect() const;
190 QSize contentsSize() const;
191
192 void setZoomFactor(qreal);
193 void setTextSizeMultiplier(qreal);
194 qreal zoomFactor() const;
195
196 void updateBackgroundRecursively(const QColor&);
197
198 void cancelLoad();
199
200 // FrameView related functions
201 QSize customLayoutSize() const;
202 void setCustomLayoutSize(const QSize&);
203 void setFixedVisibleContentRect(const QRect&);
204 void setViewportSize(const QSize&);
205 void setPaintsEntireContents(bool /*resizesToContents*/);
206 void setDelegatesScrolling(bool /*resizesToContents*/);
207
208 QWebPageAdapter* pageAdapter;
209
210// protected:
211 bool allowsScrolling;
212 int marginWidth;
213 int marginHeight;
214 Qt::ScrollBarPolicy horizontalScrollBarPolicy;
215 Qt::ScrollBarPolicy verticalScrollBarPolicy;
216#if ENABLE(ORIENTATION_EVENTS) && HAVE(QTSENSORS)
217 QOrientationSensor m_orientation;
218#endif // ENABLE(ORIENTATION_EVENTS).
219
220// private:
221 void init(QWebPageAdapter*);
222 void init(QWebPageAdapter*, QWebFrameData*);
223 WebCore::Scrollbar* horizontalScrollBar() const;
224 WebCore::Scrollbar* verticalScrollBar() const;
225
226 WebCore::Frame *frame;
227 WebCore::FrameLoaderClientQt *frameLoaderClient;
228 QUrl url;
229
230 static QWebFrameAdapter* kit(const WebCore::Frame*);
231
232// friend class ChromeClientQt;
233};
234
235#endif // QWebFrameAdapter_h
236