Key event sending update.

This commit is contained in:
Heilig Benedek 2015-09-02 02:33:40 +02:00
parent 3dd3fd9200
commit dbcd0a4235
7 changed files with 77 additions and 12 deletions

View 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);

View 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){

View 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);

View 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";

View 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";

View 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[];

View 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.