Merge pull request #3354 from nishanths/master

Add drag-entered and drag-exited events to Tray
This commit is contained in:
Cheng Zhao 2015-11-11 22:44:05 +08:00
commit 0a5b234e3d
7 changed files with 74 additions and 0 deletions

View file

@ -74,10 +74,26 @@ void Tray::OnBalloonClosed() {
Emit("balloon-closed"); Emit("balloon-closed");
} }
void Tray::OnDrop() {
Emit("drop");
}
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);
} }
void Tray::OnDragEntered() {
Emit("drag-enter");
}
void Tray::OnDragExited() {
Emit("drag-leave");
}
void Tray::OnDragEnded() {
Emit("drag-end");
}
bool Tray::IsDestroyed() const { bool Tray::IsDestroyed() const {
return !tray_icon_; return !tray_icon_;
} }

View file

@ -48,7 +48,11 @@ class Tray : public mate::TrackableObject<Tray>,
void OnBalloonShow() override; void OnBalloonShow() override;
void OnBalloonClicked() override; void OnBalloonClicked() override;
void OnBalloonClosed() override; void OnBalloonClosed() override;
void OnDrop() override;
void OnDropFiles(const std::vector<std::string>& files) override; void OnDropFiles(const std::vector<std::string>& files) override;
void OnDragEntered() override;
void OnDragExited() override;
void OnDragEnded() override;
// mate::Wrappable: // mate::Wrappable:
bool IsDestroyed() const override; bool IsDestroyed() const override;

View file

@ -55,8 +55,24 @@ void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds, int modifiers) {
OnRightClicked(bounds, modifiers)); OnRightClicked(bounds, modifiers));
} }
void TrayIcon::NotifyDrop() {
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDrop());
}
void TrayIcon::NotifyDropFiles(const std::vector<std::string>& files) { void TrayIcon::NotifyDropFiles(const std::vector<std::string>& files) {
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDropFiles(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 } // namespace atom

View file

@ -61,7 +61,11 @@ class TrayIcon {
void NotifyBalloonClosed(); void NotifyBalloonClosed();
void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(), void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
int modifiers = 0); int modifiers = 0);
void NotifyDrop();
void NotifyDropFiles(const std::vector<std::string>& files); void NotifyDropFiles(const std::vector<std::string>& files);
void NotifyDragEntered();
void NotifyDragExited();
void NotifyDragEnded();
protected: protected:
TrayIcon(); TrayIcon();

View file

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

View file

@ -22,7 +22,11 @@ class TrayIconObserver {
virtual void OnBalloonClicked() {} virtual void OnBalloonClicked() {}
virtual void OnBalloonClosed() {} virtual void OnBalloonClosed() {}
virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {} virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {}
virtual void OnDrop() {}
virtual void OnDropFiles(const std::vector<std::string>& files) {} virtual void OnDropFiles(const std::vector<std::string>& files) {}
virtual void OnDragEntered() {}
virtual void OnDragExited() {}
virtual void OnDragEnded() {}
protected: protected:
virtual ~TrayIconObserver() {} virtual ~TrayIconObserver() {}

View file

@ -112,6 +112,10 @@ Emitted when the tray balloon is clicked.
Emitted when the tray balloon is closed because of timeout or user manually Emitted when the tray balloon is closed because of timeout or user manually
closes it. closes it.
### Event: 'drop' _OS X_
Emitted when any dragged items are dropped on the tray icon.
### Event: 'drop-files' _OS X_ ### Event: 'drop-files' _OS X_
* `event` * `event`
@ -119,6 +123,18 @@ closes it.
Emitted when dragged files are dropped in the tray icon. 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 ## Methods
The `Tray` module has the following methods: The `Tray` module has the following methods: