#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"
return new Tray(image);
}
-void Tray::OnClicked() {
- Emit("clicked");
+void Tray::OnClicked(const gfx::Point& pos) {
+ Emit("clicked", pos);
}
void Tray::OnDoubleClicked() {
virtual ~Tray();
// TrayIconObserver:
- void OnClicked() override;
+ void OnClicked(const gfx::Point&) override;
void OnDoubleClicked() override;
void OnBalloonShow() override;
void OnBalloonClicked() override;
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() {
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();
#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 {
#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() {}
bool left_mouse_click) {
// Pass to the observer if appropriate.
if (left_mouse_click) {
- NotifyClicked();
+ NotifyClicked(cursor_pos);
return;
}
### Event: 'clicked'
+* `event`
+* `point` Object
+ * `x` Integer
+ * `y` Integer
+
Emitted when the tray icon is clicked.
### Event: 'double-clicked'