diff options
author | Jonatan Pålsson <jonatan.palsson@pelagicore.com> | 2014-01-30 16:10:02 +0100 |
---|---|---|
committer | Jonatan Pålsson <jonatan.palsson@pelagicore.com> | 2014-02-04 11:12:31 +0100 |
commit | dcc9ef298df2056fd776a28a2650611959f9786a (patch) | |
tree | 668c2f85b2548fd569e858f86216b7dd5cf9ddc0 | |
parent | cecf38f3b65564091290df18d0956dad733afb32 (diff) | |
download | browser-poc-dcc9ef298df2056fd776a28a2650611959f9786a.tar.gz |
Implemented get/setScrollPosition
-rw-r--r-- | browser/browserview.cpp | 23 | ||||
-rw-r--r-- | browser/browserview.h | 5 | ||||
-rw-r--r-- | browser/unit-tests/browserdbus/testbrowserdbus.cpp | 24 | ||||
-rw-r--r-- | browser/unit-tests/browserdbus/testbrowserdbus.h | 1 | ||||
-rw-r--r-- | browser/webpagewindow.cpp | 12 | ||||
-rw-r--r-- | common/browserdbus.cpp | 27 | ||||
-rw-r--r-- | common/browserdbus.h | 2 |
7 files changed, 91 insertions, 3 deletions
diff --git a/browser/browserview.cpp b/browser/browserview.cpp index 1e4b96c..7d31ba0 100644 --- a/browser/browserview.cpp +++ b/browser/browserview.cpp @@ -45,7 +45,7 @@ BrowserView::BrowserView() connect(&m_inputHandler, SIGNAL (onInputText(QString, QString, int, int, int, int, int)), this, SIGNAL (onInputText(QString, QString, int, int, int, int, int))); - connect(&m_inputHandler, SIGNAL(onScroll(uint,uint)), this, SIGNAL(onScrollPositionChanged(uint,uint))); + connect(&m_inputHandler, SIGNAL(onScroll(uint,uint)), this, SLOT(scrollPositionChanged(uint,uint))); } bool BrowserView::load(const QString &a_Url) @@ -169,3 +169,24 @@ double BrowserView::getZoomFactor() { return m_webview.zoomFactor(); } + +void BrowserView::scrollPositionChanged(uint x, uint y) +{ + m_scrollPositionX = x; + m_scrollPositionY = y; + emit onScrollPositionChanged(x,y); +} + +void BrowserView::setScrollPosition(uint x, uint y) +{ + QString cmd = QString("window.scrollTo(%1,%2);").arg(QString::number(x), QString::number(y)); + m_webview.page()->mainFrame()->evaluateJavaScript(cmd); + m_scrollPositionX = x; + m_scrollPositionY = y; +} + +void BrowserView::getScrollPosition(uint &x, uint &y) +{ + x = m_scrollPositionX; + y = m_scrollPositionY; +} diff --git a/browser/browserview.h b/browser/browserview.h index 03804e3..2642911 100644 --- a/browser/browserview.h +++ b/browser/browserview.h @@ -66,6 +66,8 @@ public: QSize contentSize(); void setZoomFactor(double); double getZoomFactor(); + void getScrollPosition(uint&, uint&); + void setScrollPosition(uint, uint); signals: void pageLoadStarted(); @@ -92,11 +94,14 @@ protected slots: void urlChanged(QUrl); void titleChanged(QString); void linkClicked(QUrl); + void scrollPositionChanged(uint x, uint y); private: QGraphicsWebView m_webview; InputHandler m_inputHandler; int m_currentProgress; + uint m_scrollPositionX = 0; + uint m_scrollPositionY = 0; }; diff --git a/browser/unit-tests/browserdbus/testbrowserdbus.cpp b/browser/unit-tests/browserdbus/testbrowserdbus.cpp index 9e1d737..393a3a7 100644 --- a/browser/unit-tests/browserdbus/testbrowserdbus.cpp +++ b/browser/unit-tests/browserdbus/testbrowserdbus.cpp @@ -154,4 +154,28 @@ void TestBrowserDBus::testCanSetAndGetZoomFactor() { QVERIFY(spy.last().value(0).toDouble() == 1); } +void TestBrowserDBus::testCanSetAndGetScrollPosition() { + uint x = 0, y = 0; + uint setX = 0, setY = 0; + m_bdb->createPageWindow(1,0,0,800,600); + QSignalSpy spy (m_bdb, SIGNAL (onScrollPositionChanged (uint, uint))); + m_bdb->loadurl(testFileUrl()); + + QTest::qSleep(300); + + setX = 0; setY = 30; + m_bdb->setScrollPosition(setX, setY); + m_bdb->getScrollPosition(x,y); + QVERIFY(y == 30); + QVERIFY(spy.wait(10000)); + QVERIFY(spy.last().value(1).toUInt() == 30); + + setX = 0; setY = 0; + m_bdb->setScrollPosition(setX, setY); + m_bdb->getScrollPosition(x,y); + QVERIFY(y == 0); + QVERIFY(spy.wait(10000)); + QVERIFY(spy.last().value(1).toUInt() == 0); +} + QTEST_MAIN (TestBrowserDBus); diff --git a/browser/unit-tests/browserdbus/testbrowserdbus.h b/browser/unit-tests/browserdbus/testbrowserdbus.h index f9cae07..d362402 100644 --- a/browser/unit-tests/browserdbus/testbrowserdbus.h +++ b/browser/unit-tests/browserdbus/testbrowserdbus.h @@ -33,6 +33,7 @@ private slots: void testGetsNotifiedWhenVisibilityChanges(); void testGetsNotifiedWhenScrollingChanges(); void testCanSetAndGetZoomFactor(); + void testCanSetAndGetScrollPosition(); private: QString testFileUrl() { diff --git a/browser/webpagewindow.cpp b/browser/webpagewindow.cpp index 99b550f..fd13759 100644 --- a/browser/webpagewindow.cpp +++ b/browser/webpagewindow.cpp @@ -215,8 +215,6 @@ QString webpagewindow::getUrl() { conn::brw::ERROR_IDS getScrollPosition(int &posX, int &posY) { } -conn::brw::ERROR_IDS webpagewindow::getScrollPosition(uint &posX, uint &posY) {} -conn::brw::ERROR_IDS webpagewindow::setScrollPosition(uint &posX, uint &posY) {} conn::brw::ERROR_IDS webpagewindow::select(){} double webpagewindow::getZoomFactor() { @@ -226,3 +224,13 @@ conn::brw::ERROR_IDS webpagewindow::setZoomFactor(double &zoomFactor) { webitem->setZoomFactor(zoomFactor); return conn::brw::EID_NO_ERROR; } + +conn::brw::ERROR_IDS webpagewindow::getScrollPosition(uint &x, uint &y) { + webitem->getScrollPosition(x,y); + return conn::brw::EID_NO_ERROR; +} + +conn::brw::ERROR_IDS webpagewindow::setScrollPosition(uint &x, uint &y) { + webitem->setScrollPosition(x,y); + return conn::brw::EID_NO_ERROR; +} diff --git a/common/browserdbus.cpp b/common/browserdbus.cpp index 99256fd..b574bdb 100644 --- a/common/browserdbus.cpp +++ b/common/browserdbus.cpp @@ -573,3 +573,30 @@ double BrowserDbus::getZoomFactor() { return 0; } } + +void BrowserDbus::getScrollPosition(uint &x, uint &y) { + qDebug() << __PRETTY_FUNCTION__; + + QDBusReply<conn::brw::ERROR_IDS> reply = actualtab->getScrollPosition(x,y); + if(reply.isValid()) { + conn::brw::ERROR_IDS ret = reply.value(); + qDebug() << "ERROR_IDS " << ret; + } else { + QDBusError error = reply.error(); + qDebug() << "ERROR " << error.name() << error.message(); + } +} + +void BrowserDbus::setScrollPosition(uint &x, uint &y) { + qDebug() << __PRETTY_FUNCTION__; + + QDBusPendingReply<conn::brw::ERROR_IDS> reply = actualtab->setScrollPosition(x,y); + reply.waitForFinished(); + if(reply.isValid()) { + conn::brw::ERROR_IDS ret = reply.value(); + qDebug() << "ERROR_IDS " << ret; + } else { + QDBusError error = reply.error(); + qDebug() << "ERROR " << error.name() << error.message(); + } +} diff --git a/common/browserdbus.h b/common/browserdbus.h index e935582..79e59cc 100644 --- a/common/browserdbus.h +++ b/common/browserdbus.h @@ -66,6 +66,8 @@ public: Q_INVOKABLE QString getTitle(); Q_INVOKABLE double getZoomFactor(); Q_INVOKABLE void setZoomFactor(double); + Q_INVOKABLE void getScrollPosition(uint &x, uint &y); + Q_INVOKABLE void setScrollPosition(uint &x, uint &y); QString title() { return m_title; } void setTitle(QString title) { m_title = title; } |