1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Old code cleanup

This commit is contained in:
David Rosca 2015-08-30 15:52:15 +02:00
parent e83734069b
commit b53bf49f75
8 changed files with 5 additions and 521 deletions

View File

@ -529,9 +529,7 @@ os2 {
mac {
HEADERS += other/macmenureceiver.h \
webtab/macwebviewscroller.h
SOURCES += other/macmenureceiver.cpp \
webtab/macwebviewscroller.cpp
RESOURCES -= data/certs.qrc
LIBS += -lcrypto -framework CoreServices

View File

@ -20,13 +20,13 @@
#include "browserwindow.h"
#include "mainapplication.h"
#include "tabbedwebview.h"
#include "webpage.h"
#include "speeddial.h"
#include "pluginproxy.h"
#include "plugininterface.h"
#include "settings.h"
#include "datapaths.h"
#include "iconprovider.h"
#include "useragentmanager.h"
#include <QTimer>
#include <QSettings>
@ -415,7 +415,7 @@ QString QupZillaSchemeReply::configPage()
}
QString page = cPage;
page.replace(QLatin1String("%USER-AGENT%"), mApp->getWindow()->weView()->page()->userAgentForUrl(QUrl()));
page.replace(QLatin1String("%USER-AGENT%"), mApp->userAgentManager()->userAgentForUrl(QUrl()));
QString pluginsString;
const QList<Plugins::Plugin> &availablePlugins = mApp->plugins()->getAvailablePlugins();

View File

@ -60,6 +60,7 @@
#include <QLineEdit>
#include <QMouseEvent>
#include <QWebEngineHistory>
#include <QWebEngineSettings>
#include <QTimer>
#include <QNetworkReply>
#include <QDesktopServices>
@ -137,15 +138,6 @@ void WebPage::scheduleAdjustPage()
}
}
bool WebPage::loadingError() const
{
#if QTWEBENGINE_DISABLED
return !mainFrame()->findFirstElement("span[id=\"qupzilla-error-page\"]").isNull();
#else
return false;
#endif
}
void WebPage::addRejectedCerts(const QList<QSslCertificate> &certs)
{
foreach (const QSslCertificate &cert, certs) {
@ -172,14 +164,6 @@ bool WebPage::containsRejectedCerts(const QList<QSslCertificate> &certs)
return matches == certs.count();
}
#if QTWEBENGINE_DISABLED
QWebElement WebPage::activeElement() const
{
QRect activeRect = inputMethodQuery(Qt::ImMicroFocus).toRect();
return mainFrame()->hitTestContent(activeRect.center()).element();
}
#endif
bool WebPage::isRunningLoop()
{
return m_runningLoop;
@ -258,37 +242,6 @@ void WebPage::watchedFileChanged(const QString &file)
}
}
#if QTWEBENGINE_DISABLED
void WebPage::printFrame(QWebEngineFrame* frame)
{
WebView* webView = qobject_cast<WebView*>(view());
if (!webView) {
return;
}
webView->printPage(frame);
}
#endif
void WebPage::addJavaScriptObject()
{
#if QTWEBENGINE_DISABLED
// Make sure all other sites have JavaScript set by user preferences
// (JavaScript is enabled in WebPage::urlChanged)
if (url().scheme() != QLatin1String("qupzilla")) {
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, m_javaScriptEnabled);
}
ExternalJsObject* jsObject = new ExternalJsObject(this);
addToJavaScriptWindowObject("external", jsObject);
if (url().toString() == QLatin1String("qupzilla:speeddial")) {
jsObject->setOnSpeedDial(true);
mApp->plugins()->speedDial()->addWebFrame(mainFrame());
}
#endif
}
void WebPage::handleUnsupportedContent(QNetworkReply* reply)
{
if (!reply) {
@ -436,23 +389,6 @@ void WebPage::windowCloseRequested()
webView->closeView();
}
#if QTWEBENGINE_DISABLED
void WebPage::frameCreated(QWebFrame* frame)
{
connect(frame, SIGNAL(initialLayoutCompleted()), this, SLOT(frameInitialLayoutCompleted()));
}
void WebPage::frameInitialLayoutCompleted()
{
QWebFrame* frame = qobject_cast<QWebFrame*>(sender());
if (!frame)
return;
// Autofill
m_passwordEntries = mApp->autoFill()->completeFrame(frame);
}
#endif
void WebPage::authentication(const QUrl &requestUrl, QAuthenticator* auth)
{
QDialog* dialog = new QDialog();
@ -587,20 +523,6 @@ void WebPage::proxyAuthentication(const QUrl &requestUrl, QAuthenticator* auth,
auth->setPassword(pass->text());
}
#if QTWEBENGINE_DISABLED
void WebPage::dbQuotaExceeded(QWebEngineFrame* frame)
{
if (!frame) {
return;
}
const QWebSecurityOrigin origin = frame->securityOrigin();
const qint64 oldQuota = origin.databaseQuota();
frame->securityOrigin().setDatabaseQuota(oldQuota * 2);
}
#endif
void WebPage::doWebSearch(const QString &text)
{
WebView* webView = qobject_cast<WebView*>(view());
@ -616,61 +538,6 @@ void WebPage::featurePermissionRequested(const QUrl &origin, const QWebEnginePag
mApp->html5PermissionsManager()->requestPermissions(this, origin, feature);
}
#ifdef USE_QTWEBKIT_2_2
void WebPage::appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota)
{
if (!origin) {
return;
}
origin->setApplicationCacheQuota(originalQuota * 2);
}
#endif // USE_QTWEBKIT_2_2
bool WebPage::event(QEvent* event)
{
if (event->type() == QEvent::Leave) {
// QWebEnginePagePrivate::leaveEvent():
// Fake a mouse move event just outside of the widget, since all
// the interesting mouse-out behavior like invalidating scrollbars
// is handled by the WebKit event handler's mouseMoved function.
// However, its implementation fake mouse move event on QCursor::pos()
// position that is in global screen coordinates. So instead of
// really faking it, it just creates mouse move event somewhere in
// page. It can for example focus a link, and then link url gets
// stuck in status bar message.
// So we are faking mouse move event with proper coordinates for
// so called "just outside of the widget" position
const QPoint cursorPos = view()->mapFromGlobal(QCursor::pos());
QPoint mousePos;
if (cursorPos.y() < 0) {
// Left on top
mousePos = QPoint(cursorPos.x(), -1);
}
else if (cursorPos.x() < 0) {
// Left on left
mousePos = QPoint(-1, cursorPos.y());
}
else if (cursorPos.y() > view()->height()) {
// Left on bottom
mousePos = QPoint(cursorPos.x(), view()->height() + 1);
}
else {
// Left on right
mousePos = QPoint(view()->width() + 1, cursorPos.y());
}
QMouseEvent fakeEvent(QEvent::MouseMove, mousePos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
return QWebEnginePage::event(&fakeEvent);
}
return QWebEnginePage::event(event);
}
bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
m_lastRequestUrl = url;
@ -865,24 +732,6 @@ void WebPage::cleanBlockedObjects()
runJavaScript(Scripts::setCss(elementHiding));
}
QString WebPage::userAgentForUrl(const QUrl &url) const
{
QString userAgent = mApp->userAgentManager()->userAgentForUrl(url);
#if QTWEBENGINE_DISABLED
if (userAgent.isEmpty()) {
userAgent = QWebEnginePage::userAgentForUrl(url);
#ifdef Q_OS_MAC
#ifdef __i386__ || __x86_64__
userAgent.replace(QLatin1String("PPC Mac OS X"), QLatin1String("Intel Mac OS X"));
#endif
#endif
}
#endif
return userAgent;
}
#if QTWEBENGINE_DISABLED
bool WebPage::supportsExtension(Extension extension) const
{
@ -1207,10 +1056,8 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg)
void WebPage::setJavaScriptEnabled(bool enabled)
{
#if QTWEBENGINE_DISABLED
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, enabled);
m_javaScriptEnabled = enabled;
#endif
}
QWebEnginePage* WebPage::createWindow(QWebEnginePage::WebWindowType type)

View File

@ -73,18 +73,12 @@ public:
bool isRunningLoop();
bool isLoading() const;
bool loadingError() const;
void addRejectedCerts(const QList<QSslCertificate> &certs);
bool containsRejectedCerts(const QList<QSslCertificate> &certs);
void setupWebChannel();
#if QTWEBENGINE_DISABLED
QWebElement activeElement() const;
#endif
QString userAgentForUrl(const QUrl &url) const;
signals:
void privacyChanged(bool status);
@ -97,30 +91,15 @@ protected slots:
private slots:
void cleanBlockedObjects();
void urlChanged(const QUrl &url);
void addJavaScriptObject();
void watchedFileChanged(const QString &file);
void windowCloseRequested();
void authentication(const QUrl &requestUrl, QAuthenticator* auth);
void proxyAuthentication(const QUrl &requestUrl, QAuthenticator* auth, const QString &proxyHost);
#if QTWEBENGINE_DISABLED
void frameCreated(QWebFrame* frame);
void frameInitialLayoutCompleted();
void dbQuotaExceeded(QWebEngineFrame* frame);
void printFrame(QWebEngineFrame* frame);
#endif
void doWebSearch(const QString &text);
void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature);
#ifdef USE_QTWEBKIT_2_2
void appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota);
#endif
protected:
bool event(QEvent* event);
private:
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE;
bool certificateError(const QWebEngineCertificateError &certificateError) Q_DECL_OVERRIDE;

View File

@ -39,10 +39,6 @@
#include "qtwebkit/spellcheck/speller.h"
#endif
#ifdef Q_OS_MAC
#include "macwebviewscroller.h"
#endif
#include <iostream>
#include <QDir>
@ -51,7 +47,6 @@
#include <QNetworkRequest>
#include <QWebEngineHistory>
#include <QClipboard>
#include <QTouchEvent>
bool WebView::s_forceContextMenuOnMouseRelease = false;
@ -60,9 +55,6 @@ WebView::WebView(QWidget* parent)
, m_siteIconLoader(0)
, m_isLoading(false)
, m_progress(0)
#if QTWEBENGINE_DISABLED
, m_clickedFrame(0)
#endif
, m_page(0)
, m_disableTouchMocking(false)
, m_isReloading(false)
@ -80,10 +72,6 @@ WebView::WebView(QWidget* parent)
installEventFilter(this);
WebInspector::registerView(this);
#ifdef Q_OS_MAC
new MacWebViewScroller(this);
#endif
}
WebView::~WebView()
@ -105,12 +93,6 @@ QIcon WebView::icon() const
return IconProvider::standardIcon(QStyle::SP_ComputerIcon);
}
#if QTWEBENGINE_DISABLED
if (!QWebEngineView::icon().isNull()) {
return QWebEngineView::icon();
}
#endif
if (!m_siteIcon.isNull() && m_siteIconUrl.host() == url().host()) {
return m_siteIcon;
}
@ -163,9 +145,6 @@ void WebView::setPage(QWebEnginePage* page)
QWebEngineView::setPage(page);
m_page = qobject_cast<WebPage*>(page);
#if QTWEBENGINE_DISABLED
connect(m_page, SIGNAL(saveFrameStateRequested(QWebEngineFrame*,QWebHistoryItem*)), this, SLOT(frameStateChanged()));
#endif
connect(m_page, SIGNAL(privacyChanged(bool)), this, SIGNAL(privacyChanged(bool)));
// Set default zoom level
@ -175,14 +154,6 @@ void WebView::setPage(QWebEnginePage* page)
initializeActions();
mApp->plugins()->emitWebPageCreated(m_page);
#if QTWEBENGINE_DISABLED
// Set white background by default.
// Fixes issue with dark themes. See #602
QPalette pal = palette();
pal.setBrush(QPalette::Base, Qt::white);
page->setPalette(pal);
#endif
}
void WebView::load(const QUrl &url)
@ -478,12 +449,6 @@ void WebView::slotLoadFinished()
m_lastUrl = url();
}
void WebView::frameStateChanged()
{
// QWebEngineFrame::baseUrl() is not updated yet, so we are invoking 0 second timer
QTimer::singleShot(0, this, SLOT(emitChangedUrl()));
}
void WebView::emitChangedUrl()
{
emit urlChanged(url());
@ -750,92 +715,6 @@ void WebView::userDefinedOpenUrlInBgTab(const QUrl &url)
userDefinedOpenUrlInNewTab(actionUrl, true);
}
void WebView::loadClickedFrame()
{
#if QTWEBENGINE_DISABLED
QUrl frameUrl = m_clickedFrame->baseUrl();
if (frameUrl.isEmpty()) {
frameUrl = m_clickedFrame->requestedUrl();
}
load(frameUrl);
#endif
}
void WebView::loadClickedFrameInNewTab(bool invert)
{
#if QTWEBENGINE_DISABLED
QUrl frameUrl = m_clickedFrame->baseUrl();
if (frameUrl.isEmpty()) {
frameUrl = m_clickedFrame->requestedUrl();
}
userDefinedOpenUrlInNewTab(frameUrl, invert);
#endif
}
void WebView::loadClickedFrameInBgTab()
{
loadClickedFrameInNewTab(true);
}
void WebView::reloadClickedFrame()
{
#if QTWEBENGINE_DISABLED
QUrl frameUrl = m_clickedFrame->baseUrl();
if (frameUrl.isEmpty()) {
frameUrl = m_clickedFrame->requestedUrl();
}
m_clickedFrame->load(frameUrl);
#endif
}
void WebView::printClickedFrame()
{
#if QTWEBENGINE_DISABLED
printPage(m_clickedFrame);
#endif
}
void WebView::clickedFrameZoomIn()
{
#if QTWEBENGINE_DISABLED
qreal zFactor = m_clickedFrame->zoomFactor() + 0.1;
if (zFactor > 2.5) {
zFactor = 2.5;
}
m_clickedFrame->setZoomFactor(zFactor);
#endif
}
void WebView::clickedFrameZoomOut()
{
#if QTWEBENGINE_DISABLED
qreal zFactor = m_clickedFrame->zoomFactor() - 0.1;
if (zFactor < 0.5) {
zFactor = 0.5;
}
m_clickedFrame->setZoomFactor(zFactor);
#endif
}
void WebView::clickedFrameZoomReset()
{
#if QTWEBENGINE_DISABLED
m_clickedFrame->setZoomFactor(zoomFactor());
#endif
}
void WebView::showClickedFrameSource()
{
#if QTWEBENGINE_DISABLED
showSource(m_clickedFrame);
#endif
}
#if QTWEBENGINE_DISABLED
void WebView::printPage(QWebEngineFrame* frame)
{
@ -1424,28 +1303,8 @@ void WebView::keyPressEvent(QKeyEvent* event)
return;
}
int eventKey = event->key();
// The right/left arrow keys within contents with right to left (RTL) layout have
// reversed behavior than left to right (LTR) layout.
// Example: Key_Right within LTR layout triggers QWebPage::MoveToNextChar but,
// Key_Right within RTL layout should trigger QWebPage::MoveToPreviousChar
// event->spontaneous() check guards recursive calling of keyPressEvent
// Events created from app have spontaneous() == false
#if QTWEBENGINE_DISABLED
if (event->spontaneous() && (eventKey == Qt::Key_Left || eventKey == Qt::Key_Right)) {
const QWebElement elementHasCursor = activeElement();
if (!elementHasCursor.isNull()) {
const QString direction = elementHasCursor.styleProperty("direction", QWebElement::ComputedStyle);
if (direction == QLatin1String("rtl")) {
eventKey = eventKey == Qt::Key_Left ? Qt::Key_Right : Qt::Key_Left;
QKeyEvent ev(event->type(), eventKey, event->modifiers(), event->text(), event->isAutoRepeat());
keyPressEvent(&ev);
return;
}
}
}
int eventKey = event->key();
switch (eventKey) {
case Qt::Key_ZoomIn:
@ -1594,9 +1453,7 @@ void WebView::keyReleaseEvent(QKeyEvent* event)
void WebView::resizeEvent(QResizeEvent* event)
{
QWebEngineView::resizeEvent(event);
#if QTWEBENGINE_DISABLED
emit viewportResized(page()->viewportSize());
#endif
emit viewportResized(size());
}
void WebView::loadRequest(const LoadRequest &req)
@ -1619,73 +1476,5 @@ bool WebView::eventFilter(QObject* obj, QEvent* event)
}
}
#if QTWEBENGINE_DISABLED
// This hack is no longer needed with QtWebKit 2.3 (bundled in Qt 5)
#if QTWEBKIT_TO_2_3
// This function was taken and modified from QTestBrowser to fix bug #33 with flightradar24.com
// You can find original source and copyright here:
// http://gitorious.org/+qtwebkit-developers/webkit/qtwebkit/blobs/qtwebkit-2.2/Tools/QtTestBrowser/launcherwindow.cpp
if (obj != this || m_disableTouchMocking) {
return false;
}
if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease ||
event->type() == QEvent::MouseButtonDblClick ||
event->type() == QEvent::MouseMove
) {
QMouseEvent* ev = static_cast<QMouseEvent*>(event);
if (ev->type() == QEvent::MouseMove && !(ev->buttons() & Qt::LeftButton)) {
return false;
}
#endif
if (ev->type() == QEvent::MouseButtonPress && !(ev->buttons() & Qt::LeftButton)) {
return false;
}
QEvent::Type type = QEvent::TouchUpdate;
QTouchEvent::TouchPoint touchPoint;
touchPoint.setId(0);
touchPoint.setScreenPos(ev->globalPos());
touchPoint.setPos(ev->pos());
touchPoint.setPressure(1);
switch (ev->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
touchPoint.setState(Qt::TouchPointPressed);
type = QEvent::TouchBegin;
break;
case QEvent::MouseButtonRelease:
touchPoint.setState(Qt::TouchPointReleased);
type = QEvent::TouchEnd;
break;
case QEvent::MouseMove:
touchPoint.setState(Qt::TouchPointMoved);
type = QEvent::TouchUpdate;
break;
default:
break;
}
QList<QTouchEvent::TouchPoint> touchPoints;
touchPoints << touchPoint;
QTouchEvent touchEv(type);
touchEv.setTouchPoints(touchPoints);
QCoreApplication::sendEvent(page(), &touchEv);
return false;
}
#endif
return QWebEngineView::eventFilter(obj, event);
}

