]> khamidou — GitHub mirrors - electron.git/commitdiff
Key event sending update.
authorHeilig Benedek <benecene@gmail.com>
Wed, 2 Sep 2015 00:33:40 +0000 (02:33 +0200)
committerHeilig Benedek <benecene@gmail.com>
Wed, 2 Sep 2015 00:33:40 +0000 (02:33 +0200)
atom/browser/api/atom_api_window.cc
atom/browser/native_window.cc
atom/browser/native_window.h
atom/common/event_types.cc
atom/common/options_switches.cc
atom/common/options_switches.h
docs/api/browser-window.md

index 7ee19783b0f275fc43f26ea408673712c77cc512..3c523f8ccdb4a43516cf12058977de41ad23c95e 100644 (file)
@@ -526,12 +526,14 @@ void Window::SendKeyboardEvent(v8::Isolate* isolate, const mate::Dictionary& dat
   auto type = blink::WebInputEvent::Type::Char;
   int modifiers = 0;
   int keycode = 0;
+  int native = 0;
   std::string type_str = "";
   std::vector<std::string> modifier_array;
 
-  data.Get(switches::kMouseEventType, &type_str);
+  data.Get(switches::kEventType, &type_str);
   data.Get(switches::kModifiers, &modifier_array);
   data.Get(switches::kKeyCode, &keycode);
+  data.Get(switches::kNativeKeyCode, &native);
 
   if(type_str.compare(event_types::kKeyDown) == 0){
     type = blink::WebInputEvent::Type::KeyDown;
@@ -565,7 +567,7 @@ void Window::SendKeyboardEvent(v8::Isolate* isolate, const mate::Dictionary& dat
     }
   }
 
-  window_->SendKeyboardEvent(type, modifiers, keycode);
+  window_->SendKeyboardEvent(type, modifiers, keycode, native);
 }
 
 void Window::SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data){
@@ -578,7 +580,7 @@ void Window::SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data){
   blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::ButtonNone;
   int modifiers = 0;
 
-  data.Get(switches::kMouseEventType, &type_str);
+  data.Get(switches::kEventType, &type_str);
   data.Get(switches::kMouseEventButton, &button_str);
   data.Get(switches::kModifiers, &modifier_array);
 
index f28a3a8bd41ff18eb943a6cb63bc2bbf14ab7b72..a9e0631489a8710bfc6bfa26d0a0797dfa9b7824 100644 (file)
@@ -47,6 +47,7 @@
 #include "ui/gfx/geometry/size.h"
 #include "ui/gfx/screen.h"
 #include "ui/gl/gpu_switching_manager.h"
+#include "ui/events/event.h"
 
 #if defined(OS_WIN)
 #include "ui/gfx/switches.h"
@@ -572,10 +573,10 @@ void NativeWindow::DevToolsClosed() {
   FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsClosed());
 }
 
-void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode){
+void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode, int nativeKeycode){
   auto keyb_event = new content::NativeWebKeyboardEvent;
 
-  keyb_event->nativeKeyCode = keycode;
+  keyb_event->nativeKeyCode = nativeKeycode;
   keyb_event->windowsKeyCode = keycode;
   keyb_event->setKeyIdentifierFromWindowsKeyCode();
   keyb_event->type = type;
@@ -584,7 +585,7 @@ void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifi
   keyb_event->timeStampSeconds = base::Time::Now().ToDoubleT();
   keyb_event->skip_in_browser = false;
 
-  if (type == blink::WebInputEvent::Char || type == blink::WebInputEvent::KeyDown) {
+  if (type == blink::WebInputEvent::Char || type == blink::WebInputEvent::RawKeyDown) {
     keyb_event->text[0] = keycode;
     keyb_event->unmodifiedText[0] = keycode;
   }
@@ -592,6 +593,11 @@ void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifi
   const auto view = web_contents()->GetRenderWidgetHostView();
   const auto host = view ? view->GetRenderWidgetHost() : nullptr;
   host->ForwardKeyboardEvent(*keyb_event);
+
+  if(keyb_event->type == blink::WebInputEvent::Type::KeyDown){
+    keyb_event->type = blink::WebInputEvent::RawKeyDown;
+    host->ForwardKeyboardEvent(*keyb_event);
+  }
 }
 
 void NativeWindow::SendMouseEvent(blink::WebInputEvent::Type type, int modifiers, blink::WebMouseEvent::Button button, int x, int y, int movementX, int movementY, int clickCount){
index 8cc1d2ff2b9a0b932eececf0e978928b5211177f..d361fcf696321813181d70f111f73720ccf8e814 100644 (file)
@@ -238,7 +238,7 @@ class NativeWindow : public content::WebContentsObserver,
 
   void OnFrameReceived(bool result, scoped_refptr<media::VideoFrame> frame);
 
-  void SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode);
+  void SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode, int nativeKeycode);
   void SendMouseEvent(blink::WebInputEvent::Type type, int modifiers, blink::WebMouseEvent::Button button, int x, int y, int movementX, int movementY, int clickCount);
   void SendMouseWheelEvent(int modifiers, int x, int y, bool clickCount);
 
