tray: send tray icon position as payload onclick OSX

This commit is contained in:
deepak1556 2015-05-01 15:24:22 +05:30
parent 4608f5e9cd
commit 6d7d068e49
8 changed files with 26 additions and 9 deletions

View file

@ -9,6 +9,7 @@
#include "atom/browser/api/atom_api_menu.h" #include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/browser.h" #include "atom/browser/browser.h"
#include "atom/browser/ui/tray_icon.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/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/string16_converter.h"
#include "native_mate/constructor.h" #include "native_mate/constructor.h"
@ -39,8 +40,8 @@ mate::Wrappable* Tray::New(const gfx::Image& image) {
return new Tray(image); return new Tray(image);
} }
void Tray::OnClicked() { void Tray::OnClicked(const gfx::Point& pos) {
Emit("clicked"); Emit("clicked", pos);
} }
void Tray::OnDoubleClicked() { void Tray::OnDoubleClicked() {

View file

@ -41,7 +41,7 @@ class Tray : public mate::EventEmitter,
virtual ~Tray(); virtual ~Tray();
// TrayIconObserver: // TrayIconObserver:
void OnClicked() override; void OnClicked(const gfx::Point&) override;
void OnDoubleClicked() override; void OnDoubleClicked() override;
void OnBalloonShow() override; void OnBalloonShow() override;
void OnBalloonClicked() override; void OnBalloonClicked() override;

View file

@ -26,8 +26,8 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
const base::string16& contents) { const base::string16& contents) {
} }
void TrayIcon::NotifyClicked() { void TrayIcon::NotifyClicked(const gfx::Point& pos) {
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked()); FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(pos));
} }
void TrayIcon::NotifyDoubleClicked() { void TrayIcon::NotifyDoubleClicked() {

View file

@ -50,7 +50,7 @@ class TrayIcon {
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); } void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); } void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
void NotifyClicked(); void NotifyClicked(const gfx::Point&);
void NotifyDoubleClicked(); void NotifyDoubleClicked();
void NotifyBalloonShow(); void NotifyBalloonShow();
void NotifyBalloonClicked(); void NotifyBalloonClicked();

View file

@ -7,6 +7,7 @@
#include "atom/browser/ui/cocoa/atom_menu_controller.h" #include "atom/browser/ui/cocoa/atom_menu_controller.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/screen.h"
@interface StatusItemController : NSObject { @interface StatusItemController : NSObject {
atom::TrayIconCocoa* trayIcon_; // weak atom::TrayIconCocoa* trayIcon_; // weak
@ -25,7 +26,13 @@
} }
- (void)handleClick:(id)sender { - (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 { - (void)handleDoubleClick:(id)sender {

View file

@ -5,11 +5,15 @@
#ifndef ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_ #ifndef ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
#define ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_ #define ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
namespace gfx {
class Point;
}
namespace atom { namespace atom {
class TrayIconObserver { class TrayIconObserver {
public: public:
virtual void OnClicked() {} virtual void OnClicked(const gfx::Point&) {}
virtual void OnDoubleClicked() {} virtual void OnDoubleClicked() {}
virtual void OnBalloonShow() {} virtual void OnBalloonShow() {}
virtual void OnBalloonClicked() {} virtual void OnBalloonClicked() {}

View file

@ -49,7 +49,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
bool left_mouse_click) { bool left_mouse_click) {
// Pass to the observer if appropriate. // Pass to the observer if appropriate.
if (left_mouse_click) { if (left_mouse_click) {
NotifyClicked(); NotifyClicked(cursor_pos);
return; return;
} }

View file

@ -46,6 +46,11 @@ Creates a new tray icon associated with the `image`.
### Event: 'clicked' ### Event: 'clicked'
* `event`
* `point` Object
* `x` Integer
* `y` Integer
Emitted when the tray icon is clicked. Emitted when the tray icon is clicked.
### Event: 'double-clicked' ### Event: 'double-clicked'