From f5cf3556b1f4fb2765d1b9793176104bf999e915 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 May 2015 11:43:05 +0800 Subject: [PATCH] Pass bounds in clicked event of tray --- atom/browser/api/atom_api_tray.cc | 4 ++-- atom/browser/api/atom_api_tray.h | 2 +- atom/browser/ui/tray_icon.cc | 4 ++-- atom/browser/ui/tray_icon.h | 3 ++- atom/browser/ui/tray_icon_cocoa.mm | 9 +++++---- atom/browser/ui/tray_icon_observer.h | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/atom/browser/api/atom_api_tray.cc b/atom/browser/api/atom_api_tray.cc index c7e0149b011..b66d95cb073 100644 --- a/atom/browser/api/atom_api_tray.cc +++ b/atom/browser/api/atom_api_tray.cc @@ -40,8 +40,8 @@ mate::Wrappable* Tray::New(const gfx::Image& image) { return new Tray(image); } -void Tray::OnClicked(const gfx::Point& pos) { - Emit("clicked", pos); +void Tray::OnClicked(const gfx::Rect& bounds) { + Emit("clicked", bounds); } void Tray::OnDoubleClicked() { diff --git a/atom/browser/api/atom_api_tray.h b/atom/browser/api/atom_api_tray.h index 38fb044d9da..5ed29ecd74f 100644 --- a/atom/browser/api/atom_api_tray.h +++ b/atom/browser/api/atom_api_tray.h @@ -41,7 +41,7 @@ class Tray : public mate::EventEmitter, virtual ~Tray(); // TrayIconObserver: - void OnClicked(const gfx::Point&) override; + void OnClicked(const gfx::Rect&) override; void OnDoubleClicked() override; void OnBalloonShow() override; void OnBalloonClicked() override; diff --git a/atom/browser/ui/tray_icon.cc b/atom/browser/ui/tray_icon.cc index 06c1f4be596..a3878f718a6 100644 --- a/atom/browser/ui/tray_icon.cc +++ b/atom/browser/ui/tray_icon.cc @@ -26,8 +26,8 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon, const base::string16& contents) { } -void TrayIcon::NotifyClicked(const gfx::Point& pos) { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(pos)); +void TrayIcon::NotifyClicked(const gfx::Rect& bounds) { + FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(bounds)); } void TrayIcon::NotifyDoubleClicked() { diff --git a/atom/browser/ui/tray_icon.h b/atom/browser/ui/tray_icon.h index 26f31a12e07..7dc67da1bac 100644 --- a/atom/browser/ui/tray_icon.h +++ b/atom/browser/ui/tray_icon.h @@ -10,6 +10,7 @@ #include "atom/browser/ui/tray_icon_observer.h" #include "base/observer_list.h" #include "ui/base/models/simple_menu_model.h" +#include "ui/gfx/geometry/rect.h" namespace atom { @@ -50,7 +51,7 @@ class TrayIcon { void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); } void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); } - void NotifyClicked(const gfx::Point&); + void NotifyClicked(const gfx::Rect& = gfx::Rect()); void NotifyDoubleClicked(); void NotifyBalloonShow(); void NotifyBalloonClicked(); diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index a68dd1c48e6..1bcbaf79ac1 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -26,13 +26,14 @@ } - (void)handleClick:(id)sender { - // Get the position of the frame of the NSStatusItem. - NSPoint pos = [NSApp currentEvent].window.frame.origin; + // Get the frame of the NSStatusItem. + NSRect frame = [NSApp currentEvent].window.frame; + gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); // Flip coordinates to gfx (0,0 in top-left corner) using current screen. NSScreen* screen = [NSScreen mainScreen]; - pos.y = NSMaxY([screen frame]) - pos.y; + bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); - trayIcon_->NotifyClicked(gfx::Point(pos.x, pos.y)); + trayIcon_->NotifyClicked(bounds); } - (void)handleDoubleClick:(id)sender { diff --git a/atom/browser/ui/tray_icon_observer.h b/atom/browser/ui/tray_icon_observer.h index 266654af21b..3a34888b531 100644 --- a/atom/browser/ui/tray_icon_observer.h +++ b/atom/browser/ui/tray_icon_observer.h @@ -6,14 +6,14 @@ #define ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_ namespace gfx { -class Point; +class Rect; } namespace atom { class TrayIconObserver { public: - virtual void OnClicked(const gfx::Point&) {} + virtual void OnClicked(const gfx::Rect&) {} virtual void OnDoubleClicked() {} virtual void OnBalloonShow() {} virtual void OnBalloonClicked() {}