Changed StringArray options to regular js objects with boolean values for better readability from the js side

This commit is contained in:
Heilig Benedek 2015-09-10 02:10:47 +02:00
parent dbcd0a4235
commit b2af370249
6 changed files with 139 additions and 80 deletions

View file

@ -528,10 +528,10 @@ void Window::SendKeyboardEvent(v8::Isolate* isolate, const mate::Dictionary& dat
int keycode = 0; int keycode = 0;
int native = 0; int native = 0;
std::string type_str = ""; std::string type_str = "";
std::vector<std::string> modifier_array; mate::Dictionary modifier_list = mate::Dictionary::CreateEmpty(isolate);
data.Get(switches::kEventType, &type_str); data.Get(switches::kEventType, &type_str);
data.Get(switches::kModifiers, &modifier_array); data.Get(switches::kModifiers, &modifier_list);
data.Get(switches::kKeyCode, &keycode); data.Get(switches::kKeyCode, &keycode);
data.Get(switches::kNativeKeyCode, &native); data.Get(switches::kNativeKeyCode, &native);
@ -543,28 +543,22 @@ void Window::SendKeyboardEvent(v8::Isolate* isolate, const mate::Dictionary& dat
type = blink::WebInputEvent::Type::Char; type = blink::WebInputEvent::Type::Char;
} }
for(std::vector<std::string>::iterator mod = modifier_array.begin(); mod != modifier_array.end(); ++mod) { std::map<std::string, bool> modifier_types;
if(mod->compare(event_types::kModifierIsKeyPad) == 0){ modifier_types[event_types::kModifierIsKeyPad] = false;
modifiers = modifiers & blink::WebInputEvent::Modifiers::IsKeyPad; modifier_types[event_types::kModifierIsAutoRepeat] = false;
}else if(mod->compare(event_types::kModifierIsAutoRepeat) == 0){ modifier_types[event_types::kModifierIsLeft] = false;
modifiers = modifiers & blink::WebInputEvent::Modifiers::IsAutoRepeat; modifier_types[event_types::kModifierIsRight] = false;
}else if(mod->compare(event_types::kModifierIsLeft) == 0){ modifier_types[event_types::kModifierShiftKey] = false;
modifiers = modifiers & blink::WebInputEvent::Modifiers::IsLeft; modifier_types[event_types::kModifierControlKey] = false;
}else if(mod->compare(event_types::kModifierIsRight) == 0){ modifier_types[event_types::kModifierAltKey] = false;
modifiers = modifiers & blink::WebInputEvent::Modifiers::IsRight; modifier_types[event_types::kModifierMetaKey] = false;
}else if(mod->compare(event_types::kModifierShiftKey) == 0){ modifier_types[event_types::kModifierCapsLockOn] = false;
modifiers = modifiers & blink::WebInputEvent::Modifiers::ShiftKey; modifier_types[event_types::kModifierNumLockOn] = false;
}else if(mod->compare(event_types::kModifierControlKey) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::ControlKey; for(std::map<std::string, bool>::iterator it = modifier_types.begin(); it != modifier_types.end(); ++it){
}else if(mod->compare(event_types::kModifierAltKey) == 0){ modifier_list.Get(it->first,&(it->second));
modifiers = modifiers & blink::WebInputEvent::Modifiers::AltKey;
}else if(mod->compare(event_types::kModifierMetaKey) == 0){ if(it->second) modifiers = modifiers & event_types::modifierStrToWebModifier(it->first);
modifiers = modifiers & blink::WebInputEvent::Modifiers::MetaKey;
}else if(mod->compare(event_types::kModifierCapsLockOn) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::CapsLockOn;
}else if(mod->compare(event_types::kModifierNumLockOn) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::NumLockOn;
}
} }
window_->SendKeyboardEvent(type, modifiers, keycode, native); window_->SendKeyboardEvent(type, modifiers, keycode, native);
@ -574,7 +568,7 @@ void Window::SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data){
int x, y, movementX, movementY, clickCount; int x, y, movementX, movementY, clickCount;
std::string type_str = ""; std::string type_str = "";
std::string button_str = ""; std::string button_str = "";
std::vector<std::string> modifier_array; mate::Dictionary modifier_list = mate::Dictionary::CreateEmpty(isolate);
blink::WebInputEvent::Type type = blink::WebInputEvent::Type::MouseMove; blink::WebInputEvent::Type type = blink::WebInputEvent::Type::MouseMove;
blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::ButtonNone; blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::ButtonNone;
@ -582,7 +576,7 @@ void Window::SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data){
data.Get(switches::kEventType, &type_str); data.Get(switches::kEventType, &type_str);
data.Get(switches::kMouseEventButton, &button_str); data.Get(switches::kMouseEventButton, &button_str);
data.Get(switches::kModifiers, &modifier_array); data.Get(switches::kModifiers, &modifier_list);
if(type_str.compare(event_types::kMouseDown) == 0){ if(type_str.compare(event_types::kMouseDown) == 0){
type = blink::WebInputEvent::Type::MouseDown; type = blink::WebInputEvent::Type::MouseDown;
@ -600,37 +594,24 @@ void Window::SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data){
type = blink::WebInputEvent::Type::MouseWheel; type = blink::WebInputEvent::Type::MouseWheel;
} }
if(button_str.compare(event_types::kMouseLeftButton) == 0){ std::map<std::string, bool> modifier_types;
modifiers = modifiers & blink::WebInputEvent::Modifiers::LeftButtonDown; modifier_types[event_types::kMouseLeftButton] = false;
button = blink::WebMouseEvent::Button::ButtonLeft; modifier_types[event_types::kMouseRightButton] = false;
}else if(button_str.compare(event_types::kMouseRightButton) == 0){ modifier_types[event_types::kMouseMiddleButton] = false;
modifiers = modifiers & blink::WebInputEvent::Modifiers::RightButtonDown; modifier_types[event_types::kModifierLeftButtonDown] = false;
button = blink::WebMouseEvent::Button::ButtonRight; modifier_types[event_types::kModifierMiddleButtonDown] = false;
}else if(button_str.compare(event_types::kMouseMiddleButton) == 0){ modifier_types[event_types::kModifierRightButtonDown] = false;
modifiers = modifiers & blink::WebInputEvent::Modifiers::MiddleButtonDown; modifier_types[event_types::kModifierShiftKey] = false;
button = blink::WebMouseEvent::Button::ButtonMiddle; modifier_types[event_types::kModifierControlKey] = false;
} modifier_types[event_types::kModifierAltKey] = false;
modifier_types[event_types::kModifierMetaKey] = false;
modifier_types[event_types::kModifierCapsLockOn] = false;
modifier_types[event_types::kModifierNumLockOn] = false;
for(std::vector<std::string>::iterator mod = modifier_array.begin(); mod != modifier_array.end(); ++mod) { for(std::map<std::string, bool>::iterator it = modifier_types.begin(); it != modifier_types.end(); ++it){
if(mod->compare(event_types::kModifierLeftButtonDown) == 0){ modifier_list.Get(it->first,&(it->second));
modifiers = modifiers & blink::WebInputEvent::Modifiers::LeftButtonDown;
}else if(mod->compare(event_types::kModifierMiddleButtonDown) == 0){ if(it->second) modifiers = modifiers & event_types::modifierStrToWebModifier(it->first);
modifiers = modifiers & blink::WebInputEvent::Modifiers::MiddleButtonDown;
}else if(mod->compare(event_types::kModifierRightButtonDown) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::RightButtonDown;
}else if(mod->compare(event_types::kModifierShiftKey) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::ShiftKey;
}else if(mod->compare(event_types::kModifierControlKey) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::ControlKey;
}else if(mod->compare(event_types::kModifierAltKey) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::AltKey;
}else if(mod->compare(event_types::kModifierMetaKey) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::MetaKey;
}else if(mod->compare(event_types::kModifierCapsLockOn) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::CapsLockOn;
}else if(mod->compare(event_types::kModifierNumLockOn) == 0){
modifiers = modifiers & blink::WebInputEvent::Modifiers::NumLockOn;
}
} }
if(type == blink::WebInputEvent::Type::MouseWheel){ if(type == blink::WebInputEvent::Type::MouseWheel){

View file

@ -332,6 +332,7 @@ class NativeWindow : public content::WebContentsObserver,
DISALLOW_COPY_AND_ASSIGN(NativeWindow); DISALLOW_COPY_AND_ASSIGN(NativeWindow);
}; };
//This class provides a way to listen to frame renders and to use the rendered frames for offscreen rendering
class RenderSubscriber : public content::RenderWidgetHostViewFrameSubscriber { class RenderSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
public: public:
RenderSubscriber(gfx::Size size, base::Callback<void(bool, scoped_refptr<media::VideoFrame>)> callback) : size_(size), callback_(callback) {} RenderSubscriber(gfx::Size size, base::Callback<void(bool, scoped_refptr<media::VideoFrame>)> callback) : size_(size), callback_(callback) {}

View file

@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "atom/common/event_types.h" #include "atom/common/event_types.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace atom { namespace atom {
@ -40,6 +41,78 @@ const char kModifierIsAutoRepeat[] = "auto-repeat";
const char kModifierIsLeft[] = "left"; const char kModifierIsLeft[] = "left";
const char kModifierIsRight[] = "right"; const char kModifierIsRight[] = "right";
} // namespace switches int modifierStrToWebModifier(std::string modifier){
if(modifier.compare(event_types::kModifierLeftButtonDown) == 0){
return blink::WebInputEvent::Modifiers::LeftButtonDown;
}else if(modifier.compare(event_types::kModifierMiddleButtonDown) == 0){
return blink::WebInputEvent::Modifiers::MiddleButtonDown;
}else if(modifier.compare(event_types::kModifierRightButtonDown) == 0){
return blink::WebInputEvent::Modifiers::RightButtonDown;
}else if(modifier.compare(event_types::kMouseLeftButton) == 0){
return blink::WebInputEvent::Modifiers::LeftButtonDown;
}else if(modifier.compare(event_types::kMouseRightButton) == 0){
return blink::WebInputEvent::Modifiers::RightButtonDown;
}else if(modifier.compare(event_types::kMouseMiddleButton) == 0){
return blink::WebInputEvent::Modifiers::MiddleButtonDown;
}else if(modifier.compare(event_types::kModifierIsKeyPad) == 0){
return blink::WebInputEvent::Modifiers::IsKeyPad;
}else if(modifier.compare(event_types::kModifierIsAutoRepeat) == 0){
return blink::WebInputEvent::Modifiers::IsAutoRepeat;
}else if(modifier.compare(event_types::kModifierIsLeft) == 0){
return blink::WebInputEvent::Modifiers::IsLeft;
}else if(modifier.compare(event_types::kModifierIsRight) == 0){
return blink::WebInputEvent::Modifiers::IsRight;
}else if(modifier.compare(event_types::kModifierShiftKey) == 0){
return blink::WebInputEvent::Modifiers::ShiftKey;
}else if(modifier.compare(event_types::kModifierControlKey) == 0){
return blink::WebInputEvent::Modifiers::ControlKey;
}else if(modifier.compare(event_types::kModifierAltKey) == 0){
return blink::WebInputEvent::Modifiers::AltKey;
}else if(modifier.compare(event_types::kModifierMetaKey) == 0){
return blink::WebInputEvent::Modifiers::MetaKey;
}else if(modifier.compare(event_types::kModifierCapsLockOn) == 0){
return blink::WebInputEvent::Modifiers::CapsLockOn;
}else if(modifier.compare(event_types::kModifierNumLockOn) == 0){
return blink::WebInputEvent::Modifiers::NumLockOn;
}else{
return 0;
}
}
} // namespace event_types
} // namespace atom } // namespace atom

