Home | History | Annotate | Download | only in Api
      1 /*
      2     Copyright (C) 2008 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 QWEBPAGE_H
     22 #define QWEBPAGE_H
     23 
     24 #include "qwebsettings.h"
     25 #include "qwebkitglobal.h"
     26 
     27 #include <QtCore/qobject.h>
     28 #include <QtCore/qurl.h>
     29 #include <QtGui/qwidget.h>
     30 
     31 QT_BEGIN_NAMESPACE
     32 class QNetworkProxy;
     33 class QUndoStack;
     34 class QMenu;
     35 class QNetworkRequest;
     36 class QNetworkReply;
     37 class QNetworkAccessManager;
     38 QT_END_NAMESPACE
     39 
     40 class QWebElement;
     41 class QWebFrame;
     42 class QWebNetworkRequest;
     43 class QWebHistory;
     44 
     45 class QWebFrameData;
     46 class QWebHistoryItem;
     47 class QWebHitTestResult;
     48 class QWebNetworkInterface;
     49 class QWebPagePrivate;
     50 class QWebPluginFactory;
     51 class QWebSecurityOrigin;
     52 class QtViewportAttributesPrivate;
     53 
     54 namespace WebCore {
     55     class ChromeClientQt;
     56     class EditorClientQt;
     57     class FrameLoaderClientQt;
     58     class InspectorClientQt;
     59     class InspectorServerRequestHandlerQt;
     60     class InspectorFrontendClientQt;
     61     class NotificationPresenterClientQt;
     62     class GeolocationPermissionClientQt;
     63     class ResourceHandle;
     64     class HitTestResult;
     65     class QNetworkReplyHandler;
     66 
     67     struct FrameLoadRequest;
     68 }
     69 
     70 class QWEBKIT_EXPORT QWebPage : public QObject {
     71     Q_OBJECT
     72 
     73     Q_PROPERTY(bool modified READ isModified)
     74     Q_PROPERTY(QString selectedText READ selectedText)
     75     Q_PROPERTY(QString selectedHtml READ selectedHtml)
     76     Q_PROPERTY(bool hasSelection READ hasSelection)
     77     Q_PROPERTY(QSize viewportSize READ viewportSize WRITE setViewportSize)
     78     Q_PROPERTY(QSize preferredContentsSize READ preferredContentsSize WRITE setPreferredContentsSize)
     79     Q_PROPERTY(bool forwardUnsupportedContent READ forwardUnsupportedContent WRITE setForwardUnsupportedContent)
     80     Q_PROPERTY(LinkDelegationPolicy linkDelegationPolicy READ linkDelegationPolicy WRITE setLinkDelegationPolicy)
     81     Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
     82     Q_PROPERTY(bool contentEditable READ isContentEditable WRITE setContentEditable)
     83     Q_ENUMS(LinkDelegationPolicy NavigationType WebAction)
     84 public:
     85     enum NavigationType {
     86         NavigationTypeLinkClicked,
     87         NavigationTypeFormSubmitted,
     88         NavigationTypeBackOrForward,
     89         NavigationTypeReload,
     90         NavigationTypeFormResubmitted,
     91         NavigationTypeOther
     92     };
     93 
     94     enum WebAction {
     95         NoWebAction = - 1,
     96 
     97         OpenLink,
     98 
     99         OpenLinkInNewWindow,
    100         OpenFrameInNewWindow,
    101 
    102         DownloadLinkToDisk,
    103         CopyLinkToClipboard,
    104 
    105         OpenImageInNewWindow,
    106         DownloadImageToDisk,
    107         CopyImageToClipboard,
    108         CopyImageUrlToClipboard,
    109 
    110         Back,
    111         Forward,
    112         Stop,
    113         Reload,
    114 
    115         Cut,
    116         Copy,
    117         Paste,
    118 
    119         Undo,
    120         Redo,
    121         MoveToNextChar,
    122         MoveToPreviousChar,
    123         MoveToNextWord,
    124         MoveToPreviousWord,
    125         MoveToNextLine,
    126         MoveToPreviousLine,
    127         MoveToStartOfLine,
    128         MoveToEndOfLine,
    129         MoveToStartOfBlock,
    130         MoveToEndOfBlock,
    131         MoveToStartOfDocument,
    132         MoveToEndOfDocument,
    133         SelectNextChar,
    134         SelectPreviousChar,
    135         SelectNextWord,
    136         SelectPreviousWord,
    137         SelectNextLine,
    138         SelectPreviousLine,
    139         SelectStartOfLine,
    140         SelectEndOfLine,
    141         SelectStartOfBlock,
    142         SelectEndOfBlock,
    143         SelectStartOfDocument,
    144         SelectEndOfDocument,
    145         DeleteStartOfWord,
    146         DeleteEndOfWord,
    147 
    148         SetTextDirectionDefault,
    149         SetTextDirectionLeftToRight,
    150         SetTextDirectionRightToLeft,
    151 
    152         ToggleBold,
    153         ToggleItalic,
    154         ToggleUnderline,
    155 
    156         InspectElement,
    157 
    158         InsertParagraphSeparator,
    159         InsertLineSeparator,
    160 
    161         SelectAll,
    162         ReloadAndBypassCache,
    163 
    164         PasteAndMatchStyle,
    165         RemoveFormat,
    166 
    167         ToggleStrikethrough,
    168         ToggleSubscript,
    169         ToggleSuperscript,
    170         InsertUnorderedList,
    171         InsertOrderedList,
    172         Indent,
    173         Outdent,
    174 
    175         AlignCenter,
    176         AlignJustified,
    177         AlignLeft,
    178         AlignRight,
    179 
    180         StopScheduledPageRefresh,
    181 
    182         WebActionCount
    183     };
    184 
    185     enum FindFlag {
    186         FindBackward = 1,
    187         FindCaseSensitively = 2,
    188         FindWrapsAroundDocument = 4,
    189         HighlightAllOccurrences = 8
    190     };
    191     Q_DECLARE_FLAGS(FindFlags, FindFlag)
    192 
    193     enum LinkDelegationPolicy {
    194         DontDelegateLinks,
    195         DelegateExternalLinks,
    196         DelegateAllLinks
    197     };
    198 
    199     enum WebWindowType {
    200         WebBrowserWindow,
    201         WebModalDialog
    202     };
    203 
    204     enum PermissionPolicy {
    205         PermissionUnknown,
    206         PermissionGrantedByUser,
    207         PermissionDeniedByUser
    208     };
    209 
    210     enum Feature {
    211         Notifications,
    212         Geolocation
    213     };
    214 
    215     class QWEBKIT_EXPORT ViewportAttributes {
    216     public:
    217         ViewportAttributes();
    218         ViewportAttributes(const QWebPage::ViewportAttributes& other);
    219 
    220         ~ViewportAttributes();
    221 
    222         QWebPage::ViewportAttributes& operator=(const QWebPage::ViewportAttributes& other);
    223 
    224         inline qreal initialScaleFactor() const { return m_initialScaleFactor; }
    225         inline qreal minimumScaleFactor() const { return m_minimumScaleFactor; }
    226         inline qreal maximumScaleFactor() const { return m_maximumScaleFactor; }
    227         inline qreal devicePixelRatio() const { return m_devicePixelRatio; }
    228         inline bool isUserScalable() const { return m_isUserScalable; }
    229         inline bool isValid() const { return m_isValid; }
    230         inline QSize size() const { return m_size; }
    231 
    232     private:
    233         QSharedDataPointer<QtViewportAttributesPrivate> d;
    234         qreal m_initialScaleFactor;
    235         qreal m_minimumScaleFactor;
    236         qreal m_maximumScaleFactor;
    237         qreal m_devicePixelRatio;
    238         bool m_isUserScalable;
    239         bool m_isValid;
    240         QSize m_size;
    241 
    242         friend class WebCore::ChromeClientQt;
    243         friend class QWebPage;
    244     };
    245 
    246 
    247     explicit QWebPage(QObject *parent = 0);
    248     ~QWebPage();
    249 
    250     QWebFrame *mainFrame() const;
    251     QWebFrame *currentFrame() const;
    252     QWebFrame* frameAt(const QPoint& pos) const;
    253 
    254     QWebHistory *history() const;
    255     QWebSettings *settings() const;
    256 
    257     void setView(QWidget *view);
    258     QWidget *view() const;
    259 
    260     bool isModified() const;
    261 #ifndef QT_NO_UNDOSTACK
    262     QUndoStack *undoStack() const;
    263 #endif
    264 
    265     void setNetworkAccessManager(QNetworkAccessManager *manager);
    266     QNetworkAccessManager *networkAccessManager() const;
    267 
    268     void setPluginFactory(QWebPluginFactory *factory);
    269     QWebPluginFactory *pluginFactory() const;
    270 
    271     quint64 totalBytes() const;
    272     quint64 bytesReceived() const;
    273 
    274     bool hasSelection() const;
    275     QString selectedText() const;
    276     QString selectedHtml() const;
    277 
    278 #ifndef QT_NO_ACTION
    279     QAction *action(WebAction action) const;
    280 #endif
    281     virtual void triggerAction(WebAction action, bool checked = false);
    282 
    283     QSize viewportSize() const;
    284     void setViewportSize(const QSize &size) const;
    285     ViewportAttributes viewportAttributesForSize(const QSize& availableSize) const;
    286 
    287     QSize preferredContentsSize() const;
    288     void setPreferredContentsSize(const QSize &size) const;
    289     void setActualVisibleContentRect(const QRect& rect) const;
    290 
    291     virtual bool event(QEvent*);
    292     bool focusNextPrevChild(bool next);
    293 
    294     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
    295 
    296     bool findText(const QString &subString, FindFlags options = 0);
    297 
    298     void setForwardUnsupportedContent(bool forward);
    299     bool forwardUnsupportedContent() const;
    300 
    301     void setLinkDelegationPolicy(LinkDelegationPolicy policy);
    302     LinkDelegationPolicy linkDelegationPolicy() const;
    303 
    304     void setPalette(const QPalette &palette);
    305     QPalette palette() const;
    306 
    307     void setContentEditable(bool editable);
    308     bool isContentEditable() const;
    309 
    310 #ifndef QT_NO_CONTEXTMENU
    311     bool swallowContextMenuEvent(QContextMenuEvent *event);
    312 #endif
    313     void updatePositionDependentActions(const QPoint &pos);
    314 
    315     QMenu *createStandardContextMenu();
    316 
    317     void setFeaturePermission(QWebFrame* frame, Feature feature, PermissionPolicy policy);
    318 
    319     QStringList supportedContentTypes() const;
    320     bool supportsContentType(const QString& mimeType) const;
    321 
    322     enum Extension {
    323         ChooseMultipleFilesExtension,
    324         ErrorPageExtension
    325     };
    326     class ExtensionOption
    327     {};
    328     class ExtensionReturn
    329     {};
    330 
    331     class ChooseMultipleFilesExtensionOption : public ExtensionOption {
    332     public:
    333         QWebFrame *parentFrame;
    334         QStringList suggestedFileNames;
    335     };
    336 
    337     class ChooseMultipleFilesExtensionReturn : public ExtensionReturn {
    338     public:
    339         QStringList fileNames;
    340     };
    341 
    342     enum ErrorDomain { QtNetwork, Http, WebKit };
    343     class ErrorPageExtensionOption : public ExtensionOption {
    344     public:
    345         QUrl url;
    346         QWebFrame* frame;
    347         ErrorDomain domain;
    348         int error;
    349         QString errorString;
    350     };
    351 
    352     class ErrorPageExtensionReturn : public ExtensionReturn {
    353     public:
    354         ErrorPageExtensionReturn() : contentType(QLatin1String("text/html")), encoding(QLatin1String("utf-8")) {};
    355         QString contentType;
    356         QString encoding;
    357         QUrl baseUrl;
    358         QByteArray content;
    359     };
    360 
    361 
    362     virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
    363     virtual bool supportsExtension(Extension extension) const;
    364 
    365     inline QWebPagePrivate* handle() const { return d; }
    366 
    367 public Q_SLOTS:
    368     bool shouldInterruptJavaScript();
    369 
    370 Q_SIGNALS:
    371     void loadStarted();
    372     void loadProgress(int progress);
    373     void loadFinished(bool ok);
    374 
    375     void linkHovered(const QString &link, const QString &title, const QString &textContent);
    376     void statusBarMessage(const QString& text);
    377     void selectionChanged();
    378     void frameCreated(QWebFrame *frame);
    379     void geometryChangeRequested(const QRect& geom);
    380     void repaintRequested(const QRect& dirtyRect);
    381     void scrollRequested(int dx, int dy, const QRect& scrollViewRect);
    382     void windowCloseRequested();
    383     void printRequested(QWebFrame *frame);
    384     void linkClicked(const QUrl &url);
    385 
    386     void toolBarVisibilityChangeRequested(bool visible);
    387     void statusBarVisibilityChangeRequested(bool visible);
    388     void menuBarVisibilityChangeRequested(bool visible);
    389 
    390     void unsupportedContent(QNetworkReply *reply);
    391     void downloadRequested(const QNetworkRequest &request);
    392 
    393     void microFocusChanged();
    394     void contentsChanged();
    395     void databaseQuotaExceeded(QWebFrame* frame, QString databaseName);
    396     void applicationCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 defaultOriginQuota);
    397 
    398     void saveFrameStateRequested(QWebFrame* frame, QWebHistoryItem* item);
    399     void restoreFrameStateRequested(QWebFrame* frame);
    400 
    401     void viewportChangeRequested();
    402 
    403     void featurePermissionRequested(QWebFrame* frame, QWebPage::Feature feature);
    404     void featurePermissionRequestCanceled(QWebFrame* frame, QWebPage::Feature feature);
    405 
    406 protected:
    407     virtual QWebPage *createWindow(WebWindowType type);
    408     virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
    409 
    410     virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
    411     virtual QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile);
    412     virtual void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg);
    413     virtual bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg);
    414     virtual bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result);
    415     virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID);
    416 
    417     virtual QString userAgentForUrl(const QUrl& url) const;
    418 
    419 private:
    420     Q_PRIVATE_SLOT(d, void _q_onLoadProgressChanged(int))
    421 #ifndef QT_NO_ACTION
    422     Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked))
    423 #endif
    424     Q_PRIVATE_SLOT(d, void _q_cleanupLeakMessages())
    425 
    426     QWebPagePrivate *d;
    427 
    428     friend class QWebFrame;
    429     friend class QWebPagePrivate;
    430     friend class QWebView;
    431     friend class QWebViewPrivate;
    432     friend class QGraphicsWebView;
    433     friend class QGraphicsWebViewPrivate;
    434     friend class QWebInspector;
    435     friend class WebCore::ChromeClientQt;
    436     friend class WebCore::EditorClientQt;
    437     friend class WebCore::FrameLoaderClientQt;
    438     friend class WebCore::InspectorClientQt;
    439     friend class WebCore::InspectorServerRequestHandlerQt;
    440     friend class WebCore::InspectorFrontendClientQt;
    441     friend class WebCore::NotificationPresenterClientQt;
    442     friend class WebCore::GeolocationPermissionClientQt;
    443     friend class WebCore::ResourceHandle;
    444     friend class WebCore::QNetworkReplyHandler;
    445     friend class DumpRenderTreeSupportQt;
    446 };
    447 
    448 Q_DECLARE_OPERATORS_FOR_FLAGS(QWebPage::FindFlags)
    449 
    450 #endif
    451