mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56: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:
parent
74e02dd1e3
commit
4d5808d915
@ -131,6 +131,11 @@ WebHitTestResult WebPage::hitTestContent(const QPoint &pos) const
|
|||||||
return WebHitTestResult(this, pos);
|
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()
|
void WebPage::scheduleAdjustPage()
|
||||||
{
|
{
|
||||||
if (view()->isLoading()) {
|
if (view()->isLoading()) {
|
||||||
|
@ -54,6 +54,8 @@ public:
|
|||||||
|
|
||||||
WebHitTestResult hitTestContent(const QPoint &pos) const;
|
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 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;
|
bool javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE;
|
||||||
void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE;
|
void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE;
|
||||||
|
@ -243,6 +243,11 @@ bool WebView::onBeforeUnload()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *WebView::inputWidget() const
|
||||||
|
{
|
||||||
|
return qobject_cast<QWidget*>(m_rwhvqt);
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
bool WebView::isUrlValid(const QUrl &url)
|
bool WebView::isUrlValid(const QUrl &url)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +63,7 @@ public:
|
|||||||
void addNotification(QWidget* notif);
|
void addNotification(QWidget* notif);
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
|
QWidget *inputWidget() const;
|
||||||
virtual QWidget* overlayWidget() = 0;
|
virtual QWidget* overlayWidget() = 0;
|
||||||
|
|
||||||
static bool isUrlValid(const QUrl &url);
|
static bool isUrlValid(const QUrl &url);
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
#include "framescroller.h"
|
#include "framescroller.h"
|
||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
|
#include "webhittestresult.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QWebFrame>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
@ -115,6 +115,19 @@ bool AutoScroller::mouseRelease(QObject* obj, QMouseEvent* event)
|
|||||||
return false;
|
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
|
double AutoScroller::scrollDivider() const
|
||||||
{
|
{
|
||||||
return m_frameScroller->scrollDivider();
|
return m_frameScroller->scrollDivider();
|
||||||
@ -154,20 +167,22 @@ bool AutoScroller::eventFilter(QObject* obj, QEvent* event)
|
|||||||
|
|
||||||
bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
|
bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
|
||||||
{
|
{
|
||||||
QWebFrame* frame = view->page()->frameAt(pos);
|
const WebHitTestResult res = view->page()->hitTestContent(pos);
|
||||||
|
|
||||||
if (!frame) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QWebHitTestResult res = frame->hitTestContent(pos);
|
|
||||||
|
|
||||||
if (res.isContentEditable() || !res.linkUrl().isEmpty()) {
|
if (res.isContentEditable() || !res.linkUrl().isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vertical = frame->scrollBarGeometry(Qt::Vertical).isValid();
|
QString source = QL1S("var out = {"
|
||||||
bool horizontal = frame->scrollBarGeometry(Qt::Horizontal).isValid();
|
" 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) {
|
if (!vertical && !horizontal) {
|
||||||
return false;
|
return false;
|
||||||
@ -193,9 +208,9 @@ bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
|
|||||||
m_indicator->move(p);
|
m_indicator->move(p);
|
||||||
m_indicator->show();
|
m_indicator->show();
|
||||||
|
|
||||||
m_frameScroller->setFrame(frame);
|
m_frameScroller->setPage(view->page());
|
||||||
|
|
||||||
m_view->grabMouse();
|
m_view->inputWidget()->grabMouse();
|
||||||
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -203,7 +218,7 @@ bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
|
|||||||
|
|
||||||
void AutoScroller::stopScrolling()
|
void AutoScroller::stopScrolling()
|
||||||
{
|
{
|
||||||
m_view->releaseMouse();
|
m_view->inputWidget()->releaseMouse();
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
|
|
||||||
m_indicator->hide();
|
m_indicator->hide();
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
|
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
|
class QWheelEvent;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QRect;
|
class QRect;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ public:
|
|||||||
bool mouseMove(QObject* obj, QMouseEvent* event);
|
bool mouseMove(QObject* obj, QMouseEvent* event);
|
||||||
bool mousePress(QObject* obj, QMouseEvent* event);
|
bool mousePress(QObject* obj, QMouseEvent* event);
|
||||||
bool mouseRelease(QObject* obj, QMouseEvent* event);
|
bool mouseRelease(QObject* obj, QMouseEvent* event);
|
||||||
|
bool wheel(QObject* obj, QWheelEvent *event);
|
||||||
|
|
||||||
double scrollDivider() const;
|
double scrollDivider() const;
|
||||||
void setScrollDivider(double divider);
|
void setScrollDivider(double divider);
|
||||||
|
@ -36,7 +36,7 @@ PluginSpec AutoScrollPlugin::pluginSpec()
|
|||||||
spec.name = "AutoScroll";
|
spec.name = "AutoScroll";
|
||||||
spec.info = "AutoScroll plugin";
|
spec.info = "AutoScroll plugin";
|
||||||
spec.description = "Provides support for autoscroll with middle mouse button";
|
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.author = "David Rosca <nowrep@gmail.com>";
|
||||||
spec.icon = QPixmap(":/autoscroll/data/scroll_all.png");
|
spec.icon = QPixmap(":/autoscroll/data/scroll_all.png");
|
||||||
spec.hasSettings = true;
|
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::MouseMoveHandler);
|
||||||
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler);
|
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler);
|
||||||
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseReleaseHandler);
|
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseReleaseHandler);
|
||||||
|
QZ_REGISTER_EVENT_HANDLER(PluginProxy::WheelEventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoScrollPlugin::unload()
|
void AutoScrollPlugin::unload()
|
||||||
@ -110,6 +111,15 @@ bool AutoScrollPlugin::mouseRelease(const Qz::ObjectName &type, QObject* obj, QM
|
|||||||
return false;
|
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
|
#if QT_VERSION < 0x050000
|
||||||
Q_EXPORT_PLUGIN2(AutoScroll, AutoScrollPlugin)
|
Q_EXPORT_PLUGIN2(AutoScroll, AutoScrollPlugin)
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
bool mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
|
bool mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
|
||||||
bool mousePress(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 mouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
|
||||||
|
bool wheelEvent(const Qz::ObjectName &type, QObject *obj, QWheelEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AutoScroller* m_scroller;
|
AutoScroller* m_scroller;
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "framescroller.h"
|
#include "framescroller.h"
|
||||||
|
#include "webpage.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWebFrame>
|
#include <QtMath>
|
||||||
#include <QtCore/qmath.h>
|
|
||||||
|
|
||||||
FrameScroller::FrameScroller(QObject* parent)
|
FrameScroller::FrameScroller(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_frame(0)
|
, m_page(0)
|
||||||
, m_lengthX(0)
|
, m_lengthX(0)
|
||||||
, m_lengthY(0)
|
, m_lengthY(0)
|
||||||
, m_divider(8.0)
|
, m_divider(8.0)
|
||||||
@ -33,9 +33,9 @@ FrameScroller::FrameScroller(QObject* parent)
|
|||||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(scrollStep()));
|
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
|
double FrameScroller::scrollDivider() const
|
||||||
@ -50,8 +50,6 @@ void FrameScroller::setScrollDivider(double divider)
|
|||||||
|
|
||||||
void FrameScroller::startScrolling(int lengthX, int lengthY)
|
void FrameScroller::startScrolling(int lengthX, int lengthY)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_frame);
|
|
||||||
|
|
||||||
m_lengthX = lengthX;
|
m_lengthX = lengthX;
|
||||||
m_lengthY = lengthY;
|
m_lengthY = lengthY;
|
||||||
|
|
||||||
@ -70,5 +68,5 @@ void FrameScroller::stopScrolling()
|
|||||||
|
|
||||||
void FrameScroller::scrollStep()
|
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));
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class QWebFrame;
|
|
||||||
|
class WebPage;
|
||||||
|
|
||||||
class FrameScroller : public QObject
|
class FrameScroller : public QObject
|
||||||
{
|
{
|
||||||
@ -30,7 +31,7 @@ class FrameScroller : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit FrameScroller(QObject* parent = 0);
|
explicit FrameScroller(QObject* parent = 0);
|
||||||
|
|
||||||
void setFrame(QWebFrame* frame);
|
void setPage(WebPage *page);
|
||||||
|
|
||||||
double scrollDivider() const;
|
double scrollDivider() const;
|
||||||
void setScrollDivider(double divider);
|
void setScrollDivider(double divider);
|
||||||
@ -42,7 +43,7 @@ private slots:
|
|||||||
void scrollStep();
|
void scrollStep();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWebFrame* m_frame;
|
WebPage *m_page;
|
||||||
QTimer* m_timer;
|
QTimer* m_timer;
|
||||||
|
|
||||||
int m_lengthX;
|
int m_lengthX;
|
||||||
|
@ -34,7 +34,7 @@ outOfDirPlugins = $$(QUPZILLA_PLUGINS_SRCDIR)
|
|||||||
|
|
||||||
# KWalletPasswords only with KDE_INTEGRATION and KWallet framework
|
# KWalletPasswords only with KDE_INTEGRATION and KWallet framework
|
||||||
!contains(DEFINES, KDE_INTEGRATION): disablePlugin(KWalletPasswords)
|
!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
|
# GnomeKeyringPasswords only with GNOME_INTEGRATION and gnome-keyring pkg-config
|
||||||
!contains(DEFINES, GNOME_INTEGRATION): disablePlugin(GnomeKeyringPasswords)
|
!contains(DEFINES, GNOME_INTEGRATION): disablePlugin(GnomeKeyringPasswords)
|
||||||
|
Loading…
Reference in New Issue
Block a user