View file

@ -5,6 +5,8 @@
#ifndef ATOM_COMMON_EVENT_TYPES_H_ #ifndef ATOM_COMMON_EVENT_TYPES_H_
#define ATOM_COMMON_EVENT_TYPES_H_ #define ATOM_COMMON_EVENT_TYPES_H_
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace atom { namespace atom {
namespace event_types { namespace event_types {
@ -41,7 +43,9 @@ extern const char kModifierIsAutoRepeat[];
extern const char kModifierIsLeft[]; extern const char kModifierIsLeft[];
extern const char kModifierIsRight[]; extern const char kModifierIsRight[];
} // namespace switches int modifierStrToWebModifier(std::string modifier);
} // namespace event_types
} // namespace atom } // namespace atom

View file

@ -759,16 +759,16 @@ Sends a mouse event to the BrowserWindow.
* `middle` String - The middle button was pressed. * `middle` String - The middle button was pressed.
* `click-count` Integer - The number of clicks associated with the mouse event. * `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. * `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. * `modifiers` Object - The modifier values associated with the event.
* `left-button-down` String - The left mouse button was pressed. * `left-button-down` Boolean - The left mouse button was pressed.
* `middle-button-down` String - The right mouse button was pressed. * `middle-button-down` Boolean - The right mouse button was pressed.
* `right-button-down` String - The middle mouse button was pressed. * `right-button-down` Boolean - The middle mouse button was pressed.
* `shift` String - The shift key was pressed. * `shift` Boolean - The shift key was pressed.
* `control` String - The control key was pressed. * `control` Boolean - The control key was pressed.
* `alt` String - The alt key was pressed. * `alt` Boolean - The alt key was pressed.
* `meta` String - The meta key was pressed. * `meta` Boolean - The meta key was pressed.
* `caps-lock` String - The caps-lock key was pressed. * `caps-lock` Boolean - The caps-lock key was on.
* `num-lock` String - The num-lock key was pressed. * `num-lock` Boolean - The num-lock key was on.
### BrowserWindow.sendKeyboardEvent(options) ### BrowserWindow.sendKeyboardEvent(options)
@ -780,17 +780,17 @@ Sends a keyboard event to the BrowserWindow.
* `char` String - Character event. * `char` String - Character event.
* `code` Integer - The key code of the key that generated the 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. * `native` Integer - The native key code of the key that generated the event.
* `modifiers` Array of Strings - The modifier values associated with the event. * `modifiers` Object - The modifier values associated with the event.
* `keypad` String - Sets the `IsKeyPad` option of the event. * `keypad` Boolean - Sets the `IsKeyPad` option of the event.
* `auto-repeat` String - Sets the `IsAutoRepeat` option of the event. * `auto-repeat` Boolean - Sets the `IsAutoRepeat` option of the event.
* `left` String - Sets the `IsLeft` option of the event. * `left` Boolean - Sets the `IsLeft` option of the event.
* `right` String - Sets the `IsRight` option of the event. * `right` Boolean - Sets the `IsRight` option of the event.
* `shift` String - The shift key was pressed. * `shift` Boolean - The shift key was pressed.
* `control` String - The control key was pressed. * `control` Boolean - The control key was pressed.
* `alt` String - The alt key was pressed. * `alt` Boolean - The alt key was pressed.
* `meta` String - The meta key was pressed. * `meta` Boolean - The meta key was pressed.
* `caps-lock` String - The caps-lock key was pressed. * `caps-lock` Boolean - The caps-lock key was on.
* `num-lock` String - The num-lock key was pressed. * `num-lock` Boolean - The num-lock key was on.
## Class: WebContents ## Class: WebContents

2
vendor/native_mate vendored

@ -1 +1 @@
Subproject commit 31b6395d9938558ea39a77ef2f432beaf2dcd4cb Subproject commit c71b1694e51fe62f646a0e92e39329d8ab569d5c