mirror of https://github.com/vitalif/phantomjs
Merge pull request #125 from robterrell/049e1f50bd54429ea2e43207ab01e10c8021988e
Added functions to WebPage class to simulate mouse move, mouse up, and mouse down using Qt.1.3
commit
2867e06c53
|
@ -43,6 +43,7 @@
|
|||
#include <QWebElement>
|
||||
#include <QWebFrame>
|
||||
#include <QWebPage>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -506,4 +507,36 @@ void WebPage::_appendScriptElement(const QString &scriptUrl) {
|
|||
m_mainFrame->evaluateJavaScript( QString(JS_APPEND_SCRIPT_ELEMENT).arg(scriptUrl) );
|
||||
}
|
||||
|
||||
void WebPage::click( int x, int y )
|
||||
{
|
||||
mouseMoveTo(x,y);
|
||||
mouseDown();
|
||||
mouseUp();
|
||||
}
|
||||
|
||||
void WebPage::mouseDown()
|
||||
{
|
||||
// qDebug() << "EventSender::mouseDown " << m_mousePos.x() << " " << m_mousePos.y();
|
||||
QMouseEvent* event = new QMouseEvent(QEvent::MouseButtonPress, m_mousePos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::postEvent( m_webPage, event);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void WebPage::mouseUp()
|
||||
{
|
||||
// qDebug() << "EventSender::mouseUp " << m_mousePos.x() << " " << m_mousePos.y();
|
||||
QMouseEvent* event = new QMouseEvent(QEvent::MouseButtonRelease, m_mousePos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::postEvent(m_webPage, event);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void WebPage::mouseMoveTo(int x, int y)
|
||||
{
|
||||
// qDebug() << "EventSender::mouseMoveTo " << x << " " << y;
|
||||
m_mousePos = QPoint(x, y);
|
||||
QMouseEvent* event = new QMouseEvent(QEvent::MouseMove, m_mousePos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
QApplication::postEvent(m_webPage, event);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
#include "webpage.moc"
|
||||
|
|
|
@ -80,6 +80,10 @@ public slots:
|
|||
bool injectJs(const QString &jsFilePath);
|
||||
void _appendScriptElement(const QString &scriptUrl);
|
||||
void uploadFile(const QString &selector, const QString &fileName);
|
||||
void click( int x, int y );
|
||||
void mouseDown();
|
||||
void mouseUp();
|
||||
void mouseMoveTo(int x, int y);
|
||||
|
||||
signals:
|
||||
void loadStarted();
|
||||
|
@ -110,6 +114,8 @@ private:
|
|||
|
||||
friend class Phantom;
|
||||
friend class CustomPage;
|
||||
|
||||
QPoint m_mousePos;
|
||||
};
|
||||
|
||||
#endif // WEBPAGE_H
|
||||
|
|
Loading…
Reference in New Issue