2
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
21
#ifndef qdeclarativewebview_p_h
22
#define qdeclarativewebview_p_h
25
#include <QDeclarativeItem>
26
#include <QtCore/QBasicTimer>
27
#include <QtCore/QUrl>
28
#include <QtNetwork/QNetworkAccessManager>
29
#include "qgraphicswebview.h"
40
QT_MODULE(Declarative)
41
class QDeclarativeWebSettings;
42
class QDeclarativeWebViewPrivate;
43
class QNetworkRequest;
44
class QDeclarativeWebView;
45
class QDeclarativeWebViewPrivate;
47
class QDeclarativeWebPage : public QWebPage {
50
explicit QDeclarativeWebPage(QDeclarativeWebView *parent);
51
~QDeclarativeWebPage();
53
QWebPage *createWindow(WebWindowType type);
54
QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile);
55
void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg);
56
bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg);
57
bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result);
60
QDeclarativeWebView *viewItem();
63
class GraphicsWebView : public QGraphicsWebView {
66
GraphicsWebView(QDeclarativeWebView* parent = 0);
68
void mousePressEvent(QGraphicsSceneMouseEvent* event);
69
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
70
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
71
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
72
void timerEvent(QTimerEvent* event);
73
bool sceneEvent(QEvent *event);
76
void doubleClick(int clickX, int clickY);
78
QDeclarativeWebView *parent;
80
QBasicTimer pressTimer;
81
int pressTime; // milliseconds before the touch event becomes a "tap and hold"
82
friend class QDeclarativeWebView;
85
class QDeclarativeWebViewAttached;
87
// TODO: browser plugins
89
class QDeclarativeWebView : public QDeclarativeItem {
92
Q_ENUMS(Status SelectionMode)
94
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
95
Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged)
96
Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged)
98
Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
100
Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged)
102
Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged)
103
Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged)
104
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
105
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
106
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
109
Q_PROPERTY(QAction* reload READ reloadAction CONSTANT)
110
Q_PROPERTY(QAction* back READ backAction CONSTANT)
111
Q_PROPERTY(QAction* forward READ forwardAction CONSTANT)
112
Q_PROPERTY(QAction* stop READ stopAction CONSTANT)
115
Q_PROPERTY(QDeclarativeWebSettings* settings READ settingsObject CONSTANT)
117
Q_PROPERTY(QDeclarativeListProperty<QObject> javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT)
119
Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged)
120
Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged)
122
Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged)
124
Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeChanged)
125
Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged)
127
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged REVISION 1)
131
QDeclarativeWebView(QDeclarativeItem *parent = 0);
132
~QDeclarativeWebView();
135
void setUrl(const QUrl &);
137
QString title() const;
139
QPixmap icon() const;
141
Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom);
142
QRect elementAreaAt(int x, int y, int minwidth, int minheight) const;
144
int pressGrabTime() const;
145
void setPressGrabTime(int);
147
int preferredWidth() const;
148
void setPreferredWidth(int);
149
int preferredHeight() const;
150
void setPreferredHeight(int);
152
enum Status { Null, Ready, Loading, Error };
153
Status status() const;
154
qreal progress() const;
155
QString statusText() const;
158
QAction *reloadAction() const;
159
QAction *backAction() const;
160
QAction *forwardAction() const;
161
QAction *stopAction() const;
164
QWebPage *page() const;
165
void setPage(QWebPage *page);
167
void load(const QNetworkRequest &request,
168
QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation,
169
const QByteArray &body = QByteArray());
171
QString html() const;
173
void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
174
void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
176
QWebHistory* history() const;
177
QWebSettings* settings() const;
178
QDeclarativeWebSettings *settingsObject() const;
180
bool renderingEnabled() const;
181
void setRenderingEnabled(bool);
183
QDeclarativeListProperty<QObject> javaScriptWindowObjects();
185
static QDeclarativeWebViewAttached* qmlAttachedProperties(QObject*);
187
QDeclarativeComponent *newWindowComponent() const;
188
void setNewWindowComponent(QDeclarativeComponent *newWindow);
189
QDeclarativeItem* newWindowParent() const;
190
void setNewWindowParent(QDeclarativeItem* newWindow);
192
bool isComponentCompletePublic() const { return isComponentComplete(); }
194
QSize contentsSize() const;
196
void setContentsScale(qreal scale);
197
qreal contentsScale() const;
200
Q_REVISION(1) QColor backgroundColor() const;
201
Q_REVISION(1) void setBackgroundColor(const QColor&);
205
void preferredWidthChanged();
206
void preferredHeightChanged();
208
void progressChanged();
209
void statusChanged(Status);
210
void titleChanged(const QString&);
212
void statusTextChanged();
214
void pressGrabTimeChanged();
215
void newWindowComponentChanged();
216
void newWindowParentChanged();
217
void renderingEnabledChanged();
218
void contentsSizeChanged(const QSize&);
219
void contentsScaleChanged();
221
void backgroundColorChanged();
228
void doubleClick(int clickX, int clickY);
230
void zoomTo(qreal zoom, int centerX, int centerY);
232
void alert(const QString& message);
235
QVariant evaluateJavaScript(const QString&);
238
void doLoadStarted();
239
void doLoadProgress(int p);
240
void doLoadFinished(bool ok);
241
void setStatusText(const QString&);
242
void windowObjectCleared();
243
void pageUrlChanged();
244
void initialLayout();
246
void updateDeclarativeWebViewSize();
248
virtual void geometryChanged(const QRectF &newGeometry,
249
const QRectF &oldGeometry);
250
QDeclarativeWebView* createWindow(QWebPage::WebWindowType type);
253
void updateContentsSize();
255
virtual void componentComplete();
256
Q_DISABLE_COPY(QDeclarativeWebView)
257
QDeclarativeWebViewPrivate* d;
258
QMouseEvent* sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent*);
259
QMouseEvent* sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent*);
260
friend class QDeclarativeWebPage;
263
class QDeclarativeWebViewAttached : public QObject {
265
Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName)
267
QDeclarativeWebViewAttached(QObject* parent)
272
QString windowObjectName() const
274
return m_windowObjectName;
277
void setWindowObjectName(const QString &n)
279
m_windowObjectName = n;
283
QString m_windowObjectName;
286
class QDeclarativeWebSettings : public QObject {
289
Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily)
290
Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily)
291
Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily)
292
Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily)
293
Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily)
294
Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily)
296
Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize)
297
Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize)
298
Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize)
299
Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize)
301
Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages)
302
Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled)
303
Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled)
304
Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled)
305
Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled)
306
Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows)
307
Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard)
308
Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled)
309
Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain)
310
Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly)
311
Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds)
312
Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled)
313
Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled)
314
Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled)
315
Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls)
318
QDeclarativeWebSettings() {}
320
QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); }
321
void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont, f); }
322
QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); }
323
void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont, f); }
324
QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); }
325
void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont, f); }
326
QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); }
327
void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont, f); }
328
QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); }
329
void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont, f); }
330
QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); }
331
void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont, f); }
333
int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); }
334
void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize, size); }
335
int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); }
336
void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize, size); }
337
int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); }
338
void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize, size); }
339
int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); }
340
void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize, size); }
342
bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); }
343
void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); }
344
bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); }
345
void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); }
346
bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); }
347
void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); }
348
bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); }
349
void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); }
350
bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); }
351
void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); }
352
bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); }
353
void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); }
354
bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); }
355
void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); }
356
bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); }
357
void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); }
358
bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); }
359
void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); }
360
bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); }
361
void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); }
362
bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); }
363
void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); }
364
bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); }
365
void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); }
366
bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); }
367
void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); }
368
bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); }
369
void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); }
370
bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); }
371
void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); }
378
QML_DECLARE_TYPE(QDeclarativeWebView)
379
QML_DECLARE_TYPE(QDeclarativeWebSettings)
380
QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES)