1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Bring back AutoScroll plugin

This time implemented in C++ and not with userscript. There
is also no support for scrolling inside frames.
This commit is contained in:
David Rosca 2015-10-02 15:23:59 +02:00
parent 74e02dd1e3
commit 4d5808d915
11 changed files with 66 additions and 26 deletions

View File

@ -131,6 +131,11 @@ WebHitTestResult WebPage::hitTestContent(const QPoint &pos) const
return WebHitTestResult(this, pos);
}
void WebPage::scroll(int x, int y)
{
runJavaScript(QSL("window.scrollTo(window.scrollX + %1, window.scrollY + %2)").arg(QString::number(x), QString::number(y)));
}
void WebPage::scheduleAdjustPage()
{
if (view()->isLoading()) {

View File

@ -54,6 +54,8 @@ public:
WebHitTestResult hitTestContent(const QPoint &pos) const;
void scroll(int x, int y);
bool javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result) Q_DECL_OVERRIDE;
bool javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE;
void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE;

View File

@ -243,6 +243,11 @@ bool WebView::onBeforeUnload()
return true;
}
QWidget *WebView::inputWidget() const
{
return qobject_cast<QWidget*>(m_rwhvqt);
}
// static
bool WebView::isUrlValid(const QUrl &url)
{

View File

@ -63,6 +63,7 @@ public:
void addNotification(QWidget* notif);
bool eventFilter(QObject *obj, QEvent *event);
QWidget *inputWidget() const;
virtual QWidget* overlayWidget() = 0;
static bool isUrlValid(const QUrl &url);

View File

@ -19,10 +19,10 @@
#include "framescroller.h"
#include "webview.h"
#include "webpage.h"
#include "webhittestresult.h"
#include <QApplication>
#include <QMouseEvent>
#include <QWebFrame>
#include <QSettings>
#include <QLabel>
@ -115,6 +115,19 @@ bool AutoScroller::mouseRelease(QObject* obj, QMouseEvent* event)
return false;
}
bool AutoScroller::wheel(QObject *obj, QWheelEvent *event)
{
Q_UNUSED(obj)
Q_UNUSED(event);
if (m_indicator->isVisible()) {
stopScrolling();
return true;
}
return false;
}
double AutoScroller::scrollDivider() const
{
return m_frameScroller->scrollDivider();
@ -154,20 +167,22 @@ bool AutoScroller::eventFilter(QObject* obj, QEvent* event)
bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
{
QWebFrame* frame = view->page()->frameAt(pos);
if (!frame) {
return false;
}
const QWebHitTestResult res = frame->hitTestContent(pos);
const WebHitTestResult res = view->page()->hitTestContent(pos);
if (res.isContentEditable() || !res.linkUrl().isEmpty()) {
return false;
}
bool vertical = frame->scrollBarGeometry(Qt::Vertical).isValid();
bool horizontal = frame->scrollBarGeometry(Qt::Horizontal).isValid();
QString source = QL1S("var out = {"
" vertical: window.innerWidth > document.documentElement.clientWidth,"
" horizontal: window.innerHeight > document.documentElement.clientHeight"
"};"
"out;");
const QVariantMap &map = view->page()->execJavaScript(source).toMap();
bool vertical = map.value(QSL("vertical")).toBool();
bool horizontal = map.value(QSL("horizontal")).toBool();
if (!vertical && !horizontal) {
return false;
@ -193,9 +208,9 @@ bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
m_indicator->move(p);
m_indicator->show();
m_frameScroller->setFrame(frame);
m_frameScroller->setPage(view->page());
m_view->grabMouse();
m_view->inputWidget()->grabMouse();
QApplication::setOverrideCursor(Qt::ArrowCursor);
return true;
@ -203,7 +218,7 @@ bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
void AutoScroller::stopScrolling()
{
m_view->releaseMouse();
m_view->inputWidget()->releaseMouse();
QApplication::restoreOverrideCursor();
m_indicator->hide();

View File

@ -22,6 +22,7 @@
#include <QPoint>
class QMouseEvent;
class QWheelEvent;
class QLabel;
class QRect;
@ -38,6 +39,7 @@ public:
bool mouseMove(QObject* obj, QMouseEvent* event);
bool mousePress(QObject* obj, QMouseEvent* event);
bool mouseRelease(QObject* obj, QMouseEvent* event);
bool wheel(QObject* obj, QWheelEvent *event);
double scrollDivider() const;
void setScrollDivider(double divider);

View File

@ -36,7 +36,7 @@ PluginSpec AutoScrollPlugin::pluginSpec()
spec.name = "AutoScroll";
spec.info = "AutoScroll plugin";
spec.description = "Provides support for autoscroll with middle mouse button";
spec.version = "0.1.5";
spec.version = "0.2.0";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":/autoscroll/data/scroll_all.png");
spec.hasSettings = true;
@ -53,6 +53,7 @@ void AutoScrollPlugin::init(InitState state, const QString &settingsPath)
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseMoveHandler);
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler);
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseReleaseHandler);
QZ_REGISTER_EVENT_HANDLER(PluginProxy::WheelEventHandler);
}
void AutoScrollPlugin::unload()
@ -110,6 +111,15 @@ bool AutoScrollPlugin::mouseRelease(const Qz::ObjectName &type, QObject* obj, QM
return false;
}
bool AutoScrollPlugin::wheelEvent(const Qz::ObjectName &type, QObject *obj, QWheelEvent *event)
{
if (type == Qz::ON_WebView) {
return m_scroller->wheel(obj, event);
}
return false;
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(AutoScroll, AutoScrollPlugin)
#endif

View File

@ -46,6 +46,7 @@ public:
bool mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
bool mousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
bool mouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
bool wheelEvent(const Qz::ObjectName &type, QObject *obj, QWheelEvent *event);
private:
AutoScroller* m_scroller;

View File

@ -16,14 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "framescroller.h"
#include "webpage.h"
#include <QTimer>
#include <QWebFrame>
#include <QtCore/qmath.h>
#include <QtMath>
FrameScroller::FrameScroller(QObject* parent)
: QObject(parent)
, m_frame(0)
, m_page(0)
, m_lengthX(0)
, m_lengthY(0)
, m_divider(8.0)
@ -33,9 +33,9 @@ FrameScroller::FrameScroller(QObject* parent)
connect(m_timer, SIGNAL(timeout()), this, SLOT(scrollStep()));
}
void FrameScroller::setFrame(QWebFrame* frame)
void FrameScroller::setPage(WebPage *page)
{
m_frame = frame;
m_page = page;
}
double FrameScroller::scrollDivider() const
@ -50,8 +50,6 @@ void FrameScroller::setScrollDivider(double divider)
void FrameScroller::startScrolling(int lengthX, int lengthY)
{
Q_ASSERT(m_frame);
m_lengthX = lengthX;
m_lengthY = lengthY;
@ -70,5 +68,5 @@ void FrameScroller::stopScrolling()
void FrameScroller::scrollStep()
{
m_frame->scroll(qCeil(m_lengthX / m_divider), qCeil(m_lengthY / m_divider));
m_page->scroll(qCeil(m_lengthX / m_divider), qCeil(m_lengthY / m_divider));
}

View File

@ -21,7 +21,8 @@
#include <QObject>
class QTimer;
class QWebFrame;
class WebPage;
class FrameScroller : public QObject
{
@ -30,7 +31,7 @@ class FrameScroller : public QObject
public:
explicit FrameScroller(QObject* parent = 0);
void setFrame(QWebFrame* frame);
void setPage(WebPage *page);
double scrollDivider() const;
void setScrollDivider(double divider);
@ -42,7 +43,7 @@ private slots:
void scrollStep();
private:
QWebFrame* m_frame;
WebPage *m_page;
QTimer* m_timer;
int m_lengthX;

View File

@ -34,7 +34,7 @@ outOfDirPlugins = $$(QUPZILLA_PLUGINS_SRCDIR)
# KWalletPasswords only with KDE_INTEGRATION and KWallet framework
!contains(DEFINES, KDE_INTEGRATION): disablePlugin(KWalletPasswords)
isEqual(QT_MAJOR_VERSION, 5): !qtHaveModule(KWallet): disablePlugin(KWalletPasswords)
!qtHaveModule(KWallet): disablePlugin(KWalletPasswords)
# GnomeKeyringPasswords only with GNOME_INTEGRATION and gnome-keyring pkg-config
!contains(DEFINES, GNOME_INTEGRATION): disablePlugin(GnomeKeyringPasswords)