diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 67c7e7e95fd8..a723df1ea940 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -9,6 +9,7 @@ #include "atom/common/keyboad_util.h" #include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" #include "content/public/browser/native_web_keyboard_event.h" #include "native_mate/dictionary.h" #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" @@ -29,10 +30,10 @@ int VectorToBitArray(const std::vector& vec) { namespace mate { template<> -struct Converter { +struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Handle val, - char* out) { - std::string code = base::StringToLowerASCII(V8ToString(val)); + base::char16* out) { + base::string16 code = base::UTF8ToUTF16(V8ToString(val)); if (code.length() != 1) return false; *out = code[0]; @@ -77,6 +78,21 @@ struct Converter { } }; +template<> +struct Converter { + static bool FromV8(v8::Isolate* isolate, v8::Handle val, + blink::WebMouseEvent::Button* out) { + std::string button = base::StringToLowerASCII(V8ToString(val)); + if (button == "left") + *out = blink::WebMouseEvent::Button::ButtonLeft; + else if (button == "middle") + *out = blink::WebMouseEvent::Button::ButtonMiddle; + else if (button == "right") + *out = blink::WebMouseEvent::Button::ButtonRight; + return true; + } +}; + template<> struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Handle val, @@ -142,16 +158,19 @@ bool Converter::FromV8( return false; if (!ConvertFromV8(isolate, val, static_cast(out))) return false; - char code; + base::char16 code; if (!dict.Get("keyCode", &code)) return false; bool shifted = false; out->windowsKeyCode = atom::KeyboardCodeFromCharCode(code, &shifted); - if (out->windowsKeyCode == ui::VKEY_UNKNOWN) - return false; if (shifted) out->modifiers |= blink::WebInputEvent::ShiftKey; out->setKeyIdentifierFromWindowsKeyCode(); + if (out->type == blink::WebInputEvent::Char + || out->type == blink::WebInputEvent::RawKeyDown) { + out->text[0] = code; + out->unmodifiedText[0] = code; + } return true; } @@ -176,6 +195,7 @@ bool Converter::FromV8( return false; if (!dict.Get("x", &out->x) || !dict.Get("y", &out->y)) return false; + dict.Get("button", &out->button); dict.Get("globalX", &out->globalX); dict.Get("globalY", &out->globalY); dict.Get("movementX", &out->movementX); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index c2dccc3a876c..b2e924e5d083 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -534,13 +534,13 @@ Sends an input `event` to the page. For keyboard events, the `event` object also have following properties: * `keyCode` String (**required**) - A single character that will be sent as - keyboard event. Can be any ASCII character on the keyboard, like `a`, `1` - and `=`. + keyboard event. Can be any UTF-8 character. For mouse events, the `event` object also have following properties: * `x` Integer (**required**) * `y` Integer (**required**) +* `button` String - The button pressed, can be `left`, `middle`, `right` * `globalX` Integer * `globalY` Integer * `movementX` Integer