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:
commit
e44f655503
7 changed files with 69 additions and 1 deletions
|
@ -122,6 +122,14 @@ void Tray::OnDropText(const std::string& text) {
|
||||||
Emit("drop-text", 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() {
|
void Tray::OnDragEntered() {
|
||||||
Emit("drag-enter");
|
Emit("drag-enter");
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ class Tray : public mate::TrackableObject<Tray>,
|
||||||
void OnDragEntered() override;
|
void OnDragEntered() override;
|
||||||
void OnDragExited() override;
|
void OnDragExited() override;
|
||||||
void OnDragEnded() 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 SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||||
void SetPressedImage(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);
|
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() {
|
void TrayIcon::NotifyDragEntered() {
|
||||||
for (TrayIconObserver& observer : observers_)
|
for (TrayIconObserver& observer : observers_)
|
||||||
observer.OnDragEntered();
|
observer.OnDragEntered();
|
||||||
|
|
|
@ -83,6 +83,10 @@ class TrayIcon {
|
||||||
void NotifyDragEntered();
|
void NotifyDragEntered();
|
||||||
void NotifyDragExited();
|
void NotifyDragExited();
|
||||||
void NotifyDragEnded();
|
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:
|
protected:
|
||||||
TrayIcon();
|
TrayIcon();
|
||||||
|
|
|
@ -54,9 +54,16 @@ const CGFloat kVerticalTitleMargin = 2;
|
||||||
statusItemWithLength:NSVariableStatusItemLength];
|
statusItemWithLength:NSVariableStatusItemLength];
|
||||||
statusItem_.reset([item retain]);
|
statusItem_.reset([item retain]);
|
||||||
[statusItem_ setView:self];
|
[statusItem_ setView:self];
|
||||||
|
|
||||||
// Finalize setup by sizing our views
|
// Finalize setup by sizing our views
|
||||||
[self updateDimensions];
|
[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;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +295,18 @@ const CGFloat kVerticalTitleMargin = 2;
|
||||||
return NSDragOperationCopy;
|
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 {
|
- (void)draggingExited:(id <NSDraggingInfo>)sender {
|
||||||
trayIcon_->NotifyDragExited();
|
trayIcon_->NotifyDragExited();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
class Rect;
|
class Rect;
|
||||||
|
class Point;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -28,6 +29,8 @@ class TrayIconObserver {
|
||||||
virtual void OnDragEntered() {}
|
virtual void OnDragEntered() {}
|
||||||
virtual void OnDragExited() {}
|
virtual void OnDragExited() {}
|
||||||
virtual void OnDragEnded() {}
|
virtual void OnDragEnded() {}
|
||||||
|
virtual void OnMouseEntered(const gfx::Point& location, int modifiers) {}
|
||||||
|
virtual void OnMouseExited(const gfx::Point& location, int modifiers) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~TrayIconObserver() {}
|
virtual ~TrayIconObserver() {}
|
||||||
|
|
|
@ -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.
|
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
|
### Instance Methods
|
||||||
|
|
||||||
The `Tray` class has the following methods:
|
The `Tray` class has the following methods:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue