Add ToV8 converter for NativeWebKeyboardEvent

This commit is contained in:
Kevin Sawicki 2016-12-13 15:52:37 -08:00
parent 3237c6751a
commit 7842040d9d
3 changed files with 27 additions and 20 deletions

View file

@ -493,27 +493,11 @@ bool WebContents::PreHandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event, const content::NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) { bool* is_keyboard_shortcut) {
const char* type = if (event.type == blink::WebInputEvent::Type::RawKeyDown
event.type == blink::WebInputEvent::Type::RawKeyDown ? "keyDown" : || event.type == blink::WebInputEvent::Type::KeyUp)
event.type == blink::WebInputEvent::Type::KeyUp ? "keyUp" : return Emit("before-input-event", event);
nullptr; else
DCHECK(type);
if (!type) {
return false; return false;
}
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate());
dict.Set("type", type);
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(event.domKey));
using Modifiers = blink::WebInputEvent::Modifiers;
dict.Set("isAutoRepeat", (event.modifiers & Modifiers::IsAutoRepeat) != 0);
dict.Set("shift", (event.modifiers & Modifiers::ShiftKey) != 0);
dict.Set("control", (event.modifiers & Modifiers::ControlKey) != 0);
dict.Set("alt", (event.modifiers & Modifiers::AltKey) != 0);
dict.Set("meta", (event.modifiers & Modifiers::MetaKey) != 0);
return Emit("before-input-event", dict);
} }
void WebContents::EnterFullscreenModeForTab(content::WebContents* source, void WebContents::EnterFullscreenModeForTab(content::WebContents* source,

View file

@ -18,6 +18,7 @@
#include "third_party/WebKit/public/web/WebFindOptions.h" #include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebInputEvent.h" #include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion.h" #include "ui/events/keycodes/keyboard_code_conversion.h"
namespace { namespace {
@ -215,6 +216,26 @@ bool Converter<content::NativeWebKeyboardEvent>::FromV8(
return true; return true;
} }
v8::Local<v8::Value> Converter<content::NativeWebKeyboardEvent>::ToV8(
v8::Isolate* isolate, const content::NativeWebKeyboardEvent& in) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
if (in.type == blink::WebInputEvent::Type::RawKeyDown)
dict.Set("type", "keyDown");
else if (in.type == blink::WebInputEvent::Type::KeyUp)
dict.Set("type", "keyUp");
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.domKey));
using Modifiers = blink::WebInputEvent::Modifiers;
dict.Set("isAutoRepeat", (in.modifiers & Modifiers::IsAutoRepeat) != 0);
dict.Set("shift", (in.modifiers & Modifiers::ShiftKey) != 0);
dict.Set("control", (in.modifiers & Modifiers::ControlKey) != 0);
dict.Set("alt", (in.modifiers & Modifiers::AltKey) != 0);
dict.Set("meta", (in.modifiers & Modifiers::MetaKey) != 0);
return dict.GetHandle();
}
bool Converter<blink::WebMouseEvent>::FromV8( bool Converter<blink::WebMouseEvent>::FromV8(
v8::Isolate* isolate, v8::Local<v8::Value> val, blink::WebMouseEvent* out) { v8::Isolate* isolate, v8::Local<v8::Value> val, blink::WebMouseEvent* out) {
mate::Dictionary dict; mate::Dictionary dict;

View file

@ -45,6 +45,8 @@ template<>
struct Converter<content::NativeWebKeyboardEvent> { struct Converter<content::NativeWebKeyboardEvent> {
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val, static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
content::NativeWebKeyboardEvent* out); content::NativeWebKeyboardEvent* out);
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const content::NativeWebKeyboardEvent& in);
}; };
template<> template<>