2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#ifndef WEBVIEW_H
|
|
|
|
#define WEBVIEW_H
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QWebEngineView>
|
|
|
|
#if QTWEBENGINE_DISABLED
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QWebElement>
|
2015-01-27 11:01:52 +01:00
|
|
|
#endif
|
2012-01-21 20:20:48 +01:00
|
|
|
|
2014-02-26 20:03:20 +01:00
|
|
|
#include "qzcommon.h"
|
2014-03-19 21:27:43 +01:00
|
|
|
#include "loadrequest.h"
|
2012-01-22 15:15:43 +01:00
|
|
|
|
2012-04-03 19:28:12 +02:00
|
|
|
class WebPage;
|
2014-03-19 21:27:43 +01:00
|
|
|
class LoadRequest;
|
2012-04-03 19:28:12 +02:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
class QUPZILLA_EXPORT WebView : public QWebEngineView
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-01-21 20:20:48 +01:00
|
|
|
explicit WebView(QWidget* parent = 0);
|
2014-03-24 21:21:07 +01:00
|
|
|
~WebView();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QIcon icon() const;
|
|
|
|
QUrl url() const;
|
|
|
|
|
2014-04-01 18:47:19 +02:00
|
|
|
QString title() const;
|
|
|
|
bool isTitleEmpty() const;
|
|
|
|
|
2012-04-03 19:28:12 +02:00
|
|
|
WebPage* page() const;
|
2015-01-27 11:01:52 +01:00
|
|
|
void setPage(QWebEnginePage* page);
|
2012-01-24 19:58:20 +01:00
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
void load(const LoadRequest &request);
|
2012-04-04 14:45:45 +02:00
|
|
|
bool loadingError() const;
|
2012-01-21 20:20:48 +01:00
|
|
|
bool isLoading() const;
|
2012-06-27 18:29:00 +02:00
|
|
|
|
|
|
|
int loadingProgress() const;
|
|
|
|
void fakeLoadingProgress(int progress);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-02-10 14:09:11 +01:00
|
|
|
bool hasRss() const;
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
2013-04-07 20:19:21 +02:00
|
|
|
QWebElement activeElement() const;
|
2015-01-27 11:01:52 +01:00
|
|
|
#endif
|
2013-02-10 14:09:11 +01:00
|
|
|
|
2014-03-29 15:49:49 +01:00
|
|
|
// Set zoom level (0 - 17)
|
|
|
|
int zoomLevel() const;
|
|
|
|
void setZoomLevel(int level);
|
|
|
|
|
2014-02-11 22:25:32 +01:00
|
|
|
// Executes window.onbeforeunload, returns true if view can be closed
|
|
|
|
bool onBeforeUnload();
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void addNotification(QWidget* notif);
|
2011-11-05 21:27:01 +01:00
|
|
|
bool eventFilter(QObject* obj, QEvent* event);
|
|
|
|
|
2014-04-01 16:32:55 +02:00
|
|
|
virtual QWidget* overlayWidget() = 0;
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
static bool isUrlValid(const QUrl &url);
|
2012-01-21 20:20:48 +01:00
|
|
|
static QUrl guessUrlFromString(const QString &string);
|
2014-03-29 15:49:49 +01:00
|
|
|
static QList<int> zoomLevels();
|
2012-01-14 11:46:06 +01:00
|
|
|
|
2014-04-05 13:20:21 +02:00
|
|
|
// Force context menu event to be sent on mouse release
|
|
|
|
// This allows to override right mouse button events (eg. for mouse gestures)
|
|
|
|
static bool forceContextMenuOnMouseRelease();
|
|
|
|
static void setForceContextMenuOnMouseRelease(bool force);
|
|
|
|
|
2011-11-08 15:20:53 +01:00
|
|
|
signals:
|
2012-01-21 20:20:48 +01:00
|
|
|
void viewportResized(QSize);
|
|
|
|
void showNotification(QWidget*);
|
2012-04-03 20:23:15 +02:00
|
|
|
void privacyChanged(bool);
|
2013-02-10 14:09:11 +01:00
|
|
|
void rssChanged(bool);
|
2014-03-29 15:49:49 +01:00
|
|
|
void zoomLevelChanged(int);
|
2011-11-08 15:20:53 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
public slots:
|
2012-01-21 20:20:48 +01:00
|
|
|
void zoomIn();
|
|
|
|
void zoomOut();
|
|
|
|
void zoomReset();
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
void editUndo();
|
|
|
|
void editRedo();
|
|
|
|
void editCut();
|
|
|
|
void editCopy();
|
|
|
|
void editPaste();
|
|
|
|
void editSelectAll();
|
|
|
|
void editDelete();
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
void reload();
|
2014-03-10 16:55:11 +01:00
|
|
|
void reloadBypassCache();
|
2011-12-15 17:43:06 +01:00
|
|
|
|
2011-10-29 23:01:17 +02:00
|
|
|
void back();
|
|
|
|
void forward();
|
2012-01-21 20:20:48 +01:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
|
|
|
void printPage(QWebEngineFrame* frame = 0);
|
|
|
|
#endif
|
2012-04-01 18:57:42 +02:00
|
|
|
void sendPageByMail();
|
2012-08-14 18:53:55 +02:00
|
|
|
void savePageAs();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-02-12 13:48:34 +01:00
|
|
|
void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlags position);
|
2013-11-09 13:32:03 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
virtual void closeView() = 0;
|
2014-06-01 21:58:41 +02:00
|
|
|
virtual void openNewTab(Qz::NewTabPositionFlags position) { Q_UNUSED(position) }
|
2014-03-19 21:27:43 +01:00
|
|
|
virtual void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) = 0;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
protected slots:
|
|
|
|
void slotLoadStarted();
|
|
|
|
void slotLoadProgress(int progress);
|
|
|
|
void slotLoadFinished();
|
|
|
|
void slotIconChanged();
|
2012-08-31 15:20:00 +02:00
|
|
|
void slotUrlChanged(const QUrl &url);
|
2011-11-27 15:43:54 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
// Context menu slots
|
2011-03-02 16:57:41 +01:00
|
|
|
void openUrlInNewWindow();
|
|
|
|
void sendLinkByMail();
|
2012-01-21 20:20:48 +01:00
|
|
|
void copyLinkToClipboard();
|
2012-03-23 13:58:31 +01:00
|
|
|
void downloadUrlToDisk();
|
2012-01-21 20:20:48 +01:00
|
|
|
void copyImageToClipboard();
|
|
|
|
void openActionUrl();
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
|
|
|
void showSource(QWebEngineFrame* frame = 0, const QString &selectedHtml = QString());
|
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
void showSiteInfo();
|
2012-01-22 11:49:58 +01:00
|
|
|
void searchSelectedText();
|
2012-06-01 20:25:37 +02:00
|
|
|
void searchSelectedTextInBackgroundTab();
|
2012-01-22 11:49:58 +01:00
|
|
|
void bookmarkLink();
|
2012-01-22 15:15:43 +01:00
|
|
|
void openUrlInSelectedTab();
|
|
|
|
void openUrlInBackgroundTab();
|
2012-01-22 11:49:58 +01:00
|
|
|
|
2012-06-26 23:39:23 +02:00
|
|
|
// To support user's option whether to open in selected or background tab
|
2012-07-03 11:28:14 +02:00
|
|
|
void userDefinedOpenUrlInNewTab(const QUrl &url = QUrl(), bool invert = false);
|
2013-01-26 12:04:30 +01:00
|
|
|
void userDefinedOpenUrlInBgTab(const QUrl &url = QUrl());
|
2012-06-26 23:39:23 +02:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
2012-03-08 13:05:57 +01:00
|
|
|
void createSearchEngine();
|
2015-01-27 11:01:52 +01:00
|
|
|
#endif
|
2012-03-08 13:05:57 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
// Clicked frame actions
|
|
|
|
void loadClickedFrame();
|
2013-01-26 12:04:30 +01:00
|
|
|
void loadClickedFrameInNewTab(bool invert = false);
|
|
|
|
void loadClickedFrameInBgTab();
|
2012-01-22 11:49:58 +01:00
|
|
|
void reloadClickedFrame();
|
|
|
|
void printClickedFrame();
|
|
|
|
void clickedFrameZoomIn();
|
|
|
|
void clickedFrameZoomOut();
|
|
|
|
void clickedFrameZoomReset();
|
|
|
|
void showClickedFrameSource();
|
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
protected:
|
2011-03-17 17:03:04 +01:00
|
|
|
void wheelEvent(QWheelEvent* event);
|
2012-01-21 20:20:48 +01:00
|
|
|
void mousePressEvent(QMouseEvent* event);
|
2012-01-24 19:12:31 +01:00
|
|
|
void mouseReleaseEvent(QMouseEvent* event);
|
2012-02-22 18:33:44 +01:00
|
|
|
void mouseMoveEvent(QMouseEvent* event);
|
2011-11-27 15:43:54 +01:00
|
|
|
void keyPressEvent(QKeyEvent* event);
|
2012-02-22 18:33:44 +01:00
|
|
|
void keyReleaseEvent(QKeyEvent* event);
|
2012-01-21 20:20:48 +01:00
|
|
|
void resizeEvent(QResizeEvent* event);
|
2011-11-27 15:43:54 +01:00
|
|
|
|
2014-06-06 23:29:49 +02:00
|
|
|
void loadRequest(const LoadRequest &req);
|
2011-03-02 16:57:41 +01:00
|
|
|
void applyZoom();
|
2012-01-21 20:20:48 +01:00
|
|
|
QUrl lastUrl();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
2012-01-22 00:20:29 +01:00
|
|
|
bool isMediaElement(const QWebElement &element);
|
2012-03-08 13:05:57 +01:00
|
|
|
void checkForForm(QMenu* menu, const QWebElement &element);
|
2012-01-22 00:20:29 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void createContextMenu(QMenu* menu, const QWebHitTestResult &hitTest, const QPoint &pos);
|
|
|
|
void createPageContextMenu(QMenu* menu, const QPoint &pos);
|
|
|
|
void createLinkContextMenu(QMenu* menu, const QWebHitTestResult &hitTest);
|
|
|
|
void createImageContextMenu(QMenu* menu, const QWebHitTestResult &hitTest);
|
|
|
|
void createSelectedTextContextMenu(QMenu* menu, const QWebHitTestResult &hitTest);
|
|
|
|
void createMediaContextMenu(QMenu* menu, const QWebHitTestResult &hitTest);
|
2015-01-27 11:01:52 +01:00
|
|
|
#endif
|
2012-01-22 00:20:29 +01:00
|
|
|
|
|
|
|
private slots:
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
2012-01-22 00:20:29 +01:00
|
|
|
void pauseMedia();
|
|
|
|
void muteMedia();
|
2015-01-27 11:01:52 +01:00
|
|
|
#endif
|
2012-03-30 13:43:47 +02:00
|
|
|
void frameStateChanged();
|
|
|
|
void emitChangedUrl();
|
2013-02-10 14:09:11 +01:00
|
|
|
void checkRss();
|
2014-01-04 22:37:18 +01:00
|
|
|
void addSpeedDial();
|
|
|
|
void configureSpeedDial();
|
2014-05-30 15:12:36 +02:00
|
|
|
void reloadAllSpeedDials();
|
2012-01-22 00:20:29 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
private:
|
2014-10-17 18:37:18 +02:00
|
|
|
void initializeActions();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QList<int> m_zoomLevels;
|
2014-03-29 15:49:49 +01:00
|
|
|
int m_currentZoomLevel;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
QIcon m_siteIcon;
|
|
|
|
QUrl m_siteIconUrl;
|
2011-10-30 17:20:22 +01:00
|
|
|
|
2012-01-21 20:20:48 +01:00
|
|
|
bool m_isLoading;
|
|
|
|
int m_progress;
|
|
|
|
QUrl m_aboutToLoadUrl;
|
|
|
|
QUrl m_lastUrl;
|
2011-11-05 21:27:01 +01:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
2012-03-08 13:05:57 +01:00
|
|
|
QWebElement m_clickedElement;
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineFrame* m_clickedFrame;
|
|
|
|
#endif
|
2012-01-24 19:12:31 +01:00
|
|
|
QUrl m_clickedUrl;
|
2012-04-01 10:48:50 +02:00
|
|
|
|
2012-04-03 19:28:12 +02:00
|
|
|
WebPage* m_page;
|
2012-04-01 10:48:50 +02:00
|
|
|
bool m_actionsInitialized;
|
2012-01-22 00:20:29 +01:00
|
|
|
|
2012-08-31 15:20:00 +02:00
|
|
|
bool m_disableTouchMocking;
|
2012-12-08 21:18:30 +01:00
|
|
|
bool m_isReloading;
|
2013-02-10 14:09:11 +01:00
|
|
|
|
|
|
|
bool m_hasRss;
|
|
|
|
bool m_rssChecked;
|
2014-04-05 13:20:21 +02:00
|
|
|
|
|
|
|
static bool s_forceContextMenuOnMouseRelease;
|
2011-03-02 16:57:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // WEBVIEW_H
|