Add location and keyboard modifiers to tray mouse events

This commit is contained in:
Kevin Sawicki 2017-06-28 12:09:12 -07:00
parent 2406d6c279
commit 70544440f9
7 changed files with 37 additions and 16 deletions

View file

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

View file

@ -59,8 +59,8 @@ class Tray : public mate::TrackableObject<Tray>,
void OnDragEntered() override;
void OnDragExited() override;
void OnDragEnded() override;
void OnMouseEntered() override;
void OnMouseExited() 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,14 +79,14 @@ void TrayIcon::NotifyDropText(const std::string& text) {
observer.OnDropText(text);
}
void TrayIcon::NotifyMouseEntered() {
void TrayIcon::NotifyMouseEntered(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_)
observer.OnMouseEntered();
observer.OnMouseEntered(location, modifiers);
}
void TrayIcon::NotifyMouseExited() {
void TrayIcon::NotifyMouseExited(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_)
observer.OnMouseExited();
observer.OnMouseExited(location, modifiers);
}
void TrayIcon::NotifyDragEntered() {

View file

@ -83,8 +83,10 @@ class TrayIcon {
void NotifyDragEntered();
void NotifyDragExited();
void NotifyDragEnded();
void NotifyMouseEntered();
void NotifyMouseExited();
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

@ -296,11 +296,15 @@ const CGFloat kVerticalTitleMargin = 2;
}
- (void)mouseExited:(NSEvent*)event {
trayIcon_->NotifyMouseExited();
trayIcon_->NotifyMouseExited(
gfx::ScreenPointFromNSPoint([event locationInWindow]),
ui::EventFlagsFromModifiers([event modifierFlags]));
}
- (void)mouseEntered:(NSEvent*)event {
trayIcon_->NotifyMouseEntered();
trayIcon_->NotifyMouseEntered(
gfx::ScreenPointFromNSPoint([event locationInWindow]),
ui::EventFlagsFromModifiers([event modifierFlags]));
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {

View file

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

View file

@ -146,10 +146,24 @@ 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