Use DOM's way of telling modifiers
This commit is contained in:
parent
625143426a
commit
8d22eeb3be
2 changed files with 28 additions and 7 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "native_mate/constructor.h"
|
#include "native_mate/constructor.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
#include "ui/events/event_constants.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
@ -41,11 +42,24 @@ mate::Wrappable* Tray::New(v8::Isolate* isolate, const gfx::Image& image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
|
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
Emit("clicked", bounds, modifiers);
|
v8::Locker locker(isolate());
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
EmitCustomEvent("clicked",
|
||||||
|
ModifiersToObject(isolate(), modifiers), bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
void Tray::OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
Emit("double-clicked", bounds, modifiers);
|
v8::Locker locker(isolate());
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
EmitCustomEvent("double-clicked",
|
||||||
|
ModifiersToObject(isolate(), modifiers), bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tray::OnRightClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
|
v8::Locker locker(isolate());
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
EmitCustomEvent("right-clicked",
|
||||||
|
ModifiersToObject(isolate(), modifiers), bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnBalloonShow() {
|
void Tray::OnBalloonShow() {
|
||||||
|
@ -60,10 +74,6 @@ void Tray::OnBalloonClosed() {
|
||||||
Emit("balloon-closed");
|
Emit("balloon-closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnRightClicked(const gfx::Rect& bounds, int modifiers) {
|
|
||||||
Emit("right-clicked", bounds, modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tray::OnDropFiles(const std::vector<std::string>& files) {
|
void Tray::OnDropFiles(const std::vector<std::string>& files) {
|
||||||
Emit("drop-files", files);
|
Emit("drop-files", files);
|
||||||
}
|
}
|
||||||
|
@ -120,6 +130,15 @@ void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
|
||||||
tray_icon_->SetContextMenu(menu->model());
|
tray_icon_->SetContextMenu(menu->model());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Object> Tray::ModifiersToObject(v8::Isolate* isolate,
|
||||||
|
int modifiers) {
|
||||||
|
mate::Dictionary obj(isolate, v8::Object::New(isolate));
|
||||||
|
obj.Set("shiftKey", static_cast<bool>(modifiers & ui::EF_SHIFT_DOWN));
|
||||||
|
obj.Set("ctrlKey", static_cast<bool>(modifiers & ui::EF_CONTROL_DOWN));
|
||||||
|
obj.Set("altKey", static_cast<bool>(modifiers & ui::EF_ALT_DOWN));
|
||||||
|
return obj.GetHandle();
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Tray::BuildPrototype(v8::Isolate* isolate,
|
void Tray::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::ObjectTemplate> prototype) {
|
||||||
|
|
|
@ -44,10 +44,10 @@ class Tray : public mate::EventEmitter,
|
||||||
// TrayIconObserver:
|
// TrayIconObserver:
|
||||||
void OnClicked(const gfx::Rect& bounds, int modifiers) override;
|
void OnClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||||
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
|
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||||
|
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||||
void OnBalloonShow() override;
|
void OnBalloonShow() override;
|
||||||
void OnBalloonClicked() override;
|
void OnBalloonClicked() override;
|
||||||
void OnBalloonClosed() override;
|
void OnBalloonClosed() override;
|
||||||
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
|
|
||||||
void OnDropFiles(const std::vector<std::string>& files) override;
|
void OnDropFiles(const std::vector<std::string>& files) override;
|
||||||
|
|
||||||
// mate::Wrappable:
|
// mate::Wrappable:
|
||||||
|
@ -64,6 +64,8 @@ class Tray : public mate::EventEmitter,
|
||||||
void SetContextMenu(mate::Arguments* args, Menu* menu);
|
void SetContextMenu(mate::Arguments* args, Menu* menu);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
v8::Local<v8::Object> ModifiersToObject(v8::Isolate* isolate, int modifiers);
|
||||||
|
|
||||||
scoped_ptr<TrayIcon> tray_icon_;
|
scoped_ptr<TrayIcon> tray_icon_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Tray);
|
DISALLOW_COPY_AND_ASSIGN(Tray);
|
||||||
|
|
Loading…
Reference in a new issue