15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// C headers
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include <stdio.h>
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// C++ headers
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <sstream>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// PPAPI headers
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/cpp/completion_callback.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/input_event.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/instance.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/point.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/var.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/utility/completion_callback_factory.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifdef PostMessage
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#undef PostMessage
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace {
268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)std::string ModifierToString(uint32_t modifier) {
288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  std::string s;
298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_SHIFTKEY) {
308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "shift ";
318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_CONTROLKEY) {
338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "ctrl ";
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_ALTKEY) {
368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "alt ";
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_METAKEY) {
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "meta ";
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_ISKEYPAD) {
428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "keypad ";
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT) {
458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "autorepeat ";
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) {
488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "left-button-down ";
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN) {
518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "middle-button-down ";
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN) {
548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "right-button-down ";
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) {
578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "caps-lock ";
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (modifier & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) {
608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    s += "num-lock ";
618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return s;
638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)std::string MouseButtonToString(PP_InputEvent_MouseButton button) {
668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  switch (button) {
678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_MOUSEBUTTON_NONE:
688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "None";
698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "Left";
718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "Middle";
738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "Right";
758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    default:
768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      std::ostringstream stream;
778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      stream << "Unrecognized (" << static_cast<int32_t>(button) << ")";
788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return stream.str();
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)std::string TouchKindToString(PP_InputEvent_Type kind) {
838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  switch (kind) {
848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_TYPE_TOUCHSTART:
858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "Start";
868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_TYPE_TOUCHMOVE:
878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "Move";
888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_TYPE_TOUCHEND:
898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "End";
908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return "Cancel";
928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    default:
938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      std::ostringstream stream;
948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      stream << "Unrecognized (" << static_cast<int32_t>(kind) << ")";
958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return stream.str();
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}  // namespace
1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
101b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class InputEventInstance : public pp::Instance {
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
103b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  explicit InputEventInstance(PP_Instance instance)
1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      : pp::Instance(instance) {
105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL |
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                       PP_INPUTEVENT_CLASS_TOUCH);
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Clicking outside of the instance's bounding box
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// will create a DidChangeFocus event (the NaCl instance is
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// out of focus). Clicking back inside the instance's
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// bounding box will create another DidChangeFocus event
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// (the NaCl instance is back in focus). The default is
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// that the instance is out of focus.
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DidChangeFocus(bool focus) {
1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    std::ostringstream stream;
1228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    stream << "DidChangeFocus:" << " focus:" << focus;
1238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    PostMessage(stream.str());
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Scrolling the mouse wheel causes a DidChangeView event.
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DidChangeView(const pp::View& view) {
1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  std::ostringstream stream;
1298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  stream << "DidChangeView:"
1308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " x:" << view.GetRect().x()
1318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " y:" << view.GetRect().y()
1328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " width:" << view.GetRect().width()
1338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " height:" << view.GetRect().height()
1348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << "\n"
1358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " IsFullscreen:" << view.IsFullscreen()
1368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " IsVisible:" << view.IsVisible()
1378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " IsPageVisible:" << view.IsPageVisible()
1388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " GetDeviceScale:" << view.GetDeviceScale()
1398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)         << " GetCSSScale:" << view.GetCSSScale();
1408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    PostMessage(stream.str());
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleInputEvent(const pp::InputEvent& event) {
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    switch (event.GetType()) {
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START:
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_IME_TEXT:
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_UNDEFINED:
1508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        // these cases are not handled.
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        break;
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_MOUSEDOWN:
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_MOUSEUP:
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_MOUSEMOVE:
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_MOUSEENTER:
15690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_MOUSELEAVE:
15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_CONTEXTMENU: {
158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        pp::MouseInputEvent mouse_event(event);
1598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        std::ostringstream stream;
1608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        stream << "Mouse event:"
1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " modifier:" << ModifierToString(mouse_event.GetModifiers())
1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " button:" << MouseButtonToString(mouse_event.GetButton())
1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " x:" << mouse_event.GetPosition().x()
1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " y:" << mouse_event.GetPosition().y()
1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " click_count:" << mouse_event.GetClickCount()
1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " time:" << mouse_event.GetTimeStamp()
1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " is_context_menu: "
1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                   << (event.GetType() == PP_INPUTEVENT_TYPE_CONTEXTMENU);
1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        PostMessage(stream.str());
1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        break;
1718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      }
1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_WHEEL: {
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        pp::WheelInputEvent wheel_event(event);
1758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        std::ostringstream stream;
1768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        stream << "Wheel event:"
1778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " modifier:" << ModifierToString(wheel_event.GetModifiers())
1788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " deltax:" << wheel_event.GetDelta().x()
1798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " deltay:" << wheel_event.GetDelta().y()
1808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " wheel_ticks_x:" << wheel_event.GetTicks().x()
1818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " wheel_ticks_y:" << wheel_event.GetTicks().y()
1828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " scroll_by_page: " << wheel_event.GetScrollByPage()
1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " time:" << wheel_event.GetTimeStamp();
1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        PostMessage(stream.str());
1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        break;
1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      }
1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_KEYDOWN:
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_KEYUP:
19190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_CHAR: {
192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        pp::KeyboardInputEvent key_event(event);
1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        std::ostringstream stream;
1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        stream << "Key event:"
1958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " modifier:" << ModifierToString(key_event.GetModifiers())
1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " key_code:" << key_event.GetKeyCode()
1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " time:" << key_event.GetTimeStamp()
1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " text:" << key_event.GetCharacterText().DebugString();
1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        PostMessage(stream.str());
2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        break;
2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      }
2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_TOUCHSTART:
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_TOUCHMOVE:
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      case PP_INPUTEVENT_TYPE_TOUCHEND:
206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      case PP_INPUTEVENT_TYPE_TOUCHCANCEL: {
207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        pp::TouchInputEvent touch_event(event);
2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        std::ostringstream stream;
2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        stream << "Touch event:" << TouchKindToString(event.GetType())
2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               << " modifier:" << ModifierToString(touch_event.GetModifiers());
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        uint32_t touch_count =
213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES);
214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        for (uint32_t i = 0; i < touch_count; ++i) {
215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          pp::TouchPoint point =
216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              touch_event.GetTouchByIndex(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, i);
2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          stream << " x[" << point.id() << "]:" << point.position().x()
2188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                 << " y[" << point.id() << "]:" << point.position().y()
2198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                 << " radii_x[" << point.id() << "]:" << point.radii().x()
2208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                 << " radii_y[" << point.id() << "]:" << point.radii().y()
2218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                 << " angle[" << point.id() << "]:" << point.rotation_angle()
2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                 << " pressure[" << point.id() << "]:" << point.pressure();
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        }
2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        stream << " time:" << touch_event.GetTimeStamp();
2258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        PostMessage(stream.str());
2268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        break;
2278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      }
2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      default: {
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        // For any unhandled events, send a message to the browser
231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        // so that the user is aware of these and can investigate.
232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        std::stringstream oss;
233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        oss << "Default (unhandled) event, type=" << event.GetType();
234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        PostMessage(oss.str());
235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      } break;
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return true;
239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
242b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class InputEventModule : public pp::Module {
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
244b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  InputEventModule() : pp::Module() {}
245b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual ~InputEventModule() {}
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual pp::Instance* CreateInstance(PP_Instance instance) {
248b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    return new InputEventInstance(instance);
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp {
253b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)Module* CreateModule() { return new InputEventModule(); }
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
255