Merge pull request #9760 from shubham2892/Add-mouse-enter-and-mouse-exit-event-for-Tray

Add mouse-enter and mouse-exit events for tray
This commit is contained in:
Kevin Sawicki 2017-06-28 12:15:32 -07:00 committed by GitHub
commit e44f655503
7 changed files with 69 additions and 1 deletions

View file

@ -122,6 +122,14 @@ void Tray::OnDropText(const std::string& text) {
Emit("drop-text", text);
}
void Tray::OnMouseEntered(const gfx::Point& location, int modifiers) {
EmitWithFlags("mouse-enter", modifiers, location);
}
void Tray::OnMouseExited(const gfx::Point& location, int modifiers) {
EmitWithFlags("mouse-leave", modifiers, location);
}
void Tray::OnDragEntered() {
Emit("drag-enter");
}

View file

@ -59,6 +59,8 @@ class Tray : public mate::TrackableObject<Tray>,
void OnDragEntered() override;
void OnDragExited() override;
void OnDragEnded() override;
void OnMouseEntered(const gfx::Point& location, int modifiers) override;
void OnMouseExited(const gfx::Point& location, int modifiers) override;
void SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
void SetPressedImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);

View file

@ -79,6 +79,16 @@ void TrayIcon::NotifyDropText(const std::string& text) {
observer.OnDropText(text);
}
void TrayIcon::NotifyMouseEntered(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_)
observer.OnMouseEntered(location, modifiers);
}
void TrayIcon::NotifyMouseExited(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_)
observer.OnMouseExited(location, modifiers);
}
void TrayIcon::NotifyDragEntered() {
for (TrayIconObserver& observer : observers_)
observer.OnDragEntered();

View file

@ -83,6 +83,10 @@ class TrayIcon {
void NotifyDragEntered();
void NotifyDragExited();
void NotifyDragEnded();
void NotifyMouseEntered(const gfx::Point& location = gfx::Point(),
int modifiers = 0);
void NotifyMouseExited(const gfx::Point& location = gfx::Point(),
int modifiers = 0);
protected:
TrayIcon();

View file

@ -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
NSTrackingArea* trackingArea = [[NSTrackingArea alloc]
initWithRect:[self bounds]
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
return self;
}
@ -288,6 +295,18 @@ const CGFloat kVerticalTitleMargin = 2;
return NSDragOperationCopy;
}
- (void)mouseExited:(NSEvent*)event {
trayIcon_->NotifyMouseExited(
gfx::ScreenPointFromNSPoint([event locationInWindow]),
ui::EventFlagsFromModifiers([event modifierFlags]));
}
- (void)mouseEntered:(NSEvent*)event {
trayIcon_->NotifyMouseEntered(
gfx::ScreenPointFromNSPoint([event locationInWindow]),
ui::EventFlagsFromModifiers([event modifierFlags]));
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
trayIcon_->NotifyDragExited();
}

View file

@ -10,6 +10,7 @@
namespace gfx {
class Rect;
class Point;
}
namespace atom {
@ -28,6 +29,8 @@ class TrayIconObserver {
virtual void OnDragEntered() {}
virtual void OnDragExited() {}
virtual void OnDragEnded() {}
virtual void OnMouseEntered(const gfx::Point& location, int modifiers) {}
virtual void OnMouseExited(const gfx::Point& location, int modifiers) {}
protected:
virtual ~TrayIconObserver() {}

View file

@ -144,6 +144,28 @@ 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_
* `event` Event
* `altKey` Boolean
* `shiftKey` Boolean
* `ctrlKey` Boolean
* `metaKey` Boolean
* `position` [Point](structures/point.md) - The position of the event
Emitted when the mouse enters the tray icon.
#### Event: 'mouse-leave' _macOS_
* `event` Event
* `altKey` Boolean
* `shiftKey` Boolean
* `ctrlKey` Boolean
* `metaKey` Boolean
* `position` [Point](structures/point.md) - The position of the event
Emitted when the mouse exits the tray icon.
### Instance Methods
The `Tray` class has the following methods: