forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputManager.h
125 lines (100 loc) · 4.31 KB
/
InputManager.h
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
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef WEBDRIVER_IE_INPUTMANAGER_H_
#define WEBDRIVER_IE_INPUTMANAGER_H_
#include <vector>
#include "DocumentHost.h"
#define USER_INTERACTION_MUTEX_NAME L"WebDriverUserInteractionMutex"
#define WAIT_TIME_IN_MILLISECONDS_PER_INPUT_EVENT 100
namespace webdriver {
// Forward declaration of classes to avoid
// circular include files.
class ElementRepository;
class InputManager {
public:
InputManager(void);
virtual ~InputManager(void);
void Initialize(ElementRepository* element_map);
int PerformInputSequence(BrowserHandle browser_wrapper,
const Json::Value& sequence);
int MouseMoveTo(BrowserHandle browser_wrapper,
std::string element_id,
bool offset_specified,
int x_offset,
int y_offset);
int MouseButtonDown(BrowserHandle browser_wrapper);
int MouseButtonUp(BrowserHandle browser_wrapper);
int MouseClick(BrowserHandle browser_wrapper, int button);
int MouseDoubleClick(BrowserHandle browser_wrapper);
int SendKeystrokes(BrowserHandle browser_wrapper,
Json::Value keystroke_array,
bool auto_release_modifier_keys);
bool SetFocusToBrowser(BrowserHandle browser_wrapper);
bool enable_native_events(void) const { return this->use_native_events_; }
void set_enable_native_events(const bool enable_native_events) {
this->use_native_events_ = enable_native_events;
}
bool require_window_focus(void) const { return this->require_window_focus_; }
void set_require_window_focus(const bool require_window_focus) {
this->require_window_focus_ = require_window_focus;
}
ELEMENT_SCROLL_BEHAVIOR scroll_behavior(void) const {
return this->scroll_behavior_;
}
void set_scroll_behavior(const ELEMENT_SCROLL_BEHAVIOR scroll_behavior) {
this->scroll_behavior_ = scroll_behavior;
}
VARIANT keyboard_state(void) const { return this->keyboard_state_; }
void set_keyboard_state(VARIANT state) { this->keyboard_state_ = state; }
VARIANT mouse_state(void) const { return this->mouse_state_; }
void set_mouse_state(VARIANT state) { this->mouse_state_ = state; }
long last_known_mouse_x(void) const { return this->last_known_mouse_x_; }
void set_last_known_mouse_x(const long x_coordinate) {
this->last_known_mouse_x_ = x_coordinate;
}
long last_known_mouse_y(void) const { return this->last_known_mouse_y_; }
void set_last_known_mouse_y(const long y_coordinate) {
this->last_known_mouse_y_ = y_coordinate;
}
private:
void GetNormalizedCoordinates(HWND window_handle,
int x,
int y,
int* normalized_x,
int* normalized_y);
void AddMouseInput(HWND window_handle, long flag, int x, int y);
void AddKeyboardInput(HWND window_handle, wchar_t character);
void InstallInputEventHooks(void);
void UninstallInputEventHooks(void);
HHOOK InstallWindowsHook(std::string hook_procedure_name, int hook_type);
bool WaitForInputEventProcessing(int input_count);
bool use_native_events_;
bool require_window_focus_;
long last_known_mouse_x_;
long last_known_mouse_y_;
bool is_shift_pressed_;
bool is_control_pressed_;
bool is_alt_pressed_;
ELEMENT_SCROLL_BEHAVIOR scroll_behavior_;
CComVariant keyboard_state_;
CComVariant mouse_state_;
ElementRepository* element_map_;
std::vector<INPUT> inputs_;
HHOOK keyboard_hook_handle_;
HHOOK mouse_hook_handle_;
};
} // namespace webdriver
#endif // WEBDRIVER_IE_INPUTMANAGER_H_