From fa2779e6b932b7f2940e1a845be7aa5aa2b1bf64 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sun, 30 Aug 2015 21:14:35 +0200 Subject: [PATCH] Bring back AutoScroll plugin --- src/plugins/AutoScroll/AutoScroll.pro | 4 - src/plugins/AutoScroll/autoscroll.qrc | 1 + src/plugins/AutoScroll/autoscroller.cpp | 218 ------------- src/plugins/AutoScroll/autoscroller.h | 59 ---- src/plugins/AutoScroll/autoscrollplugin.cpp | 80 ++--- src/plugins/AutoScroll/autoscrollplugin.h | 17 +- src/plugins/AutoScroll/autoscrollsettings.cpp | 26 +- src/plugins/AutoScroll/autoscrollsettings.h | 7 +- src/plugins/AutoScroll/autoscrollsettings.ui | 67 ++-- src/plugins/AutoScroll/data/autoscroll.js | 301 ++++++++++++++++++ src/plugins/AutoScroll/framescroller.cpp | 74 ----- src/plugins/AutoScroll/framescroller.h | 53 --- src/plugins/GreaseMonkey/gm_plugin.h | 1 - src/plugins/plugins.pro | 1 - 14 files changed, 410 insertions(+), 499 deletions(-) delete mode 100644 src/plugins/AutoScroll/autoscroller.cpp delete mode 100644 src/plugins/AutoScroll/autoscroller.h create mode 100644 src/plugins/AutoScroll/data/autoscroll.js delete mode 100644 src/plugins/AutoScroll/framescroller.cpp delete mode 100644 src/plugins/AutoScroll/framescroller.h diff --git a/src/plugins/AutoScroll/AutoScroll.pro b/src/plugins/AutoScroll/AutoScroll.pro index af9461510..0baf3951e 100644 --- a/src/plugins/AutoScroll/AutoScroll.pro +++ b/src/plugins/AutoScroll/AutoScroll.pro @@ -3,13 +3,9 @@ TARGET = $$qtLibraryTarget(AutoScroll) os2: TARGET = AutoScrl SOURCES += autoscrollplugin.cpp \ - autoscroller.cpp \ - framescroller.cpp \ autoscrollsettings.cpp HEADERS += autoscrollplugin.h \ - autoscroller.h \ - framescroller.h \ autoscrollsettings.h FORMS += \ diff --git a/src/plugins/AutoScroll/autoscroll.qrc b/src/plugins/AutoScroll/autoscroll.qrc index fb8e4f10c..46c8bcc74 100644 --- a/src/plugins/AutoScroll/autoscroll.qrc +++ b/src/plugins/AutoScroll/autoscroll.qrc @@ -31,5 +31,6 @@ locale/sr.qm locale/tr_TR.qm locale/zh_TW.qm + data/autoscroll.js diff --git a/src/plugins/AutoScroll/autoscroller.cpp b/src/plugins/AutoScroll/autoscroller.cpp deleted file mode 100644 index a64685f6a..000000000 --- a/src/plugins/AutoScroll/autoscroller.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* ============================================================ -* AutoScroll - Autoscroll for QupZilla -* Copyright (C) 2014 David Rosca -* -* 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 . -* ============================================================ */ -#include "autoscroller.h" -#include "framescroller.h" -#include "webview.h" -#include "webpage.h" - -#include -#include -#include -#include -#include - -AutoScroller::AutoScroller(const QString &settingsFile, QObject* parent) - : QObject(parent) - , m_view(0) - , m_settingsFile(settingsFile) -{ - m_indicator = new QLabel; - m_indicator->resize(32, 32); - m_indicator->setContentsMargins(0, 0, 0, 0); - m_indicator->installEventFilter(this); - - QSettings settings(m_settingsFile, QSettings::IniFormat); - settings.beginGroup("AutoScroll"); - - m_frameScroller = new FrameScroller(this); - m_frameScroller->setScrollDivider(settings.value("ScrollDivider", 8.0).toDouble()); - - settings.endGroup(); -} - -AutoScroller::~AutoScroller() -{ - delete m_indicator; -} - -bool AutoScroller::mouseMove(QObject* obj, QMouseEvent* event) -{ - Q_UNUSED(obj) - - if (m_indicator->isVisible()) { - QRect rect = indicatorGlobalRect(); - int xlength = 0; - int ylength = 0; - - if (rect.left() > event->globalPos().x()) { - xlength = event->globalPos().x() - rect.left(); - } - else if (rect.right() < event->globalPos().x()) { - xlength = event->globalPos().x() - rect.right(); - } - if (rect.top() > event->globalPos().y()) { - ylength = event->globalPos().y() - rect.top(); - } - else if (rect.bottom() < event->globalPos().y()) { - ylength = event->globalPos().y() - rect.bottom(); - } - - m_frameScroller->startScrolling(xlength, ylength); - } - - return false; -} - -bool AutoScroller::mousePress(QObject* obj, QMouseEvent* event) -{ - bool middleButton = event->buttons() == Qt::MiddleButton; - WebView* view = qobject_cast(obj); - Q_ASSERT(view); - - // Start? - if (m_view != view && middleButton) { - return showIndicator(view, event->pos()); - } - else if (!m_indicator->isVisible() && middleButton) { - return showIndicator(view, event->pos()); - } - - // Stop - if (m_indicator->isVisible()) { - stopScrolling(); - return true; - } - - return false; -} - -bool AutoScroller::mouseRelease(QObject* obj, QMouseEvent* event) -{ - Q_UNUSED(obj) - - if (m_indicator->isVisible()) { - if (!indicatorGlobalRect().contains(event->globalPos())) { - stopScrolling(); - } - return true; - } - - return false; -} - -double AutoScroller::scrollDivider() const -{ - return m_frameScroller->scrollDivider(); -} - -void AutoScroller::setScrollDivider(double divider) -{ - QSettings settings(m_settingsFile, QSettings::IniFormat); - settings.beginGroup("AutoScroll"); - settings.setValue("ScrollDivider", divider); - settings.endGroup(); - - m_frameScroller->setScrollDivider(divider); -} - -bool AutoScroller::eventFilter(QObject* obj, QEvent* event) -{ - if (obj == m_indicator) { - switch (event->type()) { - case QEvent::Enter: - m_frameScroller->stopScrolling(); - break; - - case QEvent::Wheel: - case QEvent::Hide: - case QEvent::MouseButtonPress: - stopScrolling(); - break; - - default: - break; - } - } - - return false; -} - -bool AutoScroller::showIndicator(WebView* view, const QPoint &pos) -{ - QWebFrame* frame = view->page()->frameAt(pos); - - if (!frame) { - return false; - } - - const QWebHitTestResult res = frame->hitTestContent(pos); - - if (res.isContentEditable() || !res.linkUrl().isEmpty()) { - return false; - } - - bool vertical = frame->scrollBarGeometry(Qt::Vertical).isValid(); - bool horizontal = frame->scrollBarGeometry(Qt::Horizontal).isValid(); - - if (!vertical && !horizontal) { - return false; - } - - if (vertical && horizontal) { - m_indicator->setPixmap(QPixmap(":/autoscroll/data/scroll_all.png")); - } - else if (vertical) { - m_indicator->setPixmap(QPixmap(":/autoscroll/data/scroll_vertical.png")); - } - else { - m_indicator->setPixmap(QPixmap(":/autoscroll/data/scroll_horizontal.png")); - } - - m_view = view; - - QPoint p; - p.setX(pos.x() - m_indicator->pixmap()->width() / 2); - p.setY(pos.y() - m_indicator->pixmap()->height() / 2); - - m_indicator->setParent(view->overlayWidget()); - m_indicator->move(p); - m_indicator->show(); - - m_frameScroller->setFrame(frame); - - m_view->grabMouse(); - QApplication::setOverrideCursor(Qt::ArrowCursor); - - return true; -} - -void AutoScroller::stopScrolling() -{ - m_view->releaseMouse(); - QApplication::restoreOverrideCursor(); - - m_indicator->hide(); - m_indicator->setParent(0); - m_frameScroller->stopScrolling(); -} - -QRect AutoScroller::indicatorGlobalRect() const -{ - QPoint pos = m_indicator->parentWidget()->mapToGlobal(m_indicator->geometry().topLeft()); - return QRect(pos.x(), pos.y(), m_indicator->width(), m_indicator->height()); -} diff --git a/src/plugins/AutoScroll/autoscroller.h b/src/plugins/AutoScroll/autoscroller.h deleted file mode 100644 index faee99f35..000000000 --- a/src/plugins/AutoScroll/autoscroller.h +++ /dev/null @@ -1,59 +0,0 @@ -/* ============================================================ -* AutoScroll - Autoscroll for QupZilla -* Copyright (C) 2014 David Rosca -* -* 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 . -* ============================================================ */ -#ifndef AUTOSCROLLER_H -#define AUTOSCROLLER_H - -#include -#include - -class QMouseEvent; -class QLabel; -class QRect; - -class WebView; -class FrameScroller; - -class AutoScroller : public QObject -{ - Q_OBJECT -public: - explicit AutoScroller(const QString &settingsFile, QObject* parent = 0); - ~AutoScroller(); - - bool mouseMove(QObject* obj, QMouseEvent* event); - bool mousePress(QObject* obj, QMouseEvent* event); - bool mouseRelease(QObject* obj, QMouseEvent* event); - - double scrollDivider() const; - void setScrollDivider(double divider); - -private: - bool eventFilter(QObject* obj, QEvent* event); - - bool showIndicator(WebView* view, const QPoint &pos); - void stopScrolling(); - - QRect indicatorGlobalRect() const; - - WebView* m_view; - QLabel* m_indicator; - FrameScroller* m_frameScroller; - QString m_settingsFile; -}; - -#endif // AUTOSCROLLER_H diff --git a/src/plugins/AutoScroll/autoscrollplugin.cpp b/src/plugins/AutoScroll/autoscrollplugin.cpp index 993931550..d41f17796 100644 --- a/src/plugins/AutoScroll/autoscrollplugin.cpp +++ b/src/plugins/AutoScroll/autoscrollplugin.cpp @@ -17,28 +17,28 @@ * ============================================================ */ #include "autoscrollplugin.h" #include "autoscrollsettings.h" -#include "autoscroller.h" -#include "browserwindow.h" -#include "pluginproxy.h" #include "mainapplication.h" +#include "qztools.h" +#include #include +#include +#include AutoScrollPlugin::AutoScrollPlugin() : QObject() - , m_scroller(0) { } PluginSpec AutoScrollPlugin::pluginSpec() { PluginSpec spec; - spec.name = "AutoScroll"; - spec.info = "AutoScroll plugin"; - spec.description = "Provides support for autoscroll with middle mouse button"; - spec.version = "0.1.5"; - spec.author = "David Rosca "; - spec.icon = QPixmap(":/autoscroll/data/scroll_all.png"); + spec.name = QSL("AutoScroll"); + spec.info = QSL("AutoScroll plugin"); + spec.description = QSL("Provides support for autoscroll"); + spec.version = QSL("0.2.0"); + spec.author = QSL("David Rosca "); + spec.icon = QPixmap(QSL(":/autoscroll/data/scroll_all.png")); spec.hasSettings = true; return spec; @@ -48,16 +48,17 @@ void AutoScrollPlugin::init(InitState state, const QString &settingsPath) { Q_UNUSED(state) - m_scroller = new AutoScroller(settingsPath + QL1S("/extensions.ini"), this); + m_settingsPath = settingsPath; - QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseMoveHandler); - QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler); - QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseReleaseHandler); + updateScript(); } void AutoScrollPlugin::unload() { - m_scroller->deleteLater(); + QWebEngineScript script = mApp->webProfile()->scripts()->findScript(QSL("_qupzilla_autoscroll")); + if (!script.isNull()) { + mApp->webProfile()->scripts()->remove(script); + } } bool AutoScrollPlugin::testPlugin() @@ -66,48 +67,53 @@ bool AutoScrollPlugin::testPlugin() return (Qz::VERSION == QLatin1String(QUPZILLA_VERSION)); } -QTranslator* AutoScrollPlugin::getTranslator(const QString &locale) +QTranslator *AutoScrollPlugin::getTranslator(const QString &locale) { QTranslator* translator = new QTranslator(this); - translator->load(locale, ":/autoscroll/locale/"); + translator->load(locale, QSL(":/autoscroll/locale/")); return translator; } -void AutoScrollPlugin::showSettings(QWidget* parent) +void AutoScrollPlugin::showSettings(QWidget *parent) { if (!m_settings) { - m_settings = new AutoScrollSettings(m_scroller, parent); + m_settings = new AutoScrollSettings(m_settingsPath, parent); + connect(m_settings, &AutoScrollSettings::settingsChanged, this, &AutoScrollPlugin::updateScript); } m_settings.data()->show(); m_settings.data()->raise(); } -bool AutoScrollPlugin::mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event) +void AutoScrollPlugin::updateScript() { - if (type == Qz::ON_WebView) { - return m_scroller->mouseMove(obj, event); + const QString name = QSL("_qupzilla_autoscroll"); + + QWebEngineScript oldScript = mApp->webProfile()->scripts()->findScript(name); + if (!oldScript.isNull()) { + mApp->webProfile()->scripts()->remove(oldScript); } - return false; -} + QWebEngineScript script; + script.setName(name); + script.setInjectionPoint(QWebEngineScript::DocumentCreation); + script.setWorldId(QWebEngineScript::ApplicationWorld); + script.setRunsOnSubFrames(false); -bool AutoScrollPlugin::mousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event) -{ - if (type == Qz::ON_WebView) { - return m_scroller->mousePress(obj, event); - } + QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat); + settings.beginGroup(QSL("AutoScroll")); - return false; -} + QString source = QzTools::readAllFileContents(QSL(":/autoscroll/data/autoscroll.js")); + source.replace(QSL("%MOVE_SPEED%"), settings.value(QSL("Speed"), 5).toString()); + source.replace(QSL("%CTRL_CLICK%"), settings.value(QSL("CtrlClick"), true).toString()); + source.replace(QSL("%MIDDLE_CLICK%"), settings.value(QSL("MiddleClick"), true).toString()); + source.replace(QSL("%IMG_ALL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_all.png")))); + source.replace(QSL("%IMG_HORIZONTAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_horizontal.png")))); + source.replace(QSL("%IMG_VERTICAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_vertical.png")))); -bool AutoScrollPlugin::mouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event) -{ - if (type == Qz::ON_WebView) { - return m_scroller->mouseRelease(obj, event); - } + script.setSourceCode(source); - return false; + mApp->webProfile()->scripts()->insert(script); } #if QT_VERSION < 0x050000 diff --git a/src/plugins/AutoScroll/autoscrollplugin.h b/src/plugins/AutoScroll/autoscrollplugin.h index 1e05ff18a..25bee661f 100644 --- a/src/plugins/AutoScroll/autoscrollplugin.h +++ b/src/plugins/AutoScroll/autoscrollplugin.h @@ -20,7 +20,6 @@ #include "plugininterface.h" -class AutoScroller; class AutoScrollSettings; class AutoScrollPlugin : public QObject, public PluginInterface @@ -29,7 +28,7 @@ class AutoScrollPlugin : public QObject, public PluginInterface Q_INTERFACES(PluginInterface) #if QT_VERSION >= 0x050000 - Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.TestPlugin") + Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.AutoScroll") #endif public: @@ -40,16 +39,14 @@ public: void unload(); bool testPlugin(); - QTranslator* getTranslator(const QString &locale); - void showSettings(QWidget* parent); - - 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); + QTranslator *getTranslator(const QString &locale); + void showSettings(QWidget *parent); private: - AutoScroller* m_scroller; + void updateScript(); + + QString m_settingsPath; QPointer m_settings; }; -#endif // TESTPLUGIN_H +#endif // AUTOSCROLLPLUGIN_H diff --git a/src/plugins/AutoScroll/autoscrollsettings.cpp b/src/plugins/AutoScroll/autoscrollsettings.cpp index 4a2485717..a6168649e 100644 --- a/src/plugins/AutoScroll/autoscrollsettings.cpp +++ b/src/plugins/AutoScroll/autoscrollsettings.cpp @@ -17,16 +17,24 @@ * ============================================================ */ #include "autoscrollsettings.h" #include "ui_autoscrollsettings.h" -#include "autoscroller.h" +#include "qzcommon.h" -AutoScrollSettings::AutoScrollSettings(AutoScroller* scroller, QWidget* parent) +#include + +AutoScrollSettings::AutoScrollSettings(const QString &settingsPath, QWidget *parent) : QDialog(parent) , ui(new Ui::AutoScrollSettings) - , m_scroller(scroller) + , m_settingsPath(settingsPath) { setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(this); - ui->divider->setValue(m_scroller->scrollDivider()); + + QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat); + settings.beginGroup(QSL("AutoScroll")); + + ui->speed->setValue(11 - settings.value(QSL("Speed"), 5).toInt()); + ui->ctrlScroll->setChecked(settings.value(QSL("CtrlClick"), false).toBool()); + ui->middleScroll->setChecked(settings.value(QSL("MiddleClick"), true).toBool()); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accepted())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close())); @@ -39,6 +47,14 @@ AutoScrollSettings::~AutoScrollSettings() void AutoScrollSettings::accepted() { - m_scroller->setScrollDivider(ui->divider->value()); + QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat); + settings.beginGroup(QSL("AutoScroll")); + + settings.setValue(QSL("Speed"), 11 - ui->speed->value()); + settings.setValue(QSL("CtrlClick"), ui->ctrlScroll->isChecked()); + settings.setValue(QSL("MiddleClick"), ui->middleScroll->isChecked()); + close(); + + emit settingsChanged(); } diff --git a/src/plugins/AutoScroll/autoscrollsettings.h b/src/plugins/AutoScroll/autoscrollsettings.h index c4bd27800..21c919af2 100644 --- a/src/plugins/AutoScroll/autoscrollsettings.h +++ b/src/plugins/AutoScroll/autoscrollsettings.h @@ -32,15 +32,18 @@ class AutoScrollSettings : public QDialog Q_OBJECT public: - explicit AutoScrollSettings(AutoScroller* scroller, QWidget* parent = 0); + explicit AutoScrollSettings(const QString &settingsPath, QWidget *parent = Q_NULLPTR); ~AutoScrollSettings(); +signals: + void settingsChanged(); + private slots: void accepted(); private: Ui::AutoScrollSettings* ui; - AutoScroller* m_scroller; + QString m_settingsPath; }; #endif // AUTOSCROLLSETTINGS_H diff --git a/src/plugins/AutoScroll/autoscrollsettings.ui b/src/plugins/AutoScroll/autoscrollsettings.ui index 9cbc398eb..6b754b15a 100644 --- a/src/plugins/AutoScroll/autoscrollsettings.ui +++ b/src/plugins/AutoScroll/autoscrollsettings.ui @@ -7,7 +7,7 @@ 0 0 411 - 179 + 208 @@ -89,53 +89,50 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + - Scroll Divider: + Scroll speed: - - + + + + Scroll with middle mouse + + + + + + + Scroll with Ctrl + left mouse + + + + + + + + + + + - 1.000000000000000 + 1 + + + 10 - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + - <b>Note:</b> Setting higher divider will slow down scrolling + <b>Note:</b> You must reload the page to apply the settings diff --git a/src/plugins/AutoScroll/data/autoscroll.js b/src/plugins/AutoScroll/data/autoscroll.js new file mode 100644 index 000000000..4a4061db9 --- /dev/null +++ b/src/plugins/AutoScroll/data/autoscroll.js @@ -0,0 +1,301 @@ +/* + * AutoScroll + * + * modified from https://chrome.google.com/webstore/detail/autoscroll/occjjkgifpmdgodlplnacmkejpdionan + */ + +(function () { + "use strict"; + + function hypot(x, y) { + return Math.sqrt(x * x + y * y) + } + + var startAnimation = function (f) { + (function anon() { + f(requestAnimationFrame(anon)) + })() + } + var stopAnimation = cancelAnimationFrame + + // The timer that does the actual scrolling; must be very fast so the scrolling is smooth + var cycle = { + dirX: 0, + dirY: 0, + start: function (elem) { + var self = this + + startAnimation(function (id) { + self.timeout = id + + var x = self.dirX + , y = self.dirY + + if (x !== 0) { + elem.scrollLeft += x + } + if (y !== 0) { + elem.scrollTop += y + } + }) + }, + stop: function () { + this.dirX = 0 + this.dirY = 0 + stopAnimation(this.timeout) + } + } + + var options = { + dragThreshold: 10, + moveThreshold: 20, + moveSpeed: %MOVE_SPEED%, + stickyScroll: true, + ctrlClick: %CTRL_CLICK%, + middleClick: %MIDDLE_CLICK% + } + + function make(parent, f) { + var state = {} + + function image(o) { + if (o.width && o.height) { + return "data:image/png;base64,%IMG_ALL%" + } else if (o.width) { + return "data:image/png;base64,%IMG_HORIZONTAL%" + } else { + return "data:image/png;base64,%IMG_VERTICAL%" + } + } + + function shouldSticky(x, y) { + return options["stickyScroll"] && hypot(x, y) < options["dragThreshold"] + } + + function scale(value) { + return value / options["moveSpeed"] + } + + var e = document.createElement("iframe") + e.style.setProperty("display", "none", "important") + e.style.setProperty("position", "fixed", "important") + e.style.setProperty("padding", "0px", "important") + e.style.setProperty("margin", "0px", "important") + e.style.setProperty("left", "0px", "important") + e.style.setProperty("top", "0px", "important") + e.style.setProperty("width", "100%", "important") + e.style.setProperty("height", "100%", "important") + e.style.setProperty("background-color", "transparent", "important") + e.style.setProperty("z-index", "2147483647", "important") // 32-bit signed int + e.style.setProperty("border", "none", "important") + parent.appendChild(e) + + var inner = e.contentDocument.body + + function stopScroll(e) { + if (e.stopImmediatePropagation) { + e.stopImmediatePropagation() + } + e.stopPropagation() + } + + function unclick() { + cycle.stop() + inner.style.removeProperty("cursor") + inner.style.setProperty("display", "none", "important") + e.style.setProperty("display", "none", "important") + delete state.oldX + delete state.oldY + delete state.click + + // Force relayout + getComputedStyle(inner).left; + getComputedStyle(e).left; + getComputedStyle(eCursor).left; + + removeEventListener("scroll", stopScroll, true) + } + + inner.addEventListener("mousewheel", function (event) { + event.preventDefault() + }, true) + + inner.addEventListener("mousemove", function (event) { + var x = event.clientX - state.oldX, + y = event.clientY - state.oldY + + if (hypot(x, y) > options["moveThreshold"]) { + x = scale(x) + y = scale(y) + + cycle.dirX = Math.round(x) | 0 + cycle.dirY = Math.round(y) | 0 + } else { + cycle.dirX = 0 + cycle.dirY = 0 + } + }, true) + + inner.addEventListener("mouseup", function (event) { + var x = event.clientX - state.oldX, + y = event.clientY - state.oldY + + if (state.click || !shouldSticky(x, y)) { + unclick() + } else { + state.click = true + } + }, true) + + var eCursor = document.createElement("img") + eCursor.style.setProperty("position", "absolute") + inner.appendChild(eCursor) + + function show(o, x, y) { + state.oldX = x + state.oldY = y + + addEventListener("scroll", stopScroll, true) + + eCursor.setAttribute("src", image(o)) + eCursor.style.setProperty("left", (x - 13) + "px") + eCursor.style.setProperty("top", (y - 13) + "px") + inner.style.setProperty("display", "block", "important") + e.style.setProperty("display", "block", "important") + cycle.start(o.element) + } + + f(show) + } + + var htmlNode = document.documentElement + + function isInvalid(elem) { + if (elem.localName === "input") { + return !(elem.type === "button" || + elem.type === "checkbox" || + elem.type === "file" || + elem.type === "hidden" || + elem.type === "image" || + elem.type === "radio" || + elem.type === "reset" || + elem.type === "submit") + } else { + while (true) { + if (elem === document.body || elem === htmlNode) { + return false + } else if (elem.localName === "a" && elem.href || elem.localName === "textarea") { + return true + } else { + elem = elem.parentNode + } + } + } + } + + function canScroll(elem, style) { + return style === "auto" || style === "scroll" + } + + function canScrollTop(elem, style) { + return style === "auto" || style === "scroll" || style === "visible" + } + + function hasWidth(elem, can) { + var style = getComputedStyle(elem) + return can(elem, style.overflowX) && elem.scrollWidth > elem.clientWidth + } + + function hasHeight(elem, can) { + var style = getComputedStyle(elem) + return can(elem, style.overflowY) && elem.scrollHeight > elem.clientHeight + } + + function findScroll(elem) { + while (elem !== document && + elem !== document.body && + elem !== htmlNode) { + + var width = hasWidth(elem, canScroll) + , height = hasHeight(elem, canScroll) + + if (width || height) { + return { + element: elem, + width: width, + height: height + } + + } else { + elem = elem.parentNode + } + } + + var body_width = hasWidth(document.body, canScrollTop); + var body_height = hasHeight(document.body, canScrollTop); + + var html_width = hasWidth(htmlNode, canScrollTop); + var html_height = hasHeight(htmlNode, canScrollTop); + + var width = (body_width || html_width); + var height = (body_height || html_height); + + if (width || height) { + return { + element: document.body, + width: width, + height: height + }; + } else { + return null; + } + } + + function getBody(x) { + if (x === null) { + return null; + + } else { + return { + element: (x.element === htmlNode ? document.body : x.element), + width: x.width, + height: x.height + } + } + } + + function ready(f) { + if (document.body) { + f() + } else { + var observer = new MutationObserver(function () { + if (document.body) { + observer.disconnect() + f() + } + }) + observer.observe(htmlNode, { childList: true }) + } + } + + ready(function () { + make(document.body, function (show) { + addEventListener("mousedown", function (e) { + if (((e.button === 1 && options.middleClick) || + (e.button === 0 && (e.ctrlKey || e.metaKey) && options.ctrlClick)) && + e.clientX < htmlNode.clientWidth && + !isInvalid(e.target)) { + var elem = getBody(findScroll(e.target)) + if (elem !== null) { + if (e.stopImmediatePropagation) { + e.stopImmediatePropagation() + } + e.stopPropagation() + e.preventDefault() + show(elem, e.clientX, e.clientY) + } + } + }, true) + }) + }) +})() diff --git a/src/plugins/AutoScroll/framescroller.cpp b/src/plugins/AutoScroll/framescroller.cpp deleted file mode 100644 index 9f72f0cea..000000000 --- a/src/plugins/AutoScroll/framescroller.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* ============================================================ -* AutoScroll - Autoscroll for QupZilla -* Copyright (C) 2014 David Rosca -* -* 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 . -* ============================================================ */ -#include "framescroller.h" - -#include -#include -#include - -FrameScroller::FrameScroller(QObject* parent) - : QObject(parent) - , m_frame(0) - , m_lengthX(0) - , m_lengthY(0) - , m_divider(8.0) -{ - m_timer = new QTimer(this); - m_timer->setInterval(10); - connect(m_timer, SIGNAL(timeout()), this, SLOT(scrollStep())); -} - -void FrameScroller::setFrame(QWebFrame* frame) -{ - m_frame = frame; -} - -double FrameScroller::scrollDivider() const -{ - return m_divider; -} - -void FrameScroller::setScrollDivider(double divider) -{ - m_divider = divider; -} - -void FrameScroller::startScrolling(int lengthX, int lengthY) -{ - Q_ASSERT(m_frame); - - m_lengthX = lengthX; - m_lengthY = lengthY; - - if (m_lengthX == 0 && m_lengthY == 0) { - m_timer->stop(); - } - else if (!m_timer->isActive()) { - m_timer->start(); - } -} - -void FrameScroller::stopScrolling() -{ - m_timer->stop(); -} - -void FrameScroller::scrollStep() -{ - m_frame->scroll(qCeil(m_lengthX / m_divider), qCeil(m_lengthY / m_divider)); -} diff --git a/src/plugins/AutoScroll/framescroller.h b/src/plugins/AutoScroll/framescroller.h deleted file mode 100644 index 32f1d9f92..000000000 --- a/src/plugins/AutoScroll/framescroller.h +++ /dev/null @@ -1,53 +0,0 @@ -/* ============================================================ -* AutoScroll - Autoscroll for QupZilla -* Copyright (C) 2014 David Rosca -* -* 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 . -* ============================================================ */ -#ifndef FRAMESCROLLER_H -#define FRAMESCROLLER_H - -#include - -class QTimer; -class QWebFrame; - -class FrameScroller : public QObject -{ - Q_OBJECT - -public: - explicit FrameScroller(QObject* parent = 0); - - void setFrame(QWebFrame* frame); - - double scrollDivider() const; - void setScrollDivider(double divider); - - void startScrolling(int lengthX, int lengthY); - void stopScrolling(); - -private slots: - void scrollStep(); - -private: - QWebFrame* m_frame; - QTimer* m_timer; - - int m_lengthX; - int m_lengthY; - double m_divider; -}; - -#endif // FRAMESCROLLER_H diff --git a/src/plugins/GreaseMonkey/gm_plugin.h b/src/plugins/GreaseMonkey/gm_plugin.h index ba89d8ece..3d365cd25 100644 --- a/src/plugins/GreaseMonkey/gm_plugin.h +++ b/src/plugins/GreaseMonkey/gm_plugin.h @@ -20,7 +20,6 @@ #include "plugininterface.h" -class WebPage; class GM_Manager; class GM_Plugin : public QObject, public PluginInterface diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 02d1a3d9f..21597dad6 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -42,7 +42,6 @@ isEqual(QT_MAJOR_VERSION, 5): !qtHaveModule(KWallet): disablePlugin(KWalletPassw # QtWebEngine disable disablePlugin(AccessKeysNavigation) -disablePlugin(AutoScroll) disablePlugin(CopyTitle) disablePlugin(MailHandle) disablePlugin(MouseGestures)