forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative_keyboard.cpp
More file actions
108 lines (88 loc) · 2.52 KB
/
Copy pathnative_keyboard.cpp
File metadata and controls
108 lines (88 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "build_environment.h"
#ifndef GECKO_19_COMPATIBILITY
#ifndef BUILD_ON_UNIX
#define MOZ_NO_MOZALLOC
#include <mozilla-config.h>
#endif
#include <xpcom-config.h>
#undef HAVE_CPP_CHAR16_T
#else // Gecko 1.9
#ifdef BUILD_ON_UNIX
#include <xpcom-config.h>
#endif
#endif
#include "errorcodes.h"
#include "interactions.h"
#include "logging.h"
#include "native_keyboard.h"
#ifndef GECKO_19_COMPATIBILITY
#include "mozilla/ModuleUtils.h"
#else
#include "nsIGenericFactory.h"
#endif
#include "nsIComponentManager.h"
#include "nsComponentManagerUtils.h"
#include <assert.h>
#include <nsStringAPI.h>
#include "nsISupportsPrimitives.h"
#ifdef BUILD_ON_WINDOWS
#define WD_RESULT LRESULT
#else
#define WD_RESULT int
#endif
#ifdef WEBDRIVER_GECKO_USES_ISUPPORTS1
NS_IMPL_ISUPPORTS1(nsNativeKeyboard, nsINativeKeyboard)
#else
NS_IMPL_ISUPPORTS(nsNativeKeyboard, nsINativeKeyboard)
#endif
nsNativeKeyboard::nsNativeKeyboard()
{
LOG(DEBUG) << "Native keyboard instantiated.";
}
nsNativeKeyboard::~nsNativeKeyboard()
{
}
/* void SendKeys (in nsISupports aNode, in wstring value); */
NS_IMETHODIMP nsNativeKeyboard::SendKeys(nsISupports *aNode,
#ifdef WEBDRIVER_LEGACY_GECKO
const PRUnichar *value,
#else
const char16_t *value,
#endif // WEBDRIVER_LEGACY_GECKO
bool releaseModifiers)
{
LOG(DEBUG) << "---------- Got to start of callback. aNode: " << aNode
<< " ----------";
NS_LossyConvertUTF16toASCII ascii_keys(value);
LOG(DEBUG) << "Ascii keys: " << ascii_keys.get();
LOG(DEBUG) << "Ascii string length: " << strlen(ascii_keys.get());
int i = 0;
while (value[i] != '\0') {
LOG(DEBUG) << value[i] << " ";
i++;
}
AccessibleDocumentWrapper doc(aNode);
WINDOW_HANDLE windowHandle = doc.getWindowHandle();
if (!windowHandle) {
LOG(WARN) << "Sorry, window handle is null.";
return NS_ERROR_NULL_POINTER;
}
// Note that it's OK to send wchar_t even though wchar_t is *usually*
// 32 bit, because this code (and any code that links with it) *MUST*
// be compiled with -fshort-wchar, so it's actually 16 bit and,
// incidentally, just like PRUnichar. This, of course, breaks any
// library function that uses wchar_t.
#ifdef BUILD_ON_UNIX
assert(sizeof(PRUnichar) == sizeof(wchar_t));
const wchar_t* valuePtr = (const wchar_t*) value;
#else
const PRUnichar* valuePtr = value;
#endif
sendKeys(windowHandle, valuePtr, 0);
if (releaseModifiers) {
LOG(DEBUG) << "Also releasing modifiers.";
releaseModifierKeys(windowHandle, 0);
}
LOG(DEBUG) << "Sent keys sucessfully.";
return NS_OK;
}