]> khamidou — GitHub mirrors - electron.git/commitdiff
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 94af89b81ecd96401d43482e0dacf93951e95b44..c7e0149b0114f4fb09d3620ae9c2b8e64543d74e 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 48828d2c936658dba080bdd81d42a4a63c481a97..38fb044d9dab5996d9f3511a364151cdad055b97 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 68770c1e5cfdbe04d1c1731abdaf8f4320361642..06c1f4be59676a79827898b861a9ec252a0dfd10 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 6293b39002b69480ab056103c45a47fd0101e20b..26f31a12e072c0133c982bf0fd02b9210e1cbecd 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 db2508ecc6a4c9ce18ee0a740a66b5dee1a6a21e..a68dd1c48e600f1c9fe8116d355e0149fbc35b82 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 293e5371c4cfc5e798f197e3ea81700758a62d9c..266654af21bfd9fcf94282532ed949b1f93aae79 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 99b7153631af2fa645f883f55c1e7ad98beb120e..4c227c8044aed43085e081e63eb77319ee5ae5aa 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 6d16e3b507032ddfc1f2234853450b8ba0b8543e..dd030385ad383cea03d419fd02bd302a08088b91 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'