forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative_mouse.cpp
More file actions
156 lines (114 loc) · 4.16 KB
/
Copy pathnative_mouse.cpp
File metadata and controls
156 lines (114 loc) · 4.16 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#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_mouse.h"
#ifndef GECKO_19_COMPATIBILITY
#include "mozilla/ModuleUtils.h"
#else
#include "nsIGenericFactory.h"
#endif
#include "nsIComponentManager.h"
#include "nsComponentManagerUtils.h"
#include <assert.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(nsNativeMouse, nsINativeMouse)
#else
NS_IMPL_ISUPPORTS(nsNativeMouse, nsINativeMouse)
#endif
nsNativeMouse::nsNativeMouse()
{
LOG(DEBUG) << "Native mouse instantiated.";
}
nsNativeMouse::~nsNativeMouse()
{
}
/* void mouseMove (in nsISupports aNode, in long startX, in long startY, in long endX, in long endY); */
NS_IMETHODIMP nsNativeMouse::MouseMove(nsISupports *aNode, PRInt32 startX, PRInt32 startY, PRInt32 endX, PRInt32 endY)
{
AccessibleDocumentWrapper doc(aNode);
void* windowHandle = doc.getWindowHandle();
if (!windowHandle) {
return NS_ERROR_NULL_POINTER;
}
WD_RESULT res = mouseMoveTo(windowHandle, 100, startX, startY, endX, endY);
return res == WD_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}
/* void click (in nsISupports aNode, in long x, in long y, in long button); */
NS_IMETHODIMP nsNativeMouse::Click(nsISupports *aNode, PRInt32 x, PRInt32 y, PRInt32 button)
{
AccessibleDocumentWrapper doc(aNode);
void* windowHandle = doc.getWindowHandle();
LOG(DEBUG) << "Have click window handle: " << windowHandle;
if (!windowHandle) {
LOG(WARN) << "No window handle!";
return NS_ERROR_NULL_POINTER;
}
LOG(DEBUG) << "Calling clickAt: " << x << ", " << y;
WD_RESULT res = clickAt(windowHandle, x, y, button);
LOG(DEBUG) << "Result was: " << (res == WD_SUCCESS ? "ok" : "fail");
return res == WD_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}
/* void doubleClick (in nsISupports aNode, in long x, in long y, in long button); */
NS_IMETHODIMP nsNativeMouse::DoubleClick(nsISupports *aNode, PRInt32 x, PRInt32 y)
{
AccessibleDocumentWrapper doc(aNode);
void* windowHandle = doc.getWindowHandle();
LOG(DEBUG) << "Have doubleClick window handle: " << windowHandle;
if (!windowHandle) {
LOG(WARN) << "No window handle!";
return NS_ERROR_NULL_POINTER;
}
LOG(DEBUG) << "Calling doubleClickAt: " << x << ", " << y;
WD_RESULT res = doubleClickAt(windowHandle, x, y);
LOG(DEBUG) << "Result was: " << (res == WD_SUCCESS ? "ok" : "fail");
return res == WD_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}
/* void mousePress(in nsISupports aNode, in long x, in long y, in long button); */
NS_IMETHODIMP nsNativeMouse::MousePress(nsISupports *aNode, PRInt32 x, PRInt32 y, PRInt32 button)
{
AccessibleDocumentWrapper doc(aNode);
void* windowHandle = doc.getWindowHandle();
LOG(DEBUG) << "Have mousePress window handle: " << windowHandle;
if (!windowHandle) {
LOG(WARN) << "No window handle!";
return NS_ERROR_NULL_POINTER;
}
LOG(DEBUG) << "Calling mouseDownAt at: " << x << ", " << y << " with button: " << button;
WD_RESULT res = mouseDownAt(windowHandle, x, y, button);
LOG(DEBUG) << "Result was: " << (res == WD_SUCCESS ? "ok" : "fail");
return res == WD_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}
/* void mouseRelease(in nsISupports anode, in long x, in long y, in long button); */
NS_IMETHODIMP nsNativeMouse::MouseRelease(nsISupports *aNode, PRInt32 x, PRInt32 y, PRInt32 button)
{
AccessibleDocumentWrapper doc(aNode);
void* windowHandle = doc.getWindowHandle();
LOG(DEBUG) << "Have mouseRelease window handle: " << windowHandle;
if (!windowHandle) {
LOG(WARN) << "No window handle!";
return NS_ERROR_NULL_POINTER;
}
LOG(DEBUG) << "Calling mouseUpAt: " << x << ", " << y << " with button: " << button;
WD_RESULT res = mouseUpAt(windowHandle, x, y, button);
LOG(DEBUG) << "Result was: " << (res == WD_SUCCESS ? "ok" : "fail");
return res == WD_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}