win: Implement tray.getBounds() API
authorCheng Zhao <zcbenz@gmail.com>
Tue, 21 Jun 2016 06:49:22 +0000 (15:49 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 21 Jun 2016 06:49:22 +0000 (15:49 +0900)
atom/browser/ui/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h

index 1cc6162..d12b328 100644 (file)
@@ -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);
index 95e9945..1284eba 100644 (file)
@@ -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);