1 // Copyright (c) 2015 The Chromium 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.
7 #include "ppapi/cpp/input_event.h"
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/module.h"
10 #include "ppapi/cpp/var.h"
11 #include "ppapi/cpp/var_dictionary.h"
15 class KeyTesterInstance
: public pp::Instance
{
17 explicit KeyTesterInstance(PP_Instance instance
) : pp::Instance(instance
) {
18 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD
);
21 virtual ~KeyTesterInstance() {}
23 virtual bool HandleInputEvent(const pp::InputEvent
& event
) {
24 switch (event
.GetType()) {
25 case PP_INPUTEVENT_TYPE_KEYDOWN
:
26 case PP_INPUTEVENT_TYPE_KEYUP
:
27 case PP_INPUTEVENT_TYPE_CHAR
: {
28 HandleKeyboardEvent(pp::KeyboardInputEvent(event
));
38 void HandleKeyboardEvent(const pp::KeyboardInputEvent
& event
) {
39 pp::VarDictionary out
;
40 out
.Set("type", EventTypeToString(event
.GetType()));
41 out
.Set("modifiers", (double)event
.GetModifiers());
42 out
.Set("keyCode", (double)event
.GetKeyCode());
43 out
.Set("characterText", event
.GetCharacterText());
44 out
.Set("code", event
.GetCode());
48 std::string
EventTypeToString(PP_InputEvent_Type t
) {
50 case PP_INPUTEVENT_TYPE_UNDEFINED
:
52 case PP_INPUTEVENT_TYPE_MOUSEDOWN
:
54 case PP_INPUTEVENT_TYPE_MOUSEUP
:
56 case PP_INPUTEVENT_TYPE_MOUSEMOVE
:
58 case PP_INPUTEVENT_TYPE_MOUSEENTER
:
60 case PP_INPUTEVENT_TYPE_MOUSELEAVE
:
62 case PP_INPUTEVENT_TYPE_WHEEL
:
64 case PP_INPUTEVENT_TYPE_RAWKEYDOWN
:
66 case PP_INPUTEVENT_TYPE_KEYDOWN
:
68 case PP_INPUTEVENT_TYPE_KEYUP
:
70 case PP_INPUTEVENT_TYPE_CHAR
:
72 case PP_INPUTEVENT_TYPE_CONTEXTMENU
:
74 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START
:
75 return "IME_COMPOSITION_START";
76 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE
:
77 return "IME_COMPOSITION_UPDATE";
78 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END
:
79 return "IME_COMPOSITION_END";
80 case PP_INPUTEVENT_TYPE_IME_TEXT
:
82 case PP_INPUTEVENT_TYPE_TOUCHSTART
:
84 case PP_INPUTEVENT_TYPE_TOUCHMOVE
:
86 case PP_INPUTEVENT_TYPE_TOUCHEND
:
88 case PP_INPUTEVENT_TYPE_TOUCHCANCEL
:
91 return "[UNRECOGNIZED]";
96 class KeyTesterModule
: public pp::Module
{
98 KeyTesterModule() : pp::Module() {}
99 virtual ~KeyTesterModule() {}
101 virtual pp::Instance
* CreateInstance(PP_Instance instance
) {
102 return new KeyTesterInstance(instance
);
106 } // namespace remoting
110 Module
* CreateModule() {
111 return new remoting::KeyTesterModule();