1/*
2 Copyright (C) 2008, 2009 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2008 Holger Hans Peter Freyther
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_p_h
22#define qwebpage_p_h
23
24#include "QWebPageAdapter.h"
25
26#include "qwebframe.h"
27#include "qwebpage.h"
28
29#include <QPointer>
30#include <qevent.h>
31#include <qgesture.h>
32#include <qgraphicssceneevent.h>
33#include <qgraphicswidget.h>
34#include <qmetaobject.h>
35#include <qnetworkproxy.h>
36
37
38namespace WebCore {
39class ContextMenuClientQt;
40class ContextMenuItem;
41class ContextMenu;
42class Document;
43class EditorClientQt;
44class Element;
45class IntRect;
46class Node;
47class NodeList;
48class Frame;
49}
50
51QT_BEGIN_NAMESPACE
52class QBitArray;
53class QMenu;
54class QScreen;
55class QUndoStack;
56class QWindow;
57QT_END_NAMESPACE
58
59class QtPluginWidgetAdapter;
60class QWebInspector;
61class QWebFrameAdapter;
62class UndoStepQt;
63
64class QtViewportAttributesPrivate : public QSharedData {
65public:
66 QtViewportAttributesPrivate(QWebPage::ViewportAttributes* qq)
67 : q(qq)
68 { }
69
70 QWebPage::ViewportAttributes* q;
71};
72
73class QWebPagePrivate : public QWebPageAdapter {
74public:
75 QWebPagePrivate(QWebPage*);
76 ~QWebPagePrivate();
77
78 static WebCore::Page* core(const QWebPage*);
79
80 // Adapter implementation
81 void show() override;
82 void setFocus() override;
83 void unfocus() override;
84 void setWindowRect(const QRect &) override;
85 QSize viewportSize() const override;
86 QWebPageAdapter* createWindow(bool /*dialog*/) override;
87 QObject* handle() override { return q; }
88 void consoleMessageReceived(MessageSource source, MessageLevel level, const QString& message, int lineNumber, const QString& sourceID) override;
89 void javaScriptAlert(QWebFrameAdapter*, const QString& msg) override;
90 bool javaScriptConfirm(QWebFrameAdapter*, const QString& msg) override;
91 bool javaScriptPrompt(QWebFrameAdapter*, const QString& msg, const QString& defaultValue, QString* result) override;
92 bool shouldInterruptJavaScript() override;
93 void printRequested(QWebFrameAdapter*) override;
94 void databaseQuotaExceeded(QWebFrameAdapter*, const QString& databaseName) override;
95 void applicationCacheQuotaExceeded(QWebSecurityOrigin*, quint64 defaultOriginQuota, quint64 totalSpaceNeeded) override;
96 void setToolTip(const QString&) override;
97#if USE(QT_MULTIMEDIA)
98 QWebFullScreenVideoHandler* createFullScreenVideoHandler() override;
99#endif
100 QWebFrameAdapter& mainFrameAdapter() override;
101 QStringList chooseFiles(QWebFrameAdapter*, bool allowMultiple, const QStringList& suggestedFileNames) override;
102 QColor colorSelectionRequested(const QColor& selectedColor) override;
103 std::unique_ptr<QWebSelectMethod> createSelectPopup() override;
104 QRect viewRectRelativeToWindow() override;
105 void fullScreenRequested(QWebFullScreenRequest) override;
106 void geolocationPermissionRequested(QWebFrameAdapter*) override;
107 void geolocationPermissionRequestCancelled(QWebFrameAdapter*) override;
108 void notificationsPermissionRequested(QWebFrameAdapter*) override;
109 void notificationsPermissionRequestCancelled(QWebFrameAdapter*) override;
110
111 void respondToChangedContents() override;
112 void respondToChangedSelection() override;
113 void microFocusChanged() override;
114 void triggerCopyAction() override;
115 void triggerActionForKeyEvent(QKeyEvent*) override;
116 void clearUndoStack() override;
117 bool canUndo() const override;
118 bool canRedo() const override;
119 void undo() override;
120 void redo() override;
121 void createUndoStep(QSharedPointer<UndoStepQt>) override;
122 const char* editorCommandForKeyEvent(QKeyEvent*) override;
123
124 void updateNavigationActions() override;
125 void clearCustomActions() override;
126
127 QObject* inspectorHandle() override;
128 void setInspectorFrontend(QObject*) override;
129 void setInspectorWindowTitle(const QString&) override;
130 void createWebInspector(QObject** inspectorView, QWebPageAdapter** inspectorPage) override;
131 QStringList menuActionsAsText() override;
132 void emitViewportChangeRequested() override;
133 bool acceptNavigationRequest(QWebFrameAdapter*, const QNetworkRequest&, int type) override;
134 void emitRestoreFrameStateRequested(QWebFrameAdapter*) override;
135 void emitSaveFrameStateRequested(QWebFrameAdapter*, QWebHistoryItem*) override;
136 void emitDownloadRequested(const QNetworkRequest&) override;
137 void emitFrameCreated(QWebFrameAdapter*) override;
138 QString userAgentForUrl(const QUrl &url) const override { return q->userAgentForUrl(url); }
139 bool supportsErrorPageExtension() const override { return q->supportsExtension(QWebPage::ErrorPageExtension); }
140 bool errorPageExtension(ErrorPageOption *, ErrorPageReturn *) override;
141 QtPluginWidgetAdapter* createPlugin(const QString &, const QUrl &, const QStringList &, const QStringList &) override;
142 QtPluginWidgetAdapter* adapterForWidget(QObject *) const override;
143 bool requestSoftwareInputPanel() const override;
144 void createAndSetCurrentContextMenu(const QList<MenuItemDescription>&, QBitArray*) override;
145 bool handleScrollbarContextMenuEvent(QContextMenuEvent*, bool, ScrollDirection*, ScrollGranularity*) override;
146 void recentlyAudibleChanged(bool) override;
147 void focusedElementChanged(const QWebElement&) override;
148
149
150 void createMainFrame();
151
152 void _q_webActionTriggered(bool checked);
153 void _q_customActionTriggered(bool checked);
154 void updateAction(QWebPage::WebAction);
155 void updateEditorActions();
156
157 void timerEvent(QTimerEvent*);
158
159#ifndef QT_NO_CONTEXTMENU
160 void contextMenuEvent(const QPoint& globalPos);
161#endif
162 void keyPressEvent(QKeyEvent*);
163 void keyReleaseEvent(QKeyEvent*);
164
165 template<class T> void dragEnterEvent(T*);
166 template<class T> void dragMoveEvent(T*);
167 template<class T> void dropEvent(T*);
168
169 void shortcutOverrideEvent(QKeyEvent*);
170 void leaveEvent(QEvent*);
171
172 bool gestureEvent(QGestureEvent*);
173
174 void updateWindow();
175 void _q_updateScreen(QScreen*);
176
177 void setInspector(QWebInspector*);
178 QWebInspector* getOrCreateInspector();
179
180#ifndef QT_NO_SHORTCUT
181 static QWebPage::WebAction editorActionForKeyEvent(QKeyEvent*);
182#endif
183 static const char* editorCommandForWebActions(QWebPage::WebAction);
184
185 QWebPage *q;
186 QPointer<QWebFrame> mainFrame;
187
188#ifndef QT_NO_UNDOSTACK
189 QUndoStack *undoStack;
190#endif
191
192 QPointer<QWidget> view;
193
194 QWebPage::LinkDelegationPolicy linkPolicy;
195
196 QSize m_viewportSize;
197 QSize fixedLayoutSize;
198
199 QWebHitTestResult hitTestResult;
200#ifndef QT_NO_CONTEXTMENU
201 QPointer<QMenu> currentContextMenu;
202#endif
203 QPalette palette;
204 bool useFixedLayout;
205
206 QAction *actions[QWebPage::WebActionCount];
207 QHash<int, QAction*> customActions;
208
209 QPointer <QWindow> window;
210 QWidget* inspectorFrontend;
211 QWebInspector* inspector;
212 bool inspectorIsInternalOnly; // True if created through the Inspect context menu action
213 Qt::DropAction m_lastDropAction;
214
215 QMetaMethod m_fullScreenRequested;
216 bool m_customDevicePixelRatioIsSet { false };
217};
218
219#endif
220