OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <sstream> | 5 #include <string> |
6 | 6 |
7 #include "ppapi/cpp/input_event.h" | 7 #include "ppapi/cpp/input_event.h" |
8 #include "ppapi/cpp/instance.h" | 8 #include "ppapi/cpp/instance.h" |
9 #include "ppapi/cpp/module.h" | 9 #include "ppapi/cpp/module.h" |
10 #include "ppapi/cpp/var.h" | 10 #include "ppapi/cpp/var.h" |
11 #include "ppapi/cpp/var_dictionary.h" | 11 #include "ppapi/cpp/var_dictionary.h" |
12 | 12 |
13 namespace remoting { | 13 namespace remoting { |
14 | 14 |
15 class KeyTesterInstance : public pp::Instance { | 15 class KeyTesterInstance : public pp::Instance { |
16 public: | 16 public: |
17 explicit KeyTesterInstance(PP_Instance instance) : pp::Instance(instance) { | 17 explicit KeyTesterInstance(PP_Instance instance) : pp::Instance(instance) { |
| 18 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); |
18 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 19 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
19 } | 20 } |
20 | 21 |
21 virtual ~KeyTesterInstance() {} | 22 virtual ~KeyTesterInstance() {} |
22 | 23 |
23 virtual bool HandleInputEvent(const pp::InputEvent& event) { | 24 bool HandleInputEvent(const pp::InputEvent& event) override { |
24 switch (event.GetType()) { | 25 switch (event.GetType()) { |
25 case PP_INPUTEVENT_TYPE_KEYDOWN: | 26 case PP_INPUTEVENT_TYPE_KEYDOWN: |
26 case PP_INPUTEVENT_TYPE_KEYUP: | 27 case PP_INPUTEVENT_TYPE_KEYUP: |
27 case PP_INPUTEVENT_TYPE_CHAR: { | 28 case PP_INPUTEVENT_TYPE_CHAR: { |
28 HandleKeyboardEvent(pp::KeyboardInputEvent(event)); | 29 HandleKeyboardEvent(pp::KeyboardInputEvent(event)); |
29 break; | 30 break; |
30 } | 31 } |
| 32 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
| 33 case PP_INPUTEVENT_TYPE_MOUSEUP: |
| 34 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
| 35 case PP_INPUTEVENT_TYPE_MOUSEENTER: |
| 36 case PP_INPUTEVENT_TYPE_MOUSELEAVE: |
| 37 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
| 38 HandleMouseEvent(pp::MouseInputEvent(event)); |
| 39 break; |
| 40 } |
| 41 case PP_INPUTEVENT_TYPE_WHEEL: { |
| 42 HandleWheelEvent(pp::WheelInputEvent(event)); |
| 43 break; |
| 44 } |
31 default: | 45 default: |
32 break; | 46 break; |
33 } | 47 } |
34 return true; | 48 return true; |
35 } | 49 } |
36 | 50 |
37 private: | 51 private: |
38 void HandleKeyboardEvent(const pp::KeyboardInputEvent& event) { | 52 void HandleKeyboardEvent(const pp::KeyboardInputEvent& event) { |
39 pp::VarDictionary out; | 53 pp::VarDictionary out; |
40 out.Set("type", EventTypeToString(event.GetType())); | 54 out.Set("type", EventTypeToString(event.GetType())); |
41 out.Set("modifiers", (double)event.GetModifiers()); | 55 out.Set("modifiers", (double)event.GetModifiers()); |
42 out.Set("keyCode", (double)event.GetKeyCode()); | 56 out.Set("keyCode", (double)event.GetKeyCode()); |
43 out.Set("characterText", event.GetCharacterText()); | 57 out.Set("characterText", event.GetCharacterText()); |
44 out.Set("code", event.GetCode()); | 58 out.Set("code", event.GetCode()); |
45 PostMessage(out); | 59 PostMessage(out); |
46 } | 60 } |
47 | 61 |
48 std::string EventTypeToString(PP_InputEvent_Type t) { | 62 void HandleMouseEvent(const pp::MouseInputEvent& event) { |
| 63 pp::VarDictionary out; |
| 64 out.Set("type", EventTypeToString(event.GetType())); |
| 65 out.Set("button", (double)event.GetButton()); |
| 66 out.Set("position", PointToString(event.GetPosition())); |
| 67 out.Set("clickCount", event.GetClickCount()); |
| 68 out.Set("movement", PointToString(event.GetMovement())); |
| 69 PostMessage(out); |
| 70 } |
| 71 |
| 72 void HandleWheelEvent(const pp::WheelInputEvent& event) { |
| 73 pp::VarDictionary out; |
| 74 out.Set("type", EventTypeToString(event.GetType())); |
| 75 out.Set("delta", PointToString(event.GetDelta())); |
| 76 out.Set("ticks", PointToString(event.GetTicks())); |
| 77 out.Set("scrollByPage", event.GetScrollByPage()); |
| 78 PostMessage(out); |
| 79 } |
| 80 |
| 81 template <typename T> |
| 82 static std::string PointToString(const T& point) { |
| 83 return std::to_string(point.x()) + ", " + std::to_string(point.y()); |
| 84 } |
| 85 |
| 86 static std::string EventTypeToString(PP_InputEvent_Type t) { |
49 switch (t) { | 87 switch (t) { |
50 case PP_INPUTEVENT_TYPE_UNDEFINED: | 88 case PP_INPUTEVENT_TYPE_UNDEFINED: |
51 return "UNDEFINED"; | 89 return "UNDEFINED"; |
52 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 90 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
53 return "MOUSEDOWN"; | 91 return "MOUSEDOWN"; |
54 case PP_INPUTEVENT_TYPE_MOUSEUP: | 92 case PP_INPUTEVENT_TYPE_MOUSEUP: |
55 return "MOUSEUP"; | 93 return "MOUSEUP"; |
56 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 94 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
57 return "MOUSEMOVE"; | 95 return "MOUSEMOVE"; |
58 case PP_INPUTEVENT_TYPE_MOUSEENTER: | 96 case PP_INPUTEVENT_TYPE_MOUSEENTER: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 143 |
106 } // namespace remoting | 144 } // namespace remoting |
107 | 145 |
108 namespace pp { | 146 namespace pp { |
109 | 147 |
110 Module* CreateModule() { | 148 Module* CreateModule() { |
111 return new remoting::KeyTesterModule(); | 149 return new remoting::KeyTesterModule(); |
112 } | 150 } |
113 | 151 |
114 } // namespace pp | 152 } // namespace pp |
OLD | NEW |