From 886ef1717c992eacfb827ff755ab3122b75fb12d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 21 Jun 2016 15:49:22 +0900 Subject: [PATCH] win: Implement tray.getBounds() API --- atom/browser/ui/win/notify_icon.cc | 27 ++++++++++++++++----------- atom/browser/ui/win/notify_icon.h | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index 1cc616216c6e..d12b328b0d0c 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -48,26 +48,19 @@ NotifyIcon::~NotifyIcon() { void NotifyIcon::HandleClickEvent(int modifiers, bool left_mouse_click, bool double_button_click) { - NOTIFYICONIDENTIFIER icon_id; - memset(&icon_id, 0, sizeof(NOTIFYICONIDENTIFIER)); - icon_id.uID = icon_id_; - icon_id.hWnd = window_; - icon_id.cbSize = sizeof(NOTIFYICONIDENTIFIER); - - RECT rect = { 0 }; - Shell_NotifyIconGetRect(&icon_id, &rect); + gfx::Rect bounds = GetBounds(); if (left_mouse_click) { if (double_button_click) // double left click - NotifyDoubleClicked(gfx::Rect(rect), modifiers); + NotifyDoubleClicked(bounds, modifiers); else // single left click - NotifyClicked(gfx::Rect(rect), modifiers); + NotifyClicked(bounds, modifiers); return; } else if (!double_button_click) { // single right click if (menu_model_) PopUpContextMenu(gfx::Point(), menu_model_); else - NotifyRightClicked(gfx::Rect(rect), modifiers); + NotifyRightClicked(bounds, modifiers); } } @@ -163,6 +156,18 @@ void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) { menu_model_ = menu_model; } +gfx::Rect NotifyIcon::GetBounds() { + NOTIFYICONIDENTIFIER icon_id; + memset(&icon_id, 0, sizeof(NOTIFYICONIDENTIFIER)); + icon_id.uID = icon_id_; + icon_id.hWnd = window_; + icon_id.cbSize = sizeof(NOTIFYICONIDENTIFIER); + + RECT rect = { 0 }; + Shell_NotifyIconGetRect(&icon_id, &rect); + return gfx::Rect(rect); +} + void NotifyIcon::InitIconData(NOTIFYICONDATA* icon_data) { memset(icon_data, 0, sizeof(NOTIFYICONDATA)); icon_data->cbSize = sizeof(NOTIFYICONDATA); diff --git a/atom/browser/ui/win/notify_icon.h b/atom/browser/ui/win/notify_icon.h index 95e9945a17f8..1284ebadcf1c 100644 --- a/atom/browser/ui/win/notify_icon.h +++ b/atom/browser/ui/win/notify_icon.h @@ -54,6 +54,7 @@ class NotifyIcon : public TrayIcon { void PopUpContextMenu(const gfx::Point& pos, ui::SimpleMenuModel* menu_model) override; void SetContextMenu(ui::SimpleMenuModel* menu_model) override; + gfx::Rect GetBounds() override; private: void InitIconData(NOTIFYICONDATA* icon_data);