blob: 9643da1ef3b86466d62b84b50b764e7b1bf1540c [file] [log] [blame]
Dan Sinclaircb876822018-03-22 16:21:04 +00001// Copyright 2018 The PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "samples/pdfium_test_event_helper.h"
6
7#include <stdio.h>
8
9#include <string>
10
11#include "public/fpdfview.h"
12#include "testing/test_support.h"
13
14void SendPageEvents(FPDF_FORMHANDLE form,
15 FPDF_PAGE page,
16 const std::string& events) {
17 auto lines = StringSplit(events, '\n');
18 for (auto line : lines) {
19 auto command = StringSplit(line, '#');
20 if (command[0].empty())
21 continue;
22 auto tokens = StringSplit(command[0], ',');
23 if (tokens[0] == "charcode") {
24 if (tokens.size() == 2) {
25 int keycode = atoi(tokens[1].c_str());
26 FORM_OnChar(form, page, keycode, 0);
27 } else {
28 fprintf(stderr, "charcode: bad args\n");
29 }
30 } else if (tokens[0] == "keycode") {
31 if (tokens.size() == 2) {
32 int keycode = atoi(tokens[1].c_str());
33 FORM_OnKeyDown(form, page, keycode, 0);
34 FORM_OnKeyUp(form, page, keycode, 0);
35 } else {
36 fprintf(stderr, "keycode: bad args\n");
37 }
38 } else if (tokens[0] == "mousedown") {
39 if (tokens.size() == 4) {
40 int x = atoi(tokens[2].c_str());
41 int y = atoi(tokens[3].c_str());
42 if (tokens[1] == "left")
43 FORM_OnLButtonDown(form, page, 0, x, y);
44#ifdef PDF_ENABLE_XFA
45 else if (tokens[1] == "right")
46 FORM_OnRButtonDown(form, page, 0, x, y);
47#endif
48 else
49 fprintf(stderr, "mousedown: bad button name\n");
50 } else {
51 fprintf(stderr, "mousedown: bad args\n");
52 }
53 } else if (tokens[0] == "mouseup") {
54 if (tokens.size() == 4) {
55 int x = atoi(tokens[2].c_str());
56 int y = atoi(tokens[3].c_str());
57 if (tokens[1] == "left")
58 FORM_OnLButtonUp(form, page, 0, x, y);
59#ifdef PDF_ENABLE_XFA
60 else if (tokens[1] == "right")
61 FORM_OnRButtonUp(form, page, 0, x, y);
62#endif
63 else
64 fprintf(stderr, "mouseup: bad button name\n");
65 } else {
66 fprintf(stderr, "mouseup: bad args\n");
67 }
68 } else if (tokens[0] == "mousemove") {
69 if (tokens.size() == 3) {
70 int x = atoi(tokens[1].c_str());
71 int y = atoi(tokens[2].c_str());
72 FORM_OnMouseMove(form, page, 0, x, y);
73 } else {
74 fprintf(stderr, "mousemove: bad args\n");
75 }
76 } else if (tokens[0] == "focus") {
77 if (tokens.size() == 3) {
78 int x = atoi(tokens[1].c_str());
79 int y = atoi(tokens[2].c_str());
80 FORM_OnFocus(form, page, 0, x, y);
81 } else {
82 fprintf(stderr, "focus: bad args\n");
83 }
84 } else {
85 fprintf(stderr, "Unrecognized event: %s\n", tokens[0].c_str());
86 }
87 }
88}