Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: remoting/tools/javascript_key_tester/pnacl/remoting_key_tester.cc

Issue 884703006: Handling PNaCl KeyboardInputEvent(s) in the key tester app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/tools/javascript_key_tester/pnacl/remoting_key_tester.cc
diff --git a/remoting/tools/javascript_key_tester/pnacl/remoting_key_tester.cc b/remoting/tools/javascript_key_tester/pnacl/remoting_key_tester.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ef3b4ec6a39bc5378090468cc45181668d432f33
--- /dev/null
+++ b/remoting/tools/javascript_key_tester/pnacl/remoting_key_tester.cc
@@ -0,0 +1,185 @@
+// Copyright (c) 2015 The Chromium 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 <sstream>
+
+#include "ppapi/cpp/input_event.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/var.h"
+
+namespace remoting {
+
+class KeyTesterInstance : public pp::Instance {
+ public:
+ explicit KeyTesterInstance(PP_Instance instance) : pp::Instance(instance) {
+ RequestInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD |
+ PP_INPUTEVENT_CLASS_MOUSE);
+ }
+
+ virtual ~KeyTesterInstance() {}
+
+ virtual bool HandleInputEvent(const pp::InputEvent& event) {
+ switch (event.GetType()) {
+ case PP_INPUTEVENT_TYPE_KEYDOWN:
+ case PP_INPUTEVENT_TYPE_KEYUP:
+ case PP_INPUTEVENT_TYPE_CHAR: {
+ HandleKeyboardEvent(pp::KeyboardInputEvent(event));
+ break;
+ }
+ default:
+ break;
+ }
+ return true;
+ }
+
+ private:
+ void HandleKeyboardEvent(const pp::KeyboardInputEvent& event) {
+ std::ostringstream out;
+
+ out << EventTypeToString(event.GetType()) << " : ";
+ out << ModifiersToString(event.GetModifiers()) << " : ";
+ out << "0x" << std::hex << event.GetKeyCode() << " : ";
+ out << VarToString(event.GetCharacterText()) << " : ";
+ out << VarToString(event.GetCode());
+
+ PostMessage(out.str());
Jamie 2015/01/28 22:31:27 I think this should be passed as a dictionary (or
Łukasz Anforowicz 2015/01/29 00:26:37 I wrote code that works and passes the following o
+ }
+
+ std::string VarToString(const pp::Var& var) {
+ if (var.is_undefined()) {
+ return "[undefined]";
+ }
+ if (var.is_null()) {
+ return "[null]";
+ }
+ if (!var.is_string()) {
+ return "[non-string]";
+ }
+ return var.AsString();
+ }
+
+ std::string EventTypeToString(PP_InputEvent_Type t) {
+ switch (t) {
+ case PP_INPUTEVENT_TYPE_UNDEFINED:
+ return "UNDEFINED";
+ case PP_INPUTEVENT_TYPE_MOUSEDOWN:
+ return "MOUSEDOWN";
+ case PP_INPUTEVENT_TYPE_MOUSEUP:
+ return "MOUSEUP";
+ case PP_INPUTEVENT_TYPE_MOUSEMOVE:
+ return "MOUSEMOVE";
+ case PP_INPUTEVENT_TYPE_MOUSEENTER:
+ return "MOUSEENTER";
+ case PP_INPUTEVENT_TYPE_MOUSELEAVE:
+ return "MOUSELEAVE";
+ case PP_INPUTEVENT_TYPE_WHEEL:
+ return "WHEEL";
+ case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
+ return "RAWKEYDOWN";
+ case PP_INPUTEVENT_TYPE_KEYDOWN:
+ return "KEYDOWN";
+ case PP_INPUTEVENT_TYPE_KEYUP:
+ return "KEYUP";
+ case PP_INPUTEVENT_TYPE_CHAR:
+ return "CHAR";
+ case PP_INPUTEVENT_TYPE_CONTEXTMENU:
+ return "CONTEXTMENU";
+ case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START:
+ return "IME_COMPOSITION_START";
+ case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
+ return "IME_COMPOSITION_UPDATE";
+ case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
+ return "IME_COMPOSITION_END";
+ case PP_INPUTEVENT_TYPE_IME_TEXT:
+ return "IME_TEXT";
+ case PP_INPUTEVENT_TYPE_TOUCHSTART:
+ return "TOUCHSTART";
+ case PP_INPUTEVENT_TYPE_TOUCHMOVE:
+ return "TOUCHMOVE";
+ case PP_INPUTEVENT_TYPE_TOUCHEND:
+ return "TOUCHEND";
+ case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
+ return "TOUCHCANCEL";
+ default:
+ return "[UNRECOGNIZED]";
+ }
+ }
+
+ void Append(std::ostringstream& out,
+ const std::string& str,
+ const std::string& separator) {
+ if (!out.str().empty()) {
+ out << separator;
+ }
+ out << str;
+ }
+
+ std::string ModifiersToString(uint32_t modifiers) {
+ std::ostringstream out;
+ if (modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY) {
+ Append(out, "SHIFTKEY", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY) {
+ Append(out, "CONTROLKEY", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY) {
+ Append(out, "ALTKEY", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_METAKEY) {
+ Append(out, "METAKEY", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_ISKEYPAD) {
+ Append(out, "ISKEYPAD", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT) {
+ Append(out, "ISAUTOREPEAT", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) {
+ Append(out, "LEFTBUTTONDOWN", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN) {
+ Append(out, "MIDDLEBUTTONDOWN", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN) {
+ Append(out, "RIGHTBUTTONDOWN", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) {
+ Append(out, "CAPSLOCKKEY", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) {
+ Append(out, "NUMLOCKKEY", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_ISLEFT) {
+ Append(out, "ISLEFT", "+");
+ }
+ if (modifiers & PP_INPUTEVENT_MODIFIER_ISRIGHT) {
+ Append(out, "ISRIGHT", "+");
+ }
+ if (out.str().empty()) {
+ return "[NO MODIFIERS]";
+ }
+ return out.str();
+ }
+};
+
+class KeyTesterModule : public pp::Module {
+ public:
+ KeyTesterModule() : pp::Module() {}
+ virtual ~KeyTesterModule() {}
+
+ virtual pp::Instance* CreateInstance(PP_Instance instance) {
+ return new KeyTesterInstance(instance);
+ }
+};
+
+} // namespace remoting
+
+namespace pp {
+
+Module* CreateModule() {
+ return new remoting::KeyTesterModule();
+}
+
+} // namespace pp

Powered by Google App Engine
This is Rietveld 408576698