Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/InputManager.h
2867 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#ifndef WEBDRIVER_IE_INPUTMANAGER_H_
18
#define WEBDRIVER_IE_INPUTMANAGER_H_
19
20
#include <ctime>
21
#include <map>
22
#include <vector>
23
24
#include "CustomTypes.h"
25
#include "InputState.h"
26
#include "ElementScrollBehavior.h"
27
28
namespace Json {
29
class Value;
30
}
31
32
namespace webdriver {
33
34
// Forward declaration of classes to avoid
35
// circular include files.
36
class ActionSimulator;
37
class IElementManager;
38
class InteractionsManager;
39
40
struct InputManagerSettings {
41
IElementManager* element_repository;
42
bool use_native_events;
43
bool require_window_focus;
44
bool enable_persistent_hover;
45
ElementScrollBehavior scroll_behavior;
46
};
47
48
struct KeyInfo {
49
WORD key_code;
50
UINT scan_code;
51
bool is_extended_key;
52
bool is_webdriver_key;
53
bool is_ignored_key;
54
bool is_force_scan_code;
55
wchar_t character;
56
};
57
58
class InputManager {
59
public:
60
InputManager(void);
61
virtual ~InputManager(void);
62
63
void Initialize(InputManagerSettings settings);
64
65
int PerformInputSequence(BrowserHandle browser_wrapper,
66
const Json::Value& sequence,
67
std::string* error_info);
68
void Reset(BrowserHandle browser_wrapper);
69
70
//void StartPersistentEvents(void);
71
//void StopPersistentEvents(void);
72
73
bool enable_native_events(void) const { return this->use_native_events_; }
74
75
bool require_window_focus(void) const { return this->require_window_focus_; }
76
77
bool use_persistent_hover(void) const { return this->use_persistent_hover_; }
78
79
ElementScrollBehavior scroll_behavior(void) const {
80
return this->scroll_behavior_;
81
}
82
void set_scroll_behavior(const ElementScrollBehavior scroll_behavior) {
83
this->scroll_behavior_ = scroll_behavior;
84
}
85
86
bool is_shift_pressed(void) const { return this->current_input_state_.is_shift_pressed; }
87
bool is_control_pressed(void) const { return this->current_input_state_.is_control_pressed; }
88
bool is_alt_pressed(void) const { return this->current_input_state_.is_alt_pressed; }
89
clock_t last_click_time(void) const { return this->current_input_state_.last_click_time; }
90
91
private:
92
int PointerMoveTo(BrowserHandle browser_wrapper,
93
const Json::Value& move_to_action,
94
InputState* input_state);
95
int PointerDown(BrowserHandle browser_wrapper,
96
const Json::Value& down_action,
97
InputState* input_state);
98
int PointerUp(BrowserHandle browser_wrapper,
99
const Json::Value& up_action,
100
InputState* input_state);
101
int KeyDown(BrowserHandle browser_wrapper,
102
const Json::Value& down_action,
103
InputState* input_state);
104
int KeyUp(BrowserHandle browser_wrapper,
105
const Json::Value& up_action,
106
InputState* input_state);
107
int Pause(BrowserHandle browser_wrapper,
108
const Json::Value& pause_action);
109
110
void AddMouseInput(HWND window_handle, long input_action, int x, int y);
111
void AddKeyboardInput(HWND window_handle, std::wstring key, bool key_up, InputState* input_state);
112
void AddPauseInput(HWND window_handle, int duration);
113
114
void CreateKeyboardInputItem(KeyInfo key_info, DWORD initial_flags, bool is_generating_keyup);
115
116
bool IsModifierKey(wchar_t character);
117
118
KeyInfo GetKeyInfo(HWND windows_handle, wchar_t character);
119
InputState CloneCurrentInputState(void);
120
void UpdatePressedKeys(wchar_t character, bool press_key);
121
bool IsKeyPressed(wchar_t character);
122
bool IsSingleKey(const std::wstring& input);
123
124
void SetupKeyDescriptions(void);
125
std::wstring GetKeyDescription(const wchar_t character);
126
127
int GetTicks(const Json::Value& sequences, Json::Value* ticks);
128
HANDLE AcquireMutex(void);
129
void ReleaseMutex(HANDLE mutex_handle);
130
131
bool use_native_events_;
132
bool use_persistent_hover_;
133
bool require_window_focus_;
134
135
InputState current_input_state_;
136
137
ElementScrollBehavior scroll_behavior_;
138
139
IElementManager* element_map_;
140
ActionSimulator* action_simulator_;
141
142
std::vector<INPUT> inputs_;
143
std::vector<wchar_t> pressed_keys_;
144
std::map<wchar_t, std::wstring> key_descriptions_;
145
};
146
147
} // namespace webdriver
148
149
#endif // WEBDRIVER_IE_INPUTMANAGER_H_
150
151