Add ToV8 converter for NativeWebKeyboardEvent
This commit is contained in:
parent
3237c6751a
commit
7842040d9d
3 changed files with 27 additions and 20 deletions
|
@ -493,27 +493,11 @@ bool WebContents::PreHandleKeyboardEvent(
|
|||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event,
|
||||
bool* is_keyboard_shortcut) {
|
||||
const char* type =
|
||||
event.type == blink::WebInputEvent::Type::RawKeyDown ? "keyDown" :
|
||||
event.type == blink::WebInputEvent::Type::KeyUp ? "keyUp" :
|
||||
nullptr;
|
||||
DCHECK(type);
|
||||
if (!type) {
|
||||
if (event.type == blink::WebInputEvent::Type::RawKeyDown
|
||||
|| event.type == blink::WebInputEvent::Type::KeyUp)
|
||||
return Emit("before-input-event", event);
|
||||
else
|
||||
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,
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "third_party/WebKit/public/web/WebFindOptions.h"
|
||||
#include "third_party/WebKit/public/web/WebInputEvent.h"
|
||||
#include "ui/base/clipboard/clipboard.h"
|
||||
#include "ui/events/keycodes/dom/keycode_converter.h"
|
||||
#include "ui/events/keycodes/keyboard_code_conversion.h"
|
||||
|
||||
namespace {
|
||||
|
@ -215,6 +216,26 @@ bool Converter<content::NativeWebKeyboardEvent>::FromV8(
|
|||
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(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val, blink::WebMouseEvent* out) {
|
||||
mate::Dictionary dict;
|
||||
|
|
|
@ -45,6 +45,8 @@ template<>
|
|||
struct Converter<content::NativeWebKeyboardEvent> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
content::NativeWebKeyboardEvent* out);
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const content::NativeWebKeyboardEvent& in);
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Reference in a new issue