Browse Source

Tray: Add drag-entered and drag-exited events

Nishanth Shanmugham 9 years ago
parent
commit
818892d474

+ 8 - 0
atom/browser/api/atom_api_tray.cc

@@ -78,6 +78,14 @@ void Tray::OnDropFiles(const std::vector<std::string>& files) {
   Emit("drop-files", files);
 }
 
+void Tray::OnDragEntered() {
+  Emit("drag-entered");
+}
+
+void Tray::OnDragExited() {
+  Emit("drag-exited");
+}
+
 bool Tray::IsDestroyed() const {
   return !tray_icon_;
 }

+ 2 - 0
atom/browser/api/atom_api_tray.h

@@ -49,6 +49,8 @@ class Tray : public mate::TrackableObject<Tray>,
   void OnBalloonClicked() override;
   void OnBalloonClosed() override;
   void OnDropFiles(const std::vector<std::string>& files) override;
+  void OnDragEntered() override;
+  void OnDragExited() override;
 
   // mate::Wrappable:
   bool IsDestroyed() const override;

+ 8 - 0
atom/browser/ui/tray_icon.cc

@@ -59,4 +59,12 @@ void TrayIcon::NotifyDropFiles(const std::vector<std::string>& 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());
+}
+
 }  // namespace atom

+ 2 - 0
atom/browser/ui/tray_icon.h

@@ -62,6 +62,8 @@ class TrayIcon {
   void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
                           int modifiers = 0);
   void NotifyDropFiles(const std::vector<std::string>& files);
+  void TrayIcon::NotifyDragEntered();
+  void TrayIcon::NotifyDragExited();
 
  protected:
   TrayIcon();

+ 5 - 0
atom/browser/ui/tray_icon_cocoa.mm

@@ -254,9 +254,14 @@ const CGFloat kVerticalTitleMargin = 2;
 }
 
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
+  trayIcon_->NotifyDragEntered();
   return NSDragOperationCopy;
 }
 
+- (void)draggingExited:(id <NSDraggingInfo>)sender {
+  trayIcon_->NotifyDragExited();
+}
+
 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
   NSPasteboard* pboard = [sender draggingPasteboard];
 

+ 2 - 0
atom/browser/ui/tray_icon_observer.h

@@ -23,6 +23,8 @@ class TrayIconObserver {
   virtual void OnBalloonClosed() {}
   virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {}
   virtual void OnDropFiles(const std::vector<std::string>& files) {}
+  virtual void OnDragEntered() {}
+  virtual void OnDragExited() {}
 
  protected:
   virtual ~TrayIconObserver() {}