Skip to content

Commit dcf1148

Browse files
committed
Fix prev commit
1 parent 4641c97 commit dcf1148

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

src/webdriver/extension_qt/q_view_executor.cc

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifdef OS_ANDROID
2020
#include <QtAndroidExtras/QtAndroidExtras>
2121
#include <qpa/qplatformnativeinterface.h>
22-
#include <jni.h>
22+
#include <jni.h>
2323
#endif //OS_ANDROID
2424
#else
2525
#include <QtGui/QApplication>
@@ -110,11 +110,15 @@ void QViewCmdExecutor::GetScreenShot(std::string* png, Error** error) {
110110
if (NULL == view)
111111
return;
112112

113+
QPixmap pixmap = QPixmap::grabWidget(view);
114+
115+
saveScreenshot(pixmap, png, error);
116+
}
117+
118+
void QViewCmdExecutor::saveScreenshot(QPixmap& pixmap, std::string* png, Error** error) {
113119
const FilePath::CharType kPngFileName[] = FILE_PATH_LITERAL("./screen.png");
114120
FilePath path = session_->temp_dir().Append(kPngFileName);;
115121

116-
QPixmap pixmap = QPixmap::grabWidget(view);
117-
118122
#if defined(OS_WIN)
119123
session_->logger().Log(kInfoLogLevel, "Save screenshot to - " + path.MaybeAsASCII());
120124
#elif defined(OS_POSIX)
@@ -132,7 +136,7 @@ void QViewCmdExecutor::GetScreenShot(std::string* png, Error** error) {
132136
}
133137

134138
if (!file_util::ReadFileToString(path, png))
135-
*error = new Error(kUnknownError, "Could not read screenshot file");
139+
*error = new Error(kUnknownError, "Could not read screenshot file");
136140
}
137141

138142
void QViewCmdExecutor::SendKeys(const string16& keys, Error** error) {
@@ -290,12 +294,10 @@ void QViewCmdExecutor::SetOrientation(const std::string &orientation, Error **er
290294
}
291295

292296
#ifdef OS_ANDROID
293-
294297
QPlatformNativeInterface *interface = QApplication::platformNativeInterface();
295298
jobject jactivity = (jobject)interface->nativeResourceForIntegration("QtActivity");
296299
QAndroidJniObject activity(jactivity);
297300
activity.callMethod<void>("setRequestedOrientation", "(I)V", screen_orientation);
298-
299301
#else
300302
if (((screen_orientation == 0) && (view->height() > view->width())) ||
301303
((screen_orientation == 1) && (view->height() < view->width())))
@@ -319,30 +321,6 @@ void QViewCmdExecutor::GetOrientation(std::string *orientation, Error **error)
319321
QAndroidJniObject activity(jactivity);
320322
android_orientation = activity.callMethod<jint>("setRequestedOrientation", "()I");
321323

322-
// QPlatformNativeInterface *interface = QApplication::platformNativeInterface();
323-
// JavaVM *currVM = (JavaVM *)interface->nativeResourceForIntegration("JavaVM");
324-
325-
// JNIEnv * g_env = NULL;
326-
// jint ret = currVM->AttachCurrentThread(&g_env, NULL);
327-
// if (ret != JNI_OK)
328-
// {
329-
// *error = new Error(kUnknownError, "JNI error: AttachCurrentThread failed");
330-
// return;
331-
// }
332-
// jobject activity = (jobject)interface->nativeResourceForIntegration("QtActivity");
333-
334-
// jclass cls = g_env->GetObjectClass(activity);
335-
// jmethodID mid = g_env->GetMethodID(cls, "getRequestedOrientation", "()I");
336-
337-
// if (mid == 0)
338-
// {
339-
// *error = new Error(kUnknownError, "JNI error: Method getRequestedOrientation not found");
340-
// return;
341-
// }
342-
343-
// android_orientation = g_env->CallIntMethod(activity, mid);
344-
// currVM->DetachCurrentThread();
345-
346324
if (android_orientation == 0)
347325
*orientation = "LANDSCAPE";
348326
else if (android_orientation == 1)

0 commit comments

Comments
 (0)