9
9
10
10
#include " atom/common/keyboad_util.h"
11
11
#include " base/strings/string_util.h"
12
+ #include " base/strings/utf_string_conversions.h"
12
13
#include " content/public/browser/native_web_keyboard_event.h"
13
14
#include " native_mate/dictionary.h"
14
15
#include " third_party/WebKit/public/web/WebDeviceEmulationParams.h"
@@ -29,10 +30,10 @@ int VectorToBitArray(const std::vector<T>& vec) {
29
30
namespace mate {
30
31
31
32
template <>
32
- struct Converter <char > {
33
+ struct Converter <base::char16 > {
33
34
static bool FromV8 (v8::Isolate* isolate, v8::Handle <v8::Value> val,
34
- char * out) {
35
- std::string code = base::StringToLowerASCII (V8ToString (val));
35
+ base::char16 * out) {
36
+ base::string16 code = base::UTF8ToUTF16 (V8ToString (val));
36
37
if (code.length () != 1 )
37
38
return false ;
38
39
*out = code[0 ];
@@ -77,6 +78,21 @@ struct Converter<blink::WebInputEvent::Type> {
77
78
}
78
79
};
79
80
81
+ template <>
82
+ struct Converter <blink::WebMouseEvent::Button> {
83
+ static bool FromV8 (v8::Isolate* isolate, v8::Handle <v8::Value> val,
84
+ blink::WebMouseEvent::Button* out) {
85
+ std::string button = base::StringToLowerASCII (V8ToString (val));
86
+ if (button == " left" )
87
+ *out = blink::WebMouseEvent::Button ::ButtonLeft;
88
+ else if (button == " middle" )
89
+ *out = blink::WebMouseEvent::Button ::ButtonMiddle;
90
+ else if (button == " right" )
91
+ *out = blink::WebMouseEvent::Button ::ButtonRight;
92
+ return true ;
93
+ }
94
+ };
95
+
80
96
template <>
81
97
struct Converter <blink::WebInputEvent::Modifiers> {
82
98
static bool FromV8 (v8::Isolate* isolate, v8::Handle <v8::Value> val,
@@ -142,16 +158,19 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(
142
158
return false ;
143
159
if (!ConvertFromV8 (isolate, val, static_cast <blink::WebInputEvent*>(out)))
144
160
return false ;
145
- char code;
161
+ base::char16 code;
146
162
if (!dict.Get (" keyCode" , &code))
147
163
return false ;
148
164
bool shifted = false ;
149
165
out->windowsKeyCode = atom::KeyboardCodeFromCharCode (code, &shifted);
150
- if (out->windowsKeyCode == ui::VKEY_UNKNOWN)
151
- return false ;
152
166
if (shifted)
153
167
out->modifiers |= blink::WebInputEvent::ShiftKey;
154
168
out->setKeyIdentifierFromWindowsKeyCode ();
169
+ if (out->type == blink::WebInputEvent::Char
170
+ || out->type == blink::WebInputEvent::RawKeyDown) {
171
+ out->text [0 ] = code;
172
+ out->unmodifiedText [0 ] = code;
173
+ }
155
174
return true ;
156
175
}
157
176
@@ -176,6 +195,7 @@ bool Converter<blink::WebMouseEvent>::FromV8(
176
195
return false ;
177
196
if (!dict.Get (" x" , &out->x ) || !dict.Get (" y" , &out->y ))
178
197
return false ;
198
+ dict.Get (" button" , &out->button );
179
199
dict.Get (" globalX" , &out->globalX );
180
200
dict.Get (" globalY" , &out->globalY );
181
201
dict.Get (" movementX" , &out->movementX );
0 commit comments