tray: send tray icon position as payload onclick OSX
authordeepak1556 <hop2deep@gmail.com>
Fri, 1 May 2015 09:54:22 +0000 (15:24 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Fri, 1 May 2015 14:00:01 +0000 (19:30 +0530)
atom/browser/api/atom_api_tray.cc
atom/browser/api/atom_api_tray.h
atom/browser/ui/tray_icon.cc
atom/browser/ui/tray_icon.h
atom/browser/ui/tray_icon_cocoa.mm
atom/browser/ui/tray_icon_observer.h
atom/browser/ui/win/notify_icon.cc
docs/api/tray.md

index 94af89b..c7e0149 100644 (file)
@@ -9,6 +9,7 @@
 #include "atom/browser/api/atom_api_menu.h"
 #include "atom/browser/browser.h"
 #include "atom/browser/ui/tray_icon.h"
+#include "atom/common/native_mate_converters/gfx_converter.h"
 #include "atom/common/native_mate_converters/image_converter.h"
 #include "atom/common/native_mate_converters/string16_converter.h"
 #include "native_mate/constructor.h"
@@ -39,8 +40,8 @@ mate::Wrappable* Tray::New(const gfx::Image& image) {
   return new Tray(image);
 }
 
-void Tray::OnClicked() {
-  Emit("clicked");
+void Tray::OnClicked(const gfx::Point& pos) {
+  Emit("clicked", pos);
 }
 
 void Tray::OnDoubleClicked() {
index 48828d2..38fb044 100644 (file)
@@ -41,7 +41,7 @@ class Tray : public mate::EventEmitter,
   virtual ~Tray();
 
   // TrayIconObserver:
-  void OnClicked() override;
+  void OnClicked(const gfx::Point&) override;
   void OnDoubleClicked() override;
   void OnBalloonShow() override;
   void OnBalloonClicked() override;
index 68770c1..06c1f4b 100644 (file)
@@ -26,8 +26,8 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
                               const base::string16& contents) {
 }
 
-void TrayIcon::NotifyClicked() {
-  FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked());
+void TrayIcon::NotifyClicked(const gfx::Point& pos) {
+  FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(pos));
 }
 
 void TrayIcon::NotifyDoubleClicked() {
index 6293b39..26f31a1 100644 (file)
@@ -50,7 +50,7 @@ class TrayIcon {
 
   void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
   void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
-  void NotifyClicked();
+  void NotifyClicked(const gfx::Point&);
   void NotifyDoubleClicked();
   void NotifyBalloonShow();
   void NotifyBalloonClicked();
index db2508e..a68dd1c 100644 (file)
@@ -7,6 +7,7 @@
 #include "atom/browser/ui/cocoa/atom_menu_controller.h"
 #include "base/strings/sys_string_conversions.h"
 #include "ui/gfx/image/image.h"
+#include "ui/gfx/screen.h"
 
 @interface StatusItemController : NSObject {
   atom::TrayIconCocoa* trayIcon_; // weak
 }
 
 - (void)handleClick:(id)sender {
-  trayIcon_->NotifyClicked();
+  // Get the position of the frame of the NSStatusItem.
+  NSPoint pos = [NSApp currentEvent].window.frame.origin;
+  // Flip coordinates to gfx (0,0 in top-left corner) using current screen.
+  NSScreen* screen = [NSScreen mainScreen];
+  pos.y = NSMaxY([screen frame]) - pos.y;
+
+  trayIcon_->NotifyClicked(gfx::Point(pos.x, pos.y));
 }
 
 - (void)handleDoubleClick:(id)sender {
index 293e537..266654a 100644 (file)
@@ -5,11 +5,15 @@
 #ifndef ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
 #define ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
 
+namespace gfx {
+class Point;
+}
+
 namespace atom {
 
 class TrayIconObserver {
  public:
-  virtual void OnClicked() {}
+  virtual void OnClicked(const gfx::Point&) {}
   virtual void OnDoubleClicked() {}
   virtual void OnBalloonShow() {}
   virtual void OnBalloonClicked() {}
index 99b7153..4c227c8 100644 (file)
@@ -49,7 +49,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
                                   bool left_mouse_click) {
   // Pass to the observer if appropriate.
   if (left_mouse_click) {
-    NotifyClicked();
+    NotifyClicked(cursor_pos);
     return;
   }
 
index 6d16e3b..dd03038 100644 (file)
@@ -46,6 +46,11 @@ Creates a new tray icon associated with the `image`.
 
 ### Event: 'clicked'
 
+* `event`
+* `point` Object
+  * `x` Integer
+  * `y` Integer
+
 Emitted when the tray icon is clicked.
 
 ### Event: 'double-clicked'