summaryrefslogtreecommitdiff
path: root/samples/pdfium_test_event_helper.cc
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-03-22 16:21:04 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-22 16:21:04 +0000
commitcb8768294337f42484b418141792f924d836f9d7 (patch)
tree1f38478ef41d7f670a48267d4fbac46bff3ce8d8 /samples/pdfium_test_event_helper.cc
parent0f494c86440debd22449acd9743382ba14c7a805 (diff)
downloadpdfium-cb8768294337f42484b418141792f924d836f9d7.tar.xz
Move helper methods out of pdfium_test.
This CL splits some helper code out of pdfium_test into individual files. This makes it a bit clearer what each chunk of code is doing and makes pdfium_test easier to read. Change-Id: I3dcff5a6a85ac4283336108eb3a24fa5f234284c Reviewed-on: https://pdfium-review.googlesource.com/28990 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'samples/pdfium_test_event_helper.cc')
-rw-r--r--samples/pdfium_test_event_helper.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/samples/pdfium_test_event_helper.cc b/samples/pdfium_test_event_helper.cc
new file mode 100644
index 0000000000..9643da1ef3
--- /dev/null
+++ b/samples/pdfium_test_event_helper.cc
@@ -0,0 +1,88 @@
+// Copyright 2018 The PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "samples/pdfium_test_event_helper.h"
+
+#include <stdio.h>
+
+#include <string>
+
+#include "public/fpdfview.h"
+#include "testing/test_support.h"
+
+void SendPageEvents(FPDF_FORMHANDLE form,
+ FPDF_PAGE page,
+ const std::string& events) {
+ auto lines = StringSplit(events, '\n');
+ for (auto line : lines) {
+ auto command = StringSplit(line, '#');
+ if (command[0].empty())
+ continue;
+ auto tokens = StringSplit(command[0], ',');
+ if (tokens[0] == "charcode") {
+ if (tokens.size() == 2) {
+ int keycode = atoi(tokens[1].c_str());
+ FORM_OnChar(form, page, keycode, 0);
+ } else {
+ fprintf(stderr, "charcode: bad args\n");
+ }
+ } else if (tokens[0] == "keycode") {
+ if (tokens.size() == 2) {
+ int keycode = atoi(tokens[1].c_str());
+ FORM_OnKeyDown(form, page, keycode, 0);
+ FORM_OnKeyUp(form, page, keycode, 0);
+ } else {
+ fprintf(stderr, "keycode: bad args\n");
+ }
+ } else if (tokens[0] == "mousedown") {
+ if (tokens.size() == 4) {
+ int x = atoi(tokens[2].c_str());
+ int y = atoi(tokens[3].c_str());
+ if (tokens[1] == "left")
+ FORM_OnLButtonDown(form, page, 0, x, y);
+#ifdef PDF_ENABLE_XFA
+ else if (tokens[1] == "right")
+ FORM_OnRButtonDown(form, page, 0, x, y);
+#endif
+ else
+ fprintf(stderr, "mousedown: bad button name\n");
+ } else {
+ fprintf(stderr, "mousedown: bad args\n");
+ }
+ } else if (tokens[0] == "mouseup") {
+ if (tokens.size() == 4) {
+ int x = atoi(tokens[2].c_str());
+ int y = atoi(tokens[3].c_str());
+ if (tokens[1] == "left")
+ FORM_OnLButtonUp(form, page, 0, x, y);
+#ifdef PDF_ENABLE_XFA
+ else if (tokens[1] == "right")
+ FORM_OnRButtonUp(form, page, 0, x, y);
+#endif
+ else
+ fprintf(stderr, "mouseup: bad button name\n");
+ } else {
+ fprintf(stderr, "mouseup: bad args\n");
+ }
+ } else if (tokens[0] == "mousemove") {
+ if (tokens.size() == 3) {
+ int x = atoi(tokens[1].c_str());
+ int y = atoi(tokens[2].c_str());
+ FORM_OnMouseMove(form, page, 0, x, y);
+ } else {
+ fprintf(stderr, "mousemove: bad args\n");
+ }
+ } else if (tokens[0] == "focus") {
+ if (tokens.size() == 3) {
+ int x = atoi(tokens[1].c_str());
+ int y = atoi(tokens[2].c_str());
+ FORM_OnFocus(form, page, 0, x, y);
+ } else {
+ fprintf(stderr, "focus: bad args\n");
+ }
+ } else {
+ fprintf(stderr, "Unrecognized event: %s\n", tokens[0].c_str());
+ }
+ }
+}