index dd87783e68bd5fcc1dbdab1d71ec72c56a1cc35e..3d3b901ed3ccd224e3b048434f0dc228886d8127 100644 (file)
@@ -16,8 +16,8 @@ const char kMouseLeave[] = "leave";
 const char kContextMenu[] = "context-menu";
 const char kMouseWheel[] = "wheel";
 
-const char kKeyDown[] = "key-down";
-const char kKeyUp[] = "key-up";
+const char kKeyDown[] = "down";
+const char kKeyUp[] = "up";
 const char kChar[] = "char";
 
 const char kMouseLeftButton[] = "left";
index ee70080ae6ae13e5d20af516758761530754b0c2..b47e801c41b7cf0a3dbe7dbfa4d03bfe7c3a8e81 100644 (file)
@@ -113,12 +113,13 @@ const char kAppUserModelId[] = "app-user-model-id";
 const char kOffScreenRender[] = "offscreen-render";
 
 const char kModifiers[] = "modifiers";
-const char kKeyCode[] = "keycode";
+const char kKeyCode[] = "code";
+const char kNativeKeyCode[] = "native";
 
 const char kMovementX[] = "movement-x";
 const char kMovementY[] = "movement-y";
 const char kClickCount[] = "click-count";
-const char kMouseEventType[] = "type";
+const char kEventType[] = "type";
 const char kMouseEventButton[] = "button";
 const char kMouseWheelPrecise[] = "precise";
 
index 505305deb49c9b414dfe0c6523bb2133b44661aa..062ee68466260658017c1a990ab698d70e1dbbe7 100644 (file)
@@ -64,11 +64,12 @@ extern const char kOffScreenRender[];
 
 extern const char kModifiers[];
 extern const char kKeyCode[];
+extern const char kNativeKeyCode[];
 
 extern const char kMovementX[];
 extern const char kMovementY[];
 extern const char kClickCount[];
-extern const char kMouseEventType[];
+extern const char kEventType[];
 extern const char kMouseEventButton[];
 extern const char kMouseWheelPrecise[];
 
index f0b8abc2792f06501082e309a1f3dfbab89cf934..217844897aff59fb855c7840e6a510dafd32ee30 100644 (file)
@@ -737,6 +737,61 @@ Returns whether the window is visible on all workspaces.
 Sets the offscreen rendering, if `true` the `frame-rendered` event will fire,
 when the frame changes.
 
+### BrowserWindow.sendMouseEvent(options)
+
+Sends a mouse event to the BrowserWindow.
+* `options` Object
+  * `type` String - The type of the mouse event.
+    * `down` String - Mouse down event.
+    * `up` String -  Mouse up event.
+    * `move` String - Mouse move event.
+    * `enter` String - Mouse enter event.
+    * `leave` String - Mouse leave event.
+    * `context-menu` String - Context menu event.
+    * `wheel` String - Mouse wheel event.
+  * `x` Integer - The x component of the location of the mouse event.
+  * `y` Integer - The y component of the location of the mouse event.
+  * `movement-x` Integer - The x component of the mouse movement since the last event.
+  * `movement-y` Integer - The y component of the mouse movement since the last event.
+  * `button` String - The mouse button associated with the mouse event. Also sets the associated modifier values on the event.
+    * `left` String - The left button was pressed.
+    * `right` String - The right button was pressed.
+    * `middle` String - The middle button was pressed.
+  * `click-count` Integer - The number of clicks associated with the mouse event.
+  * `precise` Boolean - For the `wheel` event type, this option sets the `hasPreciseScrollingDeltas` option of the event.
+  * `modifiers` Array of Strings - The modifier values associated with the event.
+    * `left-button-down` String - The left mouse button was pressed.
+    * `middle-button-down` String - The right mouse button was pressed.
+    * `right-button-down` String - The middle mouse button was pressed.
+    * `shift` String - The shift key was pressed.
+    * `control` String - The control key was pressed.
+    * `alt` String - The alt key was pressed.
+    * `meta` String - The meta key was pressed.
+    * `caps-lock` String - The caps-lock key was pressed.
+    * `num-lock` String - The num-lock key was pressed.
+
+### BrowserWindow.sendKeyboardEvent(options)
+
+Sends a keyboard event to the BrowserWindow.
+* `options` Object
+  * `type` String - The type of the keyboard event.
+    * `down` String - Key down event.
+    * `up` String -  Key up event.
+    * `char` String - Character event.
+  * `code` Integer - The key code of the key that generated the event.
+  * `native` Integer - The native key code of the key that generated the event.
+  * `modifiers` Array of Strings - The modifier values associated with the event.
+    * `keypad` String - Sets the `IsKeyPad` option of the event.
+    * `auto-repeat` String - Sets the `IsAutoRepeat` option of the event.
+    * `left` String - Sets the `IsLeft` option of the event.
+    * `right` String - Sets the `IsRight` option of the event.
+    * `shift` String - The shift key was pressed.
+    * `control` String - The control key was pressed.
+    * `alt` String - The alt key was pressed.
+    * `meta` String - The meta key was pressed.
+    * `caps-lock` String - The caps-lock key was pressed.
+    * `num-lock` String - The num-lock key was pressed.
+
 ## Class: WebContents
 
 A `WebContents` is responsible for rendering and controlling a web page.