WebKit/qt/declarative/qdeclarativewebview_p.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2     Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
       
     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 
       
    21 #ifndef qdeclarativewebview_p_h
       
    22 #define qdeclarativewebview_p_h
       
    23 
       
    24 #include <QtCore/QBasicTimer>
       
    25 #include <QtCore/QUrl>
       
    26 #include <QtDeclarative/QDeclarativeItem>
       
    27 #include <QtGui/QAction>
       
    28 #include <QtNetwork/QNetworkAccessManager>
       
    29 #include "qgraphicswebview.h"
       
    30 #include "qwebpage.h"
       
    31 
       
    32 
       
    33 QT_BEGIN_HEADER
       
    34 
       
    35 class QWebHistory;
       
    36 class QWebSettings;
       
    37 
       
    38 QT_BEGIN_NAMESPACE
       
    39 
       
    40 QT_MODULE(Declarative)
       
    41 class QDeclarativeWebSettings;
       
    42 class QDeclarativeWebViewPrivate;
       
    43 class QNetworkRequest;
       
    44 class QDeclarativeWebView;
       
    45 class QDeclarativeWebViewPrivate;
       
    46 
       
    47 class QDeclarativeWebPage : public QWebPage {
       
    48     Q_OBJECT
       
    49 public:
       
    50     explicit QDeclarativeWebPage(QDeclarativeWebView *parent);
       
    51     ~QDeclarativeWebPage();
       
    52 protected:
       
    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);
       
    58 
       
    59 private:
       
    60     QDeclarativeWebView *viewItem();
       
    61 };
       
    62 
       
    63 class GraphicsWebView : public QGraphicsWebView {
       
    64     Q_OBJECT
       
    65 public:
       
    66     GraphicsWebView(QDeclarativeWebView* parent = 0);
       
    67 protected:
       
    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 Q_SIGNALS:
       
    74     void doubleClick(int clickX, int clickY);
       
    75 private:
       
    76     QDeclarativeWebView *parent;
       
    77     QPointF pressPoint;
       
    78     QBasicTimer pressTimer;
       
    79     int pressTime; // milliseconds before the touch event becomes a "tap and hold"
       
    80     friend class QDeclarativeWebView;
       
    81 };
       
    82 
       
    83 class QDeclarativeWebViewAttached;
       
    84 
       
    85 // TODO: browser plugins
       
    86 
       
    87 class QDeclarativeWebView : public QDeclarativeItem {
       
    88     Q_OBJECT
       
    89 
       
    90     Q_ENUMS(Status SelectionMode)
       
    91 
       
    92     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
       
    93     Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged)
       
    94     Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged)
       
    95 
       
    96     Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
       
    97 
       
    98     Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged)
       
    99 
       
   100     Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged)
       
   101     Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged)
       
   102     Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
       
   103     Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
       
   104     Q_PROPERTY(Status status READ status NOTIFY statusChanged)
       
   105 
       
   106 #ifndef QT_NO_ACTION
       
   107     Q_PROPERTY(QAction* reload READ reloadAction CONSTANT)
       
   108     Q_PROPERTY(QAction* back READ backAction CONSTANT)
       
   109     Q_PROPERTY(QAction* forward READ forwardAction CONSTANT)
       
   110     Q_PROPERTY(QAction* stop READ stopAction CONSTANT)
       
   111 #endif
       
   112 
       
   113     Q_PROPERTY(QDeclarativeWebSettings* settings READ settingsObject CONSTANT)
       
   114 
       
   115     Q_PROPERTY(QDeclarativeListProperty<QObject> javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT)
       
   116 
       
   117     Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged)
       
   118     Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged)
       
   119 
       
   120     Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged)
       
   121 
       
   122     Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeChanged)
       
   123     Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged)
       
   124 
       
   125 public:
       
   126     QDeclarativeWebView(QDeclarativeItem *parent = 0);
       
   127     ~QDeclarativeWebView();
       
   128 
       
   129     QUrl url() const;
       
   130     void setUrl(const QUrl &);
       
   131 
       
   132     QString title() const;
       
   133 
       
   134     QPixmap icon() const;
       
   135 
       
   136     Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom);
       
   137     QRect elementAreaAt(int x, int y, int minwidth, int minheight) const;
       
   138 
       
   139     int pressGrabTime() const;
       
   140     void setPressGrabTime(int);
       
   141 
       
   142     int preferredWidth() const;
       
   143     void setPreferredWidth(int);
       
   144     int preferredHeight() const;
       
   145     void setPreferredHeight(int);
       
   146 
       
   147     enum Status { Null, Ready, Loading, Error };
       
   148     Status status() const;
       
   149     qreal progress() const;
       
   150     QString statusText() const;
       
   151 
       
   152 #ifndef QT_NO_ACTION
       
   153     QAction *reloadAction() const;
       
   154     QAction *backAction() const;
       
   155     QAction *forwardAction() const;
       
   156     QAction *stopAction() const;
       
   157 #endif
       
   158 
       
   159     QWebPage *page() const;
       
   160     void setPage(QWebPage *page);
       
   161 
       
   162     void load(const QNetworkRequest &request,
       
   163               QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation,
       
   164               const QByteArray &body = QByteArray());
       
   165 
       
   166     QString html() const;
       
   167 
       
   168     void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
       
   169     void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
       
   170 
       
   171     QWebHistory* history() const;
       
   172     QWebSettings* settings() const;
       
   173     QDeclarativeWebSettings *settingsObject() const;
       
   174 
       
   175     bool renderingEnabled() const;
       
   176     void setRenderingEnabled(bool);
       
   177 
       
   178     QDeclarativeListProperty<QObject> javaScriptWindowObjects();
       
   179 
       
   180     static QDeclarativeWebViewAttached* qmlAttachedProperties(QObject*);
       
   181 
       
   182     QDeclarativeComponent *newWindowComponent() const;
       
   183     void setNewWindowComponent(QDeclarativeComponent *newWindow);
       
   184     QDeclarativeItem* newWindowParent() const;
       
   185     void setNewWindowParent(QDeclarativeItem* newWindow);
       
   186 
       
   187     bool isComponentCompletePublic() const { return isComponentComplete(); }
       
   188 
       
   189     QSize contentsSize() const;
       
   190 
       
   191     void setContentsScale(qreal scale);
       
   192     qreal contentsScale() const;
       
   193 
       
   194 Q_SIGNALS:
       
   195     void preferredWidthChanged();
       
   196     void preferredHeightChanged();
       
   197     void urlChanged();
       
   198     void progressChanged();
       
   199     void statusChanged(Status);
       
   200     void titleChanged(const QString&);
       
   201     void iconChanged();
       
   202     void statusTextChanged();
       
   203     void htmlChanged();
       
   204     void pressGrabTimeChanged();
       
   205     void newWindowComponentChanged();
       
   206     void newWindowParentChanged();
       
   207     void renderingEnabledChanged();
       
   208     void contentsSizeChanged(const QSize&);
       
   209     void contentsScaleChanged();
       
   210 
       
   211     void loadStarted();
       
   212     void loadFinished();
       
   213     void loadFailed();
       
   214 
       
   215     void doubleClick(int clickX, int clickY);
       
   216 
       
   217     void zoomTo(qreal zoom, int centerX, int centerY);
       
   218 
       
   219     void alert(const QString& message);
       
   220 
       
   221 public Q_SLOTS:
       
   222     QVariant evaluateJavaScript(const QString&);
       
   223 
       
   224 private Q_SLOTS:
       
   225     void doLoadStarted();
       
   226     void doLoadProgress(int p);
       
   227     void doLoadFinished(bool ok);
       
   228     void setStatusText(const QString&);
       
   229     void windowObjectCleared();
       
   230     void pageUrlChanged();
       
   231     void initialLayout();
       
   232 
       
   233     void updateDeclarativeWebViewSize();
       
   234 
       
   235     virtual void geometryChanged(const QRectF &newGeometry,
       
   236                                  const QRectF &oldGeometry);
       
   237     QDeclarativeWebView* createWindow(QWebPage::WebWindowType type);
       
   238 
       
   239 private:
       
   240     void updateContentsSize();
       
   241     void init();
       
   242     virtual void componentComplete();
       
   243     Q_DISABLE_COPY(QDeclarativeWebView)
       
   244     QDeclarativeWebViewPrivate* d;
       
   245     QMouseEvent* sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent*);
       
   246     QMouseEvent* sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent*);
       
   247     friend class QDeclarativeWebPage;
       
   248 };
       
   249 
       
   250 class QDeclarativeWebViewAttached : public QObject {
       
   251     Q_OBJECT
       
   252     Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName)
       
   253 public:
       
   254     QDeclarativeWebViewAttached(QObject* parent)
       
   255         : QObject(parent)
       
   256     {
       
   257     }
       
   258 
       
   259     QString windowObjectName() const
       
   260     {
       
   261         return m_windowObjectName;
       
   262     }
       
   263 
       
   264     void setWindowObjectName(const QString &n)
       
   265     {
       
   266         m_windowObjectName = n;
       
   267     }
       
   268 
       
   269 private:
       
   270     QString m_windowObjectName;
       
   271 };
       
   272 
       
   273 class QDeclarativeWebSettings : public QObject {
       
   274     Q_OBJECT
       
   275 
       
   276     Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily)
       
   277     Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily)
       
   278     Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily)
       
   279     Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily)
       
   280     Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily)
       
   281     Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily)
       
   282 
       
   283     Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize)
       
   284     Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize)
       
   285     Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize)
       
   286     Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize)
       
   287 
       
   288     Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages)
       
   289     Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled)
       
   290     Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled)
       
   291     Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled)
       
   292     Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled)
       
   293     Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows)
       
   294     Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard)
       
   295     Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled)
       
   296     Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain)
       
   297     Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly)
       
   298     Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds)
       
   299     Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled)
       
   300     Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled)
       
   301     Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled)
       
   302     Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls)
       
   303 
       
   304 public:
       
   305     QDeclarativeWebSettings() {}
       
   306 
       
   307     QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); }
       
   308     void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont, f); }
       
   309     QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); }
       
   310     void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont, f); }
       
   311     QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); }
       
   312     void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont, f); }
       
   313     QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); }
       
   314     void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont, f); }
       
   315     QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); }
       
   316     void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont, f); }
       
   317     QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); }
       
   318     void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont, f); }
       
   319 
       
   320     int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); }
       
   321     void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize, size); }
       
   322     int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); }
       
   323     void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize, size); }
       
   324     int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); }
       
   325     void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize, size); }
       
   326     int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); }
       
   327     void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize, size); }
       
   328 
       
   329     bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); }
       
   330     void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); }
       
   331     bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); }
       
   332     void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); }
       
   333     bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); }
       
   334     void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); }
       
   335     bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); }
       
   336     void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); }
       
   337     bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); }
       
   338     void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); }
       
   339     bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); }
       
   340     void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); }
       
   341     bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); }
       
   342     void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); }
       
   343     bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); }
       
   344     void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); }
       
   345     bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); }
       
   346     void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); }
       
   347     bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); }
       
   348     void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); }
       
   349     bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); }
       
   350     void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); }
       
   351     bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); }
       
   352     void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); }
       
   353     bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); }
       
   354     void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); }
       
   355     bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); }
       
   356     void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); }
       
   357     bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); }
       
   358     void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); }
       
   359 
       
   360     QWebSettings *s;
       
   361 };
       
   362 
       
   363 QT_END_NAMESPACE
       
   364 
       
   365 QML_DECLARE_TYPE(QDeclarativeWebView)
       
   366 QML_DECLARE_TYPE(QDeclarativeWebSettings)
       
   367 QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES)
       
   368 
       
   369 QT_END_HEADER
       
   370 
       
   371 #endif