add mouse-enter and mouse-exit events for tray
This commit is contained in:
parent
a6ea316a5d
commit
8dbb8ccbab
7 changed files with 48 additions and 1 deletions
|
@ -122,6 +122,14 @@ void Tray::OnDropText(const std::string& text) {
|
|||
Emit("drop-text", text);
|
||||
}
|
||||
|
||||
void Tray::OnMouseEntered() {
|
||||
Emit("mouse-enter");
|
||||
}
|
||||
|
||||
void Tray::OnMouseExited() {
|
||||
Emit("mouse-exited");
|
||||
}
|
||||
|
||||
void Tray::OnDragEntered() {
|
||||
Emit("drag-enter");
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ class Tray : public mate::TrackableObject<Tray>,
|
|||
void OnDragEntered() override;
|
||||
void OnDragExited() override;
|
||||
void OnDragEnded() override;
|
||||
void OnMouseEntered() override;
|
||||
void OnMouseExited() override;
|
||||
|
||||
void SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||
void SetPressedImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||
|
|
|
@ -79,6 +79,16 @@ void TrayIcon::NotifyDropText(const std::string& text) {
|
|||
observer.OnDropText(text);
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyMouseEntered() {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnMouseEntered();
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyMouseExited() {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnMouseExited();
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyDragEntered() {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnDragEntered();
|
||||
|
|
|
@ -83,6 +83,8 @@ class TrayIcon {
|
|||
void NotifyDragEntered();
|
||||
void NotifyDragExited();
|
||||
void NotifyDragEnded();
|
||||
void NotifyMouseEntered();
|
||||
void NotifyMouseExited();
|
||||
|
||||
protected:
|
||||
TrayIcon();
|
||||
|
|
|
@ -54,9 +54,16 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
statusItemWithLength:NSVariableStatusItemLength];
|
||||
statusItem_.reset([item retain]);
|
||||
[statusItem_ setView:self];
|
||||
|
||||
// Finalize setup by sizing our views
|
||||
[self updateDimensions];
|
||||
|
||||
// Add NSTrackingArea for listening to mouseEnter and mouseExit events
|
||||
int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);
|
||||
NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
||||
options:opts
|
||||
owner:self
|
||||
userInfo:nil];
|
||||
[self addTrackingArea:trackingArea];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -288,6 +295,14 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
return NSDragOperationCopy;
|
||||
}
|
||||
|
||||
- (void)mouseExited:(NSEvent*)event {
|
||||
trayIcon_->NotifyMouseExited();
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(NSEvent*)event {
|
||||
trayIcon_->NotifyMouseEntered();
|
||||
}
|
||||
|
||||
- (void)draggingExited:(id <NSDraggingInfo>)sender {
|
||||
trayIcon_->NotifyDragExited();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ class TrayIconObserver {
|
|||
virtual void OnDragEntered() {}
|
||||
virtual void OnDragExited() {}
|
||||
virtual void OnDragEnded() {}
|
||||
virtual void OnMouseEntered() {}
|
||||
virtual void OnMouseExited() {}
|
||||
|
||||
protected:
|
||||
virtual ~TrayIconObserver() {}
|
||||
|
|
|
@ -144,6 +144,14 @@ Emitted when a drag operation exits the tray icon.
|
|||
|
||||
Emitted when a drag operation ends on the tray or ends at another location.
|
||||
|
||||
#### Event: 'mouse-enter' _macOS_
|
||||
|
||||
Emitted when the mouse enters the tray icon.
|
||||
|
||||
#### Event: 'mouse-exit' _macOS_
|
||||
|
||||
Emitted when the mouse exits the tray icon.
|
||||
|
||||
### Instance Methods
|
||||
|
||||
The `Tray` class has the following methods:
|
||||
|
|
Loading…
Reference in a new issue