diff --git a/atom/browser/api/atom_api_tray.cc b/atom/browser/api/atom_api_tray.cc index 0f5829e19c1..0c24240f223 100644 --- a/atom/browser/api/atom_api_tray.cc +++ b/atom/browser/api/atom_api_tray.cc @@ -74,10 +74,26 @@ void Tray::OnBalloonClosed() { Emit("balloon-closed"); } +void Tray::OnDrop() { + Emit("drop"); +} + void Tray::OnDropFiles(const std::vector& files) { Emit("drop-files", files); } +void Tray::OnDragEntered() { + Emit("drag-enter"); +} + +void Tray::OnDragExited() { + Emit("drag-leave"); +} + +void Tray::OnDragEnded() { + Emit("drag-end"); +} + bool Tray::IsDestroyed() const { return !tray_icon_; } diff --git a/atom/browser/api/atom_api_tray.h b/atom/browser/api/atom_api_tray.h index 9a423f61764..d8d6dcead16 100644 --- a/atom/browser/api/atom_api_tray.h +++ b/atom/browser/api/atom_api_tray.h @@ -48,7 +48,11 @@ class Tray : public mate::TrackableObject, void OnBalloonShow() override; void OnBalloonClicked() override; void OnBalloonClosed() override; + void OnDrop() override; void OnDropFiles(const std::vector& files) override; + void OnDragEntered() override; + void OnDragExited() override; + void OnDragEnded() override; // mate::Wrappable: bool IsDestroyed() const override; diff --git a/atom/browser/ui/tray_icon.cc b/atom/browser/ui/tray_icon.cc index d2c6bc1b259..1696aab276b 100644 --- a/atom/browser/ui/tray_icon.cc +++ b/atom/browser/ui/tray_icon.cc @@ -55,8 +55,24 @@ void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds, int modifiers) { OnRightClicked(bounds, modifiers)); } +void TrayIcon::NotifyDrop() { + FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDrop()); +} + void TrayIcon::NotifyDropFiles(const std::vector& files) { FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDropFiles(files)); } +void TrayIcon::NotifyDragEntered() { + FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragEntered()); +} + +void TrayIcon::NotifyDragExited() { + FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragExited()); +} + +void TrayIcon::NotifyDragEnded() { + FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragEnded()); +} + } // namespace atom diff --git a/atom/browser/ui/tray_icon.h b/atom/browser/ui/tray_icon.h index 539fe04f4bb..bc29acd8a25 100644 --- a/atom/browser/ui/tray_icon.h +++ b/atom/browser/ui/tray_icon.h @@ -61,7 +61,11 @@ class TrayIcon { void NotifyBalloonClosed(); void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(), int modifiers = 0); + void NotifyDrop(); void NotifyDropFiles(const std::vector& files); + void NotifyDragEntered(); + void NotifyDragExited(); + void NotifyDragEnded(); protected: TrayIcon(); diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index 34ca4e9a911..c373e94519b 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -254,9 +254,23 @@ const CGFloat kVerticalTitleMargin = 2; } - (NSDragOperation)draggingEntered:(id )sender { + trayIcon_->NotifyDragEntered(); return NSDragOperationCopy; } +- (void)draggingExited:(id )sender { + trayIcon_->NotifyDragExited(); +} + +- (void)draggingEnded:(id )sender { + trayIcon_->NotifyDragEnded(); +} + +- (BOOL)prepareForDragOperation:(id )sender { + trayIcon_->NotifyDrop(); + return YES; +} + - (BOOL)performDragOperation:(id )sender { NSPasteboard* pboard = [sender draggingPasteboard]; diff --git a/atom/browser/ui/tray_icon_observer.h b/atom/browser/ui/tray_icon_observer.h index fa8090d7d6c..ed421ed8545 100644 --- a/atom/browser/ui/tray_icon_observer.h +++ b/atom/browser/ui/tray_icon_observer.h @@ -22,7 +22,11 @@ class TrayIconObserver { virtual void OnBalloonClicked() {} virtual void OnBalloonClosed() {} virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {} + virtual void OnDrop() {} virtual void OnDropFiles(const std::vector& files) {} + virtual void OnDragEntered() {} + virtual void OnDragExited() {} + virtual void OnDragEnded() {} protected: virtual ~TrayIconObserver() {} diff --git a/docs/api/tray.md b/docs/api/tray.md index 528705acb32..47f02c5478f 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -112,6 +112,10 @@ Emitted when the tray balloon is clicked. Emitted when the tray balloon is closed because of timeout or user manually closes it. +### Event: 'drop' _OS X_ + +Emitted when any dragged items are dropped on the tray icon. + ### Event: 'drop-files' _OS X_ * `event` @@ -119,6 +123,18 @@ closes it. Emitted when dragged files are dropped in the tray icon. +### Event: 'drag-enter' _OS X_ + +Emitted when a drag operation enters the tray icon. + +### Event: 'drag-leave' _OS X_ + +Emitted when a drag operation exits the tray icon. + +### Event: 'drag-end' _OS X_ + +Emitted when a drag operation ends on the tray or ends at another location. + ## Methods The `Tray` module has the following methods: