Browse Source

Add location and keyboard modifiers to tray mouse events

Kevin Sawicki 7 years ago
parent
commit
70544440f9

+ 4 - 4
atom/browser/api/atom_api_tray.cc

@@ -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() {

+ 2 - 2
atom/browser/api/atom_api_tray.h

@@ -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);

+ 4 - 4
atom/browser/ui/tray_icon.cc

@@ -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() {

+ 4 - 2
atom/browser/ui/tray_icon.h

@@ -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();

+ 6 - 2
atom/browser/ui/tray_icon_cocoa.mm

@@ -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 {

+ 3 - 2
atom/browser/ui/tray_icon_observer.h

@@ -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() {}

+ 14 - 0
docs/api/tray.md

@@ -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