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

Unified Diff: content/child/blink_platform_impl.cc

Issue 929053004: [KeyboardEvent] Add embedder APIs to translate between Dom |key| enum and strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup of the dom_key.h Created 5 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 side-by-side diff with in-line comments
Download patch
Index: content/child/blink_platform_impl.cc
diff --git a/content/child/blink_platform_impl.cc b/content/child/blink_platform_impl.cc
index d743fffac4636fee02a2845e2dc1a113205cf13d..e09a222714bdc8ac630aaf95bf0e113981c998b9 100644
--- a/content/child/blink_platform_impl.cc
+++ b/content/child/blink_platform_impl.cc
@@ -72,6 +72,7 @@
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "ui/base/layout.h"
#include "ui/events/gestures/blink/web_gesture_curve_impl.h"
+#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
using blink::WebData;
@@ -1370,4 +1371,27 @@ int BlinkPlatformImpl::domEnumFromCodeString(const WebString& code) {
code.utf8().data()));
}
+WebString BlinkPlatformImpl::domKeyStringFromEnum(int dom_key) {
+ if (dom_key < static_cast<int>(ui::DomKey::CHARACTER)) {
+ return WebString::fromUTF8(ui::KeycodeConverter::DomKeyToKeyString(
+ static_cast<ui::DomKey>(dom_key)));
dtapuska 2015/08/13 13:36:47 This cast is undefined when dom_key is less than 0
+ } else {
+ std::string dom_key_char = base::StringPrintf("%c",
dtapuska 2015/08/13 13:36:47 Does StringPrintf work for unicode characters? ie;
+ (dom_key - static_cast<int>(ui::DomKey::CHARACTER)));
+ return WebString::fromUTF8(dom_key_char);
+ }
+}
+
+int BlinkPlatformImpl::domKeyEnumFromString(const WebString& key) {
+ ui::DomKey dom_key = ui::KeycodeConverter::KeyStringToDomKey(
+ key.utf8().data());
+ if (dom_key == ui::DomKey::CHARACTER) {
+ int dom_char;
+ base::StringToInt(key.utf8().data(), &dom_char);
dtapuska 2015/08/13 13:36:48 Can we add an ASSERT that this doesn't fail?
+ return dom_char + static_cast<int>(ui::DomKey::CHARACTER);
+ } else {
+ return static_cast<int>(dom_key);
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698