|
@@ -144,10 +144,44 @@ struct Converter<blink::WebInputEvent::Modifiers> {
|
|
|
*out = blink::WebInputEvent::Modifiers::kIsLeft;
|
|
|
else if (modifier == "right")
|
|
|
*out = blink::WebInputEvent::Modifiers::kIsRight;
|
|
|
+ // TODO(nornagon): the rest of the modifiers
|
|
|
return true;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+std::vector<std::string> ModifiersToArray(int modifiers) {
|
|
|
+ using Modifiers = blink::WebInputEvent::Modifiers;
|
|
|
+ std::vector<std::string> modifier_strings;
|
|
|
+ if (modifiers & Modifiers::kShiftKey)
|
|
|
+ modifier_strings.push_back("shift");
|
|
|
+ if (modifiers & Modifiers::kControlKey)
|
|
|
+ modifier_strings.push_back("control");
|
|
|
+ if (modifiers & Modifiers::kAltKey)
|
|
|
+ modifier_strings.push_back("alt");
|
|
|
+ if (modifiers & Modifiers::kMetaKey)
|
|
|
+ modifier_strings.push_back("meta");
|
|
|
+ if (modifiers & Modifiers::kIsKeyPad)
|
|
|
+ modifier_strings.push_back("iskeypad");
|
|
|
+ if (modifiers & Modifiers::kIsAutoRepeat)
|
|
|
+ modifier_strings.push_back("isautorepeat");
|
|
|
+ if (modifiers & Modifiers::kLeftButtonDown)
|
|
|
+ modifier_strings.push_back("leftbuttondown");
|
|
|
+ if (modifiers & Modifiers::kMiddleButtonDown)
|
|
|
+ modifier_strings.push_back("middlebuttondown");
|
|
|
+ if (modifiers & Modifiers::kRightButtonDown)
|
|
|
+ modifier_strings.push_back("rightbuttondown");
|
|
|
+ if (modifiers & Modifiers::kCapsLockOn)
|
|
|
+ modifier_strings.push_back("capslock");
|
|
|
+ if (modifiers & Modifiers::kNumLockOn)
|
|
|
+ modifier_strings.push_back("numlock");
|
|
|
+ if (modifiers & Modifiers::kIsLeft)
|
|
|
+ modifier_strings.push_back("left");
|
|
|
+ if (modifiers & Modifiers::kIsRight)
|
|
|
+ modifier_strings.push_back("right");
|
|
|
+ // TODO(nornagon): the rest of the modifiers
|
|
|
+ return modifier_strings;
|
|
|
+}
|
|
|
+
|
|
|
blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
|
|
|
v8::Local<v8::Value> val) {
|
|
|
blink::WebInputEvent::Type type = blink::WebInputEvent::Type::kUndefined;
|
|
@@ -219,6 +253,51 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(v8::Isolate* isolate,
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+int GetKeyLocationCode(const blink::WebInputEvent& key) {
|
|
|
+ // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/events/keyboard_event.h;l=46;drc=1ff6437e65b183e673b7b4f25060b74dc2ba5c37
|
|
|
+ enum KeyLocationCode {
|
|
|
+ kDomKeyLocationStandard = 0x00,
|
|
|
+ kDomKeyLocationLeft = 0x01,
|
|
|
+ kDomKeyLocationRight = 0x02,
|
|
|
+ kDomKeyLocationNumpad = 0x03
|
|
|
+ };
|
|
|
+ using Modifiers = blink::WebInputEvent::Modifiers;
|
|
|
+ if (key.GetModifiers() & Modifiers::kIsKeyPad)
|
|
|
+ return kDomKeyLocationNumpad;
|
|
|
+ if (key.GetModifiers() & Modifiers::kIsLeft)
|
|
|
+ return kDomKeyLocationLeft;
|
|
|
+ if (key.GetModifiers() & Modifiers::kIsRight)
|
|
|
+ return kDomKeyLocationRight;
|
|
|
+ return kDomKeyLocationStandard;
|
|
|
+}
|
|
|
+
|
|
|
+v8::Local<v8::Value> Converter<blink::WebKeyboardEvent>::ToV8(
|
|
|
+ v8::Isolate* isolate,
|
|
|
+ const blink::WebKeyboardEvent& in) {
|
|
|
+ gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
|
|
+
|
|
|
+ if (in.GetType() == blink::WebInputEvent::Type::kRawKeyDown)
|
|
|
+ dict.Set("type", "keyDown");
|
|
|
+ else if (in.GetType() == blink::WebInputEvent::Type::kKeyUp)
|
|
|
+ dict.Set("type", "keyUp");
|
|
|
+ dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key));
|
|
|
+ dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString(
|
|
|
+ static_cast<ui::DomCode>(in.dom_code)));
|
|
|
+
|
|
|
+ using Modifiers = blink::WebInputEvent::Modifiers;
|
|
|
+ dict.Set("isAutoRepeat", (in.GetModifiers() & Modifiers::kIsAutoRepeat) != 0);
|
|
|
+ dict.Set("isComposing", (in.GetModifiers() & Modifiers::kIsComposing) != 0);
|
|
|
+ dict.Set("shift", (in.GetModifiers() & Modifiers::kShiftKey) != 0);
|
|
|
+ dict.Set("control", (in.GetModifiers() & Modifiers::kControlKey) != 0);
|
|
|
+ dict.Set("alt", (in.GetModifiers() & Modifiers::kAltKey) != 0);
|
|
|
+ dict.Set("meta", (in.GetModifiers() & Modifiers::kMetaKey) != 0);
|
|
|
+ dict.Set("location", GetKeyLocationCode(in));
|
|
|
+ dict.Set("_modifiers", in.GetModifiers());
|
|
|
+ dict.Set("modifiers", ModifiersToArray(in.GetModifiers()));
|
|
|
+
|
|
|
+ return dict.GetHandle();
|
|
|
+}
|
|
|
+
|
|
|
bool Converter<blink::WebMouseEvent>::FromV8(v8::Isolate* isolate,
|
|
|
v8::Local<v8::Value> val,
|
|
|
blink::WebMouseEvent* out) {
|