]> khamidou — GitHub mirrors - electron.git/commitdiff
Adding option to specify the button of WebMouseEvent.
authorHeilig Benedek <benecene@gmail.com>
Fri, 25 Sep 2015 11:01:52 +0000 (13:01 +0200)
committerHeilig Benedek <benecene@gmail.com>
Fri, 25 Sep 2015 11:01:52 +0000 (13:01 +0200)
atom/common/native_mate_converters/blink_converter.cc

index 67c7e7e95fd8f0b09ecfeb87dd0ff993958d9a58..beb60737e73fb4d114e2c1d77afc77dcd35a0545 100644 (file)
@@ -77,6 +77,21 @@ struct Converter<blink::WebInputEvent::Type> {
   }
 };
 
+template<>
+struct Converter<blink::WebMouseEvent::Button> {
+  static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> 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<blink::WebInputEvent::Modifiers> {
   static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
@@ -176,6 +191,7 @@ bool Converter<blink::WebMouseEvent>::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);