Falkon Develop
Cross-platform Qt-based web browser
webview.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program 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
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef WEBVIEW_H
19#define WEBVIEW_H
20
21#include <QPointer>
22#include <QWebEngineView>
23
24#include "qzcommon.h"
25#include "loadrequest.h"
26#include "wheelhelper.h"
27
28class WebPage;
29class LoadRequest;
31
32class FALKON_EXPORT WebView : public QWebEngineView
33{
34 Q_OBJECT
35
36public:
37 explicit WebView(QWidget* parent = nullptr);
38 ~WebView() override;
39
40 QIcon icon(bool allowNull = false) const;
41 QString title(bool allowEmpty = false) const;
42
43 WebPage* page() const;
44 void setPage(WebPage* page);
45
46 void load(const QUrl &url);
47 void load(const LoadRequest &request);
48 bool isLoading() const;
49
50 int loadingProgress() const;
51
52 bool backgroundActivity() const;
53
54 // Set zoom level (0 - 17)
55 int zoomLevel() const;
56 void setZoomLevel(int level);
57
58 QPointF mapToViewport(const QPointF &pos) const;
59 QRect scrollBarGeometry(Qt::Orientation orientation) const;
60
61 void addNotification(QWidget* notif);
62 bool eventFilter(QObject *obj, QEvent *event) override;
63
64 QWidget *inputWidget() const;
65 virtual QWidget *overlayWidget() = 0;
66
67 static bool isUrlValid(const QUrl &url);
68 static QList<int> zoomLevels();
69
70 // Force context menu event to be sent on mouse release
71 // This allows to override right mouse button events (eg. for mouse gestures)
72 static bool forceContextMenuOnMouseRelease();
73 static void setForceContextMenuOnMouseRelease(bool force);
74
75Q_SIGNALS:
76 void pageChanged(WebPage *page);
77 void focusChanged(bool);
78 void viewportResized(QSize);
79 void showNotification(QWidget*);
80 void privacyChanged(bool);
83
84public Q_SLOTS:
85 void zoomIn();
86 void zoomOut();
87 void zoomReset();
88
89 void editUndo();
90 void editRedo();
91 void editCut();
92 void editCopy();
93 void editPaste();
94 void editSelectAll();
95 void editDelete();
96
97 void reloadBypassCache();
98
99 void back();
100 void forward();
101
102 void printPage();
103 void showSource();
104 void sendPageByMail();
105
106 void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlags position);
107
108 virtual void closeView() = 0;
109 virtual void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) = 0;
110
111 virtual bool isFullScreen() = 0;
112 virtual void requestFullScreen(bool enable) = 0;
113
114protected Q_SLOTS:
115 void slotLoadStarted();
116 void slotLoadProgress(int progress);
117 void slotLoadFinished(bool ok);
118 void slotIconChanged();
119 void slotUrlChanged(const QUrl &url);
120 void slotTitleChanged(const QString &title);
121
122 // Context menu slots
123 void openUrlInNewWindow();
124 void sendTextByMail();
125 void copyLinkToClipboard();
126 void savePageAs();
127 void copyImageToClipboard();
128 void downloadLinkToDisk();
129 void downloadImageToDisk();
130 void downloadMediaToDisk();
131 void openActionUrl();
132 void showSiteInfo();
133 void searchSelectedText();
134 void searchSelectedTextInBackgroundTab();
135 void bookmarkLink();
136 void openUrlInSelectedTab();
137 void openUrlInBackgroundTab();
138
139 // To support user's option whether to open in selected or background tab
140 void userDefinedOpenUrlInNewTab(const QUrl &url = QUrl(), bool invert = false);
141 void userDefinedOpenUrlInBgTab(const QUrl &url = QUrl());
142
143protected:
144 void showEvent(QShowEvent *event) override;
145 void resizeEvent(QResizeEvent *event) override;
146 void contextMenuEvent(QContextMenuEvent *event) override;
147
148 bool focusNextPrevChild(bool next) override;
149
150 virtual void _wheelEvent(QWheelEvent *event);
151 virtual void _mousePressEvent(QMouseEvent *event);
152 virtual void _mouseReleaseEvent(QMouseEvent *event);
153 virtual void _mouseMoveEvent(QMouseEvent *event);
154 virtual void _keyPressEvent(QKeyEvent *event);
155 virtual void _keyReleaseEvent(QKeyEvent *event);
156 virtual void _contextMenuEvent(QContextMenuEvent *event);
157
158 void loadRequest(const LoadRequest &req);
159 void applyZoom();
160
161 void createContextMenu(QMenu *menu, WebHitTestResult &hitTest);
162 void createPageContextMenu(QMenu *menu);
163 void createLinkContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
164 void createImageContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
165 void createSelectedTextContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
166 void createMediaContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
167
168 void checkForForm(QAction *action, const QPoint &pos);
169 void createSearchEngine();
170
171private Q_SLOTS:
172 void addSpeedDial();
173 void configureSpeedDial();
174 void reloadAllSpeedDials();
175
176 void toggleMediaPause();
177 void toggleMediaMute();
178
179private:
180 void initializeActions();
181
182 int m_currentZoomLevel;
183 int m_progress;
184 bool m_backgroundActivity;
185
186 QUrl m_clickedUrl;
187 QPointF m_clickedPos;
188
189 WebPage* m_page;
190 bool m_firstLoad;
191
192 QPointer<QWidget> m_rwhvqt;
193 WheelHelper m_wheelHelper;
194
195 static bool s_forceContextMenuOnMouseRelease;
196};
197
198#endif // WEBVIEW_H
virtual QWidget * overlayWidget()=0
void showNotification(QWidget *)
virtual void closeView()=0
void backgroundActivityChanged(bool)
virtual void requestFullScreen(bool enable)=0
virtual bool isFullScreen()=0
void focusChanged(bool)
void pageChanged(WebPage *page)
void privacyChanged(bool)
void zoomLevelChanged(int)
void viewportResized(QSize)
virtual void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position)=0
#define FALKON_EXPORT
Definition: qzcommon.h:28