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

Side by Side Diff: tests/ppapi_example_events/ppapi_example_events.cc

Issue 7395005: Proxy PPB_Input_Event, PPP_Input_Event, and associated IFs. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: copyright headers Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/trusted/plugin/ppapi/plugin_ppapi.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2011 The Native Client 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 // C headers 5 // C headers
6 #include <cassert> 6 #include <cassert>
7 #include <cstdio> 7 #include <cstdio>
8 8
9 // C++ headers 9 // C++ headers
10 #include <sstream> 10 #include <sstream>
11 #include <string> 11 #include <string>
12 12
13 // NaCl 13 // NaCl
14 #include "ppapi/c/pp_input_event.h" 14 #include "native_client/src/third_party/ppapi/cpp/input_event.h"
15 #include "ppapi/cpp/instance.h" 15 #include "native_client/src/third_party/ppapi/cpp/instance.h"
16 #include "ppapi/cpp/module.h" 16 #include "native_client/src/third_party/ppapi/cpp/module.h"
17 #include "ppapi/cpp/var.h" 17 #include "native_client/src/third_party/ppapi/cpp/point.h"
18 #include "native_client/src/third_party/ppapi/cpp/var.h"
18 19
19 namespace { 20 namespace {
20 const char* const kEventsPropertyName = "events"; 21 const char* const kEventsPropertyName = "events";
21 22
22 // Convert a given modifier to a descriptive string. Note that the actual 23 // Convert a given modifier to a descriptive string. Note that the actual
23 // declared type of modifier in each of the event structs (e.g., 24 // declared type of modifier in each of the event classes is uint32_t, but it is
24 // PP_InputEvent_Key.modifier) is uint32_t, but it is expected to be 25 // expected to be interpreted as a bitfield of 'or'ed PP_InputEvent_Modifier
25 // interpreted as a bitfield of 'or'ed PP_InputEvent_Modifier values. 26 // values.
26 std::string ModifierToString(uint32_t modifier) { 27 std::string ModifierToString(uint32_t modifier) {
27 std::string s; 28 std::string s;
28 if (modifier & PP_INPUTEVENT_MODIFIER_SHIFTKEY) { 29 if (modifier & PP_INPUTEVENT_MODIFIER_SHIFTKEY) {
29 s += "shift "; 30 s += "shift ";
30 } 31 }
31 if (modifier & PP_INPUTEVENT_MODIFIER_CONTROLKEY) { 32 if (modifier & PP_INPUTEVENT_MODIFIER_CONTROLKEY) {
32 s += "ctrl "; 33 s += "ctrl ";
33 } 34 }
34 if (modifier & PP_INPUTEVENT_MODIFIER_ALTKEY) { 35 if (modifier & PP_INPUTEVENT_MODIFIER_ALTKEY) {
35 s += "alt "; 36 s += "alt ";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 81 }
81 } 82 }
82 83
83 } // namespace 84 } // namespace
84 85
85 class EventInstance : public pp::Instance { 86 class EventInstance : public pp::Instance {
86 public: 87 public:
87 explicit EventInstance(PP_Instance instance) 88 explicit EventInstance(PP_Instance instance)
88 : pp::Instance(instance) { 89 : pp::Instance(instance) {
89 std::printf("EventInstance created.\n"); 90 std::printf("EventInstance created.\n");
91 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
92 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
90 } 93 }
91 virtual ~EventInstance() {} 94 virtual ~EventInstance() {}
92 95
93 void KeyEvent(PP_InputEvent_Key key, 96 void GotKeyEvent(const pp::KeyboardInputEvent& key_event,
94 PP_TimeTicks time, 97 const std::string& kind) {
95 const std::string& kind) {
96 std::ostringstream stream; 98 std::ostringstream stream;
97 stream << pp_instance() << ":" 99 stream << pp_instance() << ":"
98 << " Key event:" << kind.c_str() 100 << " Key event:" << kind
99 << " modifier:" << ModifierToString(key.modifier) 101 << " modifier:" << ModifierToString(key_event.GetModifiers())
100 << " key_code:" << key.key_code 102 << " key_code:" << key_event.GetKeyCode()
101 << " time:" << time 103 << " time:" << key_event.GetTimeStamp()
104 << " text:" << key_event.GetCharacterText().DebugString()
102 << "\n"; 105 << "\n";
103 std::printf("%s", stream.str().c_str()); 106 std::printf("%s", stream.str().c_str());
104 PostMessage(stream.str()); 107 PostMessage(stream.str());
105 } 108 }
106 109
107 void MouseEvent(PP_InputEvent_Mouse mouse_event, 110 void GotMouseEvent(const pp::MouseInputEvent& mouse_event,
108 PP_TimeTicks time, 111 const std::string& kind) {
109 const std::string& kind) {
110 std::ostringstream stream; 112 std::ostringstream stream;
111 stream << pp_instance() << ":" 113 stream << pp_instance() << ":"
112 << " Mouse event:" << kind.c_str() 114 << " Mouse event:" << kind
113 << " modifier:" << ModifierToString(mouse_event.modifier).c_str() 115 << " modifier:" << ModifierToString(mouse_event.GetModifiers())
114 << " button:" << MouseButtonToString(mouse_event.button).c_str() 116 << " button:" << MouseButtonToString(mouse_event.GetMouseButton())
115 << " x:" << mouse_event.x 117 << " x:" << mouse_event.GetMousePosition().x()
116 << " y:" << mouse_event.y 118 << " y:" << mouse_event.GetMousePosition().y()
117 << " click_count:" << mouse_event.click_count 119 << " click_count:" << mouse_event.GetMouseClickCount()
118 << " time:" << time 120 << " time:" << mouse_event.GetTimeStamp()
119 << "\n"; 121 << "\n";
120 std::printf("%s", stream.str().c_str()); 122 std::printf("%s", stream.str().c_str());
121 PostMessage(stream.str()); 123 PostMessage(stream.str());
122 } 124 }
123 125
124 void CharEvent(PP_InputEvent_Character char_event, PP_TimeTicks time) { 126 void GotWheelEvent(const pp::WheelInputEvent& wheel_event) {
125 std::ostringstream stream; 127 std::ostringstream stream;
126 stream << pp_instance() << ": Character event." 128 stream << pp_instance() << ": Wheel event."
127 << " modifier:" << ModifierToString(char_event.modifier).c_str() 129 << " modifier:" << ModifierToString(wheel_event.GetModifiers())
128 << " text:" << char_event.text 130 << " deltax:" << wheel_event.GetWheelDelta().x()
129 << " time:" << time 131 << " deltay:" << wheel_event.GetWheelDelta().y()
132 << " wheel_ticks_x:" << wheel_event.GetWheelTicks().x()
133 << " wheel_ticks_y:" << wheel_event.GetWheelTicks().y()
134 << " scroll_by_page:"
135 << (wheel_event.GetScrollByPage() ? "true" : "false")
130 << "\n"; 136 << "\n";
131 std::printf("%s", stream.str().c_str()); 137 std::printf("%s", stream.str().c_str());
132 PostMessage(stream.str()); 138 PostMessage(stream.str());
133 }
134
135 void WheelEvent(PP_InputEvent_Wheel wheel_event, PP_TimeTicks time) {
136 std::ostringstream stream;
137 stream << pp_instance() << ": Wheel event."
138 << " modifier:" << ModifierToString(wheel_event.modifier).c_str()
139 << " deltax:" << wheel_event.delta_x
140 << " deltay:" << wheel_event.delta_y
141 << " wheel_ticks_x:" << wheel_event.wheel_ticks_x
142 << " wheel_ticks_y:" << wheel_event.wheel_ticks_y
143 << " scroll_by_page:"
144 << (wheel_event.scroll_by_page ? "true" : "false")
145 << "\n";
146 std::printf("%s", stream.str().c_str());
147 PostMessage(stream.str());
148 } 139 }
149 140
150 // Handle an incoming input event by switching on type and dispatching 141 // Handle an incoming input event by switching on type and dispatching
151 // to the appropriate subtype handler. 142 // to the appropriate subtype handler.
152 virtual bool HandleInputEvent(const PP_InputEvent& event) { 143 virtual bool HandleInputEvent(const pp::InputEvent& event) {
153 std::printf("HandleInputEvent called\n"); 144 std::printf("HandleInputEvent called\n");
154 switch (event.type) { 145 switch (event.GetType()) {
155 case PP_INPUTEVENT_TYPE_UNDEFINED: 146 case PP_INPUTEVENT_TYPE_UNDEFINED:
156 std::printf("Undefined event.\n"); 147 std::printf("Undefined event.\n");
157 break; 148 break;
158 case PP_INPUTEVENT_TYPE_MOUSEDOWN: 149 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
159 MouseEvent(event.u.mouse, event.time_stamp, "Down"); 150 GotMouseEvent(pp::MouseInputEvent(event), "Down");
160 break; 151 break;
161 case PP_INPUTEVENT_TYPE_MOUSEUP: 152 case PP_INPUTEVENT_TYPE_MOUSEUP:
162 MouseEvent(event.u.mouse, event.time_stamp, "Up"); 153 GotMouseEvent(pp::MouseInputEvent(event), "Up");
163 break; 154 break;
164 case PP_INPUTEVENT_TYPE_MOUSEMOVE: 155 case PP_INPUTEVENT_TYPE_MOUSEMOVE:
165 MouseEvent(event.u.mouse, event.time_stamp, "Move"); 156 GotMouseEvent(pp::MouseInputEvent(event), "Move");
166 break; 157 break;
167 case PP_INPUTEVENT_TYPE_MOUSEENTER: 158 case PP_INPUTEVENT_TYPE_MOUSEENTER:
168 MouseEvent(event.u.mouse, event.time_stamp, "Enter"); 159 GotMouseEvent(pp::MouseInputEvent(event), "Enter");
169 break; 160 break;
170 case PP_INPUTEVENT_TYPE_MOUSELEAVE: 161 case PP_INPUTEVENT_TYPE_MOUSELEAVE:
171 MouseEvent(event.u.mouse, event.time_stamp, "Leave"); 162 GotMouseEvent(pp::MouseInputEvent(event), "Leave");
172 break; 163 break;
173 case PP_INPUTEVENT_TYPE_MOUSEWHEEL: 164 case PP_INPUTEVENT_TYPE_MOUSEWHEEL:
174 WheelEvent(event.u.wheel, event.time_stamp); 165 GotWheelEvent(pp::WheelInputEvent(event));
175 break; 166 break;
176 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: 167 case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
177 KeyEvent(event.u.key, event.time_stamp, "RawKeyDown"); 168 GotKeyEvent(pp::KeyboardInputEvent(event), "RawKeyDown");
178 break; 169 break;
179 case PP_INPUTEVENT_TYPE_KEYDOWN: 170 case PP_INPUTEVENT_TYPE_KEYDOWN:
180 KeyEvent(event.u.key, event.time_stamp, "Down"); 171 GotKeyEvent(pp::KeyboardInputEvent(event), "Down");
181 break; 172 break;
182 case PP_INPUTEVENT_TYPE_KEYUP: 173 case PP_INPUTEVENT_TYPE_KEYUP:
183 KeyEvent(event.u.key, event.time_stamp, "Up"); 174 GotKeyEvent(pp::KeyboardInputEvent(event), "Up");
184 break; 175 break;
185 case PP_INPUTEVENT_TYPE_CHAR: 176 case PP_INPUTEVENT_TYPE_CHAR:
186 CharEvent(event.u.character, event.time_stamp); 177 GotKeyEvent(pp::KeyboardInputEvent(event), "Character");
187 break; 178 break;
188 default: 179 default:
189 std::printf("Unrecognized event type: %d\n", event.type); 180 std::printf("Unrecognized event type: %d\n", event.GetType());
190 assert(false); 181 assert(false);
191 return false; 182 return false;
192 } 183 }
193 return true; 184 return true;
194 } 185 }
195 }; 186 };
196 187
197 // The EventModule provides an implementation of pp::Module that creates 188 // The EventModule provides an implementation of pp::Module that creates
198 // EventInstance objects when invoked. This is part of the glue code that makes 189 // EventInstance objects when invoked. This is part of the glue code that makes
199 // our example accessible to ppapi. 190 // our example accessible to ppapi.
(...skipping 10 matching lines...) Expand all
210 201
211 // Implement the required pp::CreateModule function that creates our specific 202 // Implement the required pp::CreateModule function that creates our specific
212 // kind of Module (in this case, EventModule). This is part of the glue code 203 // kind of Module (in this case, EventModule). This is part of the glue code
213 // that makes our example accessible to ppapi. 204 // that makes our example accessible to ppapi.
214 namespace pp { 205 namespace pp {
215 Module* CreateModule() { 206 Module* CreateModule() {
216 std::printf("Creating EventModule.\n"); 207 std::printf("Creating EventModule.\n");
217 return new EventModule(); 208 return new EventModule();
218 } 209 }
219 } 210 }
OLDNEW
« no previous file with comments | « src/trusted/plugin/ppapi/plugin_ppapi.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698