1#ifndef qwkpage_h
2#define qwkpage_h
3
4#include "qwebkitglobal.h"
5#include <QAction>
6#include <QMenu>
7#include <QObject>
8#include <QPoint>
9#include <QRect>
10#include <QSize>
11#include <QUrl>
12#include <WebKit2/WKBase.h>
13#include <WebKit2/WKPage.h>
14
15class QCursor;
16class QGraphicsItem;
17class QWKContext;
18class QWKGraphicsWidget;
19class QWKPreferences;
20class QWKPagePrivate;
21class QtViewportAttributesPrivate;
22class QWKHistory;
23
24class QWEBKIT_EXPORT QWKPage : public QObject {
25    Q_OBJECT
26    Q_PROPERTY(QString title READ title)
27    Q_PROPERTY(QUrl url READ url WRITE setUrl)
28
29public:
30    enum WebAction {
31        NoWebAction = - 1,
32
33        OpenLink,
34        OpenLinkInNewWindow,
35        CopyLinkToClipboard,
36        OpenImageInNewWindow,
37
38        Back,
39        Forward,
40        Stop,
41        Reload,
42
43        Cut,
44        Copy,
45        Paste,
46        SelectAll,
47
48        WebActionCount
49    };
50
51    class QWEBKIT_EXPORT ViewportAttributes {
52    public:
53        ViewportAttributes();
54        ViewportAttributes(const QWKPage::ViewportAttributes& other);
55
56        ~ViewportAttributes();
57
58        QWKPage::ViewportAttributes& operator=(const QWKPage::ViewportAttributes& other);
59
60        inline qreal initialScaleFactor() const { return m_initialScaleFactor; };
61        inline qreal minimumScaleFactor() const { return m_minimumScaleFactor; };
62        inline qreal maximumScaleFactor() const { return m_maximumScaleFactor; };
63        inline qreal devicePixelRatio() const { return m_devicePixelRatio; };
64        inline bool isUserScalable() const { return m_isUserScalable; };
65        inline bool isValid() const { return m_isValid; };
66        inline QSize size() const { return m_size; };
67
68    private:
69        QSharedDataPointer<QtViewportAttributesPrivate> d;
70        qreal m_initialScaleFactor;
71        qreal m_minimumScaleFactor;
72        qreal m_maximumScaleFactor;
73        qreal m_devicePixelRatio;
74        bool m_isUserScalable;
75        bool m_isValid;
76        QSize m_size;
77
78        friend class QWKPage;
79    };
80
81    QWKPage(QWKContext*);
82    virtual ~QWKPage();
83
84    WKPageRef pageRef() const;
85
86    QWKPreferences* preferences() const;
87
88    void load(const QUrl& url);
89    void setUrl(const QUrl& url);
90    QUrl url() const;
91
92    QString title() const;
93
94    void setViewportSize(const QSize&);
95    ViewportAttributes viewportAttributesForSize(const QSize& availableSize) const;
96
97    void setActualVisibleContentsRect(const QRect& rect) const;
98
99    void setResizesToContentsUsingLayoutSize(const QSize& targetLayoutSize);
100
101    QAction* action(WebAction action) const;
102    void triggerAction(WebAction action, bool checked = false);
103
104    typedef QWKPage* (*CreateNewPageFn)(QWKPage*);
105    void setCreateNewPageFunction(CreateNewPageFn function);
106
107    void setCustomUserAgent(const QString&);
108    QString customUserAgent() const;
109
110    qreal textZoomFactor() const;
111    qreal pageZoomFactor() const;
112    void setTextZoomFactor(qreal zoomFactor);
113    void setPageZoomFactor(qreal zoomFactor);
114    void setPageAndTextZoomFactors(qreal pageZoomFactor, qreal textZoomFactor);
115
116    QWKHistory* history() const;
117    QWKContext* context() const;
118
119    void findZoomableAreaForPoint(const QPoint&);
120
121    bool isConnectedToEngine() const;
122
123public:
124    Q_SIGNAL void statusBarMessage(const QString&);
125    Q_SIGNAL void toolTipChanged(const QString&);
126    Q_SIGNAL void titleChanged(const QString&);
127    Q_SIGNAL void loadStarted();
128    Q_SIGNAL void loadFinished(bool ok);
129    Q_SIGNAL void loadProgress(int progress);
130    Q_SIGNAL void initialLayoutCompleted();
131    Q_SIGNAL void urlChanged(const QUrl&);
132    Q_SIGNAL void contentsSizeChanged(const QSize&);
133    Q_SIGNAL void scrollRequested(int dx, int dy);
134    Q_SIGNAL void cursorChanged(const QCursor&);
135    Q_SIGNAL void viewportChangeRequested();
136    Q_SIGNAL void windowCloseRequested();
137    Q_SIGNAL void zoomableAreaFound(const QRect&);
138    Q_SIGNAL void focusNextPrevChild(bool);
139    Q_SIGNAL void showContextMenu(QSharedPointer<QMenu>);
140    Q_SIGNAL void engineConnectionChanged(bool connected);
141
142protected:
143    void timerEvent(QTimerEvent*);
144
145private:
146#ifndef QT_NO_ACTION
147    Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked));
148#endif
149    QWKPagePrivate* d;
150
151    friend class QGraphicsWKView;
152    friend class QGraphicsWKViewPrivate;
153    friend class QWKPagePrivate;
154};
155
156#endif /* qwkpage_h */
157