Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implementing modifier keys in sendEvent()

  • Loading branch information...
commit f402a8d9753395edffb4811aa1834ff31a051e27 1 parent b7ca845
@jimevans jimevans authored committed
Showing with 13 additions and 12 deletions.
  1. +12 −11 src/webpage.cpp
  2. +1 −1  src/webpage.h
View
23 src/webpage.cpp
@@ -1015,8 +1015,9 @@ QObject *WebPage::_getJsPromptCallback() {
return m_callbacks->getJsPromptCallback();
}
-void WebPage::sendEvent(const QString &type, const QVariant &arg1, const QVariant &arg2, const QString &mouseButton)
+void WebPage::sendEvent(const QString &type, const QVariant &arg1, const QVariant &arg2, const QString &mouseButton, const QVariant &modifierArg)
{
+ Qt::KeyboardModifiers keyboardModifiers(modifierArg.toInt());
// Normalize the event "type" to lowercase
const QString eventType = type.toLower();
@@ -1034,18 +1035,18 @@ void WebPage::sendEvent(const QString &type, const QVariant &arg1, const QVarian
if (arg1.type() == QVariant::Char) {
// a single char was given
text = arg1.toChar();
- key = text.at(0).toAscii();
+ key = text.at(0).unicode();
} else if (arg1.type() == QVariant::String) {
// javascript invokation of a single char
text = arg1.toString();
if (!text.isEmpty()) {
- key = text.at(0).toAscii();
+ key = text.at(0).unicode();
}
} else {
// assume a raw integer char code was given
key = arg1.toInt();
}
- QKeyEvent *keyEvent = new QKeyEvent(keyEventType, key, Qt::NoModifier, text);
+ QKeyEvent *keyEvent = new QKeyEvent(keyEventType, key, keyboardModifiers, text);
QApplication::postEvent(m_customWebPage, keyEvent);
QApplication::processEvents();
return;
@@ -1056,14 +1057,14 @@ void WebPage::sendEvent(const QString &type, const QVariant &arg1, const QVarian
if (arg1.type() == QVariant::String) {
// this is the case for e.g. sendEvent("...", 'A')
// but also works with sendEvent("...", "ABCD")
- foreach(QChar typeChar, arg1.toString()) {
- sendEvent("keydown", typeChar);
- sendEvent("keyup", typeChar);
+ foreach(const QChar typeChar, arg1.toString()) {
+ sendEvent("keydown", typeChar, NULL, NULL, modifierArg);
@detro Collaborator
detro added a note

This is breaking compilation on Ubuntu 12.10 (and maybe older).
I got not 1 but 2 people reporting the same issue, but they did it on my ghostdriver-dev because they didn't realize this change comes from Upstream.

cd src/ && make -f Makefile.phantomjs
make[1]: Entering directory `/home/lotus/app/phantomjs/src'
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DHAVE_CONFIG_H -DHAVE_FCNTL_H -DHAVE_STDARG_H -DHAVE_STDINT_H -DHAVE_UNISTD_H -DUSE_UTF8 -DSTATIC_BUILD -DQCOMMANDLINE_STATIC -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -Iqt/mkspecs/linux-g++-64 -I. -Iqt/include/QtCore -Iqt/include/QtNetwork -Iqt/include/QtGui -Iqt/include/QtWebKit -Iqt/include -Igif -Imongoose -Ilinenoise/src -Iqcommandline -Ibreakpad/src -I. -o webpage.o webpage.cpp
webpage.cpp: In member function ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’:
webpage.cpp:1061:71: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1061:71: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
webpage.cpp:1062:69: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1062:69: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
webpage.cpp:1066:71: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1066:71: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
webpage.cpp:1067:69: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1067:69: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
make[1]: *** [webpage.o] Error 1
make[1]: Leaving directory `/home/lotus/app/phantomjs/src'
make: *** [sub-src-phantomjs-pro-make_default-ordered] Error 2

@ariya and @jimevans should be aware of this.
It looks like a simple type conversion issue: something similar happened before to me, when I was returning NULL for a QVariant and the GCC on Ubuntu complained.

Do you have an Ubuntu variant you can try a fix on? If so, try replacing the NULLs with QVariant(). I'll try it myself later, but it will be several hours before I can get to it. If that works, I'll generate a pull request later today.

@detro Collaborator
detro added a note

Here is the pull request: #335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ sendEvent("keyup", typeChar, NULL, NULL, modifierArg);
}
} else {
// otherwise we assume a raw integer char-code was given
- sendEvent("keydown", arg1.toInt());
- sendEvent("keyup", arg1.toInt());
+ sendEvent("keydown", arg1.toInt(), NULL, NULL, modifierArg);
+ sendEvent("keyup", arg1.toInt(), NULL, NULL, modifierArg);
}
return;
}
@@ -1106,9 +1107,9 @@ void WebPage::sendEvent(const QString &type, const QVariant &arg1, const QVarian
m_mousePos.setY(arg2.toInt());
}
- // Prepare the Mouse event (no modifiers or other buttons are supported for now)
+ // Prepare the Mouse event
qDebug() << "Mouse Event:" << eventType << "(" << mouseEventType << ")" << m_mousePos << ")" << button << buttons;
- QMouseEvent *event = new QMouseEvent(mouseEventType, m_mousePos, button, buttons, Qt::NoModifier);
+ QMouseEvent *event = new QMouseEvent(mouseEventType, m_mousePos, button, buttons, keyboardModifiers);
// Post and process events
QApplication::postEvent(m_customWebPage, event);
View
2  src/webpage.h
@@ -248,7 +248,7 @@ public slots:
QObject *_getJsConfirmCallback();
QObject *_getJsPromptCallback();
void uploadFile(const QString &selector, const QString &fileName);
- void sendEvent(const QString &type, const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), const QString &mouseButton = QString());
+ void sendEvent(const QString &type, const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), const QString &mouseButton = QString(), const QVariant &modifierArg = QVariant());
/**
* Returns a Child Page that matches the given <code>"window.name"</code>.
@detro
Collaborator

This is breaking compilation on Ubuntu 12.10 (and maybe older).
I got not 1 but 2 people reporting the same issue, but they did it on my ghostdriver-dev because they didn't realize this change comes from Upstream.

cd src/ && make -f Makefile.phantomjs
make[1]: Entering directory `/home/lotus/app/phantomjs/src'
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DHAVE_CONFIG_H -DHAVE_FCNTL_H -DHAVE_STDARG_H -DHAVE_STDINT_H -DHAVE_UNISTD_H -DUSE_UTF8 -DSTATIC_BUILD -DQCOMMANDLINE_STATIC -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -Iqt/mkspecs/linux-g++-64 -I. -Iqt/include/QtCore -Iqt/include/QtNetwork -Iqt/include/QtGui -Iqt/include/QtWebKit -Iqt/include -Igif -Imongoose -Ilinenoise/src -Iqcommandline -Ibreakpad/src -I. -o webpage.o webpage.cpp
webpage.cpp: In member function ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’:
webpage.cpp:1061:71: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1061:71: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
webpage.cpp:1062:69: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1062:69: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
webpage.cpp:1066:71: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1066:71: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
webpage.cpp:1067:69: error: conversion from ‘long int’ to ‘const QVariant’ is ambiguous
webpage.cpp:1067:69: note: candidates are:
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:429:12: note: QVariant::QVariant(void*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: QVariant::QVariant(Qt::GlobalColor) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:219:5: note: no known conversion for argument 1 from ‘long int’ to ‘Qt::GlobalColor’
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:186:36: note: QVariant::QVariant(const char*)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:184:5: note: QVariant::QVariant(float)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:183:5: note: QVariant::QVariant(double)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:182:5: note: QVariant::QVariant(bool)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:181:5: note: QVariant::QVariant(qulonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:180:5: note: QVariant::QVariant(qlonglong)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:179:5: note: QVariant::QVariant(uint)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:178:5: note: QVariant::QVariant(int)
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: QVariant::QVariant(QVariant::Type) <near match>
qt/include/QtCore/../../src/corelib/kernel/qvariant.h:169:5: note: no known conversion for argument 1 from ‘long int’ to ‘QVariant::Type’
webpage.cpp:1018:6: error: initializing argument 3 of ‘void WebPage::sendEvent(const QString&, const QVariant&, const QVariant&, const QString&, const QVariant&)’
make[1]: *** [webpage.o] Error 1
make[1]: Leaving directory `/home/lotus/app/phantomjs/src'
make: *** [sub-src-phantomjs-pro-make_default-ordered] Error 2

@ariya and @jimevans should be aware of this.
It looks like a simple type conversion issue: something similar happened before to me, when I was returning NULL for a QVariant and the GCC on Ubuntu complained.

@jimevans

Do you have an Ubuntu variant you can try a fix on? If so, try replacing the NULLs with QVariant(). I'll try it myself later, but it will be several hours before I can get to it. If that works, I'll generate a pull request later today.

@detro
Collaborator

Here is the pull request: #335

@mariuskubilius
Please sign in to comment.
Something went wrong with that request. Please try again.