1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Revert "Bring back AutoScroll plugin"

This reverts commit fa2779e6b9.
This commit is contained in:
David Rosca 2015-10-02 14:48:25 +02:00
parent 66d0fa588d
commit 74e02dd1e3
13 changed files with 498 additions and 410 deletions

View File

@ -3,9 +3,13 @@ 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 += \

View File

@ -31,6 +31,5 @@
<file>locale/sr.qm</file>
<file>locale/tr_TR.qm</file>
<file>locale/zh_TW.qm</file>
<file>data/autoscroll.js</file>
</qresource>
</RCC>

View File

@ -0,0 +1,218 @@
/* ============================================================
* AutoScroll - Autoscroll for QupZilla
* Copyright (C) 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 "autoscroller.h"
#include "framescroller.h"
#include "webview.h"
#include "webpage.h"
#include <QApplication>
#include <QMouseEvent>
#include <QWebFrame>
#include <QSettings>
#include <QLabel>
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<WebView*>(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());
}

View File

@ -0,0 +1,59 @@
/* ============================================================
* AutoScroll - Autoscroll for QupZilla
* Copyright (C) 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 AUTOSCROLLER_H
#define AUTOSCROLLER_H
#include <QObject>
#include <QPoint>
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

View File

@ -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 <QSettings>
#include <QTranslator>
#include <QWebEngineProfile>
#include <QWebEngineScriptCollection>
AutoScrollPlugin::AutoScrollPlugin()
: QObject()
, m_scroller(0)
{
}
PluginSpec AutoScrollPlugin::pluginSpec()
{
PluginSpec spec;
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 <nowrep@gmail.com>");
spec.icon = QPixmap(QSL(":/autoscroll/data/scroll_all.png"));
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 <nowrep@gmail.com>";
spec.icon = QPixmap(":/autoscroll/data/scroll_all.png");
spec.hasSettings = true;
return spec;
@ -48,17 +48,16 @@ void AutoScrollPlugin::init(InitState state, const QString &settingsPath)
{
Q_UNUSED(state)
m_settingsPath = settingsPath;
m_scroller = new AutoScroller(settingsPath + QL1S("/extensions.ini"), this);
updateScript();
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseMoveHandler);
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler);
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseReleaseHandler);
}
void AutoScrollPlugin::unload()
{
QWebEngineScript script = mApp->webProfile()->scripts()->findScript(QSL("_qupzilla_autoscroll"));
if (!script.isNull()) {
mApp->webProfile()->scripts()->remove(script);
}
m_scroller->deleteLater();
}
bool AutoScrollPlugin::testPlugin()
@ -67,53 +66,48 @@ 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, QSL(":/autoscroll/locale/"));
translator->load(locale, ":/autoscroll/locale/");
return translator;
}
void AutoScrollPlugin::showSettings(QWidget *parent)
void AutoScrollPlugin::showSettings(QWidget* parent)
{
if (!m_settings) {
m_settings = new AutoScrollSettings(m_settingsPath, parent);
connect(m_settings, &AutoScrollSettings::settingsChanged, this, &AutoScrollPlugin::updateScript);
m_settings = new AutoScrollSettings(m_scroller, parent);
}
m_settings.data()->show();
m_settings.data()->raise();
}
void AutoScrollPlugin::updateScript()
bool AutoScrollPlugin::mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
{
const QString name = QSL("_qupzilla_autoscroll");
QWebEngineScript oldScript = mApp->webProfile()->scripts()->findScript(name);
if (!oldScript.isNull()) {
mApp->webProfile()->scripts()->remove(oldScript);
if (type == Qz::ON_WebView) {
return m_scroller->mouseMove(obj, event);
}
QWebEngineScript script;
script.setName(name);
script.setInjectionPoint(QWebEngineScript::DocumentCreation);
script.setWorldId(QWebEngineScript::ApplicationWorld);
script.setRunsOnSubFrames(false);
return false;
}
QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
settings.beginGroup(QSL("AutoScroll"));
bool AutoScrollPlugin::mousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
{
if (type == Qz::ON_WebView) {
return m_scroller->mousePress(obj, event);
}
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::pixmapToDataUrl(QPixmap(QSL(":/autoscroll/data/scroll_all.png"))).toString());
source.replace(QSL("%IMG_HORIZONTAL%"), QzTools::pixmapToDataUrl(QPixmap(QSL(":/autoscroll/data/scroll_horizontal.png"))).toString());
source.replace(QSL("%IMG_VERTICAL%"), QzTools::pixmapToDataUrl(QPixmap(QSL(":/autoscroll/data/scroll_vertical.png"))).toString());
return false;
}
script.setSourceCode(source);
bool AutoScrollPlugin::mouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
{
if (type == Qz::ON_WebView) {
return m_scroller->mouseRelease(obj, event);
}
mApp->webProfile()->scripts()->insert(script);
return false;
}
#if QT_VERSION < 0x050000

View File

@ -20,6 +20,7 @@
#include "plugininterface.h"
class AutoScroller;
class AutoScrollSettings;
class AutoScrollPlugin : public QObject, public PluginInterface
@ -28,7 +29,7 @@ class AutoScrollPlugin : public QObject, public PluginInterface
Q_INTERFACES(PluginInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.AutoScroll")
Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.TestPlugin")
#endif
public:
@ -39,14 +40,16 @@ public:
void unload();
bool testPlugin();
QTranslator *getTranslator(const QString &locale);
void showSettings(QWidget *parent);
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);
private:
void updateScript();
QString m_settingsPath;
AutoScroller* m_scroller;
QPointer<AutoScrollSettings> m_settings;
};
#endif // AUTOSCROLLPLUGIN_H
#endif // TESTPLUGIN_H

View File

@ -17,24 +17,16 @@
* ============================================================ */
#include "autoscrollsettings.h"
#include "ui_autoscrollsettings.h"
#include "qzcommon.h"
#include "autoscroller.h"
#include <QSettings>
AutoScrollSettings::AutoScrollSettings(const QString &settingsPath, QWidget *parent)
AutoScrollSettings::AutoScrollSettings(AutoScroller* scroller, QWidget* parent)
: QDialog(parent)
, ui(new Ui::AutoScrollSettings)
, m_settingsPath(settingsPath)
, m_scroller(scroller)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
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());
ui->divider->setValue(m_scroller->scrollDivider());
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accepted()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
@ -47,14 +39,6 @@ AutoScrollSettings::~AutoScrollSettings()
void AutoScrollSettings::accepted()
{
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());
m_scroller->setScrollDivider(ui->divider->value());
close();
emit settingsChanged();
}

