summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api/qwebenginepage.h
blob: 6e158f3bd28e588d0c980df334644ccbcc628ec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
    Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
    Copyright (C) 2007 Staikos Computing Services Inc.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef QWEBENGINEPAGE_H
#define QWEBENGINEPAGE_H

#include <QtWebEngineWidgets/qtwebenginewidgetsglobal.h>
#include <QtWebEngineWidgets/qwebenginesettings.h>

#include <QtCore/qobject.h>
#include <QtCore/qurl.h>
#include <QtCore/qvariant.h>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtWidgets/qwidget.h>

QT_BEGIN_NAMESPACE
class QMenu;

// FIXME: Just forward-declare the to-be-removed frame classe for now.
// Referencing calls should be ported to be page-friendly or removed individually.
class QWebEngineFrame;

class QWebEngineHistory;
class QWebEnginePagePrivate;

namespace QtWebEnginePrivate {

struct FunctorBase {
    virtual ~FunctorBase() {}
    virtual void operator()(const QVariant &) = 0;
};

template <typename F>
struct FunctorCallback : public FunctorBase {
    FunctorCallback(F callback) : m_callback(callback) {}
    virtual void operator()(const QVariant &value) Q_DECL_OVERRIDE { m_callback(value); }
private:
    F m_callback;
};
}

class QWEBENGINEWIDGETS_EXPORT QWebEngineHitTestResult {
};

class QWEBENGINEWIDGETS_EXPORT QWebEnginePage : public QObject {
    Q_OBJECT

    // Ex-QWebFrame properties
    Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
    Q_PROPERTY(QString title READ title)
    Q_PROPERTY(QUrl url READ url WRITE setUrl)

public:
    enum NavigationType {
    };

    enum WebAction {
        NoWebAction = - 1,
        Back,
        Forward,
        Stop,
        Reload,
        ReloadAndBypassCache,
        WebActionCount
    };

    enum WebWindowType {
        WebBrowserWindow,
        WebModalDialog
    };

    // Ex-QWebFrame enum

    enum FileSelectionMode {
        FileSelectOpen,
        FileSelectOpenMultiple,
    };

    explicit QWebEnginePage(QObject *parent = 0);
    ~QWebEnginePage();
    QWebEngineHistory *history() const;

    void setView(QWidget *view);
    QWidget *view() const;

#ifndef QT_NO_ACTION
    QAction *action(WebAction action) const;
#endif
    virtual void triggerAction(WebAction action, bool checked = false);

    QMenu *createStandardContextMenu();

    enum Extension {
    };
    class ExtensionOption
    {};
    class ExtensionReturn
    {};

    // Ex-QWebFrame methods
    void load(const QUrl &url);

    QString title() const;
    void setUrl(const QUrl &url);
    QUrl url() const;

    qreal zoomFactor() const;
    void setZoomFactor(qreal factor);

    void runJavaScript(const QString& scriptSource, const QString &xPath = QString());

    template <typename F>
    void runJavaScript(const QString& scriptSource, F func, const QString &xPath = QString());

Q_SIGNALS:
    void loadStarted();
    void loadProgress(int progress);
    void loadFinished(bool ok);

    void geometryChangeRequested(const QRect& geom);
    void windowCloseRequested();

    // Ex-QWebFrame signals
    void titleChanged(const QString &title);
    void urlChanged(const QUrl &url);

protected:
    virtual QWebEnginePage *createWindow(WebWindowType type);

    virtual QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes);
    virtual void javaScriptAlert(QWebEngineFrame *originatingFrame, const QString& msg);
    virtual bool javaScriptConfirm(QWebEngineFrame *originatingFrame, const QString& msg);
    virtual bool javaScriptPrompt(QWebEngineFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result);

private:
    Q_DECLARE_PRIVATE(QWebEnginePage);
#ifndef QT_NO_ACTION
    Q_PRIVATE_SLOT(d_func(), void _q_webActionTriggered(bool checked))
#endif
    void runJavaScriptHelper(const QString &source, QtWebEnginePrivate::FunctorBase *, const QString &xPath);

    friend class QWebEngineView;
    friend class QWebEngineViewPrivate;
};

template <typename F>
inline void QWebEnginePage::runJavaScript(const QString &scriptSource, F func, const QString &xPath)
{
    runJavaScriptHelper(scriptSource, new QtWebEnginePrivate::FunctorCallback<F>(func), xPath);
}

QT_END_NAMESPACE

#endif // QWEBENGINEPAGE_H