1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_ICON_WIN_H_ 6 #define CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_ICON_WIN_H_ 7 8 #include <windows.h> 9 #include <shellapi.h> 10 11 #include <memory> 12 13 #include "base/compiler_specific.h" 14 #include "base/macros.h" 15 #include "base/win/scoped_gdi_object.h" 16 #include "chrome/browser/status_icons/status_icon.h" 17 18 namespace gfx { 19 class Point; 20 } 21 22 namespace views { 23 class MenuRunner; 24 } 25 26 class StatusTrayWin; 27 28 class StatusIconWin : public StatusIcon { 29 public: 30 // Constructor which provides this icon's unique ID and messaging window. 31 StatusIconWin(StatusTrayWin* tray, UINT id, HWND window, UINT message); 32 ~StatusIconWin() override; 33 34 // Handles a click event from the user - if |left_button_click| is true and 35 // there is a registered observer, passes the click event to the observer, 36 // otherwise displays the context menu if there is one. 37 void HandleClickEvent(const gfx::Point& cursor_pos, bool left_button_click); 38 39 // Handles a click on the balloon from the user. 40 void HandleBalloonClickEvent(); 41 42 // Re-creates the status tray icon now after the taskbar has been created. 43 void ResetIcon(); 44 icon_id()45 UINT icon_id() const { return icon_id_; } window()46 HWND window() const { return window_; } message_id()47 UINT message_id() const { return message_id_; } 48 49 // Overridden from StatusIcon: 50 void SetImage(const gfx::ImageSkia& image) override; 51 void SetToolTip(const base::string16& tool_tip) override; 52 void DisplayBalloon(const gfx::ImageSkia& icon, 53 const base::string16& title, 54 const base::string16& contents, 55 const message_center::NotifierId& notifier_id) override; 56 void ForceVisible() override; 57 58 protected: 59 // Overridden from StatusIcon: 60 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override; 61 62 private: 63 void InitIconData(NOTIFYICONDATA* icon_data); 64 65 // The tray that owns us. Weak. 66 StatusTrayWin* tray_; 67 68 // The unique ID corresponding to this icon. 69 UINT icon_id_; 70 71 // Window used for processing messages from this icon. 72 HWND window_; 73 74 // The message identifier used for status icon messages. 75 UINT message_id_; 76 77 // The currently-displayed icon for the window. 78 base::win::ScopedHICON icon_; 79 80 // The currently-displayed icon for the notification balloon. 81 base::win::ScopedHICON balloon_icon_; 82 83 // Not owned. 84 ui::MenuModel* menu_model_ = nullptr; 85 86 // Context menu associated with this icon (if any). 87 std::unique_ptr<views::MenuRunner> menu_runner_; 88 89 DISALLOW_COPY_AND_ASSIGN(StatusIconWin); 90 }; 91 92 #endif // CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_ICON_WIN_H_ 93