View File

@ -32,18 +32,15 @@ class AutoScrollSettings : public QDialog
Q_OBJECT
public:
explicit AutoScrollSettings(const QString &settingsPath, QWidget *parent = Q_NULLPTR);
explicit AutoScrollSettings(AutoScroller* scroller, QWidget* parent = 0);
~AutoScrollSettings();
signals:
void settingsChanged();
private slots:
void accepted();
private:
Ui::AutoScrollSettings* ui;
QString m_settingsPath;
AutoScroller* m_scroller;
};
#endif // AUTOSCROLLSETTINGS_H

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>411</width>
<height>208</height>
<height>179</height>
</rect>
</property>
<property name="windowTitle">
@ -89,50 +89,53 @@
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Scroll speed:</string>
<string>Scroll Divider:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Scroll with middle mouse</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Scroll with Ctrl + left mouse</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="middleScroll"/>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="ctrlScroll"/>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="speed">
<item>
<widget class="QDoubleSpinBox" name="divider">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_6">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;b&gt;Note:&lt;/b&gt; You must reload the page to apply the settings</string>
<string>&lt;b&gt;Note:&lt;/b&gt; Setting higher divider will slow down scrolling</string>
</property>
</widget>
</item>

View File

@ -1,301 +0,0 @@
/*
* 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 "%IMG_ALL%"
} else if (o.width) {
return "%IMG_HORIZONTAL%"
} else {
return "%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)
})
})
})()

View File

@ -0,0 +1,74 @@
/* ============================================================
* AutoScroll - Autoscroll for QupZilla
* Copyright (C) 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 "framescroller.h"
#include <QTimer>
#include <QWebFrame>
#include <QtCore/qmath.h>
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));
}

View File

@ -0,0 +1,53 @@
/* ============================================================
* AutoScroll - Autoscroll for QupZilla
* Copyright (C) 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 FRAMESCROLLER_H
#define FRAMESCROLLER_H
#include <QObject>
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

View File

@ -20,6 +20,7 @@
#include "plugininterface.h"
class WebPage;
class GM_Manager;
class GM_Plugin : public QObject, public PluginInterface