diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-08 10:12:56 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-08 10:12:56 +0000 |
commit | 06b5f9d7e45641c4869007a0e269c7e6f84e20bd (patch) | |
tree | edb431ead003f47073296fc2d308ce8ec7e124ba /ppapi/example/example.cc | |
parent | 76670b64eed6f75e10692221bd58164b4a06db87 (diff) | |
download | chromium_src-06b5f9d7e45641c4869007a0e269c7e6f84e20bd.zip chromium_src-06b5f9d7e45641c4869007a0e269c7e6f84e20bd.tar.gz chromium_src-06b5f9d7e45641c4869007a0e269c7e6f84e20bd.tar.bz2 |
Expose scancodes to PP_InputEvent_Key events that are independent of the input language/layout in effect, i.e. that represent the physical key pressed, independent of its meaning in the current context.
This will inherently rely on the nativeKeyCode field of Chrome's WebKeyboardEvents.
BUG=
TEST=
Review URL: http://codereview.chromium.org/6691066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80918 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/example/example.cc')
-rw-r--r-- | ppapi/example/example.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc index f9ae799..e8c3995 100644 --- a/ppapi/example/example.cc +++ b/ppapi/example/example.cc @@ -10,6 +10,7 @@ #include <time.h> #include <algorithm> +#include <sstream> #include "ppapi/c/dev/ppb_console_dev.h" #include "ppapi/c/dev/ppb_cursor_control_dev.h" @@ -17,6 +18,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_input_event.h" #include "ppapi/c/pp_rect.h" +#include "ppapi/c/ppb_var.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/dev/scriptable_object_deprecated.h" #include "ppapi/cpp/graphics_2d.h" @@ -26,7 +28,6 @@ #include "ppapi/cpp/rect.h" #include "ppapi/cpp/url_loader.h" #include "ppapi/cpp/url_request_info.h" -#include "ppapi/cpp/var.h" static const int kStepsPerCircle = 800; @@ -192,6 +193,22 @@ class MyInstance : public pp::Instance, public MyFetcherClient { return true; } + void HandleKeyEvent(const PP_InputEvent_Key& key_event) { + Log(PP_LOGLEVEL_LOG, "HandleKeyDownEvent"); + + // Stringify the Windows-style and Native key codes + std::ostringstream last_key_down_text; + last_key_down_text << "vkey=" << key_event.key_code + << " native=" << key_event.native_key_code + << " usb=" << std::hex << key_event.usb_key_code; + + // Locate the field to update in the page DOM + pp::Var window = GetWindowObject(); + pp::Var doc = window.GetProperty("document"); + pp::Var last_key_down = doc.Call("getElementById", "lastKeyDown"); + last_key_down.SetProperty("innerHTML", last_key_down_text.str()); + } + virtual bool HandleInputEvent(const PP_InputEvent& event) { switch (event.type) { case PP_INPUTEVENT_TYPE_MOUSEDOWN: @@ -201,6 +218,7 @@ class MyInstance : public pp::Instance, public MyFetcherClient { case PP_INPUTEVENT_TYPE_MOUSEMOVE: return true; case PP_INPUTEVENT_TYPE_KEYDOWN: + HandleKeyEvent(event.u.key); return true; default: return false; |