summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-08 10:12:56 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-08 10:12:56 +0000
commit06b5f9d7e45641c4869007a0e269c7e6f84e20bd (patch)
treeedb431ead003f47073296fc2d308ce8ec7e124ba /ppapi
parent76670b64eed6f75e10692221bd58164b4a06db87 (diff)
downloadchromium_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')
-rw-r--r--ppapi/c/pp_input_event.h21
-rw-r--r--ppapi/example/example.cc20
-rw-r--r--ppapi/example/example.html1
3 files changed, 37 insertions, 5 deletions
diff --git a/ppapi/c/pp_input_event.h b/ppapi/c/pp_input_event.h
index cb10932..15d3eaf 100644
--- a/ppapi/c/pp_input_event.h
+++ b/ppapi/c/pp_input_event.h
@@ -114,13 +114,26 @@ struct PP_InputEvent_Key {
uint32_t modifier;
/**
- * The key code.
+ * |key_code| reflects the deprecated DOM KeyboardEvent |keyCode| field.
+ * Chrome populates this with the Windows-style Virtual Key code of the key.
*/
-
-// TODO(brettw) define what these actually are.
uint32_t key_code;
+
+ /**
+ * |native_key_code| reflects the hardware and/or platform specific code for
+ * the key.
+ */
+ uint32_t native_key_code;
+
+ /**
+ * |usb_key_code| contains the equivalent USB HID Page and Usage codes for
+ * the key, in the high- and low-order 16-bit words respectively. See
+ * http://www.usb.org/developers/hidpage/ for tables of HID Usage codes.
+ * If the no USB HID Usage equivalent is known for the key, the code is zero.
+ */
+ uint32_t usb_key_code;
};
-PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Key, 8);
+PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Key, 16);
/**
* @}
*/
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;
diff --git a/ppapi/example/example.html b/ppapi/example/example.html
index 7146b3f..bd056d6 100644
--- a/ppapi/example/example.html
+++ b/ppapi/example/example.html
@@ -33,6 +33,7 @@ function ToggleSize() {
<button onclick='Test()'>Test</button>
<button onclick='ToggleSize()'>Toggle Size</button>
<div id="fps" style="background-color:white; font-weight:bold; padding:4px; width:200px;">FPS GOES HERE</div>
+ <div id="lastKeyDown" style="background-color:white; font-weight:bold; padding:4px; width:200px;">LAST KEY DOWN GOES HERE</div>
<div id="size" style="background-color:white; font-weight:bold; padding:4px; width:200px;"></div>
<object id="plugin" type="application/x-ppapi-example" width="400" height="400" border="2px"></object>
<hr>