5#include "samples/helpers/event.h"
12#include "public/fpdf_fwlevent.h"
13#include "public/fpdfview.h"
14#include "testing/fx_string_testhelpers.h"
18uint32_t GetModifiers(
std::string modifiers_string) {
19 uint32_t modifiers = 0;
20 if (modifiers_string.find(
"shift") != std::string::npos) {
23 if (modifiers_string.find(
"control") != std::string::npos) {
26 if (modifiers_string.find(
"alt") != std::string::npos) {
33void SendCharCodeEvent(FPDF_FORMHANDLE form,
35 const std::vector<std::string>& tokens) {
36 if (tokens.size() != 2) {
37 fprintf(stderr,
"charcode: bad args\n");
41 int charcode = atoi(tokens[1].c_str());
45void SendKeyCodeEvent(FPDF_FORMHANDLE form,
47 const std::vector<std::string>& tokens) {
48 if (tokens.size() < 2 || tokens.size() > 3) {
49 fprintf(stderr,
"keycode: bad args\n");
53 int keycode = atoi(tokens[1].c_str());
54 uint32_t modifiers = tokens.size() >= 3 ? GetModifiers(tokens[2]) : 0;
59void SendMouseDownEvent(FPDF_FORMHANDLE form,
61 const std::vector<std::string>& tokens) {
62 if (tokens.size() < 4 && tokens.size() > 5) {
63 fprintf(stderr,
"mousedown: bad args\n");
67 int x = atoi(tokens[2].c_str());
68 int y = atoi(tokens[3].c_str());
69 uint32_t modifiers = tokens.size() >= 5 ? GetModifiers(tokens[4]) : 0;
71 if (tokens[1] ==
"left") {
73 }
else if (tokens[1] ==
"right") {
76 fprintf(stderr,
"mousedown: bad button name\n");
80void SendMouseUpEvent(FPDF_FORMHANDLE form,
82 const std::vector<std::string>& tokens) {
83 if (tokens.size() < 4 && tokens.size() > 5) {
84 fprintf(stderr,
"mouseup: bad args\n");
88 int x = atoi(tokens[2].c_str());
89 int y = atoi(tokens[3].c_str());
90 int modifiers = tokens.size() >= 5 ? GetModifiers(tokens[4]) : 0;
91 if (tokens[1] ==
"left") {
93 }
else if (tokens[1] ==
"right") {
96 fprintf(stderr,
"mouseup: bad button name\n");
100void SendMouseDoubleClickEvent(FPDF_FORMHANDLE form,
102 const std::vector<std::string>& tokens) {
103 if (tokens.size() < 4 && tokens.size() > 5) {
104 fprintf(stderr,
"mousedoubleclick: bad args\n");
108 int x = atoi(tokens[2].c_str());
109 int y = atoi(tokens[3].c_str());
110 int modifiers = tokens.size() >= 5 ? GetModifiers(tokens[4]) : 0;
111 if (tokens[1] !=
"left") {
112 fprintf(stderr,
"mousedoubleclick: bad button name\n");
118void SendMouseMoveEvent(FPDF_FORMHANDLE form,
120 const std::vector<std::string>& tokens) {
121 if (tokens.size() != 3) {
122 fprintf(stderr,
"mousemove: bad args\n");
126 int x = atoi(tokens[1].c_str());
127 int y = atoi(tokens[2].c_str());
131void SendMouseWheelEvent(FPDF_FORMHANDLE form,
133 const std::vector<std::string>& tokens) {
134 if (tokens.size() < 5 && tokens.size() > 6) {
135 fprintf(stderr,
"mousewheel: bad args\n");
139 const FS_POINTF point = {
static_cast<
float>(atoi(tokens[1].c_str())),
140 static_cast<
float>(atoi(tokens[2].c_str()))};
141 int delta_x = atoi(tokens[3].c_str());
142 int delta_y = atoi(tokens[4].c_str());
143 int modifiers = tokens.size() >= 6 ? GetModifiers(tokens[5]) : 0;
147void SendFocusEvent(FPDF_FORMHANDLE form,
149 const std::vector<std::string>& tokens) {
150 if (tokens.size() != 3) {
151 fprintf(stderr,
"focus: bad args\n");
155 int x = atoi(tokens[1].c_str());
156 int y = atoi(tokens[2].c_str());
164 const std::string& events,
165 const std::function<
void()>& idler) {
166 auto lines = StringSplit(events,
'\n');
167 for (
const auto& line : lines) {
168 auto command = StringSplit(line,
'#');
169 if (command[0].empty()) {
172 auto tokens = StringSplit(command[0],
',');
173 if (tokens[0] ==
"charcode") {
174 SendCharCodeEvent(form, page, tokens);
175 }
else if (tokens[0] ==
"keycode") {
176 SendKeyCodeEvent(form, page, tokens);
177 }
else if (tokens[0] ==
"mousedown") {
178 SendMouseDownEvent(form, page, tokens);
179 }
else if (tokens[0] ==
"mouseup") {
180 SendMouseUpEvent(form, page, tokens);
181 }
else if (tokens[0] ==
"mousedoubleclick") {
182 SendMouseDoubleClickEvent(form, page, tokens);
183 }
else if (tokens[0] ==
"mousemove") {
184 SendMouseMoveEvent(form, page, tokens);
185 }
else if (tokens[0] ==
"mousewheel") {
186 SendMouseWheelEvent(form, page, tokens);
187 }
else if (tokens[0] ==
"focus") {
188 SendFocusEvent(form, page, tokens);
190 fprintf(stderr,
"Unrecognized event: %s\n", tokens[0].c_str());
void SendPageEvents(FPDF_FORMHANDLE form, FPDF_PAGE page, const std::string &events, const std::function< void()> &idler)
@ FWL_EVENTFLAG_ControlKey