View File

@ -142,17 +142,6 @@ protected slots:
void createSearchEngine();
#endif
// Clicked frame actions
void loadClickedFrame();
void loadClickedFrameInNewTab(bool invert = false);
void loadClickedFrameInBgTab();
void reloadClickedFrame();
void printClickedFrame();
void clickedFrameZoomIn();
void clickedFrameZoomOut();
void clickedFrameZoomReset();
void showClickedFrameSource();
protected:
void wheelEvent(QWheelEvent* event);
void mousePressEvent(QMouseEvent* event);
@ -183,7 +172,6 @@ private slots:
void pauseMedia();
void muteMedia();
#endif
void frameStateChanged();
void emitChangedUrl();
void addSpeedDial();
void configureSpeedDial();
@ -206,7 +194,6 @@ private:
#if QTWEBENGINE_DISABLED
QWebElement m_clickedElement;
QWebEngineFrame* m_clickedFrame;
#endif
QUrl m_clickedUrl;

View File

@ -1,68 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#include "macwebviewscroller.h"
#include <QApplication>
#include <QWheelEvent>
#include <QWebView>
#include <QTimer>
// Workaround for QTBUG-22269 (Extremely slow scrolling on Apple trackpads)
// https://bugreports.qt-project.org/browse/QTBUG-22269
MacWebViewScroller::MacWebViewScroller(QWebView* view)
: QObject(view)
, m_view(view)
, m_timerRunning(false)
, m_delta(0)
{
view->installEventFilter(this);
}
bool MacWebViewScroller::eventFilter(QObject* obj, QEvent* event)
{
if (obj != m_view || event->type() != QEvent::Wheel) {
return false;
}
QWheelEvent* ev = static_cast<QWheelEvent*>(event);
if (ev->buttons() != Qt::NoButton || ev->modifiers() != Qt::NoModifier) {
return false;
}
if (!m_timerRunning) {
m_delta = ev->delta();
m_pos = ev->pos();
m_globalPos = ev->globalPos();
QTimer::singleShot(25, this, SLOT(sendWheelEvent()));
m_timerRunning = true;
}
else {
m_delta += ev->delta();
}
return true;
}
void MacWebViewScroller::sendWheelEvent()
{
QWheelEvent ev(m_pos, m_delta, Qt::NoButton, Qt::NoModifier);
m_view->event(&ev);
m_timerRunning = false;
}

View File

@ -1,48 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#ifndef MACWEBVIEWSCROLLER_H
#define MACWEBVIEWSCROLLER_H
#include <QObject>
#include <QPoint>
class QWheelEvent;
class QWebView;
class MacWebViewScroller : public QObject
{
Q_OBJECT
public:
explicit MacWebViewScroller(QWebView* view);
bool eventFilter(QObject* obj, QEvent* event);
private slots:
void sendWheelEvent();
private:
QWebView* m_view;
bool m_timerRunning;
int m_delta;
QPoint m_pos;
QPoint m_globalPos;
};
#endif // MACWEBVIEWSCROLLER_H